42 lines
1.6 KiB
PHP
42 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace KupShop\I18nBundle\Resources\script;
|
|
|
|
use KupShop\AdminBundle\Util\Script\Script;
|
|
use KupShop\I18nBundle\Translations\BlocksTranslation;
|
|
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
|
|
|
|
class RegenerateBlocksContent extends Script
|
|
{
|
|
use \DatabaseCommunication;
|
|
|
|
protected static $name = 'Přegenerovat obsah překladu bloků';
|
|
protected static $defaultParameters = ['lang' => 'sk', 'blockIDs' => []];
|
|
|
|
/** @var BlocksTranslation */
|
|
private $blocksTranslation;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->blocksTranslation = ServiceContainer::getService(BlocksTranslation::class);
|
|
}
|
|
|
|
protected function run(array $arguments)
|
|
{
|
|
foreach ($arguments['blockIDs'] as $objectID) {
|
|
$blockTransl = $this->selectSQL('blocks_translations', ['id_block' => $objectID, 'id_language' => $arguments['lang']])
|
|
->fetch();
|
|
if ($blockTransl && !empty($blockTransl['json_content'])) {
|
|
$response = $this->blocksTranslation->renderBlock($blockTransl['json_content'], "block with ID '{$objectID}' and lang '{$arguments['lang']}'");
|
|
if ($success = ($response['success'] ?? false)) {
|
|
$this->updateSQL('blocks_translations', ['content' => $response['html']], ['id_block' => $objectID, 'id_language' => $arguments['lang']]);
|
|
}
|
|
$this->log($objectID.' - '.$arguments['lang'].': '.($success ? 'OK' : json_encode($response)).'<br/>'.PHP_EOL);
|
|
}
|
|
}
|
|
$this->log('Hotovo');
|
|
}
|
|
}
|
|
|
|
return RegenerateBlocksContent::class;
|