This commit is contained in:
Julio Cesar Laura Avendaño
2018-11-06 15:43:32 -04:00
parent 166b66dc40
commit 7d3d5b19a1
3 changed files with 87 additions and 11 deletions

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}
}