diff --git a/.github/workflows/push-to-drupal-org.yml b/.github/workflows/push-to-drupal-org.yml new file mode 100644 index 0000000..a5fd9cb --- /dev/null +++ b/.github/workflows/push-to-drupal-org.yml @@ -0,0 +1,46 @@ +name: Push changes to drupal.org + +on: + workflow_dispatch: + push: + create: + +env: + SSH_USER: git + SSH_HOST: git.drupal.org + SSH_KEY: ${{ secrets.drupal_org_key }} + DRUPAL_ORG_REPO: git@drupal-org:project/yandex_yml.git + +jobs: + push: + runs-on: ubuntu-latest + steps: + - name: Create SSH key + run: | + mkdir -p ~/.ssh + echo "$SSH_KEY" > ~/.ssh/id_rsa + chmod 600 ~/.ssh/id_rsa + cat >>~/.ssh/config <=5.6" - } + "name": "drupal/yandex_yml", + "type": "drupal-module", + "description": "Yandex YML (Yandex Market Language) generator.", + "keywords": [ + "Drupal" + ], + "license": "GPL-2.0+", + "homepage": "https://www.drupal.org/project/yandex_yml", + "minimum-stability": "dev", + "support": { + "issues": "https://www.drupal.org/project/issues/yandex_yml", + "source": "http://cgit.drupalcode.org/yandex_yml" + }, + "require": { + "php": ">=5.6", + "drupal/core": "^^9 || ^10" + } } diff --git a/src/Xml/Element.php b/src/Xml/Element.php index 86c12ea..d812e19 100644 --- a/src/Xml/Element.php +++ b/src/Xml/Element.php @@ -89,6 +89,15 @@ public function getElementAttributes() { return $this->attributes; } + /** + * {@inheritDoc} + */ + public function setElementAttributes(array $attributes) { + $this->attributes = $attributes; + + return $this; + } + /** * {@inheritDoc} */ diff --git a/src/Xml/ElementInterface.php b/src/Xml/ElementInterface.php index f54c2ab..e5d8532 100644 --- a/src/Xml/ElementInterface.php +++ b/src/Xml/ElementInterface.php @@ -17,6 +17,17 @@ interface ElementInterface { */ public function getElementAttributes(); + /** + * Sets element attributes. + * + * @param array $attributes + * An array with attribute elements. + * + * @return \Drupal\yandex_yml\Xml\ElementInterface + * The current instance of element. + */ + public function setElementAttributes(array $attributes); + /** * Adds attribute for element. * @@ -58,7 +69,7 @@ public function getElementName(); /** * Gets element value. * - * @return null|string + * @return mixed * An element value. */ public function getElementValue(); diff --git a/src/YandexYml/Currency/Currency.php b/src/YandexYml/Currency/Currency.php index 99d59f5..d929ced 100644 --- a/src/YandexYml/Currency/Currency.php +++ b/src/YandexYml/Currency/Currency.php @@ -17,7 +17,7 @@ final class Currency extends Element { * * @param string $id * The currency ID. - * @param $rate + * @param string|int $rate * The rate value. */ public function __construct($id, $rate) { @@ -32,14 +32,14 @@ public function __construct($id, $rate) { * * @param string $id * The currency id. - * * @return \Drupal\yandex_yml\YandexYml\Currency\Currency * The current currency. - * @example RUR, RUB, USD, EUR, UAH, KZT. * + * @example RUR, RUB, USD, EUR, UAH, KZT. */ protected function setId($id) { $this->addElementAttribute(new Attribute('id', $id)); + return $this; } /** @@ -62,6 +62,7 @@ protected function setId($id) { */ protected function setRate($rate) { $this->addElementAttribute(new Attribute('rate', $rate)); + return $this; } -} \ No newline at end of file +} diff --git a/src/YandexYml/Offer/Offer.php b/src/YandexYml/Offer/Offer.php index 2bbbe54..f901cf7 100644 --- a/src/YandexYml/Offer/Offer.php +++ b/src/YandexYml/Offer/Offer.php @@ -23,13 +23,13 @@ abstract class Offer extends Element implements OfferInterface { * * @param int|string $id * The offer internal ID - * @param $url + * @param string $url * The offer URL. - * @param $price + * @param string $price * The offer price. - * @param $currency_id + * @param string $currency_id * The currency for price. - * @param $category_id + * @param string $category_id * The category ID. * @param bool|null $price_from * The price from or not. diff --git a/src/YandexYml/Shop/Shop.php b/src/YandexYml/Shop/Shop.php index cc4fbcd..9c5360a 100644 --- a/src/YandexYml/Shop/Shop.php +++ b/src/YandexYml/Shop/Shop.php @@ -27,10 +27,6 @@ final class Shop extends Element { * The full company name which owns the shop. * @param null|string $url * The shop home page. - * @param null|string $platform - * The platform name. - * @param null|string $version - * The platform version. */ public function __construct( $name, diff --git a/src/YandexYmlGenerator.php b/src/YandexYmlGenerator.php index d5a2020..ba84c42 100644 --- a/src/YandexYmlGenerator.php +++ b/src/YandexYmlGenerator.php @@ -14,8 +14,6 @@ */ class YandexYmlGenerator implements YandexYmlGeneratorInterface { - protected $counter; - /** * The XML writer. * @@ -77,14 +75,6 @@ public function __construct( $this->dateTime = $date_time; $this->dateFormatter = $date_formatter; $this->fileSystem = $file_system; - - // Prepare temporary file. - $this->tempFilePath = $this->fileSystem->tempnam('temporary://yandex_yml', 'yml_'); - // Initialization of file. - $this->writer = new XMLWriter(); - $this->writer->openURI($this->tempFilePath); - $this->writer->setIndentString("\t"); - $this->writer->setIndent(TRUE); } /** @@ -94,7 +84,10 @@ public function __construct( * leading dashes for path. */ public function generateFile($filename = 'products.xml', $destination_path = 'public://') { - $this->buildData(); + $this->prepareTemporaryFile() + ->setWriter() + ->buildData(); + $this->fileSystem->copy( $this->tempFilePath, $destination_path . $filename, @@ -102,6 +95,27 @@ public function generateFile($filename = 'products.xml', $destination_path = 'pu ); } + /** + * Prepare temporary file. + */ + protected function prepareTemporaryFile() { + $this->tempFilePath = $this->fileSystem->tempnam('temporary://yandex_yml', 'yml_'); + + return $this; + } + + /** + * Initialize the XML writer. + */ + protected function setWriter() { + $this->writer = new XMLWriter(); + $this->writer->openURI($this->tempFilePath); + $this->writer->setIndentString("\t"); + $this->writer->setIndent(TRUE); + + return $this; + } + /** * Write elements to writer object. */ diff --git a/yandex_yml.info.yml b/yandex_yml.info.yml index a4a04d5..c78b4b3 100644 --- a/yandex_yml.info.yml +++ b/yandex_yml.info.yml @@ -1,4 +1,4 @@ name: Yandex YML type: module description: Yandex YML (Yandex Market Language) generator. -core: 8.x +core_version_requirement: ^9 || ^10