From 750af449d307e0033c504b6f140d51197f8347bf Mon Sep 17 00:00:00 2001 From: fredo Date: Thu, 19 Oct 2023 14:01:33 +0000 Subject: [PATCH 1/2] created update-translation --- .../actions/config/update-translation.php | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100755 packages/core/actions/config/update-translation.php diff --git a/packages/core/actions/config/update-translation.php b/packages/core/actions/config/update-translation.php new file mode 100755 index 000000000..d7ef92477 --- /dev/null +++ b/packages/core/actions/config/update-translation.php @@ -0,0 +1,107 @@ + 'This is the core_config_update-translation controller created with core_config_create-controller.', + 'response' => [ + 'charset' => 'utf-8', + 'accept-origin' => '*' + ], + 'params' => [ + "package" => [ + "description" => "name of the package of the entity", + "type" => "string", + "required" => true + ], + "entity" => [ + "description" => "name of the entity to edit", + "type" => "string", + "required" => true + ], + "lang" => [ + "description" => "lang of the translation", + "type" => "string", + "required" => true + ], + "payload" => [ + "type" => "text", + "default" => "{}" + ], + "create_lang" => [ + "type" => "boolean", + "default" => false + ] + ], + 'access' => [ + 'visibility' => 'protected', + 'groups' => ['users'] + ], + 'providers' => ['context'] +]); +/** + * @var \equal\php\context Context + */ +$context = $providers['context']; + +$package = $params["package"]; +$entity = $params["entity"]; +$lang = $params["lang"]; +$payload = $params["payload"]; +$create = $params["create_lang"]; + +// Checking if package exists +if(!file_exists(QN_BASEDIR."/packages/{$package}")) { + throw new Exception('missing_package_dir', QN_ERROR_INVALID_CONFIG); +} + +// Creating language folder +if(!is_dir(QN_BASEDIR."/packages/{$package}/i18n") && ($create==0) ){ + throw new Exception('no_translation_folder', QN_ERROR_INVALID_CONFIG); +} +if(!is_dir(QN_BASEDIR."/packages/{$package}/i18n/{$lang}") && ($create==0)){ + throw new Exception('language_does_not_exist_in_package', QN_ERROR_INVALID_CONFIG); +} +if(!is_dir(QN_BASEDIR."/packages/{$package}/i18n/{$lang}") && !mkdir(QN_BASEDIR."/packages/{$package}/i18n/{$lang}",true)) { + throw new Exception('io_error', QN_ERROR_INVALID_CONFIG); +} + +$parts = explode("\\",$entity); + +$filename = array_pop($parts).".json"; + +$dir = implode("/",$parts); + +if(!is_dir(QN_BASEDIR."/packages/{$package}/i18n/{$lang}/{$dir}")) { + if($create == 0) { + throw new Exception('this_traduction_does_not_exist', QN_ERROR_INVALID_CONFIG); + } + mkdir(QN_BASEDIR."/packages/{$package}/i18n/{$lang}/{$dir}",true); +} + +$json = json_decode($payload,true); + +if($json === null) { + throw new Exception('payload_not_valid', QN_ERROR_INVALID_CONFIG); +} + +$pretty = json_encode($json,JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); + +if(!$pretty) { + throw new Exception('payload_not_valid', QN_ERROR_INVALID_CONFIG); +} + +$f = fopen(QN_BASEDIR."/packages/{$package}/i18n/{$lang}/{$dir}/{$filename}","w"); + +if(!$f) { + throw new Exception('io_error', QN_ERROR_INVALID_CONFIG); +} + +fputs($f,$pretty); + +fclose($f); + +$res = file_get_contents(QN_BASEDIR."/packages/{$package}/i18n/{$lang}/{$dir}/{$filename}"); + +$context->httpResponse() + ->body($pretty) + ->status(200) + ->send(); \ No newline at end of file From 3a039f7e60fd5f45c535ca8dbdb1b956beb965f2 Mon Sep 17 00:00:00 2001 From: fredo Date: Fri, 20 Oct 2023 09:59:13 +0000 Subject: [PATCH 2/2] fixed the entity check to allow controller --- packages/core/data/config/translations.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) mode change 100644 => 100755 packages/core/data/config/translations.php diff --git a/packages/core/data/config/translations.php b/packages/core/data/config/translations.php old mode 100644 new mode 100755 index 2b5e3e52e..163ae631e --- a/packages/core/data/config/translations.php +++ b/packages/core/data/config/translations.php @@ -53,8 +53,15 @@ if(!isset($params['entity'])) { throw new Exception('package_or_entity_required', QN_ERROR_MISSING_PARAM); } - if(!class_exists($params['entity'])) { - throw new Exception('unknown_entity', QN_ERROR_INVALID_PARAM); + $temp = explode("\\", str_replace("_","\\",$params['entity'])); + $pkg = array_shift($temp); + $path = implode("/",$temp); + if( + !file_exists(QN_BASEDIR."/packages/{$pkg}/classes/{$path}.class.php") + && !file_exists(QN_BASEDIR."/packages/{$pkg}/actions/{$path}.php") + && !file_exists(QN_BASEDIR."/packages/{$pkg}/data/{$path}.php") + ) { + throw new Exception("unknown_entity", QN_ERROR_INVALID_PARAM); } $entity = $params['entity']; $map_views_ids = [];