Merged in bugfix/PMCORE-1476 (pull request #7340)
PMCORE-1476 Approved-by: Julio Cesar Laura Avendaño <contact@julio-laura.com>
This commit is contained in:
@@ -9,6 +9,7 @@ use ProcessMaker\Model\Dynaform;
|
|||||||
use ProcessMaker\Model\InputDocument;
|
use ProcessMaker\Model\InputDocument;
|
||||||
use ProcessMaker\Model\OutputDocument;
|
use ProcessMaker\Model\OutputDocument;
|
||||||
use ProcessMaker\Model\Process;
|
use ProcessMaker\Model\Process;
|
||||||
|
use ProcessMaker\Model\ProcessVariables;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
class ProcessesTest extends TestCase
|
class ProcessesTest extends TestCase
|
||||||
@@ -479,4 +480,70 @@ class ProcessesTest extends TestCase
|
|||||||
$this->assertObjectHasAttribute($key, $result);
|
$this->assertObjectHasAttribute($key, $result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test it create a variable from old xml fields
|
||||||
|
*
|
||||||
|
* @covers \Processes::createProcessVariables()
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function it_create_variables_from_import_old()
|
||||||
|
{
|
||||||
|
$process = factory(\ProcessMaker\Model\Process::class)->create();
|
||||||
|
$attributes[] = [
|
||||||
|
'VAR_UID' => G::generateUniqueID(),
|
||||||
|
'PRJ_UID' => $process->PRO_UID,
|
||||||
|
'VAR_NAME' => 'varTest',
|
||||||
|
'VAR_FIELD_TYPE' => 'integer',
|
||||||
|
'VAR_FIELD_SIZE' => 10,
|
||||||
|
'VAR_LABEL' => 'string',
|
||||||
|
'VAR_DBCONNECTION' => '',
|
||||||
|
'VAR_SQL' => '',
|
||||||
|
'VAR_NULL' => 0,
|
||||||
|
'VAR_DEFAULT' => '',
|
||||||
|
'VAR_ACCEPTED_VALUES' => '[]',
|
||||||
|
'INP_DOC_UID' => ''
|
||||||
|
];
|
||||||
|
$processes = new Processes();
|
||||||
|
$processes->createProcessVariables($attributes);
|
||||||
|
$result = ProcessVariables::getVariables($process->PRO_ID);
|
||||||
|
$this->assertNotEmpty($result);
|
||||||
|
$result = head($result);
|
||||||
|
$this->assertArrayHasKey('PRO_ID', $result, "The result does not contains 'PRO_ID' as a key");
|
||||||
|
$this->assertArrayHasKey('VAR_FIELD_TYPE_ID', $result, "The result does not contains 'VAR_FIELD_TYPE_ID' as a key");
|
||||||
|
$this->assertEquals($result['VAR_FIELD_TYPE_ID'], 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test it create a variable from new xml fields
|
||||||
|
*
|
||||||
|
* @covers \Processes::createProcessVariables()
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function it_create_variables_from_import_new()
|
||||||
|
{
|
||||||
|
$process = factory(\ProcessMaker\Model\Process::class)->create();
|
||||||
|
$attributes[] = [
|
||||||
|
'VAR_UID' => G::generateUniqueID(),
|
||||||
|
'PRJ_UID' => $process->PRO_UID,
|
||||||
|
'VAR_NAME' => 'varTest',
|
||||||
|
'VAR_FIELD_TYPE' => 'string',
|
||||||
|
'VAR_FIELD_TYPE_ID' => 1,
|
||||||
|
'VAR_FIELD_SIZE' => 10,
|
||||||
|
'VAR_LABEL' => 'string',
|
||||||
|
'VAR_DBCONNECTION' => '',
|
||||||
|
'VAR_SQL' => '',
|
||||||
|
'VAR_NULL' => 0,
|
||||||
|
'VAR_DEFAULT' => '',
|
||||||
|
'VAR_ACCEPTED_VALUES' => '[]',
|
||||||
|
'INP_DOC_UID' => ''
|
||||||
|
];
|
||||||
|
$processes = new Processes();
|
||||||
|
$processes->createProcessVariables($attributes);
|
||||||
|
$result = ProcessVariables::getVariables($process->PRO_ID);
|
||||||
|
$this->assertNotEmpty($result);
|
||||||
|
$result = head($result);
|
||||||
|
$this->assertArrayHasKey('PRO_ID', $result, "The result does not contains 'PRO_ID' as a key");
|
||||||
|
$this->assertArrayHasKey('VAR_FIELD_TYPE_ID', $result, "The result does not contains 'VAR_FIELD_TYPE_ID' as a key");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use ProcessMaker\BusinessModel\EmailEvent;
|
use ProcessMaker\BusinessModel\EmailEvent;
|
||||||
|
use ProcessMaker\BusinessModel\Variable as BmVariable;
|
||||||
use ProcessMaker\Core\System;
|
use ProcessMaker\Core\System;
|
||||||
|
|
||||||
class Processes
|
class Processes
|
||||||
@@ -1863,8 +1864,21 @@ class Processes
|
|||||||
$criteria = new Criteria(ProcessVariablesPeer::DATABASE_NAME);
|
$criteria = new Criteria(ProcessVariablesPeer::DATABASE_NAME);
|
||||||
$criteria->add(ProcessVariablesPeer::VAR_UID, $row['VAR_UID']);
|
$criteria->add(ProcessVariablesPeer::VAR_UID, $row['VAR_UID']);
|
||||||
$criteria->add(ProcessVariablesPeer::PRJ_UID, $row['PRJ_UID']);
|
$criteria->add(ProcessVariablesPeer::PRJ_UID, $row['PRJ_UID']);
|
||||||
|
// Load the PRO_ID
|
||||||
|
$process = new Process();
|
||||||
|
if ($process->processExists($row['PRJ_UID'])) {
|
||||||
|
$processRow = $process->load($row['PRJ_UID']);
|
||||||
|
$row['PRO_ID'] = $processRow['PRO_ID'];
|
||||||
|
if (!empty($row['PRO_ID'])) {
|
||||||
|
$criteria->add(ProcessVariablesPeer::PRO_ID, $row['PRO_ID']);
|
||||||
|
}
|
||||||
|
}
|
||||||
$criteria->add(ProcessVariablesPeer::VAR_NAME, $row['VAR_NAME']);
|
$criteria->add(ProcessVariablesPeer::VAR_NAME, $row['VAR_NAME']);
|
||||||
$criteria->add(ProcessVariablesPeer::VAR_FIELD_TYPE, $row['VAR_FIELD_TYPE']);
|
$criteria->add(ProcessVariablesPeer::VAR_FIELD_TYPE, $row['VAR_FIELD_TYPE']);
|
||||||
|
if (empty($row['VAR_FIELD_TYPE_ID'])) {
|
||||||
|
$row['VAR_FIELD_TYPE_ID'] = BmVariable::$varTypesValues[$row["VAR_FIELD_TYPE"]];
|
||||||
|
}
|
||||||
|
$criteria->add(ProcessVariablesPeer::VAR_FIELD_TYPE_ID, $row['VAR_FIELD_TYPE_ID']);
|
||||||
$criteria->add(ProcessVariablesPeer::VAR_FIELD_SIZE, $row['VAR_FIELD_SIZE']);
|
$criteria->add(ProcessVariablesPeer::VAR_FIELD_SIZE, $row['VAR_FIELD_SIZE']);
|
||||||
$criteria->add(ProcessVariablesPeer::VAR_LABEL, $row['VAR_LABEL']);
|
$criteria->add(ProcessVariablesPeer::VAR_LABEL, $row['VAR_LABEL']);
|
||||||
$criteria->add(ProcessVariablesPeer::VAR_DBCONNECTION, $row['VAR_DBCONNECTION']);
|
$criteria->add(ProcessVariablesPeer::VAR_DBCONNECTION, $row['VAR_DBCONNECTION']);
|
||||||
@@ -3609,6 +3623,8 @@ class Processes
|
|||||||
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
||||||
$oDataset->next();
|
$oDataset->next();
|
||||||
while ($aRow = $oDataset->getRow()) {
|
while ($aRow = $oDataset->getRow()) {
|
||||||
|
unset($aRow['VAR_ID']);
|
||||||
|
unset($aRow['PRO_ID']);
|
||||||
$aVars[] = $aRow;
|
$aVars[] = $aRow;
|
||||||
$oDataset->next();
|
$oDataset->next();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace ProcessMaker\Importer;
|
namespace ProcessMaker\Importer;
|
||||||
|
|
||||||
|
use Process as ModelProcess;
|
||||||
use Processes;
|
use Processes;
|
||||||
use ProcessMaker\BusinessModel\Migrator;
|
use ProcessMaker\BusinessModel\Migrator;
|
||||||
use ProcessMaker\BusinessModel\Migrator\ImportException;
|
use ProcessMaker\BusinessModel\Migrator\ImportException;
|
||||||
use ProcessMaker\Model\Process;
|
use ProcessMaker\Model\Process;
|
||||||
|
use ProcessMaker\Model\ProcessVariables;
|
||||||
use ProcessMaker\Project;
|
use ProcessMaker\Project;
|
||||||
use ProcessMaker\Project\Adapter;
|
use ProcessMaker\Project\Adapter;
|
||||||
use ProcessMaker\Util;
|
use ProcessMaker\Util;
|
||||||
@@ -333,7 +335,7 @@ abstract class Importer
|
|||||||
$diagram = $project->getStruct($projectUid);
|
$diagram = $project->getStruct($projectUid);
|
||||||
$res = $project->updateFromStruct($projectUid, $diagram);
|
$res = $project->updateFromStruct($projectUid, $diagram);
|
||||||
}
|
}
|
||||||
$this->updateTheProcessOwner($projectUid);
|
$this->updateProcessInformation($projectUid);
|
||||||
return $projectUid;
|
return $projectUid;
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@@ -342,17 +344,20 @@ abstract class Importer
|
|||||||
/*----------------------------------********---------------------------------*/
|
/*----------------------------------********---------------------------------*/
|
||||||
|
|
||||||
$result = $this->doImport($generateUid);
|
$result = $this->doImport($generateUid);
|
||||||
$this->updateTheProcessOwner($result);
|
$this->updateProcessInformation($result);
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This updates the process owner.
|
* This updates information related to the process
|
||||||
|
*
|
||||||
* @param string $proUid
|
* @param string $proUid
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function updateTheProcessOwner(string $proUid): void
|
private function updateProcessInformation(string $proUid): void
|
||||||
{
|
{
|
||||||
|
// Update the process owner
|
||||||
$processOwner = $this->data["usr_uid"];
|
$processOwner = $this->data["usr_uid"];
|
||||||
|
|
||||||
$currentProcess = $this->getCurrentProcess();
|
$currentProcess = $this->getCurrentProcess();
|
||||||
@@ -363,6 +368,17 @@ abstract class Importer
|
|||||||
$process->update([
|
$process->update([
|
||||||
'PRO_CREATE_USER' => $processOwner
|
'PRO_CREATE_USER' => $processOwner
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// Update the process Variables with the PRO_ID related
|
||||||
|
$process = new ModelProcess();
|
||||||
|
if ($process->processExists($proUid)) {
|
||||||
|
$processRow = $process->load($proUid);
|
||||||
|
$proId = $processRow['PRO_ID'];
|
||||||
|
$processVar = ProcessVariables::where('PRJ_UID', '=', $proUid);
|
||||||
|
$processVar->update([
|
||||||
|
'PRO_ID' => $proId
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -887,7 +903,7 @@ abstract class Importer
|
|||||||
$this->importData["tables"]["workflow"]["process"] = $this->importData["tables"]["workflow"]["process"][0];
|
$this->importData["tables"]["workflow"]["process"] = $this->importData["tables"]["workflow"]["process"][0];
|
||||||
|
|
||||||
$result = $this->doImport(true, false);
|
$result = $this->doImport(true, false);
|
||||||
$this->updateTheProcessOwner($result);
|
$this->updateProcessInformation($result);
|
||||||
return ['prj_uid' => $result];
|
return ['prj_uid' => $result];
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return $e->getMessage();
|
return $e->getMessage();
|
||||||
|
|||||||
Reference in New Issue
Block a user