diff options
author | Kamil Tekiela <tekiela246@gmail.com> | 2022-08-17 21:03:14 +0300 |
---|---|---|
committer | Kamil Tekiela <tekiela246@gmail.com> | 2022-08-17 21:21:33 +0300 |
commit | 6d91494935781808fba3ff2686cbdb349a7173f1 (patch) | |
tree | 3910c843ea25bf4117f54d1869e65a5bfe006a49 /libraries | |
parent | de1eb66dbfa1647617a56c8aa1e97f41bd220b36 (diff) |
Extract doTransformations
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
Diffstat (limited to 'libraries')
-rw-r--r-- | libraries/classes/Controllers/Table/ReplaceController.php | 161 |
1 files changed, 83 insertions, 78 deletions
diff --git a/libraries/classes/Controllers/Table/ReplaceController.php b/libraries/classes/Controllers/Table/ReplaceController.php index 448e2f24dc..6b61cf12de 100644 --- a/libraries/classes/Controllers/Table/ReplaceController.php +++ b/libraries/classes/Controllers/Table/ReplaceController.php @@ -442,84 +442,7 @@ final class ReplaceController extends AbstractController * transformed fields, if they were edited. After that, output the correct * link/transformed value and exit */ - if (isset($_POST['rel_fields_list']) && $_POST['rel_fields_list'] != '') { - $map = $this->relation->getForeigners($GLOBALS['db'], $GLOBALS['table']); - - /** @var array<int,array> $relation_fields */ - $relation_fields = []; - parse_str($_POST['rel_fields_list'], $relation_fields); - - // loop for each relation cell - foreach ($relation_fields as $cell_index => $curr_rel_field) { - foreach ($curr_rel_field as $relation_field => $relation_field_value) { - $where_comparison = "='" . $relation_field_value . "'"; - $dispval = $this->insertEdit->getDisplayValueForForeignTableColumn( - $where_comparison, - $map, - $relation_field - ); - - $extra_data['relations'][$cell_index] = $this->insertEdit->getLinkForRelationalDisplayField( - $map, - $relation_field, - $where_comparison, - $dispval, - $relation_field_value - ); - } - } - } - - if (isset($_POST['do_transformations']) && $_POST['do_transformations'] == true) { - $edited_values = []; - parse_str($_POST['transform_fields_list'], $edited_values); - - if (! isset($extra_data)) { - $extra_data = []; - } - - $transformation_types = [ - 'input_transformation', - 'transformation', - ]; - foreach ($mimeMap as $transformation) { - $column_name = $transformation['column_name']; - foreach ($transformation_types as $type) { - $file = Core::securePath($transformation[$type]); - $extra_data = $this->insertEdit->transformEditedValues( - $GLOBALS['db'], - $GLOBALS['table'], - $transformation, - $edited_values, - $file, - $column_name, - $extra_data, - $type - ); - } - } - } - - // Need to check the inline edited value can be truncated by MySQL - // without informing while saving - $column_name = $_POST['fields_name']['multi_edit'][0][0]; - - $this->insertEdit->verifyWhetherValueCanBeTruncatedAndAppendExtraData( - $GLOBALS['db'], - $GLOBALS['table'], - $column_name, - $extra_data - ); - - /**Get the total row count of the table*/ - $_table = new Table($_POST['table'], $_POST['db']); - $extra_data['row_count'] = $_table->countRecords(); - - $extra_data['sql_query'] = Generator::getMessage($GLOBALS['message'], $GLOBALS['display_query']); - - $this->response->setRequestStatus($GLOBALS['message']->isSuccess()); - $this->response->addJSON('message', $GLOBALS['message']); - $this->response->addJSON($extra_data); + $this->doTransformations($mimeMap); return; } @@ -582,4 +505,86 @@ final class ReplaceController extends AbstractController /** @psalm-suppress UnresolvableInclude */ require ROOT_PATH . Core::securePath($gotoInclude); } + + private function doTransformations(array $mimeMap): void + { + if (isset($_POST['rel_fields_list']) && $_POST['rel_fields_list'] != '') { + $map = $this->relation->getForeigners($GLOBALS['db'], $GLOBALS['table']); + + /** @var array<int,array> $relation_fields */ + $relation_fields = []; + parse_str($_POST['rel_fields_list'], $relation_fields); + + // loop for each relation cell + foreach ($relation_fields as $cell_index => $curr_rel_field) { + foreach ($curr_rel_field as $relation_field => $relation_field_value) { + $where_comparison = "='" . $relation_field_value . "'"; + $dispval = $this->insertEdit->getDisplayValueForForeignTableColumn( + $where_comparison, + $map, + $relation_field + ); + + $extra_data['relations'][$cell_index] = $this->insertEdit->getLinkForRelationalDisplayField( + $map, + $relation_field, + $where_comparison, + $dispval, + $relation_field_value + ); + } + } + } + + if (isset($_POST['do_transformations']) && $_POST['do_transformations'] == true) { + $edited_values = []; + parse_str($_POST['transform_fields_list'], $edited_values); + + if (! isset($extra_data)) { + $extra_data = []; + } + + $transformation_types = [ + 'input_transformation', + 'transformation', + ]; + foreach ($mimeMap as $transformation) { + $column_name = $transformation['column_name']; + foreach ($transformation_types as $type) { + $file = Core::securePath($transformation[$type]); + $extra_data = $this->insertEdit->transformEditedValues( + $GLOBALS['db'], + $GLOBALS['table'], + $transformation, + $edited_values, + $file, + $column_name, + $extra_data, + $type + ); + } + } + } + + // Need to check the inline edited value can be truncated by MySQL + // without informing while saving + $column_name = $_POST['fields_name']['multi_edit'][0][0]; + + $this->insertEdit->verifyWhetherValueCanBeTruncatedAndAppendExtraData( + $GLOBALS['db'], + $GLOBALS['table'], + $column_name, + $extra_data + ); + + /**Get the total row count of the table*/ + $_table = new Table($_POST['table'], $_POST['db']); + $extra_data['row_count'] = $_table->countRecords(); + + $extra_data['sql_query'] = Generator::getMessage($GLOBALS['message'], $GLOBALS['display_query']); + + $this->response->setRequestStatus($GLOBALS['message']->isSuccess()); + $this->response->addJSON('message', $GLOBALS['message']); + $this->response->addJSON($extra_data); + } } |