diff --git a/.github/workflows/grumphp.yml b/.github/workflows/grumphp.yml index d540a3d..33c7ecf 100644 --- a/.github/workflows/grumphp.yml +++ b/.github/workflows/grumphp.yml @@ -8,11 +8,9 @@ jobs: fail-fast: true matrix: php-versions: - - "7.4" - - "8.1" + - "8.3" dependencies: - "lowest" - - "highest" steps: - name: Checkout repo uses: actions/checkout@v2 @@ -29,4 +27,4 @@ jobs: run: composer install - name: GrumPHP - run: ./vendor/bin/grumphp run \ No newline at end of file + run: ./vendor/bin/grumphp run diff --git a/Api/Data/TranslationInterface.php b/Api/Data/TranslationInterface.php index 870a8df..b2e6b16 100644 --- a/Api/Data/TranslationInterface.php +++ b/Api/Data/TranslationInterface.php @@ -69,14 +69,14 @@ public function setFrontend($frontend); /** * Retrieve existing extension attributes object or create a new one. * - * @return \Phpro\Translations\Api\Data\TranslationExtensionInterface|null + * @return TranslationExtensionInterface|null */ public function getExtensionAttributes(); /** * Set an extension attributes object. * - * @param \Phpro\Translations\Api\Data\TranslationExtensionInterface $extensionAttributes + * @param TranslationExtensionInterface $extensionAttributes * @return $this */ public function setExtensionAttributes( diff --git a/Api/TranslationRepositoryInterface.php b/Api/TranslationRepositoryInterface.php index 16159b6..fe0f56d 100644 --- a/Api/TranslationRepositoryInterface.php +++ b/Api/TranslationRepositoryInterface.php @@ -11,9 +11,9 @@ interface TranslationRepositoryInterface /** * Save Translation * - * @param \Phpro\Translations\Api\Data\TranslationInterface $translation + * @param Data\TranslationInterface $translation * @throws \Magento\Framework\Exception\LocalizedException - * @return \Phpro\Translations\Api\Data\TranslationInterface + * @return Data\TranslationInterface */ public function save( Data\TranslationInterface $translation @@ -24,16 +24,16 @@ public function save( * * @param string $translationId * @throws \Magento\Framework\Exception\LocalizedException - * @return \Phpro\Translations\Api\Data\TranslationInterface + * @return Data\TranslationInterface */ public function getById($translationId); /** * Retrieve Translation matching the specified criteria. * - * @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria + * @param SearchCriteriaInterface $searchCriteria * @throws \Magento\Framework\Exception\LocalizedException - * @return \Phpro\Translations\Api\Data\TranslationSearchResultsInterface + * @return Data\TranslationSearchResultsInterface */ public function getList( SearchCriteriaInterface $searchCriteria diff --git a/Block/Adminhtml/Translation/Edit/GenericButton.php b/Block/Adminhtml/Translation/Edit/GenericButton.php index ab91135..a59406d 100644 --- a/Block/Adminhtml/Translation/Edit/GenericButton.php +++ b/Block/Adminhtml/Translation/Edit/GenericButton.php @@ -13,7 +13,7 @@ abstract class GenericButton protected $context; /** - * @param \Magento\Backend\Block\Widget\Context $context + * @param Context $context */ public function __construct(Context $context) { diff --git a/CHANGELOG.md b/CHANGELOG.md index a6f2764..3fb5cc7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,7 +25,14 @@ ## [1.2.2] - 2022-10-14 ### Added - Hyva support: remove requirejs from head.additional -- + ## [1.3.0] - 2024-03-28 ### Updated -- PHP ^8.1 compatibility \ No newline at end of file +- PHP ^8.1 compatibility + +## [1.4.0] - 2024-06-05 +### Updated +- Set minimum PHP version to 8.3 +### Bugfix +- Fix return types console commands +- Locales are not found if set in env.php and not in core_config_table diff --git a/Console/Command/Export.php b/Console/Command/Export.php index 70e679b..ba52606 100644 --- a/Console/Command/Export.php +++ b/Console/Command/Export.php @@ -42,7 +42,7 @@ protected function configure(): void * @param InputInterface $input * @param OutputInterface $output */ - protected function execute(InputInterface $input, OutputInterface $output): void + protected function execute(InputInterface $input, OutputInterface $output): int { try { $locales = $input->getArgument(self::ARGUMENT_LOCALES); @@ -61,6 +61,9 @@ protected function execute(InputInterface $input, OutputInterface $output): void $output->writeln('Done!'); } catch (\Exception $e) { $output->writeln('' . $e->getMessage() . ''); + return Command::FAILURE; } + + return Command::SUCCESS; } } diff --git a/Console/Command/GenerateFrontendTranslations.php b/Console/Command/GenerateFrontendTranslations.php index f004bbc..692d013 100644 --- a/Console/Command/GenerateFrontendTranslations.php +++ b/Console/Command/GenerateFrontendTranslations.php @@ -42,7 +42,7 @@ protected function configure(): void * @param InputInterface $input * @param OutputInterface $output */ - protected function execute(InputInterface $input, OutputInterface $output): void + protected function execute(InputInterface $input, OutputInterface $output): int { try { $storeId = (int)$input->getArgument('storeId'); @@ -62,7 +62,10 @@ protected function execute(InputInterface $input, OutputInterface $output): void $output->writeln('Please clean full_page and block_html caches manually'); } catch (\Exception $e) { $output->writeln('' . $e->getMessage() . ''); + return Command::FAILURE; } + + return Command::SUCCESS; } /** diff --git a/Console/Command/Import.php b/Console/Command/Import.php index 7565758..1575281 100644 --- a/Console/Command/Import.php +++ b/Console/Command/Import.php @@ -55,7 +55,7 @@ protected function configure(): void * @param InputInterface $input * @param OutputInterface $output */ - protected function execute(InputInterface $input, OutputInterface $output): void + protected function execute(InputInterface $input, OutputInterface $output): int { try { $csvFile = $input->getArgument(self::ARGUMENT_CSV_FILE); @@ -84,6 +84,9 @@ protected function execute(InputInterface $input, OutputInterface $output): void $output->writeln('Done!'); } catch (\Exception $e) { $output->writeln('' . $e->getMessage() . ''); + return Command::FAILURE; } + + return Command::SUCCESS; } } diff --git a/Console/Command/ImportFull.php b/Console/Command/ImportFull.php index 525c913..f128f2a 100644 --- a/Console/Command/ImportFull.php +++ b/Console/Command/ImportFull.php @@ -53,7 +53,7 @@ protected function configure(): void * @param InputInterface $input * @param OutputInterface $output */ - protected function execute(InputInterface $input, OutputInterface $output): void + protected function execute(InputInterface $input, OutputInterface $output): int { try { $csvFile = $input->getArgument(self::ARGUMENT_CSV_FILE); @@ -80,6 +80,9 @@ protected function execute(InputInterface $input, OutputInterface $output): void $output->writeln('Done!'); } catch (\Exception $e) { $output->writeln('' . $e->getMessage() . ''); + return Command::FAILURE; } + + return Command::SUCCESS; } } diff --git a/Console/Command/PrepareKeysCommand.php b/Console/Command/PrepareKeysCommand.php index e0bbbda..cccd4c4 100644 --- a/Console/Command/PrepareKeysCommand.php +++ b/Console/Command/PrepareKeysCommand.php @@ -37,6 +37,7 @@ public function __construct( ResolverFactory $optionResolverFactory, Parser $parser, TranslationDataManagementInterface $translationDataManagement, + private readonly \Phpro\Translations\Model\Translation\Source\Locales $localeSource, string $name = null ) { $this->optionResolverFactory = $optionResolverFactory; @@ -64,26 +65,33 @@ protected function configure() * * @return void */ - protected function execute(InputInterface $input, OutputInterface $output): void + protected function execute(InputInterface $input, OutputInterface $output): int { - $phraseCollector = new PhraseCollector(new Tokenizer()); - $adapters = [ - 'php' => new Php($phraseCollector), - 'html' => new Html(), - 'js' => new Js(), - 'xml' => new Xml(), - ]; - $optionResolver = $this->optionResolverFactory->create(BP, false); - foreach ($adapters as $type => $adapter) { - $this->parser->addAdapter($type, $adapter); - } - $this->parser->parse($optionResolver->getOptions()); - $phraseList = $this->parser->getPhrases(); + try { + $phraseCollector = new PhraseCollector(new Tokenizer()); + $adapters = [ + 'php' => new Php($phraseCollector), + 'html' => new Html(), + 'js' => new Js(), + 'xml' => new Xml(), + ]; + $optionResolver = $this->optionResolverFactory->create(BP, false); + foreach ($adapters as $type => $adapter) { + $this->parser->addAdapter($type, $adapter); + } + $this->parser->parse($optionResolver->getOptions()); + $phraseList = $this->parser->getPhrases(); + + foreach ($phraseList as $phrase) { + $this->translationDataManagement->prepare($phrase->getPhrase(), $phrase->getTranslation()); + } - foreach ($phraseList as $phrase) { - $this->translationDataManagement->prepare($phrase->getPhrase(), $phrase->getTranslation()); + $output->writeln('Keys successfully created.'); + } catch (\Exception $e) { + $output->writeln('' . $e->getMessage() . ''); + return Command::FAILURE; } - $output->writeln('Keys successfully created.'); + return Command::SUCCESS; } } diff --git a/Model/Translation/Source/Locales.php b/Model/Translation/Source/Locales.php index 5d08ac4..b762407 100644 --- a/Model/Translation/Source/Locales.php +++ b/Model/Translation/Source/Locales.php @@ -3,40 +3,31 @@ namespace Phpro\Translations\Model\Translation\Source; -use Magento\Framework\App\ResourceConnection; +use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\Data\OptionSourceInterface; +use Magento\Store\Model\StoreManager; class Locales implements OptionSourceInterface { private const XML_PATH_LOCALE = 'general/locale/code'; - /** - * @var ResourceConnection - */ - private $resourceConnection; - - public function __construct(ResourceConnection $resourceConnection) - { - $this->resourceConnection = $resourceConnection; + public function __construct( + private readonly ScopeConfigInterface $scopeConfig, + private readonly StoreManager $storeManager, + ) { } /** * @inheritDoc */ - public function toOptionArray() + public function toOptionArray(): array { - $result = []; - $connection = $this->resourceConnection->getConnection(); - $bind = [':config_path' => self::XML_PATH_LOCALE]; - $select = $connection - ->select() - ->from($this->resourceConnection->getTableName('core_config_data'), 'value') - ->distinct(true) - ->where('path = :config_path'); - $rowSet = $connection->fetchAll($select, $bind); + $stores = $this->storeManager->getStores(); - foreach ($rowSet as $row) { - $result[] = ['value' => $row['value'], 'label' => $row['value']]; + $result = []; + foreach ($stores as $store) { + $locale = $this->scopeConfig->getValue(self::XML_PATH_LOCALE, 'stores', $store->getId()); + $result[] = ['value' => $locale, 'label' => $store->getName()]; } return $result; diff --git a/composer.json b/composer.json index a607f2e..943ffac 100644 --- a/composer.json +++ b/composer.json @@ -11,18 +11,18 @@ } ], "require": { - "php": "~7.4.0||^8.1", + "php": "^8.3", "magento/framework": "^102.0|^103.0", "magento/module-backend": "^101.0|^102.0", "magento/module-ui": "^101.0|^102.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "~3.4.0", - "magento/magento-coding-standard": "21", + "friendsofphp/php-cs-fixer": "~3.59.0", + "magento/magento-coding-standard": "^33", "php-parallel-lint/php-parallel-lint": "^1.3", - "phpro/grumphp-shim": "^1.5", - "phpunit/phpunit": "^8.5", - "squizlabs/php_codesniffer": "~3.4" + "phpro/grumphp-shim": "^2.6", + "phpunit/phpunit": "^9.5", + "squizlabs/php_codesniffer": "~3.7" }, "autoload": { "psr-4": { @@ -42,15 +42,16 @@ "sort-packages": true, "allow-plugins": { "phpro/grumphp-shim": true, - "magento/composer-dependency-version-audit-plugin": true + "magento/composer-dependency-version-audit-plugin": true, + "dealerdirect/phpcodesniffer-composer-installer": true } }, "scripts": { "post-install-cmd": [ - "([ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard,../../phpcompatibility/php-compatibility/PHPCompatibility)" + "([ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard/,../../magento/php-compatibility-fork)" ], "post-update-cmd": [ - "([ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard,../../phpcompatibility/php-compatibility/PHPCompatibility)" + "([ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard/,../../magento/php-compatibility-fork)" ] } } diff --git a/registration.php b/registration.php index 556395e..0ca21ba 100644 --- a/registration.php +++ b/registration.php @@ -1,6 +1,6 @@