67 lines
1.9 KiB
PHP
67 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace KupShop\I18nBundle\Resources\script;
|
|
|
|
use KupShop\AdminBundle\Util\Script\Script;
|
|
use KupShop\KupShopBundle\Util\StringUtil;
|
|
|
|
class DeleteTranslations extends Script
|
|
{
|
|
use \DatabaseCommunication;
|
|
|
|
protected static $name = 'Smazání překladů';
|
|
protected static $defaultParameters = [
|
|
'language' => 'cs',
|
|
// all - všechny tabulky překlady, nebo vyjmenované bez "_translations"
|
|
'table' => ['ALL'],
|
|
];
|
|
|
|
protected function run(array $arguments)
|
|
{
|
|
$language = $arguments['language'] ?? [];
|
|
if (empty($language)) {
|
|
$this->log('Argument "language" cannot be empty!');
|
|
|
|
return;
|
|
}
|
|
|
|
$table = $arguments['table'] ?? [];
|
|
if (empty($table)) {
|
|
$this->log('Argument "table" cannot be empty!');
|
|
|
|
return;
|
|
}
|
|
|
|
$this->log("Deleting translations of language: {$language}");
|
|
|
|
if (($arguments['table'][0] ?? false) != 'ALL') {
|
|
foreach ($table as $tableName) {
|
|
$tableName .= '_translations';
|
|
$this->deleteTranslations($tableName, $language);
|
|
}
|
|
} else {
|
|
$conn = $this->getDbalConnection();
|
|
$tm = $conn->getSchemaManager();
|
|
foreach ($tm->listTableNames() as $tableName) {
|
|
if (!StringUtil::endsWith($tableName, '_translations')) {
|
|
continue;
|
|
}
|
|
|
|
$this->deleteTranslations($tableName, $language);
|
|
}
|
|
}
|
|
|
|
$this->log('Done');
|
|
}
|
|
|
|
protected function deleteTranslations($tableName, $language)
|
|
{
|
|
$this->log("Deleting translations from table: {$tableName}");
|
|
sqlQuery("DELETE FROM `{$tableName}`
|
|
WHERE id_language=:language", ['language' => $language]);
|
|
$this->log('Deleted');
|
|
}
|
|
}
|
|
|
|
return DeleteTranslations::class;
|