Merged release/3.4.0 into bugfix/PMC-1054

This commit is contained in:
Paula Quispe
2019-08-14 11:46:35 -04:00
3 changed files with 268 additions and 250 deletions

View File

@@ -80,9 +80,9 @@ class TemplatePowerParser
public $tpl_include;
//Array( [filename/varcontent], [T_BYFILE/T_BYVAR] )
public $tpl_count;
public $parent = Array ();
public $parent = [];
// $parent[{blockname}] = {parentblockname}
public $defBlock = Array ();
public $defBlock = [];
public $rootBlockName;
public $ignore_stack;
public $version;
@@ -95,52 +95,52 @@ class TemplatePowerParser
* @param string $type
* @access private
*/
public function TemplatePowerParser ($tpl_file, $type)
public function __construct($tpl_file, $type)
{
$this->version = '3.0.2';
$this->tpl_base = Array ($tpl_file,$type);
$this->tpl_base = [$tpl_file, $type];
$this->tpl_count = 0;
$this->ignore_stack = Array (false);
$this->ignore_stack = [false];
}
/**
* TemplatePowerParser::__errorAlert()
* TemplatePowerParser::errorAlert()
*
* @param string $message
*
* @access private
*/
public function __errorAlert ($message)
public function errorAlert($message)
{
print ('<br>' . $message . '<br>' . "\r\n");
}
/**
* TemplatePowerParser::__prepare()
* TemplatePowerParser::prepare()
*
* @access private
* @return void
*/
public function __prepare ()
public function prepare()
{
$this->defBlock[TP_ROOTBLOCK] = Array ();
$tplvar = $this->__prepareTemplate( $this->tpl_base[0], $this->tpl_base[1] );
$this->defBlock[TP_ROOTBLOCK] = [];
$tplvar = $this->prepareTemplate($this->tpl_base[0], $this->tpl_base[1]);
$initdev["varrow"] = 0;
$initdev["coderow"] = 0;
$initdev["index"] = 0;
$initdev["ignore"] = false;
$this->__parseTemplate( $tplvar, TP_ROOTBLOCK, $initdev );
$this->__cleanUp();
$this->parseTemplate($tplvar, TP_ROOTBLOCK, $initdev);
$this->cleanUp();
}
/**
* TemplatePowerParser::__cleanUp()
* TemplatePowerParser::cleanUp()
*
* @return void
*
* @access private
*/
public function __cleanUp ()
public function cleanUp()
{
for ($i = 0; $i <= $this->tpl_count; $i++) {
$tplvar = 'tpl_rawContent' . $i;
@@ -149,21 +149,21 @@ class TemplatePowerParser
}
/**
* TemplatePowerParser::__prepareTemplate()
* TemplatePowerParser::prepareTemplate()
*
* @param string $tpl_file
* @param string $type
* @access private
*/
public function __prepareTemplate ($tpl_file, $type)
public function prepareTemplate($tpl_file, $type)
{
$tplvar = 'tpl_rawContent' . $this->tpl_count;
if ($type == T_BYVAR) {
$this->{$tplvar}["content"] = preg_split( "/\n/", $tpl_file, - 1, PREG_SPLIT_DELIM_CAPTURE );
$this->{$tplvar}["content"] = preg_split("/\r\n/", $tpl_file, -1, PREG_SPLIT_DELIM_CAPTURE);
} else {
//Trigger the error in the local scope of the function
//trigger_error ("Some error", E_USER_WARNING);
$this->{$tplvar}["content"] = @file( $tpl_file ) or die( $this->__errorAlert( 'TemplatePower Error: Couldn\'t open [ ' . $tpl_file . ' ]!' ) );
$this->{$tplvar}["content"] = @file($tpl_file) or die($this->errorAlert('TemplatePower Error: Couldn\'t open [ ' . $tpl_file . ' ]!'));
}
$this->{$tplvar}["size"] = sizeof($this->{$tplvar}["content"]);
$this->tpl_count++;
@@ -171,14 +171,14 @@ class TemplatePowerParser
}
/**
* TemplatePowerParser::__parseTemplate()
* TemplatePowerParser::parseTemplate()
*
* @param string $tplvar
* @param string $blockname
* @param string $initdev
* @access private
*/
public function __parseTemplate ($tplvar, $blockname, $initdev)
public function parseTemplate($tplvar, $blockname, $initdev)
{
$coderow = $initdev["coderow"];
$varrow = $initdev["varrow"];
@@ -195,7 +195,8 @@ class TemplatePowerParser
}
} else {
if (!end($this->ignore_stack)) {
if (preg_match( '/<!--[ ]?(START|END|INCLUDE|INCLUDESCRIPT|REUSE) BLOCK : (.+)-->/', $this->{$tplvar}["content"][$index], $regs )) {
if (preg_match('/<!--[ ]?(START|END|INCLUDE|INCLUDESCRIPT|REUSE) BLOCK : (.+)-->/',
$this->{$tplvar}["content"][$index], $regs)) {
//remove trailing and leading spaces
$regs[2] = trim($regs[2]);
if ($regs[1] == 'INCLUDE') {
@@ -218,8 +219,8 @@ class TemplatePowerParser
$initdev["coderow"] = $coderow;
$initdev["index"] = 0;
$initdev["ignore"] = false;
$tplvar2 = $this->__prepareTemplate( $tpl_file, $type );
$initdev = $this->__parseTemplate( $tplvar2, $blockname, $initdev );
$tplvar2 = $this->prepareTemplate($tpl_file, $type);
$initdev = $this->parseTemplate($tplvar2, $blockname, $initdev);
$coderow = $initdev["coderow"];
$varrow = $initdev["varrow"];
}
@@ -240,7 +241,7 @@ class TemplatePowerParser
ob_start();
if ($type == T_BYFILE) {
if (!@include_once($include_file)) {
$this->__errorAlert( 'TemplatePower Error: Couldn\'t include script [ ' . $include_file . ' ]!' );
$this->errorAlert('TemplatePower Error: Couldn\'t include script [ ' . $include_file . ' ]!');
exit();
}
} else {
@@ -265,7 +266,7 @@ class TemplatePowerParser
$this->index[$copybname] = 0;
$this->parent[$copybname] = $blockname;
} else {
$this->__errorAlert( 'TemplatePower Error: Can\'t find block \'' . $originalbname . '\' to REUSE as \'' . $copybname . '\'' );
$this->errorAlert('TemplatePower Error: Can\'t find block \'' . $originalbname . '\' to REUSE as \'' . $copybname . '\'');
}
} else {
//so it isn't a correct REUSE tag, save as code
@@ -279,7 +280,7 @@ class TemplatePowerParser
} else {
//its the start of a block
//make a child block and tell the parent that he has a child
$this->defBlock[$regs[2]] = Array ();
$this->defBlock[$regs[2]] = [];
$this->defBlock[$blockname]["_B:" . $regs[2]] = '';
//set some vars that we need for the assign functions etc.
$this->index[$regs[2]] = 0;
@@ -290,7 +291,7 @@ class TemplatePowerParser
$initdev["coderow"] = 0;
$initdev["index"] = $index;
$initdev["ignore"] = false;
$initdev = $this->__parseTemplate( $tplvar, $regs[2], $initdev );
$initdev = $this->parseTemplate($tplvar, $regs[2], $initdev);
$index = $initdev["index"];
}
}
@@ -326,7 +327,8 @@ class TemplatePowerParser
//is there some code after the varname left?
if (($pos + 1) != $strlength) {
//yes, save that code
$this->defBlock[$blockname]["_C:$coderow"] = substr( current( $sstr ), ($pos + 1), ($strlength - ($pos + 1)) );
$this->defBlock[$blockname]["_C:$coderow"] = substr(current($sstr), ($pos + 1),
($strlength - ($pos + 1)));
$coderow++;
}
}
@@ -354,7 +356,7 @@ class TemplatePowerParser
/**
* TemplatePowerParser::version()
*
* @return void
* @return string
* @access public
*/
public function version()
@@ -373,7 +375,7 @@ class TemplatePowerParser
*/
public function assignInclude($iblockname, $value, $type = T_BYFILE)
{
$this->tpl_include["$iblockname"] = Array ($value,$type);
$this->tpl_include["$iblockname"] = [$value, $type];
}
}
@@ -384,26 +386,26 @@ class TemplatePowerParser
*/
class TemplatePower extends TemplatePowerParser
{
public $index = Array ();
public $index = [];
// $index[{blockname}] = {indexnumber}
public $content = Array ();
public $content = [];
public $currentBlock;
public $showUnAssigned;
public $serialized;
public $globalvars = Array ();
public $globalvars = [];
public $prepared;
/**
* TemplatePower::TemplatePower()
* TemplatePower::__construct()
*
* @param string $tpl_file
* @param string $type
* @return void
* @access public
*/
public function TemplatePower ($tpl_file = '', $type = T_BYFILE)
public function __construct($tpl_file = '', $type = T_BYFILE)
{
TemplatePowerParser::TemplatePowerParser( $tpl_file, $type );
TemplatePowerParser::__construct($tpl_file, $type);
$this->prepared = false;
$this->showUnAssigned = false;
$this->serialized = false;
@@ -411,17 +413,17 @@ class TemplatePower extends TemplatePowerParser
}
/**
* TemplatePower::__deSerializeTPL()
* TemplatePower::deSerializeTPL()
*
* @param string $stpl_file
* @param string $tplvar
* @return void
* @access private
*/
public function __deSerializeTPL ($stpl_file, $type)
public function deSerializeTPL($stpl_file, $type)
{
if ($type == T_BYFILE) {
$serializedTPL = @file( $stpl_file ) or die( $this->__errorAlert( 'TemplatePower Error: Can\'t open [ ' . $stpl_file . ' ]!' ) );
$serializedTPL = @file($stpl_file) or die($this->errorAlert('TemplatePower Error: Can\'t open [ ' . $stpl_file . ' ]!'));
} else {
$serializedTPL = $stpl_file;
}
@@ -432,19 +434,19 @@ class TemplatePower extends TemplatePowerParser
}
/**
* TemplatePower::__makeContentRoot()
* TemplatePower::makeContentRoot()
*
* @return void
* @access private
*/
public function __makeContentRoot ()
public function makeContentRoot()
{
$this->content[TP_ROOTBLOCK . "_0"][0] = Array (TP_ROOTBLOCK);
$this->content[TP_ROOTBLOCK . "_0"][0] = [TP_ROOTBLOCK];
$this->currentBlock = &$this->content[TP_ROOTBLOCK . "_0"][0];
}
/**
* TemplatePower::__assign()
* TemplatePower::assignPrivate()
*
* @param string $varname
* @param string $value
@@ -452,7 +454,7 @@ class TemplatePower extends TemplatePowerParser
*
* @access private
*/
public function __assign ($varname, $value)
public function assignPrivate($varname, $value)
{
if (sizeof($regs = explode('.', $varname)) == 2) {
//this is faster then preg_match
@@ -468,26 +470,26 @@ class TemplatePower extends TemplatePowerParser
}
/**
* TemplatePower::__assignGlobal()
* TemplatePower::assignGlobalPrivate()
*
* @param string $varname
* @param string $value
* @return void
* @access private
*/
public function __assignGlobal ($varname, $value)
public function assignGlobalPrivate($varname, $value)
{
$this->globalvars[$varname] = $value;
}
/**
* TemplatePower::__outputContent()
* TemplatePower::outputContent()
*
* @param string $blockname
* @return void
* @access private
*/
public function __outputContent ($blockname)
public function outputContent($blockname)
{
$numrows = sizeof($this->content[$blockname]);
for ($i = 0; $i < $numrows; $i++) {
@@ -506,7 +508,8 @@ class TemplatePower extends TemplatePowerParser
//if it is load an xml label.
//if not continues with non assigned value.
if (preg_match("/(.+):(.+)/", $defValue, $xmlreg)) {
$value = G::LoadTranslation(/*$xmlreg[1],*/$xmlreg[2] );
$value = G::LoadTranslation(/*$xmlreg[1],*/
$xmlreg[2]);
} else {
if ($this->showUnAssigned) {
//$value = '{'. $this->defBlock[ $defblockname ][$k] .'}';
@@ -519,12 +522,13 @@ class TemplatePower extends TemplatePowerParser
} else {
$value = $this->content[$blockname][$i]["_V:" . $defValue];
}
if ($this->unhtmlentities)
if ($this->unhtmlentities) {
$value = G::unhtmlentities($value);
}
print ($value);
} elseif ($k[1] == 'B') {
if (isset($this->content[$blockname][$i][$k])) {
$this->__outputContent( $this->content[$blockname][$i][$k] );
$this->outputContent($this->content[$blockname][$i][$k]);
}
}
}
@@ -532,12 +536,12 @@ class TemplatePower extends TemplatePowerParser
}
/**
* function __printVars
* function printVars
*
* @return void
* @access public
*/
public function __printVars ()
public function printVars()
{
var_dump($this->defBlock);
print ("<br>--------------------<br>");
@@ -560,7 +564,7 @@ class TemplatePower extends TemplatePowerParser
public function serializedBase()
{
$this->serialized = true;
$this->__deSerializeTPL( $this->tpl_base[0], $this->tpl_base[1] );
$this->deSerializeTPL($this->tpl_base[0], $this->tpl_base[1]);
}
/**
@@ -584,11 +588,11 @@ class TemplatePower extends TemplatePowerParser
public function prepare()
{
if (!$this->serialized) {
TemplatePowerParser::__prepare();
TemplatePowerParser::prepare();
}
$this->prepared = true;
$this->index[TP_ROOTBLOCK] = 0;
$this->__makeContentRoot();
$this->makeContentRoot();
}
/**
@@ -610,15 +614,16 @@ class TemplatePower extends TemplatePowerParser
$this->index[$blockname] += 1;
$ind_blockname = $blockname . '_' . $this->index[$blockname];
if (!isset($this->content[$ind_blockname])) {
$this->content[$ind_blockname] = Array ();
$this->content[$ind_blockname] = [];
}
//tell the parent where his (possible) children are located
$parent[$lastitem]["_B:$blockname"] = $ind_blockname;
}
//now, make a copy of the block defenition
$blocksize = sizeof($this->content[$ind_blockname]);
$this->content[$ind_blockname][$blocksize] = Array ($blockname
);
$this->content[$ind_blockname][$blocksize] = [
$blockname
];
//link the current block to the block we just created
$this->currentBlock = &$this->content[$ind_blockname][$blocksize];
}
@@ -636,10 +641,10 @@ class TemplatePower extends TemplatePowerParser
{
if (is_array($varname)) {
foreach ($varname as $var => $value) {
$this->__assignGlobal( $var, $value );
$this->assignGlobalPrivate($var, $value);
}
} else {
$this->__assignGlobal( $varname, $value );
$this->assignGlobalPrivate($varname, $value);
}
}
@@ -655,10 +660,10 @@ class TemplatePower extends TemplatePowerParser
{
if (is_array($varname)) {
foreach ($varname as $var => $value) {
$this->__assign( $var, $value );
$this->assignPrivate($var, $value);
}
} else {
$this->__assign( $varname, $value );
$this->assignPrivate($varname, $value);
}
}
@@ -712,9 +717,9 @@ class TemplatePower extends TemplatePowerParser
public function printToScreen()
{
if ($this->prepared) {
$this->__outputContent( TP_ROOTBLOCK . '_0' );
$this->outputContent(TP_ROOTBLOCK . '_0');
} else {
$this->__errorAlert( 'TemplatePower Error: Template isn\'t prepared!' );
$this->errorAlert('TemplatePower Error: Template isn\'t prepared!');
}
}

View File

@@ -625,6 +625,7 @@ function database_upgrade($args)
foreach ($workspaces as $workspace) {
try {
$workspace->upgradeDatabase();
$workspace->close();
} catch (Exception $e) {
G::outRes("> Error: " . CLI::error($e->getMessage()) . "\n");
}

View File

@@ -1354,7 +1354,6 @@ class WorkspaceTools
// Ending the schema update
CLI::logging("-> Schema Updated\n");
$this->closeDatabase();
return true;
}
@@ -2562,40 +2561,22 @@ class WorkspaceTools
throw new Exception($errorMessage);
}
// Clean the queries array
$listQueries = [];
// Canceled List
$listQueries[] = new RunProcessUpgradeQuery($this->name, $this->updateListProId('LIST_CANCELED'));
$listQueries[] = new RunProcessUpgradeQuery($this->name, $this->updateListUsrId('LIST_CANCELED'));
$listQueries[] = new RunProcessUpgradeQuery($this->name, $this->updateListTasId('LIST_CANCELED'));
// Inbox List
$listQueries[] = new RunProcessUpgradeQuery($this->name, $this->updateListProId('LIST_INBOX'));
$listQueries[] = new RunProcessUpgradeQuery($this->name, $this->updateListUsrId('LIST_INBOX'));
$listQueries[] = new RunProcessUpgradeQuery($this->name, $this->updateListTasId('LIST_INBOX'));
$listQueries[] = new RunProcessUpgradeQuery($this->name, $this->updateListAppStatusId('LIST_INBOX'));
// Participated List
$listQueries[] = new RunProcessUpgradeQuery($this->name, $this->updateListProId('LIST_PARTICIPATED_LAST'));
$listQueries[] = new RunProcessUpgradeQuery($this->name, $this->updateListUsrId('LIST_PARTICIPATED_LAST'));
$listQueries[] = new RunProcessUpgradeQuery($this->name, $this->updateListTasId('LIST_PARTICIPATED_LAST'));
$listQueries[] = new RunProcessUpgradeQuery($this->name, $this->updateListAppStatusId('LIST_PARTICIPATED_LAST'));
$listQueries[] = new RunProcessUpgradeQuery($this->name, $this->updateListParticipatedLastCurrentUser());
// Unassigned List
$listQueries[] = new RunProcessUpgradeQuery($this->name, $this->updateListProId('LIST_UNASSIGNED'));
$listQueries[] = new RunProcessUpgradeQuery($this->name, $this->updateListTasId('LIST_UNASSIGNED'));
// Updating PRO_ID field
$this->runUpdateListField(['LIST_CANCELED', 'LIST_INBOX', 'LIST_PARTICIPATED_LAST', 'LIST_UNASSIGNED'], 'updateListProId');
// Run queries in multiple threads for update the list tables
$processesManager = new ProcessesManager($listQueries);
$processesManager->run();
// Updating TAS_ID field
$this->runUpdateListField(['LIST_CANCELED', 'LIST_INBOX', 'LIST_PARTICIPATED_LAST', 'LIST_UNASSIGNED'], 'updateListTasId');
// If exists an error throw an exception
if (!empty($processesManager->getErrors())) {
$errorMessage = '';
foreach ($processesManager->getErrors() as $error) {
$errorMessage .= $error['rawAnswer'] . PHP_EOL;
}
throw new Exception($errorMessage);
}
// Updating USR_ID field
$this->runUpdateListField(['LIST_CANCELED', 'LIST_INBOX', 'LIST_PARTICIPATED_LAST'], 'updateListUsrId');
// Updating APP_STATUS_ID field
$this->runUpdateListField(['LIST_INBOX', 'LIST_PARTICIPATED_LAST'], 'updateListAppStatusId');
// Updating Last Current User Information
$this->runUpdateListField(['LIST_PARTICIPATED_LAST'], 'updateListParticipatedLastCurrentUser');
// Updating flags for the list population
$this->listFirstExecution('insert');
$this->listFirstExecution('insert', 'unassigned');
}
@@ -2986,6 +2967,37 @@ class WorkspaceTools
$stmt->executeQuery($this->updateListTasId('LIST_UNASSIGNED'));
}
/**
* Run the update queries for the specified tables
*
* @param array $listTables
* @param string $methodName
*
* @throws Exception
*/
public function runUpdateListField(array $listTables, $methodName) {
// Clean the queries array
$listQueries = [];
// Get the queries
foreach ($listTables as $listTable) {
$listQueries[] = new RunProcessUpgradeQuery($this->name, $this->$methodName($listTable));
}
// Run queries in multiple threads for update the list tables
$processesManager = new ProcessesManager($listQueries);
$processesManager->run();
// If exists an error throw an exception
if (!empty($processesManager->getErrors())) {
$errorMessage = '';
foreach ($processesManager->getErrors() as $error) {
$errorMessage .= $error['rawAnswer'] . PHP_EOL;
}
throw new Exception($errorMessage);
}
}
/**
* Return query to update PRO_ID in list table
*