Skip to content

Commit

Permalink
README fixes and refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarosław Zieliński committed Oct 29, 2024
1 parent e622497 commit 6eb29c5
Show file tree
Hide file tree
Showing 24 changed files with 300 additions and 228 deletions.
42 changes: 21 additions & 21 deletions Console/Command/CacheFlush.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class CacheFlush extends Command
{
public const TRANSLATION = 'translation';

public const LIST = 'list';

/**
* @var array
*/
Expand Down Expand Up @@ -51,7 +53,8 @@ protected function configure()
{
$this->setName('torah:cache:flush');
$this->setDescription('JaroslawZielinski Torah cache flush');
$this->addArgument(self::TRANSLATION, InputArgument::REQUIRED, (string)__('translation'));
$this->addOption(self::LIST,'l', $mode = null, (string)__('see translation codes avaiable.'));
$this->addArgument(self::TRANSLATION, InputArgument::OPTIONAL, (string)__('translation code'));
}

private function displayMessages(OutputInterface $output): int
Expand All @@ -67,38 +70,35 @@ private function addMessage(string $message, ...$args): void
$this->messages[] = sprintf($message, ...$args);
}

private function listTranslations(OutputInterface $output): void
{
foreach (Resources::TORAH_TRANSLATIONS as $code => $label) {
$output->writeln(
(string)__('%1 <fg=yellow;options=bold>%2</>', $code, str_replace(['&apos;'], ['\''], $label))
);
}
}

/**
* {@inheritDoc}
* @throws \Exception
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
try {
$translation = $input->getArgument(self::TRANSLATION);
$translation = $input->getArgument(self::TRANSLATION) ?? null;
$list = $input->getOption(self::LIST);
if ($list) {
$this->listTranslations($output);
} else if ($translation && !$list) {
$availableTranslations = array_keys(Resources::TORAH_TRANSLATIONS);
if (!in_array($translation, $availableTranslations)) {
$availableTranslationsStr = print_r($availableTranslations, true);
$message = str_replace(['Array
(
', '
)
'], ['', ''], $availableTranslationsStr);
throw new \Exception(sprintf((string)__('Use the following available translations:
%s'), $message));
throw new \Exception((string)__('Unkown translation: %1', $translation));
}
$result = $this->repository->delete($translation);
$resultMsg = sprintf((string)__('For \'%s\' cache flushed with result \'%s\''), $translation, $result);
$output->writeln($resultMsg);
} catch (\Exception $e) {
$message = sprintf(
'<fg=red;options=bold>Something went wrong</>: <fg=white>\'%s\'</>: <fg=yellow>
%s</>.',
$e->getMessage(),
$e->getTraceAsString()
);
$this->logger->error($e->getMessage(), $e->getTrace());
$output->writeln($message);
return 1;
} else {
throw new \Exception(sprintf((string)__('Translation parameter empty.')));
}
return $this->displayMessages($output);
}
Expand Down
43 changes: 21 additions & 22 deletions Console/Command/CacheWarm.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class CacheWarm extends Command
{
public const TRANSLATION = 'translation';

public const LIST = 'list';

/**
* @var array
*/
Expand Down Expand Up @@ -67,7 +69,8 @@ protected function configure()
{
$this->setName('torah:cache:warm');
$this->setDescription('JaroslawZielinski Torah cache warm');
$this->addArgument(self::TRANSLATION, InputArgument::REQUIRED, (string)__('Translation'));
$this->addOption(self::LIST,'l', $mode = null, (string)__('see translation codes avaiable.'));
$this->addArgument(self::TRANSLATION, InputArgument::OPTIONAL, (string)__('translation code'));
}

private function displayMessages(OutputInterface $output): int
Expand All @@ -83,42 +86,38 @@ private function addMessage(string $message, ...$args): void
$this->messages[] = sprintf($message, ...$args);
}

private function listTranslations(OutputInterface $output): void
{
foreach (Resources::TORAH_TRANSLATIONS as $code => $label) {
$output->writeln(
(string)__('%1 <fg=yellow;options=bold>%2</>', $code, str_replace(['&apos;'], ['\''], $label))
);
}
}

/**
* {@inheritDoc}
* @throws \Exception
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->output = $output;
try {
$translation = $input->getArgument(self::TRANSLATION);
$translation = $input->getArgument(self::TRANSLATION) ?? null;
$list = $input->getOption(self::LIST);
if ($list) {
$this->listTranslations($output);
} else if ($translation && !$list) {
$availableTranslations = array_keys(Resources::TORAH_TRANSLATIONS);
if (!in_array($translation, $availableTranslations)) {
$availableTranslationsStr = print_r($availableTranslations, true);
$message = str_replace(['Array
(
', '
)
'], ['', ''], $availableTranslationsStr);
throw new \Exception(sprintf((string)__('Use one of the following available translations:
%s'), $message));
throw new \Exception((string)__('Unkown translation: %1', $translation));
}
$this->warmCache->execute(
$translation,
[$this, 'start'],
[$this, 'iteration'],
[$this, 'end']
);
} catch (\Exception $e) {
$message = sprintf(
'<fg=red;options=bold>Something went wrong</>: <fg=white>\'%s\'</>: <fg=yellow>
%s</>.',
$e->getMessage(),
$e->getTraceAsString()
);
$this->logger->error($e->getMessage(), $e->getTrace());
$output->writeln($message);
return 1;
} else {
throw new \Exception(sprintf((string)__('Translation parameter empty.')));
}
return $this->displayMessages($output);
}
Expand Down
3 changes: 2 additions & 1 deletion Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,8 @@ public function getTorahInputDivision(): string

public function isTorahInputBibleToolsEnabled(): bool
{
return $this->scopeConfig
$cacheEnable = $this->isTorahCacheEnabled();
return $cacheEnable && $this->scopeConfig
->isSetFlag(self::CONFIG_PATH_TORAHINPUT_BIBLETOOLSENABLED, ScopeInterface::SCOPE_STORE);
}

Expand Down
8 changes: 7 additions & 1 deletion Model/ResourceModel/Quote/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,16 @@ protected function _initSelect()
->joinLeft(
['groups' => $this->getTable('torahverse_groups')],
'main_table.group_id = groups.group_id',
['groupName' => 'groups.name', 'colour_value', 'groupCode' => 'groups.code']
[
'groupName' => 'groups.name',
'colour_value',
'groupCode' => 'groups.code',
'code' => 'main_table.code'
]
);
$this->addFilterToMap('groupName', 'groups.name');
$this->addFilterToMap('groupCode', 'groups.code');
$this->addFilterToMap('name', 'main_table.name');
$this->addFilterToMap('code', 'main_table.code');
}
}
8 changes: 7 additions & 1 deletion Model/ResourceModel/Verse/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,16 @@ protected function _initSelect()
->joinLeft(
['groups' => $this->getTable('torahverse_groups')],
'main_table.group_id = groups.group_id',
['groupName' => 'groups.name', 'colour_value', 'groupCode' => 'groups.code']
[
'groupName' => 'groups.name',
'colour_value',
'groupCode' => 'groups.code',
'code' => 'main_table.code'
]
);
$this->addFilterToMap('groupName', 'groups.name');
$this->addFilterToMap('groupCode', 'groups.code');
$this->addFilterToMap('name', 'main_table.name');
$this->addFilterToMap('code', 'main_table.code');
}
}
Loading

0 comments on commit 6eb29c5

Please sign in to comment.