From 3882cde9f9a2aa51a8701e1874f9965659ddd8ff Mon Sep 17 00:00:00 2001 From: Roly Rudy Gutierrez Pinto Date: Wed, 10 Nov 2021 12:04:39 -0400 Subject: [PATCH] PMCORE-1062 [18214] Warning message of multiple file upload control is not translating --- workflow/engine/classes/model/Translation.php | 106 ++++++------------ .../src/ProcessMaker/Model/Translation.php | 14 +++ 2 files changed, 46 insertions(+), 74 deletions(-) create mode 100644 workflow/engine/src/ProcessMaker/Model/Translation.php diff --git a/workflow/engine/classes/model/Translation.php b/workflow/engine/classes/model/Translation.php index 3463fa736..8df46605f 100644 --- a/workflow/engine/classes/model/Translation.php +++ b/workflow/engine/classes/model/Translation.php @@ -1,43 +1,9 @@ . - * - * For more information, contact Colosa Inc, 2566 Le Jeune Rd., - * Coral Gables, FL, 33134, USA, or email info@colosa.com. - * - */ -//require_once 'classes/model/om/BaseTranslation.php'; +use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Log; +use ProcessMaker\Model\Translation as ModelTranslation; -/** - * Skeleton subclass for representing a row from the 'TRANSLATION' table. - * - * - * - * You should add additional methods to this class to meet the - * application requirements. This class will only be generated as - * long as it does not already exist in the output directory. - * - * @package workflow.engine.classes.model - */ class Translation extends BaseTranslation { @@ -198,52 +164,44 @@ class Translation extends BaseTranslation } } - /* Load strings from a Database for labels MAFE. - * - */ - public function generateFileTranslationMafe () + /** + * Load strings from a Database for labels MAFE. + * @return array + */ + public function generateFileTranslationMafe() { - $translation = Array (); - - $c = new Criteria(); - $c->add( TranslationPeer::TRN_ID, '%ID_MAFE_%', Criteria::LIKE ); - $c->addAscendingOrderByColumn( 'TRN_CATEGORY' ); - $c->addAscendingOrderByColumn( 'TRN_ID' ); - //$c->addAscendingOrderByColumn( 'TRN_LANG' ); - $tranlations = TranslationPeer::doSelect( $c ); - - $mafeFolder = PATH_HTML . "translations"; - $cacheFileMafe = PATH_HTML . "translations" . PATH_SEP. 'translationsMafe' . ".js"; - - foreach ($tranlations as $key => $row) { - if ($row->getTrnCategory() === 'LABEL') { - $translation[$row->getTrnLang()][$row->getTrnId()] = $row->getTrnValue(); - } - } - try { + $translation = []; + $result = ModelTranslation::select() + ->where('TRN_ID', 'LIKE', '%ID_MAFE_%') + ->where('TRN_CATEGORY', '=', 'LABEL') + ->orderBy('TRN_CATEGORY', 'asc') + ->orderBy('TRN_ID', 'asc') + ->get(); + foreach ($result as $object) { + $translation[$object->TRN_LANG][$object->TRN_ID] = $object->TRN_VALUE; + } + $mafeFolder = PATH_HTML . "translations"; G::verifyPath($mafeFolder, true); - if (! is_dir( dirname( $cacheFileMafe ) )) { - G::mk_dir( dirname( $cacheFileMafe ) ); + if (!is_dir($mafeFolder)) { + G::mk_dir($mafeFolder); } - $f = fopen( $cacheFileMafe, 'w' ); - if ($f == false) { - error_log("Error: Cannot write into cacheFileMafe: $cacheFileMafe\n"); - } else { - fwrite( $f, "var __TRANSLATIONMAFE = " . Bootstrap::json_encode( $translation ) . ";\n"); - fclose( $f ); + $cacheFileMafe = PATH_HTML . "translations" . PATH_SEP . 'translationsMafe' . ".js"; + $status = file_put_contents($cacheFileMafe, "var __TRANSLATIONMAFE = " . Bootstrap::json_encode($translation) . ";\n"); + if ($status === false) { + Log::channel(':generateFileTranslationMafe')->error("Cannot write into cacheFileMafe: {$cacheFileMafe}", Bootstrap::context()); } - $res['cacheFileMafe'] = $cacheFileMafe; - $res['languague'] = (is_array($cacheFileMafe) || $cacheFileMafe instanceof Countable) ? count($cacheFileMafe) : 0; - $res['rowsMafeJS'] = count( $translation ); - return $res; + return [ + 'cacheFileMafe' => $cacheFileMafe, + 'languague' => 0, //must be deprecated + 'rowsMafeJS' => count($translation) + ]; } catch (Exception $e) { - $token = strtotime("now"); - PMException::registerErrorLog($e, $token); - G::outRes( G::LoadTranslation("ID_EXCEPTION_LOG_INTERFAZ", array($token)) ); + Log::channel(':generateFileTranslationMafe')->error($e->getMessage(), Bootstrap::context()); + G::outRes(G::LoadTranslation("ID_EXCEPTION_LOG_INTERFAZ", [strtotime("now")])); } } diff --git a/workflow/engine/src/ProcessMaker/Model/Translation.php b/workflow/engine/src/ProcessMaker/Model/Translation.php new file mode 100644 index 000000000..6288ee433 --- /dev/null +++ b/workflow/engine/src/ProcessMaker/Model/Translation.php @@ -0,0 +1,14 @@ +