Conflicts

This commit is contained in:
Paula Quispe
2020-06-12 19:04:53 -04:00
33 changed files with 2799 additions and 620 deletions

View File

@@ -1178,7 +1178,9 @@ class DynaForm
}
foreach ($oldColumns as $oldColumn) {
if (strtolower(AdditionalTables::getPHPName($column->id)) === strtolower(AdditionalTables::getPHPName($oldColumn->id))) {
$identicals[] = "'" . $column->id . "' - '" . $oldColumn->id . "'";
if (strtolower(AdditionalTables::getPHPName($column->var_name)) === strtolower(AdditionalTables::getPHPName($oldColumn->var_name))) {
$identicals[] = "'" . $column->id . "' - '" . $oldColumn->id . "'";
}
}
}
}

View File

@@ -26,6 +26,16 @@ class Variable
'object' => 10
];
/**
* Get the variables types accepted
*
* @return array
*/
public function getVariableTypes()
{
return $this->variableTypes;
}
/**
* Create Variable for a Process
*
@@ -355,6 +365,33 @@ class Variable
return $arrayVariables;
}
/**
* Get data of Variables related to the specific type
*
* @param string $processUid Unique id of Process
* @param int $typeVarId
* @param int $start
* @param int $limit
* @param string $search
* @param string $prefix
*
* @return array, return an array with varaibles filter by type
*/
public function getVariablesByType($processUid, $typeVarId = 0, $start = null, $limit = null, $search = null, $prefix = null)
{
//Verify data
$proId = Validator::proUid($processUid, '$prj_uid');
$variables = ProcessVariables::getVariablesByType($proId, $typeVarId, $start, $limit, $search);
$arrayVariables = [];
foreach ($variables as $var) {
$arrayVariables[] = [
'value' => is_null($prefix) ? $var['VAR_NAME'] : $prefix . $var['VAR_NAME'],
];
}
return $arrayVariables;
}
/**
* Verify field definition
*

View File

@@ -1,80 +0,0 @@
<?php
namespace ProcessMaker\Commands;
use ProcessMaker\Core\ProcOpen;
class GenerateDataReport extends ProcOpen
{
private $workspace;
private $tableName;
private $type;
private $processUid;
private $gridKey;
private $addTabUid;
private $className;
private $pathWorkspace;
private $start;
private $limit;
/**
* Initializes the command parameters.
* @param string $workspace
* @param string $tableName
* @param string $type
* @param string $processUid
* @param string $gridKey
* @param string $addTabUid
* @param string $className
* @param string $pathWorkspace
* @param integer $start
* @param integer $limit
*/
public function __construct(
$workspace,
$tableName,
$type = 'NORMAL',
$processUid = '',
$gridKey = '',
$addTabUid = '',
$className = '',
$pathWorkspace,
$start = 0,
$limit = 10)
{
$this->workspace = $workspace;
$this->tableName = $tableName;
$this->type = $type;
$this->processUid = $processUid;
$this->gridKey = $gridKey;
$this->addTabUid = $addTabUid;
$this->className = $className;
$this->pathWorkspace = $pathWorkspace;
$this->start = $start;
$this->limit = $limit;
$this->setCwd(PATH_TRUNK);
parent::__construct($this->buildCommand());
}
/**
* Returns the command to execute.
* @return string
*/
private function buildCommand(): string
{
$command = PHP_BINDIR . "/php "
. "./processmaker "
. "'generate-data-report' "
. "'{$this->workspace}' "
. "'tableName={$this->tableName}' "
. "'type={$this->type}' "
. "'process={$this->processUid}' "
. "'gridKey={$this->gridKey}' "
. "'additionalTable={$this->addTabUid}' "
. "'className={$this->className}' "
. "'pathWorkspace={$this->pathWorkspace}' "
. "'start={$this->start}' "
. "'limit={$this->limit}' ";
return $command;
}
}

View File

@@ -1,42 +0,0 @@
<?php
namespace ProcessMaker\Commands;
use ProcessMaker\Core\ProcOpen;
class PopulateTableReport extends ProcOpen
{
private $workspace;
private $sql;
private $isRbac;
/**
* Initializes the command parameters.
* @param string $workspace
* @param string $sql
* @param boolean $isRbac
*/
public function __construct($workspace, $sql, $isRbac = false)
{
$this->workspace = $workspace;
$this->sql = $sql;
$this->isRbac = $isRbac;
$this->setCwd(PATH_TRUNK);
parent::__construct($this->buildCommand());
}
/**
* Returns the command to execute.
* @return string
*/
public function buildCommand()
{
$command = PHP_BINDIR . "/php "
. "./processmaker "
. "'populate-table' "
. "'{$this->workspace}' "
. base64_encode($this->sql) . " "
. ($this->isRbac ? "'1'" : "'0'");
return $command;
}
}

View File

@@ -1,92 +0,0 @@
<?php
namespace ProcessMaker\Core;
class MultiProcOpen
{
/**
* Represents the waiting time before starting the process monitoring.
* @var integer
*/
private $sleepTime = 1;
/**
* This method obtains a paging by returning the start and limit indexes
* compatible with the mysql pagination in its call function.
* The return function must return an instance of the object "ProcessMaker\Core\ProcOpen".
* Returns an array containing the status, content, and errors generated by
* the open process.
* @param int $size
* @param int $chunk
* @param callable $callback
* @return array
*/
public function chunk(int $size, int $chunk, callable $callback): array
{
$start = 0;
$limit = $chunk;
$queries = [];
for ($i = 1; $start < $size; $i++) {
$queries[] = $callback($size, $start, $limit);
$start = $i * $limit;
}
return $this->run($queries);
}
/**
* Open a set of background processes.
* The array must contain one or more instances of the object inherited from
* the class "ProcessMaker\Core\ProcOpen"
* Returns an array containing the status, content, and errors generated by
* the open process.
* @param array $processes
* @return array
*/
public function run(array $processes): array
{
foreach ($processes as $procOpen) {
$procOpen->open();
}
return $this->processMonitoring($processes);
}
/**
* It monitors the open processes, verifying if they have ended or thrown an
* error and later closing the resources related to the process.
* Returns an array containing the status, content, and errors generated by
* the open process.
* @param array $processes
* @return array
*/
private function processMonitoring(array $processes): array
{
sleep($this->sleepTime); //this sleep is very important
$i = 0;
$n = count($processes);
if ($n === 0) {
return [];
}
$outputs = [];
do {
$index = $i % $n;
if (isset($processes[$index])) {
$procOpen = $processes[$index];
$status = $procOpen->getStatus();
$contents = $procOpen->getContents();
$errors = $procOpen->getErrors();
if ($status->running === false || !empty($errors)) {
$outputs[] = [
"status" => $status,
"contents" => $contents,
"errors" => $errors,
];
$procOpen->terminate();
$procOpen->close();
unset($processes[$index]);
}
}
$i = $i + 1;
} while (!empty($processes));
return $outputs;
}
}

View File

@@ -1,126 +0,0 @@
<?php
namespace ProcessMaker\Core;
class ProcOpen
{
private $command;
private $resource;
private $descriptorspec;
private $pipes;
private $cwd;
/**
* This initializes the descriptors and the command for the open process.
* @param string $command
*/
public function __construct(string $command)
{
$this->descriptorspec = [
['pipe', 'r'],
['pipe', 'w'],
['pipe', 'w']
];
$this->command = $command;
}
/**
* Gets the resource that represents the process.
* @return resource
*/
public function getResource()
{
return $this->resource;
}
/**
* Sets the process execution directory.
* @param string $cwd
*/
public function setCwd(string $cwd)
{
$this->cwd = $cwd;
}
/**
* Open a background process.
*/
public function open()
{
if (empty($this->cwd)) {
$this->resource = proc_open($this->command, $this->descriptorspec, $this->pipes);
} else {
$this->resource = proc_open($this->command, $this->descriptorspec, $this->pipes, $this->cwd);
}
}
/**
* Get the content of the process when it is finished.
* @return string
*/
public function getContents()
{
if (is_resource($this->pipes[1])) {
return stream_get_contents($this->pipes[1]);
}
return "";
}
/**
* Get the process errors when it is finished.
* @return string
*/
public function getErrors()
{
if (is_resource($this->pipes[2])) {
return stream_get_contents($this->pipes[2]);
}
return "";
}
/**
* Close the resources related to the open process.
* return void
*/
public function close()
{
if (is_resource($this->resource)) {
foreach ($this->pipes as $value) {
fclose($value);
}
proc_close($this->resource);
}
}
/**
* End the process before it ends.
*/
public function terminate()
{
if (is_resource($this->resource)) {
proc_terminate($this->resource);
}
}
/**
* Gets the status of the process.
* @return object
*/
public function getStatus()
{
$status = [
"command" => $this->command,
"pid" => null,
"running" => false,
"signaled" => false,
"stopped" => false,
"exitcode" => -1,
"termsig" => 0,
"stopsig" => 0
];
if (is_resource($this->resource)) {
$status = proc_get_status($this->resource);
}
return (object) $status;
}
}

View File

@@ -77,7 +77,9 @@ class System
'highlight_home_folder_enable' => 0,
'highlight_home_folder_refresh_time' => 10,
'highlight_home_folder_scope' => 'unassigned', // For now only this list is supported
'disable_advanced_search_case_title_fulltext' => 0
'disable_advanced_search_case_title_fulltext' => 0,
'pmftotalcalculation_floating_point_number' => 10,
'report_table_batch_regeneration' => 1000
];
/**

View File

@@ -72,8 +72,21 @@ class ProcessVariables extends Model
*/
public function scopeProcessId($query, int $proId)
{
return $query->where('PRO_ID', $proId);
return $query->where('PROCESS_VARIABLES.PRO_ID', $proId);
}
/**
* Scope a query to filter a specific type for variable
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param int $typeId
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeTypeId($query, int $typeId)
{
return $query->where('VAR_FIELD_TYPE_ID', $typeId);
}
/**
* Return the variables list
*
@@ -96,4 +109,46 @@ class ProcessVariables extends Model
return $variablesList;
}
/**
* Return the variables list
*
* @param int $proId
* @param int $typeId
* @param int $start
* @param int $limit
* @param string $search
*
* @return array
*/
public static function getVariablesByType(int $proId, int $typeId = 0, $start = null, $limit = null, $search = null)
{
$query = ProcessVariables::query()->select();
$query->leftJoin('DB_SOURCE', function ($join) {
$join->on('DB_SOURCE.PRO_ID', '=', 'PROCESS_VARIABLES.PRO_ID');
});
$query->processId($proId);
// Check if we need to filter the type of variables
if ($typeId > 0) {
$query->typeId($typeId);
}
// search a specific variable name
if (!empty($search)) {
$query->where('VAR_NAME', 'LIKE', "${search}%");
}
// order by varNane
$query->orderBy('VAR_NAME', 'ASC');
// Check if we need to add a pagination
if(!is_null($start) && !is_null($limit)) {
$query->offset($start)->limit($limit);
}
// Get records
$results = $query->get();
$variablesList = [];
$results->each(function ($item, $key) use (&$variablesList) {
$variablesList[] = $item->toArray();
});
return $variablesList;
}
}

View File

@@ -1,8 +1,12 @@
<?php
namespace ProcessMaker\Services\Api\Project;
use \ProcessMaker\Services\Api;
use \Luracast\Restler\RestException;
use Exception;
use G;
use Luracast\Restler\RestException;
use ProcessMaker\BusinessModel\Variable as BmVariable;
use ProcessMaker\Services\Api;
/**
* Project\Variable Api Controller
*
@@ -28,6 +32,43 @@ class Variable extends Api
}
}
/**
* Get variables by type
*
* @url GET /:prj_uid/process-variables/:typeVariable/paged
*
* @param string $prj_uid {@min 32}{@max 32}
* @param string $typeVariable {@from path}
* @param int $start {@from path}
* @param int $limit {@from path}
* @param string $search {@from path}
*/
public function doGetVariablesByType($prj_uid, $typeVariable, $start = null, $limit = null, $search = null)
{
try {
$variable = new BmVariable();
$typesAccepted = $variable::$varTypesValues;
if (!empty($typesAccepted[$typeVariable])) {
$typeVatId = $typesAccepted[$typeVariable];
} else {
throw new Exception(G::LoadTranslation("ID_INVALID_VALUE_ONLY_ACCEPTS_VALUES", ['$typeVariable', implode(',', $variable->getVariableTypes())]));
}
// Review if the word has the prefix
$count = preg_match_all('/\@(?:([\@\%\#\?\$\=\&Qq\!])|([a-zA-Z\_][\w\-\>\:]*)\(((?:[^\\\\\)]*(?:[\\\\][\w\W])?)*)\))((?:\s*\[[\'"]?\w+[\'"]?\])+|\-\>([a-zA-Z\_]\w*))?/', $search, $match, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE);
// Check if the search has some prefix
$prefix = '';
if ($count) {
$prefix = substr($search,0,2);
$search = substr($search,2);
}
$response = $variable->getVariablesByType($prj_uid, $typeVatId, $start, $limit, $search, $prefix);
return $response;
} catch (Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
/**
* @url GET /:prj_uid/process-variable/:var_uid
*