Skip to content

Commit f5936bd

Browse files
committed
version 2.3.34
2 parents 98b16f7 + 935d3ba commit f5936bd

File tree

7 files changed

+103
-58
lines changed

7 files changed

+103
-58
lines changed

totum/common/Field.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Field
4141
'setToPinned' => 3,
4242
'inAddRecalc' => 4,
4343
];
44-
protected const NO_ERROR_IN_VALUE = ['checkbox'];
44+
protected const NO_ERROR_IN_VALUE = ['checkbox', 'number'];
4545

4646
public static array $fields = [];
4747
protected $data;
@@ -775,6 +775,10 @@ protected function calculate(array &$newVal, $oldRow, $row, $oldTbl, $tbl, $vars
775775

776776
$this->table->calcLog($Log, 'result', $newVal['v']);
777777
} catch (\Exception $exception) {
778+
if (method_exists($exception, 'addPath')) {
779+
$exception->addPath($this->translate('field [[%s]] of [[%s]] table',
780+
[$this->data['name'], $this->table->getTableRow()['name']]) . (!empty($row['id']) ? ' id ' . $row['id'] : ''));
781+
}
778782
$this->table->calcLog($Log, 'error', $exception->getMessage());
779783
throw $exception;
780784
}

totum/common/Lang/RU.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class RU implements LangInterface
2424
'The function is only available for cycles tables.' => 'Функция доступна только для таблиц циклов.',
2525

2626
'System error. Action type not specified.' => 'Системная ошибка. Не указан тип действия.',
27+
'Field [[%s]] of table [[%s]] in row with id [[%s]] contains non-numeric data'=>'Поле [[%s]] таблицы [[%s]] в строке с id [[%s]] содержит нечисловую информацию',
2728
'Scheme source not defined.' => 'Не определен источник схемы.',
2829
'Fill in the parameter [[%s]].' => 'Заполните параметр [[%s]].',
2930
'Parametr [[%s]] is required.' => 'Параметр [[%s]] обязателен.',

totum/common/Totum.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*/
2828
class Totum
2929
{
30-
public const VERSION = '2.3.33';
30+
public const VERSION = '2.3.34';
3131

3232

3333
public const TABLE_CODE_PARAMS = ['row_format', 'table_format'];

totum/common/sql/Sql.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ public function errorHandler(string $errorCode, $query_string, $error = null, $d
314314
$exp = new tableSaveOrDeadLockException($error);
315315
}else {
316316
$exp = new SqlException($error);
317+
$exp->addSqlErrorCode($errorCode);
317318
$exp->addPath($query_string);
318319
$exp->addPath(json_encode($data, JSON_UNESCAPED_UNICODE));
319320
}

totum/common/sql/SqlException.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,18 @@
77

88
class SqlException extends criticalErrorException
99
{
10+
protected string $sqlErrorCode;
11+
12+
public function addSqlErrorCode(string $errorCode)
13+
{
14+
$this->sqlErrorCode=$errorCode;
15+
}
16+
17+
/**
18+
* @return string
19+
*/
20+
public function getSqlErrorCode(): string
21+
{
22+
return $this->sqlErrorCode;
23+
}
1024
}

totum/moduls/Table/TableController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,9 @@ public function actionTable(ServerRequestInterface $request)
550550
}
551551
} catch (criticalErrorException $e) {
552552
$error = $this->translate('Error: %s', $e->getMessage());
553+
if ($this->User && $this->User->isCreator() && $e->getPathMess()) {
554+
$error .= '<br/>' . $e->getPathMess();
555+
}
553556
}
554557

555558

totum/tableTypes/RealTables.php

Lines changed: 78 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -343,83 +343,105 @@ protected function getByParamsFromRows($params, $returnType, $sectionReplaces)
343343
$fieldsString .= $f;
344344
}
345345

346+
try {
347+
if ($returnType === 'rows' || $returnType === 'row') {
346348

347-
if ($returnType === 'rows' || $returnType === 'row') {
348349

349-
350-
//техническая выборка - не трогать
351-
if ($params['field'] === ['__all__']) {
352-
$notLoaded = '';
353-
if ($this->withoutNotLoaded) {
354-
foreach ($this->sortedFields['column'] as $field) {
355-
if ($field['notLoaded'] ?? null) {
356-
$notLoaded .= ', \'{"v": "**NOT LOADED**"}\' as ' . $field['name'];
350+
//техническая выборка - не трогать
351+
if ($params['field'] === ['__all__']) {
352+
$notLoaded = '';
353+
if ($this->withoutNotLoaded) {
354+
foreach ($this->sortedFields['column'] as $field) {
355+
if ($field['notLoaded'] ?? null) {
356+
$notLoaded .= ', \'{"v": "**NOT LOADED**"}\' as ' . $field['name'];
357+
}
357358
}
358359
}
360+
361+
return $this->model->executePrepared(
362+
true,
363+
(object)['whereStr' => $whereStr, 'params' => $paramsWhere],
364+
'*' . $notLoaded,
365+
$order,
366+
$limit
367+
);
359368
}
360369

361-
return $this->model->executePrepared(
370+
371+
if ($returnType === 'rows') {
372+
$rows = $this->model->executePrepared(
373+
true,
374+
(object)['whereStr' => $whereStr, 'params' => $paramsWhere],
375+
$fieldsString,
376+
$order,
377+
$limit
378+
)->fetchAll();
379+
if (!empty($params['with__sectionFunction'])) {
380+
foreach ($rows as &$row) {
381+
$row['__sectionFunction'] = function () use ($sectionReplaces, $row, $params) {
382+
return $sectionReplaces($row)[$params['sfield'][0]] ?? null;
383+
};
384+
}
385+
unset($row);
386+
} else {
387+
foreach ($rows as &$row) {
388+
$row = $sectionReplaces($row);
389+
}
390+
unset($row);
391+
}
392+
return $rows;
393+
} elseif ($row = $this->model->executePrepared(
362394
true,
363395
(object)['whereStr' => $whereStr, 'params' => $paramsWhere],
364-
'*' . $notLoaded,
365-
$order,
366-
$limit
367-
);
368-
}
369-
370-
371-
if ($returnType === 'rows') {
372-
$rows = $this->model->executePrepared(
396+
$fieldsString,
397+
$order
398+
)->fetch()) {
399+
return $sectionReplaces($row);
400+
} else {
401+
return [];
402+
}
403+
} else {
404+
$r = $this->model->executePrepared(
373405
true,
374406
(object)['whereStr' => $whereStr, 'params' => $paramsWhere],
375407
$fieldsString,
376408
$order,
377409
$limit
378410
)->fetchAll();
379-
if (!empty($params['with__sectionFunction'])) {
380-
foreach ($rows as &$row) {
381-
$row['__sectionFunction'] = function () use ($sectionReplaces, $row, $params) {
382-
return $sectionReplaces($row)[$params['sfield'][0]] ?? null;
383-
};
411+
412+
if ($returnType === 'field') {
413+
if ($r) {
414+
return $sectionReplaces($r[0])[$params['field'][0]];
384415
}
385-
unset($row);
416+
return null;
386417
} else {
387-
foreach ($rows as &$row) {
388-
$row = $sectionReplaces($row);
418+
foreach ($r as &$row) {
419+
$row = $sectionReplaces($row)[$params['field'][0]];
389420
}
390421
unset($row);
391422
}
392-
return $rows;
393-
} elseif ($row = $this->model->executePrepared(
394-
true,
395-
(object)['whereStr' => $whereStr, 'params' => $paramsWhere],
396-
$fieldsString,
397-
$order
398-
)->fetch()) {
399-
return $sectionReplaces($row);
400-
} else {
401-
return [];
402423
}
403-
} else {
404-
$r = $this->model->executePrepared(
405-
true,
406-
(object)['whereStr' => $whereStr, 'params' => $paramsWhere],
407-
$fieldsString,
408-
$order,
409-
$limit
410-
)->fetchAll();
411-
412-
if ($returnType === 'field') {
413-
if ($r) {
414-
return $sectionReplaces($r[0])[$params['field'][0]];
415-
}
416-
return null;
417-
} else {
418-
foreach ($r as &$row) {
419-
$row = $sectionReplaces($row)[$params['field'][0]];
424+
} catch (SqlException $exception) {
425+
if ($exception->getSqlErrorCode() === '22P02') {
426+
foreach ($params['where'] as $_w) {
427+
if (key_exists($_w['field'], $this->fields)) {
428+
if ($this->fields[$_w['field']]['type'] === 'number') {
429+
$row = $this->Totum->getConfig()->getSql(false)->get('select id from ' . $this->model->getTableName()
430+
. " where {$_w['field']}->>'v' !~ '^\d+(\.\d+)?$' ");
431+
if ($row) {
432+
$field = $_w['field'];
433+
break;
434+
}
435+
}
436+
}
420437
}
421-
unset($row);
438+
if(!empty($field) && !empty($row)){
439+
errorException::criticalException($this->translate('Field [[%s]] of table [[%s]] in row with id [[%s]] contains non-numeric data', [$field, $this->getTableRow()['name'], $row['id']]), $this->Totum);
440+
}else{
441+
errorException::criticalException($this->translate('One of number fields of table [[%s]] contains non-numeric data. We cann\'t find what and where', $this->getTableRow()['name']), $this->Totum);
442+
}
422443
}
444+
throw $exception;
423445
}
424446

425447
return $r;
@@ -1447,7 +1469,7 @@ protected function getWhereFromParams($paramsWhere, $withoutDeleted = true)
14471469
$isNumeric = false;
14481470
if ($fieldName === 'is_del') {
14491471
$withoutDeleted = false;
1450-
} elseif ($fieldName === 'id' || $fieldName === 'n') {
1472+
} elseif ($fieldName === 'id' || $fieldName === 'n' || $fields[$fieldName]['type'] === 'number') {
14511473
$valueCheck = (array)$value;
14521474
$isRemovedValues = false;
14531475
foreach ($valueCheck as $i => $v) {

0 commit comments

Comments
 (0)