51 lines
1.5 KiB
PHP
51 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace KupShop\I18nBundle\Resources\script;
|
|
|
|
use KupShop\AdminBundle\Util\Script\Script;
|
|
use KupShop\KupShopBundle\Util\StringUtil;
|
|
|
|
class CopyLanguage extends Script
|
|
{
|
|
use \DatabaseCommunication;
|
|
|
|
protected static $name = 'Kopírování jazyků';
|
|
protected static $defaultParameters = ['from' => 'cs', 'to' => 'sk'];
|
|
|
|
protected function run(array $arguments)
|
|
{
|
|
$this->log("Kopiruji jazyk z {$arguments['from']} do {$arguments['to']}");
|
|
|
|
$conn = $this->getDbalConnection();
|
|
$tm = $conn->getSchemaManager();
|
|
|
|
foreach ($tm->listTableNames() as $tableName) {
|
|
if (!StringUtil::endsWith($tableName, '_translations')) {
|
|
continue;
|
|
}
|
|
|
|
$columns = [];
|
|
foreach ($tm->listTableColumns($tableName) as $column) {
|
|
if ($column->getName() == 'id_language') {
|
|
$columns[] = "'{$arguments['to']}'";
|
|
} elseif ($column->getName() == 'id') {
|
|
$columns[] = 'NULL';
|
|
} else {
|
|
$columns[] = $column->getName();
|
|
}
|
|
}
|
|
|
|
$columns = join(', ', $columns);
|
|
|
|
$this->log("Kopiruju {$tableName}");
|
|
sqlQuery("INSERT IGNORE INTO `{$tableName}`
|
|
SELECT {$columns} FROM `{$tableName}`
|
|
WHERE id_language=:id_from", ['id_from' => $arguments['from']]);
|
|
}
|
|
|
|
$this->log('Hotovo');
|
|
}
|
|
}
|
|
|
|
return CopyLanguage::class;
|