diff --git a/.github/workflows/grumphp.yml b/.github/workflows/grumphp.yml
index d540a3d..b5938a6 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"
dependencies:
- "lowest"
- - "highest"
steps:
- name: Checkout repo
uses: actions/checkout@v2
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a6f2764..3588d25 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -28,4 +28,9 @@
-
## [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
+### Bugfix
+- Fix return types console commands
+- Locales are not found if set in env.php and not in core_config_table
\ No newline at end of file
diff --git a/Console/Command/Export.php b/Console/Command/Export.php
index 70e679b..2c951ed 100644
--- a/Console/Command/Export.php
+++ b/Console/Command/Export.php
@@ -42,8 +42,10 @@ 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
{
+ $exitCode = 0;
+
try {
$locales = $input->getArgument(self::ARGUMENT_LOCALES);
@@ -61,6 +63,9 @@ protected function execute(InputInterface $input, OutputInterface $output): void
$output->writeln('Done!');
} catch (\Exception $e) {
$output->writeln('' . $e->getMessage() . '');
+ $exitCode = 1;
}
+
+ return $exitCode;
}
}
diff --git a/Console/Command/GenerateFrontendTranslations.php b/Console/Command/GenerateFrontendTranslations.php
index f004bbc..d48a527 100644
--- a/Console/Command/GenerateFrontendTranslations.php
+++ b/Console/Command/GenerateFrontendTranslations.php
@@ -42,8 +42,10 @@ 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
{
+ $exitCode = 0;
+
try {
$storeId = (int)$input->getArgument('storeId');
$statsCollection = $this->generatedTranslations($storeId);
@@ -62,7 +64,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() . '');
+ $exitCode = 1;
}
+
+ return $exitCode;
}
/**
diff --git a/Console/Command/Import.php b/Console/Command/Import.php
index 7565758..c4dec1c 100644
--- a/Console/Command/Import.php
+++ b/Console/Command/Import.php
@@ -55,8 +55,10 @@ 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
{
+ $exitCode = 0;
+
try {
$csvFile = $input->getArgument(self::ARGUMENT_CSV_FILE);
$locale = $input->getArgument(self::ARGUMENT_LOCALE);
@@ -84,6 +86,9 @@ protected function execute(InputInterface $input, OutputInterface $output): void
$output->writeln('Done!');
} catch (\Exception $e) {
$output->writeln('' . $e->getMessage() . '');
+ $exitCode = 1;
}
+
+ return $exitCode;
}
}
diff --git a/Console/Command/ImportFull.php b/Console/Command/ImportFull.php
index 525c913..56e5ff0 100644
--- a/Console/Command/ImportFull.php
+++ b/Console/Command/ImportFull.php
@@ -53,8 +53,10 @@ 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
{
+ $exitCode = 0;
+
try {
$csvFile = $input->getArgument(self::ARGUMENT_CSV_FILE);
@@ -80,6 +82,9 @@ protected function execute(InputInterface $input, OutputInterface $output): void
$output->writeln('Done!');
} catch (\Exception $e) {
$output->writeln('' . $e->getMessage() . '');
+ $exitCode = 1;
}
+
+ return $exitCode;
}
}
diff --git a/Console/Command/PrepareKeysCommand.php b/Console/Command/PrepareKeysCommand.php
index e0bbbda..8871201 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,35 @@ 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();
+ $exitCode = 0;
+
+ 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() . '');
+ $exitCode = 1;
}
- $output->writeln('Keys successfully created.');
+ return $exitCode;
}
}
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..98bf304 100644
--- a/composer.json
+++ b/composer.json
@@ -11,7 +11,7 @@
}
],
"require": {
- "php": "~7.4.0||^8.1",
+ "php": "^8.1",
"magento/framework": "^102.0|^103.0",
"magento/module-backend": "^101.0|^102.0",
"magento/module-ui": "^101.0|^102.0"