Skip to content

Commit

Permalink
version 2.4.40.0
Browse files Browse the repository at this point in the history
  • Loading branch information
poluninatm committed May 6, 2022
2 parents 4025732 + 8a6d9f1 commit f595e49
Show file tree
Hide file tree
Showing 22 changed files with 1,634 additions and 70 deletions.
2 changes: 1 addition & 1 deletion http/css/main.css

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions http/html.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

<link rel="stylesheet"
type="text/css"
href="/css/main.css?v=5ce5924">
<script src="/js/main.js?v=ceaba86"></script>
href="/css/main.css?v=b8ec1f1">
<script src="/js/main.js?v=1231fc8"></script>

</head>
<body id="pk">
Expand Down
4 changes: 2 additions & 2 deletions http/js/main.js

Large diffs are not rendered by default.

22 changes: 7 additions & 15 deletions totum/commands/SchemaUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,19 @@ protected function execute(InputInterface $input, OutputInterface $output)

$file = $input->getArgument('file');

if ($file === 'sys_update') {
$file = dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'moduls' . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . 'start_' . $Conf->getLang() . '.json.gz.ttm';
}

$TotumInstall = new TotumInstall(
$Conf,
new User(['login' => 'service', 'roles' => ["1"], 'id' => 1], $Conf),
$output
);

if (!is_file($file)) {
throw new errorException('File not found');
}
if (!($cont = file_get_contents($file))) {
throw new errorException('File is empty');
}
if (!($cont = gzdecode($cont))) {
throw new errorException('File is not gzip');
}
if (!($cont = json_decode($cont, true))) {
throw new errorException('File is not json');
if ($file === 'sys_update') {
$path = dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'moduls' . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR;
$file = $path. 'start.json.gz.ttm';
$cont = $TotumInstall->getDataFromFile($file);
$cont = $TotumInstall->schemaTranslate($cont, $path.$Conf->getLang() . '.json', $Conf->getLang() !== 'en' ? $path.'en.json' : null);
}else{
$cont = $TotumInstall->getDataFromFile($file);
}

if (($matches = json_decode($sourceName, true)) && is_array($matches) && key_exists(
Expand Down
5 changes: 5 additions & 0 deletions totum/common/Lang/RU.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,11 @@ class RU implements LangInterface
'Authorization lost.' => 'Потеряна авторизация.',
'Scheme file not found.' => 'Файл схемы не найден.',
'Scheme not found.' => 'Схема не найдена.',
'Scheme file is empty' => 'Файл схемы пуст',
'Wrong format scheme file.' => 'Файл схемы неверного формата.',

'Translates file not found.' => 'Файл перевода не найден.',
'Translates file is empty' => 'Файл перевода пуст',
'Wrong format file' => 'Файл неверного формата',

'Administrator' => 'Администратор',
Expand Down Expand Up @@ -258,6 +262,7 @@ class RU implements LangInterface
'You cannot delete system tables.' => 'Нельзя удалять системные таблицы.',
'You cannot delete system fields.' => 'Нельзя удалять системные поля.',
'The [[%s]] field is already present in the table.' => 'Поле [[%s]] уже есть в таблице.',
'The [[%s]] field is already present in the [[%s]] table.' => 'Поле [[%s]] уже есть в таблице [[%s]].',
'Fill in the field parameters.' => 'Заполните параметры поля.',
'You can\'t make a boss of someone who is in a subordinate' => 'Нельзя сделать начальником того, кто есть в подчиненных',
'Log is empty.' => 'Log пуст.',
Expand Down
2 changes: 1 addition & 1 deletion totum/common/Totum.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/
class Totum
{
public const VERSION = '2.3.39.0';
public const VERSION = '2.4.40.0';


public const TABLE_CODE_PARAMS = ['row_format', 'table_format', 'on_duplicate', 'default_action'];
Expand Down
68 changes: 64 additions & 4 deletions totum/common/TotumInstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,12 @@ public function getDataFromFile($path)
if (!is_file($path)) {
throw new errorException($this->translate('Scheme file not found.'));
}
if (!($filedata = gzdecode(file_get_contents($path)))) {

if (!($filedata = file_get_contents($path))) {
throw new errorException($this->translate('Scheme file is empty'));
}

if (!($filedata = gzdecode($filedata))) {
throw new errorException($this->translate('Wrong format scheme file.'));
}
if (!($schema = json_decode($filedata, true))) {
Expand All @@ -207,6 +212,56 @@ public function getDataFromFile($path)
return $schema;
}

public function getTranslatesFromFile($path)
{
if (!is_file($path)) {
throw new errorException($this->translate('Translates file not found.'));
}

if (!($filedata = file_get_contents($path))) {
throw new errorException($this->translate('Translates file is empty'));
}

if (!($schema = json_decode($filedata, true))) {
throw new errorException($this->translate('Wrong format file.'));
}
return $schema;
}

public function schemaTranslate($data, $pathToLang, $pathToBackLang = null)
{
$translates = [];
if ($pathToLang) {
$translates = $this->getTranslatesFromFile($pathToLang);
if ($pathToBackLang) {
$translates = $translates + $this->getTranslatesFromFile($pathToBackLang);
}
}

if ($translates) {
$translate = function ($v) use (&$translate, $translates) {
if (is_array($v)) {
$vt = [];
foreach ($v as $k => $_v) {
$vt[$translate($k)] = $translate($_v);
}
return $vt;
} elseif (is_string($v)) {
return preg_replace_callback("~\{\{[/a-zA-Z0-9,?'!_\-]+\}\}~",
function ($template) use ($translates) {
if (!key_exists($template[0], $translates)) {
var_dump($template[0]);
}
return $translates[$template[0]] ?? $template[0];
},
$v);
} else return $v;
};
$data = $translate($data);
}
return $data;
}

public function systemTableFieldsApply($fields, $tableId)
{
$selectFields = $this->Totum->getNamedModel(TablesFields::class)->getAll(
Expand Down Expand Up @@ -296,7 +351,7 @@ public function createSchema($post, $getFilePath)
$Sql->transactionStart();

$this->consoleLog('Check/create schema');
if($this->Config->getSchema()==='public'){
if ($this->Config->getSchema() === 'public') {
throw new errorException($this->translate('You can\'t install totum in schema "public"'));
}

Expand All @@ -305,7 +360,12 @@ public function createSchema($post, $getFilePath)
$this->consoleLog('Upload start sql');
$this->applySql($getFilePath('start.sql'));

$data = $this->getDataFromFile($getFilePath('start_' . strtolower($this->Totum->getConfig()->getLang()) . '.json.gz.ttm'));
$data = $this->getDataFromFile($getFilePath('start.json.gz.ttm'));
$lang = strtolower($this->Totum->getConfig()->getLang());

$data = $this->schemaTranslate($data,
$getFilePath($lang . '.json'),
$lang !== 'en' ? $getFilePath('en.json') : null);

$this->consoleLog('Install base tables');
$baseTablesIds = $this->installBaseTables($data);
Expand Down Expand Up @@ -932,7 +992,7 @@ public function updateDataExecCodes($schemaRows, array $categoriesMatches, array
$keys[$key],
JSON_UNESCAPED_UNICODE
);
} elseif ($key !== 'id') {
} elseif ($key !== 'id' && (is_int($keys[$key]) || is_float($keys[$key]))) {
$keys[$key] = strval($keys[$key]);
}
}
Expand Down
46 changes: 27 additions & 19 deletions totum/common/calculates/Calculate.php
Original file line number Diff line number Diff line change
Expand Up @@ -610,30 +610,38 @@ function ($m) {
return '""';
}
$qoute = $this->CodeStrings[$m[1]][0];

switch ($qoute) {
case '"':
case "'":
return $qoute . substr($this->CodeStrings[$m[1]], 1) . $qoute;
default:
$back_replace_strings = function ($str) {
return preg_replace_callback(
'/"(\d+)"/',
function ($matches) {
if ($matches[1] === '') {
return '""';
}
return '"' . $this->CodeStrings[$matches[1]] . '"';
},
$str
);
};
}

$replaced = $back_replace_strings($this->CodeStrings[$m[1]]);
return substr($this->CodeStrings[$m[1]], 0, 4) . '`' . substr(
$replaced,
4
) . '`';
if (str_starts_with($this->CodeStrings[$m[1]], 'json')) {
return $this->CodeStrings[$m[1]];
}

if (str_starts_with($this->CodeStrings[$m[1]], 'str')) {
$typeLength = 3;
} else {
$typeLength = 4;
}
$type = substr($this->CodeStrings[$m[1]], 0, $typeLength);

$back_replace_strings = function ($str) {
return preg_replace_callback(
'/"(\d+)"/',
function ($matches) {
return '"' . substr($this->CodeStrings[$matches[1]], 1) . '"';
},
$str
);
};

$replaced = $back_replace_strings($this->CodeStrings[$m[1]]);
return $type . '`' . substr($replaced, $typeLength) . '`';


},
$code
);
Expand Down Expand Up @@ -1170,7 +1178,7 @@ function ($item, $isSection, $_itemFull) use ($WhereFieldName, &$paramArray, &$r

$this->__processParamItems($paramArray['items'],
function ($item, $isSection) use (&$r, &$itemsNames) {
if(is_array($item)){
if (is_array($item)) {
throw new errorException($this->translate('The key must be an one value',
$item));
}
Expand Down
6 changes: 4 additions & 2 deletions totum/common/calculates/ParsesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,15 +265,17 @@ protected function parseTotumCond($string): ?bool
return $actions;
};

$checkValue = function ($varIn, $onlyBool = true) {
$numCode = 0;

$checkValue = function ($varIn, $onlyBool = true) use (&$numCode) {
if ($varIn === 'false' || $varIn === false) {
return false;
}
if ($varIn === 'true' || $varIn === true) {
return true;
}

$var = $this->execSubCode($varIn, 'CondCode ' . $varIn);
$var = $this->execSubCode($varIn, 'CondCode ' . (++$numCode));

if ($onlyBool) {
if ($var === 'false' || $var === false) {
Expand Down
4 changes: 2 additions & 2 deletions totum/models/TablesFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function update($params, $where, $oldRow = null): int
if (key_exists('name', $params)) {
$name = json_decode($params['name'], true)['v'];
if ($this->getPrepared(['table_name' => $oldRow['table_name']['v'], 'name' => $name])) {
throw new errorException($this->translate('The [[%s]] field is already present in the table.', $name));
throw new errorException($this->translate('The [[%s]] field is already present in the [[%s]] table.', [$name, $oldRow['table_name']['v']]));
}
$tableRow = $this->Totum->getTableRow($oldRow['table_name']['v']);

Expand Down Expand Up @@ -126,7 +126,7 @@ function ($v) {
$category = $decodedVars['category'];

if ($this->fieldExits($decodedVars['table_id'], $decodedVars['name'], $decodedVars['version'])) {
throw new errorException($this->translate('The [[%s]] field is already present in the table.', $name));
throw new errorException($this->translate('The [[%s]] field is already present in the [[%s]] table.', [$name, $decodedVars['table_id']]));
}

/*$this->checkParams($vars, $tableRowId);*/
Expand Down
4 changes: 4 additions & 0 deletions totum/moduls/Table/ReadTableActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2053,9 +2053,13 @@ protected function getTableClientChangedData($data, $force = false)

if ($changedIds['deleted']) {
$return['chdata']['deleted'] = array_keys($changedIds['deleted']);
if($pageIds){
$pageIds = array_diff($pageIds, array_keys($changedIds['deleted']));
}
}
if ($changedIds['restored']) {
$return['chdata']['deleted'] = array_keys($changedIds['restored']);
$pageIds = array_diff($pageIds, array_keys($changedIds['restored']));
}

//Отправка на клиент изменений, селектов и форматов
Expand Down
Loading

0 comments on commit f595e49

Please sign in to comment.