diff --git a/workflow/engine/bin/tasks/cliWorkspaces.php b/workflow/engine/bin/tasks/cliWorkspaces.php index 488f1cce7..f5bec86ea 100644 --- a/workflow/engine/bin/tasks/cliWorkspaces.php +++ b/workflow/engine/bin/tasks/cliWorkspaces.php @@ -351,6 +351,17 @@ EOT CLI::taskArg('workspace'); CLI::taskRun("run_clear_dyn_content_history_data"); +/** + * Sync JSON definition of the Forms with Input Documents information + */ +CLI::taskName('sync-forms-with-info-from-input-documents'); +CLI::taskDescription(<< Cleaning history data from APP_HISTORY process took " . ($stop - $start) . " seconds.\n"); } + +/** + * Sync JSON definition of the Forms with Input Documents information + * + * @param array $args + * @param array $opts + * + * @return void + */ + +function run_sync_forms_with_info_from_input_documents($args, $opts) { + if (count($args) === 1) { + //This variable is not defined and does not involve its value in this + //task, it is removed at the end of the method. + $_SERVER['REQUEST_URI'] = ''; + if (!defined('SYS_SKIN')) { + $conf = new Configurations(); + define('SYS_SKIN', $conf->getConfiguration('SKIN_CRON', '')); + } + CLI::logging('Sync JSON definition of the Forms with Input Documents information from workspace: ' . pakeColor::colorize($args[0], 'INFO') . "\n"); + $workspaceTools = new WorkspaceTools($args[0]); + $workspaceTools->syncFormsWithInputDocumentInfo(); + unset($_SERVER['REQUEST_URI']); + } else { + $workspaces = get_workspaces_from_args($args); + foreach ($workspaces as $workspace) { + passthru(PHP_BINARY . ' processmaker sync-forms-with-info-from-input-documents ' . + $workspace->name); + } + } +} diff --git a/workflow/engine/classes/PmDynaform.php b/workflow/engine/classes/PmDynaform.php index 79f62ffd4..eae7215a9 100644 --- a/workflow/engine/classes/PmDynaform.php +++ b/workflow/engine/classes/PmDynaform.php @@ -1507,12 +1507,21 @@ class PmDynaform } } + /** + * Sync JSON definition of the Forms with Input Document information + * in all forms from a process + * + * @param string $processUid + * @param array $inputDocument + */ public function synchronizeInputDocument($processUid, $inputDocument) { - $criteria = new Criteria("workflow"); + $criteria = new Criteria('workflow'); $criteria->addSelectColumn(DynaformPeer::DYN_UID); $criteria->addSelectColumn(DynaformPeer::DYN_CONTENT); $criteria->add(DynaformPeer::PRO_UID, $processUid, Criteria::EQUAL); + // Only select the forms with an input document related to a field + $criteria->add(DynaformPeer::DYN_CONTENT, '%"sizeUnity":%', Criteria::LIKE); $rsCriteria = DynaformPeer::doSelectRS($criteria); $rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC); while ($rsCriteria->next()) { @@ -1524,7 +1533,7 @@ class PmDynaform if ($json2 !== $aRow['DYN_CONTENT']) { $con = Propel::getConnection(DynaformPeer::DATABASE_NAME); $con->begin(); - $oPro = DynaformPeer::retrieveByPk($aRow["DYN_UID"]); + $oPro = DynaformPeer::retrieveByPk($aRow['DYN_UID']); $oPro->setDynContent($json2); $oPro->save(); $con->commit(); @@ -1532,6 +1541,13 @@ class PmDynaform } } + /** + * Replace values from an Input Document related to the form, + * for fields of type "file" and "multipleFile" + * + * @param object $json + * @param array $inputDocument + */ private function jsonsid(&$json, $inputDocument) { foreach ($json as $key => $value) { @@ -1541,15 +1557,8 @@ class PmDynaform $this->jsonsid($value, $inputDocument); } if (!$sw1 && !$sw2) { - if ($key === "type" && $json->type === "file" && $json->variable !== "") { - $a = new Criteria("workflow"); - $a->addSelectColumn(ProcessVariablesPeer::INP_DOC_UID); - $a->add(ProcessVariablesPeer::VAR_NAME, $json->variable, Criteria::EQUAL); - $ds = DynaformPeer::doSelectRS($a); - $ds->setFetchmode(ResultSet::FETCHMODE_ASSOC); - $ds->next(); - $row = $ds->getRow(); - if (isset($row) && $row["INP_DOC_UID"] === $inputDocument["INP_DOC_UID"]) { + if ($key === "type" && ($json->type === "file" || $json->type === "multipleFile") && isset($json->inp_doc_uid)) { + if ($json->inp_doc_uid === $inputDocument["INP_DOC_UID"]) { if (isset($json->size)) { $json->size = $inputDocument["INP_DOC_MAX_FILESIZE"]; } @@ -1560,6 +1569,8 @@ class PmDynaform $json->extensions = $inputDocument["INP_DOC_TYPE_FILE"]; } } + } else if ($key === "type" && $json->type === "grid" && !empty($json->columns)) { + $this->jsonsid($json->columns, $inputDocument); } } } diff --git a/workflow/engine/classes/WorkspaceTools.php b/workflow/engine/classes/WorkspaceTools.php index 3e4d4dfca..611e5da25 100644 --- a/workflow/engine/classes/WorkspaceTools.php +++ b/workflow/engine/classes/WorkspaceTools.php @@ -5,6 +5,7 @@ use Illuminate\Support\Facades\DB; /*----------------------------------********---------------------------------*/ use ProcessMaker\ChangeLog\ChangeLog; /*----------------------------------********---------------------------------*/ +use ProcessMaker\BusinessModel\Process as BmProcess; use ProcessMaker\Core\Installer; use ProcessMaker\Core\System; use ProcessMaker\Plugins\Adapters\PluginAdapter; @@ -4596,4 +4597,26 @@ class WorkspaceTools } } } + + /** + * Sync JSON definition of the Forms with Input Documents information + */ + public function syncFormsWithInputDocumentInfo() { + // Initialize Propel and instance the required classes + $this->initPropel(true); + $processInstance = new Process(); + $bmProcessInstance = new BmProcess(); + $pmDynaform = new PmDynaform(); + + // Get all active processes + $processes = $processInstance->getAllProcesses(0, ''); + foreach ($processes as $process) { + // Get all Input Documents from a process + $inputDocuments = $bmProcessInstance->getInputDocuments($process['PRO_UID']); + foreach ($inputDocuments as $inputDocument) { + // Sync JSON definition of the Forms + $pmDynaform->synchronizeInputDocument($process['PRO_UID'], $inputDocument); + } + } + } }