2010-12-02 23:34:41 +00:00
< ? php
2013-03-14 15:50:49 -04:00
2010-12-02 23:34:41 +00:00
/**
* Utility functions to manage a workspace .
*
2011-11-08 17:37:47 -04:00
* @ author Alexandre Rosenfeld
2010-12-02 23:34:41 +00:00
*/
2017-03-29 15:12:11 -04:00
G :: LoadSystem ( 'dbMaintenance' );
G :: LoadClass ( " cli " );
G :: LoadClass ( " multipleFilesBackup " );
2011-11-08 17:37:47 -04:00
/**
2011-02-01 12:49:40 +00:00
* class workspaceTools
2012-10-18 13:05:23 -04:00
*
2011-02-03 11:13:21 +00:00
* @ package workflow . engine . classes
2011-02-01 12:49:40 +00:00
*/
2012-10-18 13:05:23 -04:00
class workspaceTools
{
2013-03-14 15:50:49 -04:00
public $name = null ;
public $path = null ;
public $db = null ;
public $dbPath = null ;
public $dbInfo = null ;
public $dbInfoRegExp = " /( *define * \ ( *'(?P<key>.*?)' *, * \n * *')(?P<value>.*?)(' * \ ) *;.*)/ " ;
public $initPropel = false ;
public $initPropelRoot = false ;
2017-03-08 18:08:52 -04:00
public static $populateIdsQueries = array (
' UPDATE LIST_CANCELED SET
USR_ID = ( SELECT USR_ID FROM USERS WHERE USERS . USR_UID = LIST_CANCELED . USR_UID ),
TAS_ID = ( SELECT TAS_ID FROM TASK WHERE TASK . TAS_UID = LIST_CANCELED . TAS_UID ),
PRO_ID = ( SELECT PRO_ID FROM PROCESS WHERE PROCESS . PRO_UID = LIST_CANCELED . PRO_UID ) ' ,
' UPDATE LIST_COMPLETED SET
USR_ID = ( SELECT USR_ID FROM USERS WHERE USERS . USR_UID = LIST_COMPLETED . USR_UID ),
TAS_ID = ( SELECT TAS_ID FROM TASK WHERE TASK . TAS_UID = LIST_COMPLETED . TAS_UID ),
PRO_ID = ( SELECT PRO_ID FROM PROCESS WHERE PROCESS . PRO_UID = LIST_COMPLETED . PRO_UID ) ' ,
' UPDATE LIST_INBOX SET
USR_ID = ( SELECT USR_ID FROM USERS WHERE USERS . USR_UID = LIST_INBOX . USR_UID ),
TAS_ID = ( SELECT TAS_ID FROM TASK WHERE TASK . TAS_UID = LIST_INBOX . TAS_UID ),
PRO_ID = ( SELECT PRO_ID FROM PROCESS WHERE PROCESS . PRO_UID = LIST_INBOX . PRO_UID ) ' ,
' UPDATE LIST_MY_INBOX SET
USR_ID = ( SELECT USR_ID FROM USERS WHERE USERS . USR_UID = LIST_MY_INBOX . USR_UID ),
TAS_ID = ( SELECT TAS_ID FROM TASK WHERE TASK . TAS_UID = LIST_MY_INBOX . TAS_UID ),
PRO_ID = ( SELECT PRO_ID FROM PROCESS WHERE PROCESS . PRO_UID = LIST_MY_INBOX . PRO_UID ) ' ,
' UPDATE LIST_PARTICIPATED_HISTORY SET
USR_ID = ( SELECT USR_ID FROM USERS WHERE USERS . USR_UID = LIST_PARTICIPATED_HISTORY . USR_UID ),
TAS_ID = ( SELECT TAS_ID FROM TASK WHERE TASK . TAS_UID = LIST_PARTICIPATED_HISTORY . TAS_UID ),
PRO_ID = ( SELECT PRO_ID FROM PROCESS WHERE PROCESS . PRO_UID = LIST_PARTICIPATED_HISTORY . PRO_UID ) ' ,
' UPDATE LIST_PARTICIPATED_LAST SET
USR_ID = ( SELECT USR_ID FROM USERS WHERE USERS . USR_UID = LIST_PARTICIPATED_LAST . USR_UID ),
TAS_ID = ( SELECT TAS_ID FROM TASK WHERE TASK . TAS_UID = LIST_PARTICIPATED_LAST . TAS_UID ),
PRO_ID = ( SELECT PRO_ID FROM PROCESS WHERE PROCESS . PRO_UID = LIST_PARTICIPATED_LAST . PRO_UID ) ' ,
' UPDATE LIST_PAUSED SET
USR_ID = ( SELECT USR_ID FROM USERS WHERE USERS . USR_UID = LIST_PAUSED . USR_UID ),
TAS_ID = ( SELECT TAS_ID FROM TASK WHERE TASK . TAS_UID = LIST_PAUSED . TAS_UID ),
PRO_ID = ( SELECT PRO_ID FROM PROCESS WHERE PROCESS . PRO_UID = LIST_PAUSED . PRO_UID ) ' ,
' UPDATE LIST_UNASSIGNED SET
TAS_ID = ( SELECT TAS_ID FROM TASK WHERE TASK . TAS_UID = LIST_UNASSIGNED . TAS_UID ),
PRO_ID = ( SELECT PRO_ID FROM PROCESS WHERE PROCESS . PRO_UID = LIST_UNASSIGNED . PRO_UID ) ' ,
' UPDATE LIST_UNASSIGNED_GROUP SET
USR_ID = ( SELECT USR_ID FROM USERS WHERE USERS . USR_UID = LIST_UNASSIGNED_GROUP . USR_UID ) ' ,
);
2012-10-18 13:05:23 -04:00
/**
* Create a workspace tools object .
* Note that workspace might not exist when
* this object is created , however most methods requires that a workspace with
* this name does exists .
*
* @ author Alexandre Rosenfeld < alexandre @ colosa . com >
* @ access public
* @ param string $workspaceName name of the workspace
*/
2013-03-14 15:50:49 -04:00
public function __construct ( $workspaceName )
2012-10-18 13:05:23 -04:00
{
$this -> name = $workspaceName ;
$this -> path = PATH_DB . $this -> name ;
$this -> dbPath = $this -> path . '/db.php' ;
if ( $this -> workspaceExists ()) {
$this -> getDBInfo ();
}
}
/**
* Returns true if the workspace already exists
*
* @ return bool
*/
2013-03-14 15:50:49 -04:00
public function workspaceExists ()
2012-10-18 13:05:23 -04:00
{
2013-03-14 15:50:49 -04:00
return ( file_exists ( $this -> path ) && file_exists ( $this -> dbPath ));
2012-10-18 13:05:23 -04:00
}
2010-12-02 23:34:41 +00:00
2012-09-26 10:15:20 -04:00
/**
* Upgrade this workspace to the latest system version
*
2016-09-21 15:26:01 -04:00
* @ param bool $buildCacheView
* @ param string $workSpace
* @ param bool $onedb
* @ param string $lang
* @ param array $arrayOptTranslation
*
* @ return void
2012-09-26 10:15:20 -04:00
*/
2016-09-21 15:26:01 -04:00
public function upgrade ( $buildCacheView = false , $workSpace = SYS_SYS , $onedb = false , $lang = 'en' , array $arrayOptTranslation = null )
2014-10-03 10:31:50 -04:00
{
2016-09-21 15:26:01 -04:00
if ( is_null ( $arrayOptTranslation )) {
$arrayOptTranslation = [ 'updateXml' => true , 'updateMafe' => true ];
}
2016-08-29 11:08:27 -04:00
$start = microtime ( true );
CLI :: logging ( " > Updating database... \n " );
$this -> upgradeDatabase ( $onedb );
$stop = microtime ( true );
CLI :: logging ( " <*> Database Upgrade Process took " . ( $stop - $start ) . " seconds. \n " );
$start = microtime ( true );
CLI :: logging ( " > Check Intermediate Email Event... \n " );
$this -> checkIntermediateEmailEvent ();
$stop = microtime ( true );
CLI :: logging ( " <*> Database Upgrade Process took " . ( $stop - $start ) . " seconds. \n " );
$start = microtime ( true );
CLI :: logging ( " > Verify enterprise old... \n " );
$this -> verifyFilesOldEnterprise ( $workSpace );
$stop = microtime ( true );
CLI :: logging ( " <*> Verify took " . ( $stop - $start ) . " seconds. \n " );
$start = microtime ( true );
CLI :: logging ( " > Updating translations... \n " );
2016-09-21 15:26:01 -04:00
$this -> upgradeTranslation ( $arrayOptTranslation [ 'updateXml' ], $arrayOptTranslation [ 'updateMafe' ]);
2016-08-29 11:08:27 -04:00
$stop = microtime ( true );
$final = $stop - $start ;
CLI :: logging ( " <*> Updating Translations Process took $final seconds. \n " );
$start = microtime ( true );
CLI :: logging ( " > Updating Content... \n " );
$this -> upgradeContent ( $workSpace );
$stop = microtime ( true );
$final = $stop - $start ;
CLI :: logging ( " <*> Updating Content Process took $final seconds. \n " );
$start = microtime ( true );
CLI :: logging ( " > Check Mafe Requirements... \n " );
$this -> checkMafeRequirements ( $workSpace , $lang );
$stop = microtime ( true );
$final = $stop - $start ;
CLI :: logging ( " <*> Check Mafe Requirements Process took $final seconds. \n " );
$start = microtime ( true );
CLI :: logging ( " > Backup log files... \n " );
$this -> backupLogFiles ();
$stop = microtime ( true );
$final = $stop - $start ;
CLI :: logging ( " <*> Backup log files Process took $final seconds. \n " );
2017-03-09 09:51:33 -04:00
$start = microtime ( true );
CLI :: logging ( " > Optimizing content data... \n " );
$this -> migrateContent ( $workSpace , $lang );
$stop = microtime ( true );
CLI :: logging ( " <*> Optimizing content data took " . ( $stop - $start ) . " seconds. \n " );
2016-08-29 11:08:27 -04:00
/*----------------------------------********---------------------------------*/
$start = microtime ( true );
CLI :: logging ( " > Migrate new lists... \n " );
$this -> migrateList ( $workSpace , false , $lang );
$stop = microtime ( true );
$final = $stop - $start ;
CLI :: logging ( " <*> Migrate new lists Process took $final seconds. \n " );
/*----------------------------------********---------------------------------*/
$start = microtime ( true );
CLI :: logging ( " > Updating Files Manager... \n " );
$this -> processFilesUpgrade ();
$stop = microtime ( true );
CLI :: logging ( " <*> Updating Files Manager took " . ( $stop - $start ) . " seconds. \n " );
2014-09-19 12:06:13 -04:00
$start = microtime ( true );
2016-08-29 11:06:44 -04:00
CLI :: logging ( " > Clean access and refresh tokens... \n " );
$this -> cleanTokens ( $workSpace );
2014-09-19 12:06:13 -04:00
$stop = microtime ( true );
2016-08-29 11:06:44 -04:00
CLI :: logging ( " <*> Clean access and refresh tokens took " . ( $stop - $start ) . " seconds. \n " );
2016-12-21 17:06:01 -04:00
$start = microtime ( true );
CLI :: logging ( " > Optimizing Self-Service data... \n " );
$this -> migrateSelfServiceRecordsRun ( $workSpace );
$stop = microtime ( true );
CLI :: logging ( " <*> Migrating Self-Service records Process took " . ( $stop - $start ) . " seconds. \n " );
2017-01-10 17:51:08 -04:00
$start = microtime ( true );
2017-02-13 14:50:48 -04:00
CLI :: logging ( " > Migrating and populating indexing for avoiding the use of table APP_CACHE_VIEW... \n " );
2017-01-10 17:51:08 -04:00
$this -> migratePopulateIndexingACV ( $workSpace );
$stop = microtime ( true );
2017-02-13 14:50:48 -04:00
CLI :: logging ( " <*> Migrating an populating indexing for avoiding the use of table APP_CACHE_VIEW process took " . ( $stop - $start ) . " seconds. \n " );
2017-03-09 18:24:34 -04:00
$start = microtime ( true );
CLI :: logging ( " > Updating rows in Web Entry table for classic processes... \n " );
$this -> updatingWebEntryClassicModel ( $workSpace );
$stop = microtime ( true );
CLI :: logging ( " <*> Updating rows in Web Entry table for classic processes took " . ( $stop - $start ) . " seconds. \n " );
2013-06-25 13:50:38 -04:00
}
2013-06-19 10:38:48 -04:00
2013-06-25 13:50:38 -04:00
/**
* Updating cases directories structure
*
*/
public function updateStructureDirectories ( $workSpace = SYS_SYS )
{
2013-04-29 16:48:29 -04:00
$start = microtime ( true );
CLI :: logging ( " > Updating cases directories structure... \n " );
$this -> upgradeCasesDirectoryStructure ( $workSpace );
$stop = microtime ( true );
$final = $stop - $start ;
2013-05-20 10:02:16 -04:00
CLI :: logging ( " <*> Database Upgrade Structure Process took $final seconds. \n " );
2012-09-26 10:15:20 -04:00
}
2010-12-16 20:36:29 +00:00
2016-08-12 16:49:21 -04:00
public function checkIntermediateEmailEvent ()
{
$oEmailEvent = new \ProcessMaker\BusinessModel\EmailEvent ();
$oEmailServer = new \ProcessMaker\BusinessModel\EmailServer ();
$oCriteria = $oEmailEvent -> getEmailEventCriteriaEmailServer ();
$rsCriteria = \EmailServerPeer :: doSelectRS ( $oCriteria );
$rsCriteria -> setFetchmode ( \ResultSet :: FETCHMODE_ASSOC );
while ( $rsCriteria -> next ()) {
$row = $rsCriteria -> getRow ();
$newUidData = $oEmailServer -> getUidEmailServer ( $row [ 'EMAIL_EVENT_FROM' ]);
if ( is_array ( $newUidData )) {
$oEmailEvent -> update ( $row [ 'EMAIL_EVENT_UID' ], $newUidData );
}
}
}
2012-10-18 13:05:23 -04:00
/**
* Scan the db . php file for database information and return it as an array
*
* @ return array with database information
2010-12-16 20:36:29 +00:00
*/
2013-03-14 15:50:49 -04:00
public function getDBInfo ()
2012-10-18 13:05:23 -04:00
{
2013-03-14 15:50:49 -04:00
if ( ! $this -> workspaceExists ()) {
throw new Exception ( " Could not get db.php in workspace " . $this -> name );
2012-10-18 13:05:23 -04:00
}
2013-03-14 15:50:49 -04:00
if ( isset ( $this -> dbInfo )) {
2012-10-18 13:05:23 -04:00
return $this -> dbInfo ;
}
2013-03-14 15:50:49 -04:00
$sDbFile = file_get_contents ( $this -> dbPath );
2012-10-18 13:05:23 -04:00
/* This regular expression will match any " define ('<key>', '<value>'); "
* with any combination of whitespace between words .
* Each match will have these groups :
* (( define ( '(<key>)2' , ')1 (<value>)3 (' );) 4 ) 0
*/
2013-03-14 15:50:49 -04:00
preg_match_all ( $this -> dbInfoRegExp , $sDbFile , $matches , PREG_SET_ORDER );
$values = array ();
2012-10-18 13:05:23 -04:00
foreach ( $matches as $match ) {
$values [ $match [ 'key' ]] = $match [ 'value' ];
}
$this -> dbAdapter = $values [ " DB_ADAPTER " ];
$this -> dbName = $values [ " DB_NAME " ];
$this -> dbHost = $values [ " DB_HOST " ];
$this -> dbUser = $values [ " DB_USER " ];
$this -> dbPass = $values [ " DB_PASS " ];
2014-01-17 14:39:29 -04:00
$this -> dbRbacHost = $values [ " DB_RBAC_HOST " ];
$this -> dbRbacName = $values [ " DB_RBAC_NAME " ];
$this -> dbRbacUser = $values [ " DB_RBAC_USER " ];
2013-11-21 09:10:42 -04:00
$this -> dbRbacPass = $values [ " DB_RBAC_PASS " ];
2012-10-18 13:05:23 -04:00
return $this -> dbInfo = $values ;
2010-12-02 23:34:41 +00:00
}
2012-10-18 13:05:23 -04:00
2013-03-14 15:50:49 -04:00
private function resetDBInfoCallback ( $matches )
2014-10-03 10:31:50 -04:00
{
2012-10-18 13:05:23 -04:00
/* This function changes the values of defines while keeping their formatting
* intact .
* $matches will contain several groups :
* (( define ( '(<key>)2' , ')1 (<value>)3 (' );) 4 ) 0
2011-01-14 23:11:13 +00:00
*/
2013-05-13 09:45:56 -04:00
$key = isset ( $matches [ 'key' ]) ? $matches [ 'key' ] : $matches [ 2 ];
$value = isset ( $matches [ 'value' ]) ? $matches [ 'value' ] : $matches [ 3 ];
2014-10-03 10:31:50 -04:00
2016-03-03 12:09:38 -04:00
if ( $this -> onedb ) {
$dbInfo = $this -> getDBInfo ();
2016-11-04 17:10:36 -04:00
$dbPrefix = array ( 'DB_NAME' => 'wf_' , 'DB_RBAC_NAME' => 'wf_' , 'DB_REPORT_NAME' => 'wf_' );
$dbPrefixUser = array ( 'DB_USER' => 'wf_' , 'DB_RBAC_USER' => 'wf_' , 'DB_REPORT_USER' => 'wf_' );
2016-03-03 12:09:38 -04:00
} else {
2016-11-04 17:10:36 -04:00
$dbPrefix = array ( 'DB_NAME' => 'wf_' , 'DB_RBAC_NAME' => 'rb_' , 'DB_REPORT_NAME' => 'rp_' );
$dbPrefixUser = array ( 'DB_USER' => 'wf_' , 'DB_RBAC_USER' => 'rb_' , 'DB_REPORT_USER' => 'rp_' );
2014-09-04 16:28:17 -04:00
}
2013-03-14 15:50:49 -04:00
if ( array_search ( $key , array ( 'DB_HOST' , 'DB_RBAC_HOST' , 'DB_REPORT_HOST' )) !== false ) {
2012-10-18 13:05:23 -04:00
/* Change the database hostname for these keys */
$value = $this -> newHost ;
2013-03-14 15:50:49 -04:00
} elseif ( array_key_exists ( $key , $dbPrefix )) {
2012-10-18 13:05:23 -04:00
if ( $this -> resetDBNames ) {
/* Change the database name to the new workspace , following the standard
* of prefix ( either wf_ , rp_ , rb_ ) and the workspace name .
*/
2016-03-03 12:09:38 -04:00
if ( $this -> unify ) {
$nameDb = explode ( " _ " , $value );
if ( ! isset ( $nameDb [ 1 ])) {
$dbName = $value ;
} else {
$dbName = $dbPrefix [ $key ] . $nameDb [ 1 ];
}
} else {
$dbName = $dbPrefix [ $key ] . $this -> name ;
}
2012-10-18 13:05:23 -04:00
} else {
$dbName = $value ;
}
$this -> resetDBDiff [ $value ] = $dbName ;
$value = $dbName ;
2016-11-04 17:10:36 -04:00
} elseif ( array_key_exists ( $key , $dbPrefixUser )) {
if ( $this -> resetDBNames ) {
$dbName = $this -> dbGrantUser ;
} else {
$dbName = $value ;
}
$this -> resetDBDiff [ 'DB_USER' ] = $dbName ;
$value = $dbName ;
2012-10-18 13:05:23 -04:00
}
2017-02-14 15:09:57 -04:00
if ( array_search ( $key , array ( 'DB_PASS' , 'DB_RBAC_PASS' , 'DB_REPORT_PASS' )) !== false && ! empty ( $this -> dbGrantUserPassword )) {
$value = $this -> dbGrantUserPassword ;
}
2012-10-18 13:05:23 -04:00
return $matches [ 1 ] . $value . $matches [ 4 ];
2011-01-14 23:11:13 +00:00
}
2012-10-18 13:05:23 -04:00
/**
* Reset the database information to that of a newly created workspace .
*
* This assumes this workspace already has a db . php file , which will be changed
* to contain the new information .
* This function will reset the database hostname to the system database .
* If reseting database names , it will also use the the prefixes rp_ ,
* rb_ and wf_ , with the workspace name as database names .
*
* @ param string $newHost the new hostname for the database
* @ param bool $resetDBNames if true , also reset all database names
* @ return array contains the new database names as values
2011-01-14 23:11:13 +00:00
*/
2014-10-27 18:14:16 -04:00
public function resetDBInfo ( $newHost , $resetDBNames = true , $onedb = false , $unify = false )
2012-10-18 13:05:23 -04:00
{
2013-03-14 15:50:49 -04:00
if ( count ( explode ( " : " , $newHost )) < 2 ) {
2012-10-18 13:05:23 -04:00
$newHost .= ':3306' ;
}
$this -> newHost = $newHost ;
$this -> resetDBNames = $resetDBNames ;
2013-03-14 15:50:49 -04:00
$this -> resetDBDiff = array ();
2014-10-09 10:36:34 -04:00
$this -> onedb = $onedb ;
2014-10-27 18:14:16 -04:00
$this -> unify = $unify ;
2016-11-04 17:10:36 -04:00
if ( $resetDBNames ) {
$this -> dbGrantUser = uniqid ( 'wf_' );
2017-02-14 15:09:57 -04:00
$this -> dbGrantUserPassword = G :: generate_password ( 12 , " luns " , " . " );
2016-11-04 17:10:36 -04:00
}
2012-10-18 13:05:23 -04:00
2013-03-14 15:50:49 -04:00
if ( ! $this -> workspaceExists ()) {
throw new Exception ( " Could not find db.php in the workspace " );
2012-10-18 13:05:23 -04:00
}
2013-03-14 15:50:49 -04:00
$sDbFile = file_get_contents ( $this -> dbPath );
2014-10-03 10:31:50 -04:00
2012-10-18 13:05:23 -04:00
if ( $sDbFile === false ) {
2013-03-14 15:50:49 -04:00
throw new Exception ( " Could not read database information from db.php " );
}
/* Match all defines in the config file . Check updateDBCallback to know what
* keys are changed and what groups are matched .
* This regular expression will match any " define ('<key>', '<value>'); "
* with any combination of whitespace between words .
*/
$sNewDbFile = preg_replace_callback ( " /( *define * \ ( *'(?P<key>.*?)' *, * \n * *')(?P<value>.*?)(' * \ ) *;.*)/ " , array ( & $this , 'resetDBInfoCallback' ), $sDbFile );
if ( file_put_contents ( $this -> dbPath , $sNewDbFile ) === false ) {
throw new Exception ( " Could not write database information to db.php " );
2012-10-18 13:05:23 -04:00
}
$newDBNames = $this -> resetDBDiff ;
2013-03-14 15:50:49 -04:00
unset ( $this -> resetDBDiff );
unset ( $this -> resetDBNames );
2012-10-18 13:05:23 -04:00
//Clear the cached information about db.php
2013-03-14 15:50:49 -04:00
unset ( $this -> dbInfo );
2012-10-18 13:05:23 -04:00
return $newDBNames ;
}
/**
* Get DB information for this workspace , such as hostname , username and password .
*
* @ param string $dbName a db name , such as wf , rp and rb
* @ return array with all the database information .
*/
2013-03-14 15:50:49 -04:00
public function getDBCredentials ( $dbName )
2012-10-18 13:05:23 -04:00
{
2013-03-14 15:50:49 -04:00
$prefixes = array ( " wf " => " " , " rp " => " REPORT_ " , " rb " => " RBAC_ " );
2012-10-18 13:05:23 -04:00
$prefix = $prefixes [ $dbName ];
$dbInfo = $this -> getDBInfo ();
2013-03-14 15:50:49 -04:00
return array ( 'adapter' => $dbInfo [ " DB_ADAPTER " ], 'name' => $dbInfo [ " DB_ " . $prefix . " NAME " ], 'host' => $dbInfo [ " DB_ " . $prefix . " HOST " ], 'user' => $dbInfo [ " DB_ " . $prefix . " USER " ], 'pass' => $dbInfo [ " DB_ " . $prefix . " PASS " ], 'dsn' => sprintf ( " %s://%s:%s@%s/%s?encoding=utf8 " , $dbInfo [ 'DB_ADAPTER' ], $dbInfo [ " DB_ " . $prefix . " USER " ], $dbInfo [ " DB_ " . $prefix . " PASS " ], $dbInfo [ " DB_ " . $prefix . " HOST " ], $dbInfo [ " DB_ " . $prefix . " NAME " ]));
2012-10-18 13:05:23 -04:00
}
/**
* Initialize a Propel connection to the database
*
* @ param bool $root wheter to also initialize a root connection
* @ return the Propel connection
*/
2013-03-14 15:50:49 -04:00
public function initPropel ( $root = false )
2012-10-18 13:05:23 -04:00
{
2013-03-14 15:50:49 -04:00
if (( $this -> initPropel && ! $root ) || ( $this -> initPropelRoot && $root )) {
2012-10-18 13:05:23 -04:00
return ;
}
2013-03-14 15:50:49 -04:00
$wfDetails = $this -> getDBCredentials ( " wf " );
$rbDetails = $this -> getDBCredentials ( " rb " );
$rpDetails = $this -> getDBCredentials ( " rp " );
2012-10-18 13:05:23 -04:00
2013-03-14 15:50:49 -04:00
$config = array ( 'datasources' => array ( 'workflow' => array ( 'connection' => $wfDetails [ " dsn " ], 'adapter' => $wfDetails [ " adapter " ]
2016-03-03 12:09:38 -04:00
), 'rbac' => array ( 'connection' => $rbDetails [ " dsn " ], 'adapter' => $rbDetails [ " adapter " ]
), 'rp' => array ( 'connection' => $rpDetails [ " dsn " ], 'adapter' => $rpDetails [ " adapter " ]
)
)
2012-10-18 13:05:23 -04:00
);
2010-12-16 20:36:29 +00:00
2012-10-18 13:05:23 -04:00
if ( $root ) {
2013-03-14 15:50:49 -04:00
$dbHash = @ explode ( SYSTEM_HASH , G :: decrypt ( HASH_INSTALLATION , SYSTEM_HASH ));
2010-12-16 20:36:29 +00:00
2012-10-18 13:05:23 -04:00
$dbInfo = $this -> getDBInfo ();
$host = $dbHash [ 0 ];
$user = $dbHash [ 1 ];
$pass = $dbHash [ 2 ];
$dbName = $dbInfo [ " DB_NAME " ];
2010-12-16 20:36:29 +00:00
2013-03-14 15:50:49 -04:00
$rootConfig = array (
'datasources' => array ( 'root' => array ( 'connection' => " mysql:// $user : $pass @ $host / $dbName ?encoding=utf8 " , 'adapter' => " mysql " ))
2012-10-18 13:05:23 -04:00
);
2010-12-16 20:36:29 +00:00
2013-03-14 15:50:49 -04:00
$config [ " datasources " ] = array_merge ( $config [ " datasources " ], $rootConfig [ " datasources " ]);
2010-12-16 20:36:29 +00:00
2012-10-18 13:05:23 -04:00
$this -> initPropelRoot = true ;
}
2010-12-02 23:34:41 +00:00
2012-10-18 13:05:23 -04:00
$this -> initPropel = true ;
2010-12-02 23:34:41 +00:00
2016-03-03 12:09:38 -04:00
require_once ( " propel/Propel.php " );
require_once ( " creole/Creole.php " );
2010-12-16 20:36:29 +00:00
2013-03-14 15:50:49 -04:00
Propel :: initConfiguration ( $config );
2012-10-18 13:05:23 -04:00
}
2010-12-16 20:36:29 +00:00
2012-10-18 13:05:23 -04:00
/**
* Close the propel connection from initPropel
*/
2013-03-14 15:50:49 -04:00
private function closePropel ()
2012-10-18 13:05:23 -04:00
{
Propel :: close ();
$this -> initPropel = false ;
$this -> initPropelRoot = false ;
}
2010-12-16 20:36:29 +00:00
2012-09-26 10:15:20 -04:00
/**
* Upgrade this workspace Content .
*/
2013-03-14 15:50:49 -04:00
public function upgradeContent ( $workSpace = SYS_SYS )
2012-10-18 13:05:23 -04:00
{
2013-03-14 15:50:49 -04:00
$this -> initPropel ( true );
2012-12-14 16:42:57 -04:00
//require_once 'classes/model/Translation.php';
2012-10-12 14:57:51 -04:00
$translation = new Translation ();
$information = $translation -> getTranslationEnvironments ();
2013-03-14 15:50:49 -04:00
$arrayLang = array ();
2012-10-12 14:57:51 -04:00
foreach ( $information as $key => $value ) {
2013-03-14 15:50:49 -04:00
$arrayLang [] = trim ( $value [ 'LOCALE' ]);
2012-09-26 10:15:20 -04:00
}
2012-12-14 16:42:57 -04:00
//require_once ('classes/model/Content.php');
2012-09-26 10:15:20 -04:00
$regenerateContent = new Content ();
2013-03-14 15:50:49 -04:00
$regenerateContent -> regenerateContent ( $arrayLang , $workSpace );
2012-09-26 10:15:20 -04:00
}
2012-10-18 13:05:23 -04:00
/**
* Upgrade this workspace translations from all avaliable languages .
*
2016-09-21 15:26:01 -04:00
* @ param bool $flagXml Update XML
* @ param bool $flagMafe Update MAFE
*
* @ return void
2012-10-18 13:05:23 -04:00
*/
2016-09-21 15:26:01 -04:00
public function upgradeTranslation ( $flagXml = true , $flagMafe = true )
2012-10-18 13:05:23 -04:00
{
2013-03-14 15:50:49 -04:00
$this -> initPropel ( true );
2016-09-27 14:01:06 -04:00
$this -> checkDataConsistenceInContentTable ();
2013-03-14 15:50:49 -04:00
G :: LoadThirdParty ( 'pear/json' , 'class.json' );
2016-09-21 15:26:01 -04:00
$language = new Language ();
2012-10-18 13:05:23 -04:00
foreach ( System :: listPoFiles () as $poFile ) {
2013-03-14 15:50:49 -04:00
$poName = basename ( $poFile );
$names = explode ( " . " , basename ( $poFile ));
$extension = array_pop ( $names );
$langid = array_pop ( $names );
2016-09-21 15:26:01 -04:00
CLI :: logging ( 'Updating Database translations with ' . $poName . " \n " );
if ( $flagXml ) {
CLI :: logging ( 'Updating XML form translations with ' . $poName . " \n " );
2012-10-18 13:05:23 -04:00
}
2016-09-21 15:26:01 -04:00
if ( $flagMafe ) {
CLI :: logging ( 'Updating MAFE translations with ' . $poName . " \n " );
}
$language -> import ( $poFile , $flagXml , true , $flagMafe );
2012-10-18 13:05:23 -04:00
}
2010-12-02 23:34:41 +00:00
}
2016-09-27 14:01:06 -04:00
/**
* Verification of the Content data table for column CON_ID
* @ return void
*/
private function checkDataConsistenceInContentTable ()
{
$criteriaSelect = new Criteria ( " workflow " );
$criteriaSelect -> add (
$criteriaSelect -> getNewCriterion ( ContentPeer :: CON_ID , '%' . " ' " . '%' , Criteria :: LIKE ) -> addOr (
$criteriaSelect -> getNewCriterion ( ContentPeer :: CON_ID , '%' . '"' . '%' , Criteria :: LIKE )));
BasePeer :: doDelete ( $criteriaSelect , Propel :: getConnection ( " workflow " ));
}
2012-10-18 13:05:23 -04:00
/**
* Get a connection to this workspace wf database
*
* @ return database connection
*/
2013-11-21 09:10:42 -04:00
private function getDatabase ( $rbac = false )
2014-10-27 11:25:17 -04:00
{
2015-07-28 09:55:05 -04:00
if ( isset ( $this -> db ) && $this -> db -> isConnected () && ( $rbac == false && $this -> db -> getDatabaseName () == $this -> dbName )) {
2012-10-18 13:05:23 -04:00
return $this -> db ;
}
2013-11-21 09:10:42 -04:00
2013-03-14 15:50:49 -04:00
G :: LoadSystem ( 'database_' . strtolower ( $this -> dbAdapter ));
2016-03-03 12:09:38 -04:00
if ( $rbac == true ) {
2013-11-21 09:10:42 -04:00
$this -> db = new database ( $this -> dbAdapter , $this -> dbRbacHost , $this -> dbRbacUser , $this -> dbRbacPass , $this -> dbRbacName );
} else {
2016-03-03 12:09:38 -04:00
$this -> db = new database ( $this -> dbAdapter , $this -> dbHost , $this -> dbUser , $this -> dbPass , $this -> dbName );
2013-11-21 09:10:42 -04:00
}
2013-03-14 15:50:49 -04:00
if ( ! $this -> db -> isConnected ()) {
$this -> db -> logQuery ( 'No available connection to database!' );
throw new Exception ( " Could not connect to database " );
2012-10-18 13:05:23 -04:00
}
return $this -> db ;
2010-12-02 23:34:41 +00:00
}
2014-01-17 14:39:29 -04:00
2012-10-18 13:05:23 -04:00
/**
* Close any database opened with getDatabase
*/
2013-03-14 15:50:49 -04:00
private function closeDatabase ()
2012-10-18 13:05:23 -04:00
{
2013-03-14 15:50:49 -04:00
if ( ! isset ( $this -> db )) {
2012-10-18 13:05:23 -04:00
return ;
}
$this -> db -> close ();
$this -> db = null ;
2010-12-02 23:34:41 +00:00
}
2012-10-18 13:05:23 -04:00
/**
* Close all currently opened databases
*/
2013-03-14 15:50:49 -04:00
public function close ()
2012-10-18 13:05:23 -04:00
{
$this -> closePropel ();
$this -> closeDatabase ();
2010-12-02 23:34:41 +00:00
}
2012-10-18 13:05:23 -04:00
/**
* Get the current workspace database schema
*
* @ return array with the database schema
*/
2013-11-22 13:54:30 -04:00
public function getSchema ( $rbac = false )
2012-10-18 13:05:23 -04:00
{
2016-03-03 12:09:38 -04:00
$oDataBase = $this -> getDatabase ( $rbac );
2010-12-02 23:34:41 +00:00
2013-03-14 15:50:49 -04:00
$aOldSchema = array ();
2010-12-02 23:34:41 +00:00
2012-10-18 13:05:23 -04:00
try {
$oDataBase -> iFetchType = MYSQL_NUM ;
2013-03-14 15:50:49 -04:00
$oDataset1 = $oDataBase -> executeQuery ( $oDataBase -> generateShowTablesSQL ());
2012-10-18 13:05:23 -04:00
} catch ( Exception $e ) {
2013-03-14 15:50:49 -04:00
$oDataBase -> logQuery ( $e -> getmessage ());
2012-10-18 13:05:23 -04:00
return null ;
2010-12-02 23:34:41 +00:00
}
2012-10-18 13:05:23 -04:00
//going thru all tables in current WF_ database
2013-03-14 15:50:49 -04:00
while ( $aRow1 = $oDataBase -> getRegistry ( $oDataset1 )) {
$aPrimaryKeys = array ();
$sTable = strtoupper ( $aRow1 [ 0 ]);
2012-10-18 13:05:23 -04:00
//get description of each table, ( column and primary keys )
//$oDataset2 = $oDataBase->executeQuery( $oDataBase->generateDescTableSQL($aRow1[0]) );
2013-03-14 15:50:49 -04:00
$oDataset2 = $oDataBase -> executeQuery ( $oDataBase -> generateDescTableSQL ( $sTable ));
$aOldSchema [ $sTable ] = array ();
2012-10-18 13:05:23 -04:00
$oDataBase -> iFetchType = MYSQL_ASSOC ;
2013-03-14 15:50:49 -04:00
while ( $aRow2 = $oDataBase -> getRegistry ( $oDataset2 )) {
2012-10-18 13:05:23 -04:00
$aOldSchema [ $sTable ][ $aRow2 [ 'Field' ]][ 'Field' ] = $aRow2 [ 'Field' ];
$aOldSchema [ $sTable ][ $aRow2 [ 'Field' ]][ 'Type' ] = $aRow2 [ 'Type' ];
$aOldSchema [ $sTable ][ $aRow2 [ 'Field' ]][ 'Null' ] = $aRow2 [ 'Null' ];
$aOldSchema [ $sTable ][ $aRow2 [ 'Field' ]][ 'Default' ] = $aRow2 [ 'Default' ];
}
//get indexes of each table SHOW INDEX FROM `ADDITIONAL_TABLES`; -- WHERE Key_name <> 'PRIMARY'
2013-03-14 15:50:49 -04:00
$oDataset2 = $oDataBase -> executeQuery ( $oDataBase -> generateTableIndexSQL ( $aRow1 [ 0 ]));
2012-10-18 13:05:23 -04:00
$oDataBase -> iFetchType = MYSQL_ASSOC ;
2013-03-14 15:50:49 -04:00
while ( $aRow2 = $oDataBase -> getRegistry ( $oDataset2 )) {
if ( ! isset ( $aOldSchema [ $sTable ][ 'INDEXES' ])) {
$aOldSchema [ $sTable ][ 'INDEXES' ] = array ();
2012-10-18 13:05:23 -04:00
}
2013-03-14 15:50:49 -04:00
if ( ! isset ( $aOldSchema [ $sTable ][ 'INDEXES' ][ $aRow2 [ 'Key_name' ]])) {
$aOldSchema [ $sTable ][ 'INDEXES' ][ $aRow2 [ 'Key_name' ]] = array ();
2012-10-18 13:05:23 -04:00
}
$aOldSchema [ $sTable ][ 'INDEXES' ][ $aRow2 [ 'Key_name' ]][] = $aRow2 [ 'Column_name' ];
}
$oDataBase -> iFetchType = MYSQL_NUM ; //this line is neccesary because the next fetch needs to be with MYSQL_NUM
}
//finally return the array with old schema obtained from the Database
2013-03-14 15:50:49 -04:00
if ( count ( $aOldSchema ) == 0 ) {
2012-10-18 13:05:23 -04:00
$aOldSchema = null ;
}
return $aOldSchema ;
2010-12-02 23:34:41 +00:00
}
2015-08-12 09:30:43 -04:00
/**
* Upgrade triggers of tables ( Database )
*
2016-03-03 12:09:38 -04:00
* @ param bool $flagRecreate Recreate
* @ param string $language Language
2015-08-12 09:30:43 -04:00
*
* return void
*/
private function upgradeTriggersOfTables ( $flagRecreate , $language )
{
try {
$appCacheView = new AppCacheView ();
$appCacheView -> setPathToAppCacheFiles ( PATH_METHODS . " setup " . PATH_SEP . " setupSchemas " . PATH_SEP );
$result = $appCacheView -> triggerAppDelegationInsert ( $language , $flagRecreate );
$result = $appCacheView -> triggerAppDelegationUpdate ( $language , $flagRecreate );
$result = $appCacheView -> triggerApplicationUpdate ( $language , $flagRecreate );
$result = $appCacheView -> triggerApplicationDelete ( $language , $flagRecreate );
$result = $appCacheView -> triggerSubApplicationInsert ( $language , $flagRecreate );
$result = $appCacheView -> triggerContentUpdate ( $language , $flagRecreate );
} catch ( Exception $e ) {
throw $e ;
}
}
2012-10-18 13:05:23 -04:00
/**
* Upgrade the AppCacheView table to the latest system version .
*
* This recreates the table and populates with data .
*
2015-08-12 09:30:43 -04:00
* @ param bool $flagRecreate only check if the upgrade is needed if true
2012-10-18 13:05:23 -04:00
* @ param string $lang not currently used
*/
2015-08-12 09:30:43 -04:00
public function upgradeCacheView ( $fill = true , $flagRecreate = false , $lang = " en " )
2014-10-03 10:31:50 -04:00
{
2013-03-14 15:50:49 -04:00
$this -> initPropel ( true );
2012-10-18 13:05:23 -04:00
2012-12-14 16:42:57 -04:00
//require_once ('classes/model/AppCacheView.php');
2012-10-18 13:05:23 -04:00
//check the language, if no info in config about language, the default is 'en'
2012-12-14 16:42:57 -04:00
G :: LoadClass ( " configuration " );
2012-10-18 13:05:23 -04:00
$oConf = new Configurations ();
2013-03-14 15:50:49 -04:00
$oConf -> loadConfig ( $x , 'APP_CACHE_VIEW_ENGINE' , '' , '' , '' , '' );
2012-10-18 13:05:23 -04:00
$appCacheViewEngine = $oConf -> aConfig ;
//setup the appcacheview object, and the path for the sql files
$appCache = new AppCacheView ();
2013-03-14 15:50:49 -04:00
$appCache -> setPathToAppCacheFiles ( PATH_METHODS . 'setup' . PATH_SEP . 'setupSchemas' . PATH_SEP );
2014-10-03 10:31:50 -04:00
2013-03-14 15:50:49 -04:00
$userGrants = $appCache -> checkGrantsForUser ( false );
2014-10-03 10:31:50 -04:00
2012-10-18 13:05:23 -04:00
$currentUser = $userGrants [ 'user' ];
$currentUserIsSuper = $userGrants [ 'super' ];
//if user does not have the SUPER privilege we need to use the root user and grant the SUPER priv. to normal user.
2014-10-03 10:31:50 -04:00
2013-03-14 15:50:49 -04:00
if ( ! $currentUserIsSuper ) {
$appCache -> checkGrantsForUser ( true );
$appCache -> setSuperForUser ( $currentUser );
2012-10-18 13:05:23 -04:00
$currentUserIsSuper = true ;
}
2014-10-03 10:31:50 -04:00
2014-09-17 10:51:36 -04:00
CLI :: logging ( " -> Creating tables \n " );
2012-10-18 13:05:23 -04:00
//now check if table APPCACHEVIEW exists, and it have correct number of fields, etc.
$res = $appCache -> checkAppCacheView ();
2014-09-17 10:51:36 -04:00
CLI :: logging ( " -> Update DEL_LAST_INDEX field in APP_DELEGATION table \n " );
2013-01-28 16:49:00 -04:00
//Update APP_DELEGATION.DEL_LAST_INDEX data
2015-08-12 09:30:43 -04:00
$res = $appCache -> updateAppDelegationDelLastIndex ( $lang , $flagRecreate );
2014-10-03 10:31:50 -04:00
2016-03-03 12:09:38 -04:00
2013-06-19 10:38:48 -04:00
2013-03-14 15:50:49 -04:00
CLI :: logging ( " -> Creating triggers \n " );
2015-08-12 09:30:43 -04:00
2012-10-18 13:05:23 -04:00
//now check if we have the triggers installed
2015-08-12 09:30:43 -04:00
$this -> upgradeTriggersOfTables ( $flagRecreate , $lang );
2012-10-18 13:05:23 -04:00
if ( $fill ) {
2013-05-17 10:39:48 -04:00
CLI :: logging ( " -> Rebuild Cache View with language $lang ... \n " );
2012-10-18 13:05:23 -04:00
//build using the method in AppCacheView Class
2013-03-14 15:50:49 -04:00
$res = $appCache -> fillAppCacheView ( $lang );
2012-10-18 13:05:23 -04:00
}
2014-06-03 11:21:25 -04:00
//set status in config table
$confParams = Array ( 'LANG' => $lang , 'STATUS' => 'active' );
2012-10-18 13:05:23 -04:00
$oConf -> aConfig = $confParams ;
2013-03-14 15:50:49 -04:00
$oConf -> saveConfig ( 'APP_CACHE_VIEW_ENGINE' , '' , '' , '' );
2012-10-18 13:05:23 -04:00
// removing casesList configuration records. TODO: removing these lines that resets all the configurations records
$oCriteria = new Criteria ();
2013-03-14 15:50:49 -04:00
$oCriteria -> add ( ConfigurationPeer :: CFG_UID , " casesList " );
$oCriteria -> add ( ConfigurationPeer :: OBJ_UID , array ( " todo " , " draft " , " sent " , " unassigned " , " paused " , " cancelled " ), Criteria :: NOT_IN );
ConfigurationPeer :: doDelete ( $oCriteria );
2012-10-18 13:05:23 -04:00
// end of reset
2014-07-31 17:00:31 -04:00
//close connection
2014-10-27 18:22:22 -04:00
if ( substr ( PHP_OS , 0 , 3 ) != 'WIN' ) {
2016-03-03 12:09:38 -04:00
$connection = Propel :: getConnection ( 'workflow' );
2014-07-31 17:00:31 -04:00
2014-10-27 18:22:22 -04:00
$sql_sleep = " SELECT * FROM information_schema.processlist WHERE command = 'Sleep' and user = SUBSTRING_INDEX(USER(),'@',1) and db = DATABASE() ORDER BY id; " ;
$stmt_sleep = $connection -> createStatement ();
2016-03-03 12:09:38 -04:00
$rs_sleep = $stmt_sleep -> executeQuery ( $sql_sleep , ResultSet :: FETCHMODE_ASSOC );
2014-07-31 17:00:31 -04:00
2014-10-27 18:22:22 -04:00
while ( $rs_sleep -> next ()) {
$row_sleep = $rs_sleep -> getRow ();
2016-03-03 12:09:38 -04:00
$oStatement_sleep = $connection -> prepareStatement ( " kill " . $row_sleep [ 'ID' ]);
2014-10-27 18:22:22 -04:00
$oStatement_sleep -> executeQuery ();
}
2014-07-31 17:00:31 -04:00
2015-04-13 17:25:52 -04:00
$sql_query = " SELECT * FROM information_schema.processlist WHERE user = SUBSTRING_INDEX(USER(),'@',1) and db = DATABASE() and time > 0 ORDER BY id; " ;
2014-10-27 18:22:22 -04:00
$stmt_query = $connection -> createStatement ();
2016-03-03 12:09:38 -04:00
$rs_query = $stmt_query -> executeQuery ( $sql_query , ResultSet :: FETCHMODE_ASSOC );
2014-07-31 17:00:31 -04:00
2014-10-27 18:22:22 -04:00
while ( $rs_query -> next ()) {
$row_query = $rs_query -> getRow ();
2016-03-03 12:09:38 -04:00
$oStatement_query = $connection -> prepareStatement ( " kill " . $row_query [ 'ID' ]);
2014-10-27 18:22:22 -04:00
$oStatement_query -> executeQuery ();
}
2014-07-28 09:50:40 -04:00
}
2010-12-02 23:34:41 +00:00
}
2013-04-29 16:48:29 -04:00
/**
* fix the 32 K issue , by migrating / files directory structure to an uid tree structure based .
* @ param $workspace got the site ( s ) the manager wants to upgrade
*/
2016-03-03 12:09:38 -04:00
public function upgradeCasesDirectoryStructure ( $workspace )
2013-04-29 16:48:29 -04:00
{
2016-05-03 17:35:04 -04:00
define ( 'PATH_DOCUMENT' , PATH_DATA . 'sites' . DIRECTORY_SEPARATOR . $workspace . DIRECTORY_SEPARATOR . 'files' );
if ( ! is_writable ( PATH_DOCUMENT )) {
2013-05-08 10:57:35 -04:00
CLI :: logging ( CLI :: error ( " Error: " . PATH_DOCUMENT . " is not writable... please check the su permissions. \n " ));
2013-04-29 16:48:29 -04:00
return ;
}
$directory = array ();
$blackHoleDir = G :: getBlackHoleDir ();
$directory = glob ( PATH_DOCUMENT . " * " , GLOB_ONLYDIR );
$dirslength = sizeof ( $directory );
2016-03-03 12:09:38 -04:00
if ( !@ chdir ( PATH_DOCUMENT )) {
2013-05-08 10:57:35 -04:00
CLI :: logging ( CLI :: error ( " Cannot use Document directory. The upgrade must be done as root. \n " ));
2013-04-29 16:48:29 -04:00
return ;
}
//Start migration
for ( $index = 0 ; $index < $dirslength ; $index ++ ) {
2016-05-03 17:35:04 -04:00
$depthdirlevel = explode ( DIRECTORY_SEPARATOR , $directory [ $index ]);
2013-04-29 16:48:29 -04:00
$lastlength = sizeof ( $depthdirlevel );
$UIdDir = $depthdirlevel [ $lastlength - 1 ];
$lenDir = strlen ( $UIdDir );
if ( $lenDir == 32 && $UIdDir != $blackHoleDir ) {
$len = count ( scandir ( $UIdDir ));
if ( $len > 2 ) {
//lenght = 2, because the function check . and .. dir links
$newDiretory = G :: getPathFromUIDPlain ( $UIdDir );
CLI :: logging ( " Migrating $UIdDir to $newDiretory\n " );
2013-07-12 15:57:54 -04:00
G :: mk_dir ( $newDiretory , 0777 );
2013-04-29 16:48:29 -04:00
//echo `cp -R $UIdDir/* $newDiretory/`;
2013-07-12 15:57:54 -04:00
2013-04-29 16:48:29 -04:00
if ( G :: recursive_copy ( $UIdDir , $newDiretory )) {
CLI :: logging ( " Removing $UIdDir ... \n " );
G :: rm_dir ( $UIdDir );
2016-05-03 17:35:04 -04:00
rmdir ( $UIdDir ); //remove the diretory itself, G::rm_dir cannot do it
2013-04-29 16:48:29 -04:00
} else {
2013-05-08 10:57:35 -04:00
CLI :: logging ( CLI :: error ( " Error: Failure at coping from $UIdDir ... \n " ));
2013-06-26 13:15:43 -04:00
}
2013-04-29 16:48:29 -04:00
} else {
CLI :: logging ( " $UIdDir is empty, removing it \n " );
2016-05-03 17:35:04 -04:00
rmdir ( $UIdDir ); //remove the diretory itself
2013-04-29 16:48:29 -04:00
}
}
}
//Start '0' directory migration
2016-05-03 17:35:04 -04:00
$black = PATH_DOCUMENT . $blackHoleDir . DIRECTORY_SEPARATOR ;
2013-04-29 16:48:29 -04:00
if ( is_dir ( $black )) {
$newpattern = array ();
2016-05-03 17:35:04 -04:00
$file = glob ( $black . '*.*' ); //files only
2013-04-29 16:48:29 -04:00
$dirlen = count ( $file );
for ( $index = 0 ; $index < $dirlen ; $index ++ ) {
2016-05-03 17:35:04 -04:00
$levelfile = explode ( DIRECTORY_SEPARATOR , $file [ $index ]);
2013-04-29 16:48:29 -04:00
$lastlevel = sizeof ( $levelfile );
$goalFile = $levelfile [ $lastlevel - 1 ];
$newpattern = G :: getPathFromFileUIDPlain ( $blackHoleDir , $goalFile );
CLI :: logging ( " Migrating $blackHoleDir file: $goalFile\n " );
2013-07-12 15:57:54 -04:00
G :: mk_dir ( $blackHoleDir . PATH_SEP . $newpattern [ 0 ], 0777 );
2013-04-29 16:48:29 -04:00
//echo `cp -R $black$goalFile $black$newpattern[0]/$newpattern[1]`;
2013-07-12 15:57:54 -04:00
2016-05-03 17:35:04 -04:00
if ( copy ( $black . $goalFile , $black . $newpattern [ 0 ] . DIRECTORY_SEPARATOR . $newpattern [ 1 ])) {
2013-04-29 16:48:29 -04:00
unlink ( $file [ $index ]);
} else {
2013-05-08 10:57:35 -04:00
CLI :: logging ( CLI :: error ( " Error: Failure at copy $file[$index] files... \n " ));
2013-06-26 13:15:43 -04:00
}
2013-04-29 16:48:29 -04:00
}
}
//Set value of 2 to the directory structure version.
$this -> initPropel ( true );
G :: LoadClass ( " configuration " );
$conf = new Configurations ();
2013-06-25 13:50:38 -04:00
if ( ! $conf -> exists ( " ENVIRONMENT_SETTINGS " )) {
2016-03-03 12:09:38 -04:00
$conf -> aConfig = array ( " format " => '@userName (@firstName @lastName)' ,
" dateFormat " => 'd/m/Y' ,
" startCaseHideProcessInf " => false ,
" casesListDateFormat " => 'Y-m-d H:i:s' ,
" casesListRowNumber " => 25 ,
" casesListRefreshTime " => 120 );
$conf -> saveConfig ( 'ENVIRONMENT_SETTINGS' , '' );
2013-04-29 16:48:29 -04:00
}
2013-06-25 13:50:38 -04:00
$conf -> setDirectoryStructureVer ( 2 );
CLI :: logging ( CLI :: info ( " Version Directory Structure is 2 now. \n " ));
2013-04-29 16:48:29 -04:00
}
2012-10-18 13:05:23 -04:00
/**
* Upgrade this workspace database to the latest plugins schema
*/
2013-03-14 15:50:49 -04:00
public function upgradePluginsDatabase ()
2012-10-18 13:05:23 -04:00
{
foreach ( System :: getPlugins () as $pluginName ) {
2013-03-14 15:50:49 -04:00
$pluginSchema = System :: getPluginSchema ( $pluginName );
2012-10-18 13:05:23 -04:00
if ( $pluginSchema !== false ) {
2013-03-14 15:50:49 -04:00
CLI :: logging ( " Updating plugin " . CLI :: info ( $pluginName ) . " \n " );
$this -> upgradeSchema ( $pluginSchema );
2012-10-18 13:05:23 -04:00
}
}
2010-12-02 23:34:41 +00:00
}
2012-10-18 13:05:23 -04:00
/**
* Upgrade this workspace database to the latest system schema
*
* @ param bool $checkOnly only check if the upgrade is needed if true
* @ return array bool upgradeSchema for more information
*/
2016-03-03 12:09:38 -04:00
public function upgradeDatabase ( $onedb = false , $checkOnly = false )
2014-10-03 10:31:50 -04:00
{
2013-06-05 10:08:40 -04:00
G :: LoadClass ( " patch " );
2016-03-03 12:09:38 -04:00
$this -> initPropel ( true );
2014-09-09 12:17:14 -04:00
p11835 :: $dbAdapter = $this -> dbAdapter ;
2013-06-05 16:23:39 -04:00
p11835 :: isApplicable ();
2014-09-09 12:17:14 -04:00
$systemSchema = System :: getSystemSchema ( $this -> dbAdapter );
$systemSchemaRbac = System :: getSystemSchemaRbac ( $this -> dbAdapter ); // get the Rbac Schema
2016-02-17 16:44:14 -04:00
$this -> registerSystemTables ( array_merge ( $systemSchema , $systemSchemaRbac ));
2016-03-03 12:09:38 -04:00
$this -> upgradeSchema ( $systemSchema );
$this -> upgradeSchema ( $systemSchemaRbac , false , true , $onedb ); // perform Upgrade to Rbac
2012-10-18 13:05:23 -04:00
$this -> upgradeData ();
2016-03-03 12:09:38 -04:00
$this -> checkRbacPermissions (); //check or add new permissions
2016-04-01 16:43:37 -04:00
$this -> checkSequenceNumber ();
2016-06-14 13:43:49 -04:00
$this -> migrateIteeToDummytask ( $this -> name );
2016-08-13 13:52:07 -04:00
$this -> upgradeConfiguration ();
2016-08-18 12:21:29 -04:00
/*----------------------------------********---------------------------------*/
$this -> upgradeAuditLog ( $this -> name );
/*----------------------------------********---------------------------------*/
2015-05-22 16:07:42 -04:00
//There records in table "EMAIL_SERVER"
$criteria = new Criteria ( " workflow " );
$criteria -> addSelectColumn ( EmailServerPeer :: MESS_UID );
$criteria -> setOffset ( 0 );
$criteria -> setLimit ( 1 );
$rsCriteria = EmailServerPeer :: doSelectRS ( $criteria );
if ( ! $rsCriteria -> next ()) {
//Insert the first record
$arrayData = array ();
2015-06-01 14:15:53 -04:00
$emailSever = new \ProcessMaker\BusinessModel\EmailServer ();
2015-05-22 16:07:42 -04:00
$emailConfiguration = System :: getEmailConfiguration ();
2015-06-01 14:15:53 -04:00
if ( ! empty ( $emailConfiguration )) {
2015-05-22 16:07:42 -04:00
$arrayData [ " MESS_ENGINE " ] = $emailConfiguration [ " MESS_ENGINE " ];
switch ( $emailConfiguration [ " MESS_ENGINE " ]) {
case " PHPMAILER " :
$arrayData [ " MESS_SERVER " ] = $emailConfiguration [ " MESS_SERVER " ];
$arrayData [ " MESS_PORT " ] = ( int )( $emailConfiguration [ " MESS_PORT " ]);
$arrayData [ " MESS_RAUTH " ] = ( is_numeric ( $emailConfiguration [ " MESS_RAUTH " ])) ? ( int )( $emailConfiguration [ " MESS_RAUTH " ]) : (( $emailConfiguration [ " MESS_RAUTH " ] . " " == " true " ) ? 1 : 0 );
$arrayData [ " MESS_ACCOUNT " ] = $emailConfiguration [ " MESS_ACCOUNT " ];
$arrayData [ " MESS_PASSWORD " ] = $emailConfiguration [ " MESS_PASSWORD " ];
$arrayData [ " MESS_FROM_MAIL " ] = ( isset ( $emailConfiguration [ " MESS_FROM_MAIL " ])) ? $emailConfiguration [ " MESS_FROM_MAIL " ] : " " ;
$arrayData [ " MESS_FROM_NAME " ] = ( isset ( $emailConfiguration [ " MESS_FROM_NAME " ])) ? $emailConfiguration [ " MESS_FROM_NAME " ] : " " ;
$arrayData [ " SMTPSECURE " ] = $emailConfiguration [ " SMTPSecure " ];
$arrayData [ " MESS_TRY_SEND_INMEDIATLY " ] = ( isset ( $emailConfiguration [ " MESS_TRY_SEND_INMEDIATLY " ]) && ( $emailConfiguration [ " MESS_TRY_SEND_INMEDIATLY " ] . " " == " true " || $emailConfiguration [ " MESS_TRY_SEND_INMEDIATLY " ] . " " == " 1 " )) ? 1 : 0 ;
2015-07-13 11:16:35 -04:00
$arrayData [ " MAIL_TO " ] = isset ( $emailConfiguration [ " MAIL_TO " ]) ? $emailConfiguration [ " MAIL_TO " ] : '' ;
2015-05-22 16:07:42 -04:00
$arrayData [ " MESS_DEFAULT " ] = ( isset ( $emailConfiguration [ " MESS_ENABLED " ]) && $emailConfiguration [ " MESS_ENABLED " ] . " " == " 1 " ) ? 1 : 0 ;
break ;
case " MAIL " :
$arrayData [ " MESS_SERVER " ] = " " ;
$arrayData [ " MESS_FROM_MAIL " ] = ( isset ( $emailConfiguration [ " MESS_FROM_MAIL " ])) ? $emailConfiguration [ " MESS_FROM_MAIL " ] : " " ;
$arrayData [ " MESS_FROM_NAME " ] = ( isset ( $emailConfiguration [ " MESS_FROM_NAME " ])) ? $emailConfiguration [ " MESS_FROM_NAME " ] : " " ;
$arrayData [ " MESS_TRY_SEND_INMEDIATLY " ] = ( isset ( $emailConfiguration [ " MESS_TRY_SEND_INMEDIATLY " ]) && ( $emailConfiguration [ " MESS_TRY_SEND_INMEDIATLY " ] . " " == " true " || $emailConfiguration [ " MESS_TRY_SEND_INMEDIATLY " ] . " " == " 1 " )) ? 1 : 0 ;
$arrayData [ " MESS_ACCOUNT " ] = " " ;
$arrayData [ " MESS_PASSWORD " ] = " " ;
$arrayData [ " MAIL_TO " ] = ( isset ( $emailConfiguration [ " MAIL_TO " ])) ? $emailConfiguration [ " MAIL_TO " ] : " " ;
$arrayData [ " MESS_DEFAULT " ] = ( isset ( $emailConfiguration [ " MESS_ENABLED " ]) && $emailConfiguration [ " MESS_ENABLED " ] . " " == " 1 " ) ? 1 : 0 ;
break ;
}
$arrayData = $emailSever -> create ( $arrayData );
} else {
2015-08-19 10:02:43 -04:00
$arrayData [ " MESS_ENGINE " ] = " MAIL " ;
$arrayData [ " MESS_SERVER " ] = " " ;
$arrayData [ " MESS_ACCOUNT " ] = " " ;
$arrayData [ " MESS_PASSWORD " ] = " " ;
$arrayData [ " MAIL_TO " ] = " " ;
$arrayData [ " MESS_DEFAULT " ] = 1 ;
$arrayData = $emailSever -> create2 ( $arrayData );
2015-05-22 16:07:42 -04:00
}
}
2013-06-05 16:23:39 -04:00
p11835 :: execute ();
2015-05-22 16:07:42 -04:00
2012-10-18 13:05:23 -04:00
return true ;
2013-06-26 13:15:43 -04:00
}
2012-10-18 13:05:23 -04:00
2014-09-09 12:34:49 -04:00
private function setFormatRows ()
{
switch ( $this -> dbAdapter ) {
case 'mysql' :
$this -> assoc = MYSQL_ASSOC ;
$this -> num = MYSQL_NUM ;
break ;
case 'sqlsrv' :
$this -> assoc = SQLSRV_FETCH_ASSOC ;
$this -> num = SQLSRV_FETCH_NUMERIC ;
break ;
default :
throw new Exception ( " Unknown adapter hae been set for associate fetch index row format. " );
break ;
}
}
2012-10-18 13:05:23 -04:00
/**
* Upgrade this workspace database from a schema
*
* @ param array $schema the schema information , such as returned from getSystemSchema
* @ param bool $checkOnly only check if the upgrade is needed if true
* @ return array bool the changes if checkOnly is true , else return
* true on success
*/
2014-09-04 16:28:17 -04:00
public function upgradeSchema ( $schema , $checkOnly = false , $rbac = false , $onedb = false )
2012-10-18 13:05:23 -04:00
{
$dbInfo = $this -> getDBInfo ();
2014-10-03 10:31:50 -04:00
2014-09-09 17:31:39 -04:00
if ( $dbInfo [ 'DB_NAME' ] == $dbInfo [ 'DB_RBAC_NAME' ]) {
$onedb = true ;
} else {
$onedb = false ;
}
2012-10-18 13:05:23 -04:00
2013-03-14 15:50:49 -04:00
if ( strcmp ( $dbInfo [ " DB_ADAPTER " ], " mysql " ) != 0 ) {
throw new Exception ( " Only MySQL is supported " );
2012-10-18 13:05:23 -04:00
}
2014-09-09 12:34:49 -04:00
$this -> setFormatRows ();
2013-11-28 16:44:08 -04:00
$workspaceSchema = $this -> getSchema ( $rbac );
2014-09-04 16:28:17 -04:00
$oDataBase = $this -> getDatabase ( $rbac );
if ( ! $onedb ) {
2014-09-09 12:34:49 -04:00
if ( $rbac ){
2014-09-04 16:28:17 -04:00
$rename = System :: verifyRbacSchema ( $workspaceSchema );
if ( count ( $rename ) > 0 ) {
foreach ( $rename as $tableName ) {
$oDataBase -> executeQuery ( $oDataBase -> generateRenameTableSQL ( $tableName ));
}
}
}
}
2017-02-14 15:09:57 -04:00
$workspaceSchema = $this -> getSchema ( $rbac );
2013-03-14 15:50:49 -04:00
$changes = System :: compareSchema ( $workspaceSchema , $schema );
2013-11-21 09:10:42 -04:00
2013-03-14 15:50:49 -04:00
$changed = ( count ( $changes [ 'tablesToAdd' ]) > 0 || count ( $changes [ 'tablesToAlter' ]) > 0 || count ( $changes [ 'tablesWithNewIndex' ]) > 0 || count ( $changes [ 'tablesToAlterIndex' ]) > 0 );
2013-11-21 09:10:42 -04:00
2013-03-14 15:50:49 -04:00
if ( $checkOnly || ( ! $changed )) {
2012-10-18 13:05:23 -04:00
if ( $changed ) {
return $changes ;
} else {
2014-09-09 12:17:14 -04:00
CLI :: logging ( " -> Nothing to change in the data base structure of " . (( $rbac == true ) ? " RBAC " : " WORKFLOW " ) . " \n " );
2012-10-18 13:05:23 -04:00
return $changed ;
}
}
2013-11-22 13:54:30 -04:00
2014-09-09 12:34:49 -04:00
$oDataBase -> iFetchType = $this -> num ;
2012-10-18 13:05:23 -04:00
2013-03-14 15:50:49 -04:00
$oDataBase -> logQuery ( count ( $changes ));
2012-10-18 13:05:23 -04:00
2013-03-14 15:50:49 -04:00
if ( ! empty ( $changes [ 'tablesToAdd' ])) {
CLI :: logging ( " -> " . count ( $changes [ 'tablesToAdd' ]) . " tables to add \n " );
2012-10-18 13:05:23 -04:00
}
2014-10-09 10:36:34 -04:00
2012-10-18 13:05:23 -04:00
foreach ( $changes [ 'tablesToAdd' ] as $sTable => $aColumns ) {
2013-03-14 15:50:49 -04:00
$oDataBase -> executeQuery ( $oDataBase -> generateCreateTableSQL ( $sTable , $aColumns ));
if ( isset ( $changes [ 'tablesToAdd' ][ $sTable ][ 'INDEXES' ])) {
2012-10-18 13:05:23 -04:00
foreach ( $changes [ 'tablesToAdd' ][ $sTable ][ 'INDEXES' ] as $indexName => $aIndex ) {
2013-03-14 15:50:49 -04:00
$oDataBase -> executeQuery ( $oDataBase -> generateAddKeysSQL ( $sTable , $indexName , $aIndex ));
2012-10-18 13:05:23 -04:00
}
}
}
2013-03-14 15:50:49 -04:00
if ( ! empty ( $changes [ 'tablesToAlter' ])) {
CLI :: logging ( " -> " . count ( $changes [ 'tablesToAlter' ]) . " tables to alter \n " );
2012-10-18 13:05:23 -04:00
}
2014-10-09 10:36:34 -04:00
2012-10-18 13:05:23 -04:00
foreach ( $changes [ 'tablesToAlter' ] as $sTable => $aActions ) {
foreach ( $aActions as $sAction => $aAction ) {
foreach ( $aAction as $sColumn => $vData ) {
switch ( $sAction ) {
case 'DROP' :
2013-03-14 15:50:49 -04:00
$oDataBase -> executeQuery ( $oDataBase -> generateDropColumnSQL ( $sTable , $vData ));
2012-10-18 13:05:23 -04:00
break ;
case 'ADD' :
2016-09-09 15:15:51 -04:00
if ( $oDataBase -> checkPatchHor1787 ( $sTable , $sColumn , $vData )) {
$oDataBase -> executeQuery ( $oDataBase -> generateCheckAddColumnSQL ( $sTable , $sColumn , $vData ));
$oDataBase -> executeQuery ( $oDataBase -> deleteAllIndexesIntable ( $sTable , $sColumn , $vData ));
}
2013-03-14 15:50:49 -04:00
$oDataBase -> executeQuery ( $oDataBase -> generateAddColumnSQL ( $sTable , $sColumn , $vData ));
2012-10-18 13:05:23 -04:00
break ;
case 'CHANGE' :
2013-03-14 15:50:49 -04:00
$oDataBase -> executeQuery ( $oDataBase -> generateChangeColumnSQL ( $sTable , $sColumn , $vData ));
2012-10-18 13:05:23 -04:00
break ;
}
}
}
}
2013-03-14 15:50:49 -04:00
if ( ! empty ( $changes [ 'tablesWithNewIndex' ])) {
CLI :: logging ( " -> " . count ( $changes [ 'tablesWithNewIndex' ]) . " indexes to add \n " );
2012-10-18 13:05:23 -04:00
}
foreach ( $changes [ 'tablesWithNewIndex' ] as $sTable => $aIndexes ) {
foreach ( $aIndexes as $sIndexName => $aIndexFields ) {
2013-03-14 15:50:49 -04:00
$oDataBase -> executeQuery ( $oDataBase -> generateAddKeysSQL ( $sTable , $sIndexName , $aIndexFields ));
2012-10-18 13:05:23 -04:00
}
}
2013-03-14 15:50:49 -04:00
if ( ! empty ( $changes [ 'tablesToAlterIndex' ])) {
CLI :: logging ( " -> " . count ( $changes [ 'tablesToAlterIndex' ]) . " indexes to alter \n " );
2012-10-18 13:05:23 -04:00
}
foreach ( $changes [ 'tablesToAlterIndex' ] as $sTable => $aIndexes ) {
foreach ( $aIndexes as $sIndexName => $aIndexFields ) {
2013-03-14 15:50:49 -04:00
$oDataBase -> executeQuery ( $oDataBase -> generateDropKeySQL ( $sTable , $sIndexName ));
$oDataBase -> executeQuery ( $oDataBase -> generateAddKeysSQL ( $sTable , $sIndexName , $aIndexFields ));
2012-10-18 13:05:23 -04:00
}
}
$this -> closeDatabase ();
return true ;
2011-11-08 17:37:47 -04:00
}
2012-10-18 13:05:23 -04:00
2013-03-14 15:50:49 -04:00
public function upgradeData ()
2012-10-18 13:05:23 -04:00
{
2013-03-14 15:50:49 -04:00
if ( file_exists ( PATH_CORE . 'data' . PATH_SEP . 'check.data' )) {
$checkData = unserialize ( file_get_contents ( PATH_CORE . 'data' . PATH_SEP . 'check.data' ));
if ( is_array ( $checkData )) {
2015-04-16 14:54:27 -04:00
/*----------------------------------********---------------------------------*/
$licensedFeatures = & PMLicensedFeatures :: getSingleton ();
$checkData = $licensedFeatures -> addNewFeatures ( $checkData );
2015-04-21 13:17:16 -04:00
$catalog = new Catalog ();
$checkData = $catalog -> registerRows ( $checkData );
2015-04-16 14:54:27 -04:00
/*----------------------------------********---------------------------------*/
2012-10-18 13:05:23 -04:00
foreach ( $checkData as $checkThis ) {
2013-03-14 15:50:49 -04:00
$this -> updateThisRegistry ( $checkThis );
2012-10-18 13:05:23 -04:00
}
}
}
2011-11-08 17:37:47 -04:00
}
2012-10-18 13:05:23 -04:00
2013-03-14 15:50:49 -04:00
public function updateThisRegistry ( $data )
2012-10-18 13:05:23 -04:00
{
$dataBase = $this -> getDatabase ();
$sql = '' ;
switch ( $data [ 'action' ]) {
case 1 :
2013-03-14 15:50:49 -04:00
$sql = $dataBase -> generateInsertSQL ( $data [ 'table' ], $data [ 'data' ]);
2012-10-18 13:05:23 -04:00
$message = " -> Row added in { $data [ 'table' ] } \n " ;
break ;
case 2 :
2013-03-14 15:50:49 -04:00
$sql = $dataBase -> generateUpdateSQL ( $data [ 'table' ], $data [ 'keys' ], $data [ 'data' ]);
2012-10-18 13:05:23 -04:00
$message = " -> Row updated in { $data [ 'table' ] } \n " ;
break ;
case 3 :
2013-03-14 15:50:49 -04:00
$sql = $dataBase -> generateDeleteSQL ( $data [ 'table' ], $data [ 'keys' ], $data [ 'data' ]);
2012-10-18 13:05:23 -04:00
$message = " -> Row deleted in { $data [ 'table' ] } \n " ;
break ;
case 4 :
2013-03-14 15:50:49 -04:00
$sql = $dataBase -> generateSelectSQL ( $data [ 'table' ], $data [ 'keys' ], $data [ 'data' ]);
$dataset = $dataBase -> executeQuery ( $sql );
if ( $dataBase -> getRegistry ( $dataset )) {
$sql = $dataBase -> generateDeleteSQL ( $data [ 'table' ], $data [ 'keys' ], $data [ 'data' ]);
$dataBase -> executeQuery ( $sql );
2012-10-18 13:05:23 -04:00
}
2013-03-14 15:50:49 -04:00
$sql = $dataBase -> generateInsertSQL ( $data [ 'table' ], $data [ 'data' ]);
2012-10-18 13:05:23 -04:00
$message = " -> Row updated in { $data [ 'table' ] } \n " ;
break ;
}
if ( $sql != '' ) {
2013-03-14 15:50:49 -04:00
$dataBase -> executeQuery ( $sql );
CLI :: logging ( $message );
2012-10-18 13:05:23 -04:00
}
2010-12-16 20:36:29 +00:00
}
2012-10-18 13:05:23 -04:00
/**
* Get metadata from this workspace
*
* @ param string $path the directory where to create the sql files
* @ return array information about this workspace
*/
2013-03-14 15:50:49 -04:00
public function getMetadata ()
2012-10-18 13:05:23 -04:00
{
2013-03-14 15:50:49 -04:00
$Fields = array_merge ( System :: getSysInfo (), $this -> getDBInfo ());
2012-10-18 13:05:23 -04:00
$Fields [ 'WORKSPACE_NAME' ] = $this -> name ;
2013-03-14 15:50:49 -04:00
if ( isset ( $this -> dbHost )) {
2012-10-18 13:05:23 -04:00
//TODO: This code stopped working with the refactoring
//require_once ("propel/Propel.php");
//G::LoadClass('dbConnections');
//$dbConns = new dbConnections('');
//$availdb = '';
//foreach( $dbConns->getDbServicesAvailables() as $key => $val ) {
//if(!empty($availdb))
// $availdb .= ', ';
// $availdb .= $val['name'];
//}
2013-03-14 15:50:49 -04:00
G :: LoadClass ( 'net' );
$dbNetView = new NET ( $this -> dbHost );
$dbNetView -> loginDbServer ( $this -> dbUser , $this -> dbPass );
2012-10-18 13:05:23 -04:00
try {
2014-10-09 10:36:34 -04:00
if ( ! defined ( 'DB_ADAPTER' )) {
require_once ( $this -> dbPath );
}
2013-03-14 15:50:49 -04:00
$sMySQLVersion = $dbNetView -> getDbServerVersion ( 'mysql' );
2012-10-18 13:05:23 -04:00
} catch ( Exception $oException ) {
$sMySQLVersion = 'Unknown' ;
}
2013-03-14 15:50:49 -04:00
$Fields [ 'DATABASE' ] = $dbNetView -> dbName ( $this -> dbAdapter ) . ' (Version ' . $sMySQLVersion . ')' ;
2012-10-18 13:05:23 -04:00
$Fields [ 'DATABASE_SERVER' ] = $this -> dbHost ;
$Fields [ 'DATABASE_NAME' ] = $this -> dbName ;
$Fields [ 'AVAILABLE_DB' ] = " Not defined " ;
//$Fields['AVAILABLE_DB'] = $availdb;
} else {
$Fields [ 'DATABASE' ] = " Not defined " ;
$Fields [ 'DATABASE_SERVER' ] = " Not defined " ;
$Fields [ 'DATABASE_NAME' ] = " Not defined " ;
$Fields [ 'AVAILABLE_DB' ] = " Not defined " ;
}
return $Fields ;
2010-12-16 20:36:29 +00:00
}
2012-10-18 13:05:23 -04:00
/**
* Print the system information gathered from getSysInfo
*/
2013-03-14 15:50:49 -04:00
public static function printSysInfo ()
2012-10-18 13:05:23 -04:00
{
$fields = System :: getSysInfo ();
2013-03-14 15:50:49 -04:00
$info = array (
'ProcessMaker Version' => $fields [ 'PM_VERSION' ],
'System' => $fields [ 'SYSTEM' ],
'PHP Version' => $fields [ 'PHP' ],
'Server Address' => $fields [ 'SERVER_ADDR' ],
'Client IP Address' => $fields [ 'IP' ],
'Plugins' => ( count ( $fields [ 'PLUGINS_LIST' ]) > 0 ) ? $fields [ 'PLUGINS_LIST' ][ 0 ] : 'None'
2012-10-18 13:05:23 -04:00
);
foreach ( $fields [ 'PLUGINS_LIST' ] as $k => $v ) {
if ( $k == 0 ) {
continue ;
}
$info [] = $v ;
}
foreach ( $info as $k => $v ) {
2013-03-14 15:50:49 -04:00
if ( is_numeric ( $k )) {
2012-10-18 13:05:23 -04:00
$k = " " ;
}
2013-03-14 15:50:49 -04:00
CLI :: logging ( sprintf ( " %20s %s \n " , $k , pakeColor :: colorize ( $v , 'INFO' )));
2012-10-18 13:05:23 -04:00
}
2010-12-16 20:36:29 +00:00
}
2013-03-14 15:50:49 -04:00
public function printInfo ( $fields = null )
2012-10-18 13:05:23 -04:00
{
2013-03-14 15:50:49 -04:00
if ( ! $fields ) {
2012-10-18 13:05:23 -04:00
$fields = $this -> getMetadata ();
}
2011-02-25 21:02:27 +00:00
2012-10-18 13:05:23 -04:00
$wfDsn = $fields [ 'DB_ADAPTER' ] . '://' . $fields [ 'DB_USER' ] . ':' . $fields [ 'DB_PASS' ] . '@' . $fields [ 'DB_HOST' ] . '/' . $fields [ 'DB_NAME' ];
2014-10-03 10:31:50 -04:00
2014-10-10 15:09:26 -04:00
if ( $fields [ 'DB_NAME' ] == $fields [ 'DB_RBAC_NAME' ]) {
$info = array ( 'Workspace Name' => $fields [ 'WORKSPACE_NAME' ], 'Workflow Database' => sprintf ( " %s://%s:%s@%s/%s " , $fields [ 'DB_ADAPTER' ], $fields [ 'DB_USER' ], $fields [ 'DB_PASS' ], $fields [ 'DB_HOST' ], $fields [ 'DB_NAME' ]), 'MySql Version' => $fields [ 'DATABASE' ]);
} else {
2013-03-14 15:50:49 -04:00
$info = array ( 'Workspace Name' => $fields [ 'WORKSPACE_NAME' ],
//'Available Databases' => $fields['AVAILABLE_DB'],
'Workflow Database' => sprintf ( " %s://%s:%s@%s/%s " , $fields [ 'DB_ADAPTER' ], $fields [ 'DB_USER' ], $fields [ 'DB_PASS' ], $fields [ 'DB_HOST' ], $fields [ 'DB_NAME' ]), 'RBAC Database' => sprintf ( " %s://%s:%s@%s/%s " , $fields [ 'DB_ADAPTER' ], $fields [ 'DB_RBAC_USER' ], $fields [ 'DB_RBAC_PASS' ], $fields [ 'DB_RBAC_HOST' ], $fields [ 'DB_RBAC_NAME' ]), 'Report Database' => sprintf ( " %s://%s:%s@%s/%s " , $fields [ 'DB_ADAPTER' ], $fields [ 'DB_REPORT_USER' ], $fields [ 'DB_REPORT_PASS' ], $fields [ 'DB_REPORT_HOST' ], $fields [ 'DB_REPORT_NAME' ]), 'MySql Version' => $fields [ 'DATABASE' ]
2012-10-18 13:05:23 -04:00
);
2014-10-10 15:09:26 -04:00
}
2012-10-18 13:05:23 -04:00
foreach ( $info as $k => $v ) {
2013-03-14 15:50:49 -04:00
if ( is_numeric ( $k )) {
2012-10-18 13:05:23 -04:00
$k = " " ;
}
2013-03-14 15:50:49 -04:00
CLI :: logging ( sprintf ( " %20s %s \n " , $k , pakeColor :: colorize ( $v , 'INFO' )));
2012-10-18 13:05:23 -04:00
}
2011-02-17 20:51:26 +00:00
}
2012-10-18 13:05:23 -04:00
/**
* Print workspace information
*
* @ param bool $printSysInfo include sys info as well or not
*/
2013-03-14 15:50:49 -04:00
public function printMetadata ( $printSysInfo = true )
2012-10-18 13:05:23 -04:00
{
if ( $printSysInfo ) {
workspaceTools :: printSysInfo ();
2013-03-14 15:50:49 -04:00
CLI :: logging ( " \n " );
2012-10-18 13:05:23 -04:00
}
2013-03-14 15:50:49 -04:00
workspaceTools :: printInfo ( $this -> getMetadata ());
2010-12-16 20:36:29 +00:00
}
2011-03-10 15:18:52 +00:00
2012-10-18 13:05:23 -04:00
/**
* exports this workspace database to the specified path
*
* This function is used mainly for backup purposes .
*
* @ param string $path the directory where to create the sql files
*/
2014-09-04 16:28:17 -04:00
public function exportDatabase ( $path , $onedb = false )
2012-10-18 13:05:23 -04:00
{
$dbInfo = $this -> getDBInfo ();
2014-10-27 11:25:17 -04:00
2014-09-04 16:28:17 -04:00
if ( $onedb ) {
$databases = array ( " rb " , " rp " );
2014-10-10 15:09:26 -04:00
} else if ( $dbInfo [ 'DB_NAME' ] == $dbInfo [ 'DB_RBAC_NAME' ]) {
$databases = array ( " wf " );
2014-09-04 16:28:17 -04:00
} else {
$databases = array ( " wf " , " rp " , " rb " );
}
2013-03-14 15:50:49 -04:00
$dbNames = array ();
2014-10-27 11:25:17 -04:00
foreach ( $databases as $db ) {
2013-03-14 15:50:49 -04:00
$dbInfo = $this -> getDBCredentials ( $db );
$oDbMaintainer = new DataBaseMaintenance ( $dbInfo [ " host " ], $dbInfo [ " user " ], $dbInfo [ " pass " ]);
CLI :: logging ( " Saving database { $dbInfo [ " name " ] } \n " );
$oDbMaintainer -> connect ( $dbInfo [ " name " ]);
$oDbMaintainer -> setTempDir ( $path . " / " );
$oDbMaintainer -> backupDataBase ( $oDbMaintainer -> getTempDir () . $dbInfo [ " name " ] . " .sql " );
2012-10-18 13:05:23 -04:00
$dbNames [] = $dbInfo ;
}
return $dbNames ;
2010-12-20 15:26:23 +00:00
}
2012-10-18 13:05:23 -04:00
/**
* adds files to the backup archive
2011-01-14 23:11:13 +00:00
*/
2013-03-14 15:50:49 -04:00
private function addToBackup ( $backup , $filename , $pathRoot , $archiveRoot = " " )
2012-10-18 13:05:23 -04:00
{
2013-03-14 15:50:49 -04:00
if ( is_file ( $filename )) {
CLI :: logging ( " -> $filename\n " );
$backup -> addModify ( $filename , $archiveRoot , $pathRoot );
2012-10-18 13:05:23 -04:00
} else {
2013-03-14 15:50:49 -04:00
CLI :: logging ( " + $filename\n " );
$backup -> addModify ( $filename , $archiveRoot , $pathRoot );
2012-10-18 13:05:23 -04:00
//foreach (glob($filename . "/*") as $item) {
// $this->addToBackup($backup, $item, $pathRoot, $archiveRoot);
//}
}
2011-02-17 20:51:26 +00:00
}
2012-10-18 13:05:23 -04:00
/**
* Creates a backup archive , which can be used instead of a filename to backup
*
* @ param string $filename the backup filename
* @ param bool $compress wheter to compress or not
*/
2013-03-14 15:50:49 -04:00
static public function createBackup ( $filename , $compress = true )
2012-10-18 13:05:23 -04:00
{
2013-03-14 15:50:49 -04:00
G :: LoadThirdParty ( 'pear/Archive' , 'Tar' );
if ( ! file_exists ( dirname ( $filename ))) {
mkdir ( dirname ( $filename ));
2012-10-18 13:05:23 -04:00
}
2013-03-14 15:50:49 -04:00
if ( file_exists ( $filename )) {
unlink ( $filename );
2012-10-18 13:05:23 -04:00
}
2013-03-14 15:50:49 -04:00
$backup = new Archive_Tar ( $filename );
2012-10-18 13:05:23 -04:00
return $backup ;
2011-02-17 20:51:26 +00:00
}
2012-10-18 13:05:23 -04:00
/**
* create a backup of this workspace
*
* Exports the database and copies the files to an archive specified , so this
* workspace can later be restored .
*
* @ param string | archive $filename archive filename to use as backup or
* archive object created by createBackup
* @ param bool $compress specifies wheter the backup is compressed or not
2011-01-14 23:11:13 +00:00
*/
2013-03-14 15:50:49 -04:00
public function backup ( $backupFile , $compress = true )
2014-10-27 11:25:17 -04:00
{
2012-10-18 13:05:23 -04:00
/* $filename can be a string , in which case it ' s used as the filename of
* the backup , or it can be a previously created tar , which allows for
* multiple workspaces in one backup .
*/
2013-03-14 15:50:49 -04:00
if ( ! $this -> workspaceExists ()) {
throw new Exception ( " Workspace ' { $this -> name } ' not found " );
2012-10-18 13:05:23 -04:00
}
2013-03-14 15:50:49 -04:00
if ( is_string ( $backupFile )) {
$backup = $this -> createBackup ( $backupFile );
2012-10-18 13:05:23 -04:00
$filename = $backupFile ;
} else {
$backup = $backupFile ;
$filename = $backup -> _tarname ;
}
2013-03-14 15:50:49 -04:00
if ( ! file_exists ( PATH_DATA . " upgrade/ " )) {
mkdir ( PATH_DATA . " upgrade/ " );
2012-10-18 13:05:23 -04:00
}
2013-03-14 15:50:49 -04:00
$tempDirectory = PATH_DATA . " upgrade/ " . basename ( tempnam ( __FILE__ , '' ));
mkdir ( $tempDirectory );
2012-10-18 13:05:23 -04:00
$metadata = $this -> getMetadata ();
2013-03-14 15:50:49 -04:00
CLI :: logging ( " Backing up database... \n " );
$metadata [ " databases " ] = $this -> exportDatabase ( $tempDirectory );
$metadata [ " directories " ] = array ( " { $this -> name } .files " );
2012-10-18 13:05:23 -04:00
$metadata [ " version " ] = 1 ;
2016-04-14 17:44:40 -04:00
$metadata [ 'backupEngineVersion' ] = 2 ;
2012-10-18 13:05:23 -04:00
$metaFilename = " $tempDirectory / { $this -> name } .meta " ;
/* Write metadata to file , but make it prettier before . The metadata is just
* a JSON codified array .
*/
2013-03-14 15:50:49 -04:00
if ( ! file_put_contents ( $metaFilename , str_replace ( array ( " , " , " { " , " } "
), array ( " , \n " , " { \n " , " \n } \n "
), G :: json_encode ( $metadata )))) {
throw new Exception ( " Could not create backup metadata " );
2012-10-18 13:05:23 -04:00
}
2013-03-14 15:50:49 -04:00
CLI :: logging ( " Copying database to backup... \n " );
$this -> addToBackup ( $backup , $tempDirectory , $tempDirectory );
CLI :: logging ( " Copying files to backup... \n " );
2012-10-18 13:05:23 -04:00
2013-03-14 15:50:49 -04:00
$this -> addToBackup ( $backup , $this -> path , $this -> path , " { $this -> name } .files " );
2012-10-18 13:05:23 -04:00
//Remove leftovers.
2013-03-14 15:50:49 -04:00
G :: rm_dir ( $tempDirectory );
2011-02-17 20:51:26 +00:00
}
2012-10-18 13:05:23 -04:00
//TODO: Move to class.dbMaintenance.php
/**
* create a user in the database
*
* Create a user specified by the parameters and grant all priviledges for
* the database specified , when the user connects from the hostname .
* Drops the user if it already exists .
* This function only supports MySQL .
*
* @ param string $username username
* @ param string $password password
* @ param string $hostname the hostname the user will be connecting from
* @ param string $database the database to grant permissions
*/
2015-08-05 22:41:55 -04:00
public function createDBUser ( $username , $password , $hostname , $database )
2012-10-18 13:05:23 -04:00
{
2013-03-14 15:50:49 -04:00
mysql_select_db ( " mysql " );
$hostname = array_shift ( explode ( " : " , $hostname ));
2012-10-18 13:05:23 -04:00
$sqlstmt = " SELECT * FROM user WHERE user = ' $username ' AND host = ' $hostname ' " ;
2013-03-14 15:50:49 -04:00
$result = mysql_query ( $sqlstmt );
2012-10-18 13:05:23 -04:00
if ( $result === false ) {
2013-03-14 15:50:49 -04:00
throw new Exception ( " Unable to retrieve users: " . mysql_error ());
2012-10-18 13:05:23 -04:00
}
2013-03-14 15:50:49 -04:00
$users = mysql_num_rows ( $result );
2017-02-14 15:09:57 -04:00
if ( $users === 0 ) {
CLI :: logging ( " Creating user $username for $hostname\n " );
$result = mysql_query ( " CREATE USER ' $username '@' $hostname ' IDENTIFIED BY ' $password ' " );
2012-10-18 13:05:23 -04:00
if ( $result === false ) {
2017-02-14 15:09:57 -04:00
throw new Exception ( " Unable to create user $username : " . mysql_error ());
2012-10-18 13:05:23 -04:00
}
}
2013-03-14 15:50:49 -04:00
$result = mysql_query ( " GRANT ALL ON $database .* TO ' $username '@' $hostname ' " );
2012-10-18 13:05:23 -04:00
if ( $result === false ) {
2013-03-14 15:50:49 -04:00
throw new Exception ( " Unable to grant priviledges to user $username : " . mysql_error ());
2012-10-18 13:05:23 -04:00
}
2011-01-14 23:11:13 +00:00
}
2012-10-18 13:05:23 -04:00
//TODO: Move to class.dbMaintenance.php
/**
* executes a mysql script
*
* This function supports scripts with -- comments in the beginning of a line
* and multi - line statements .
* It does not support other forms of comments ( such as /*... or {{ ... }}) .
*
* @ param string $filename the script filename
* @ param string $database the database to execute this script into
*/
2016-04-14 17:44:40 -04:00
public function executeSQLScript ( $database , $filename , $parameters , $versionBackupEngine = 1 )
2012-10-18 13:05:23 -04:00
{
2013-03-14 15:50:49 -04:00
mysql_query ( " CREATE DATABASE IF NOT EXISTS " . mysql_real_escape_string ( $database ));
2013-08-21 16:59:33 -04:00
2014-10-31 17:38:55 -04:00
//check function shell_exec
$disabled_functions = ini_get ( 'disable_functions' );
$flag = false ;
2016-03-03 12:09:38 -04:00
if ( $disabled_functions != '' ) {
2014-10-31 17:38:55 -04:00
$arr = explode ( ',' , $disabled_functions );
sort ( $arr );
if ( in_array ( " shell_exec " , $arr )) {
$flag = true ;
}
}
// Check if mysql exist on server
2014-10-03 13:38:16 -04:00
$flagFunction = null ;
2016-03-03 12:09:38 -04:00
if ( ! $flag ) {
2013-08-15 16:05:27 -04:00
$flagFunction = shell_exec ( 'mysql --version' );
}
2013-08-21 16:59:33 -04:00
2016-04-12 16:33:21 -04:00
$arrayRegExpEngineSearch = array ( " / \ ) \ s*TYPE \ s*= \ s*(InnoDB)/i " , " / \ ) \ s*TYPE \ s*= \ s*(MyISAM)/i " , " /SET \ s*FOREIGN_KEY_CHECKS \ s*= \ s*0 \ s*;/ " );
$arrayRegExpEngineReplace = array ( " ) ENGINE= \\ 1 DEFAULT CHARSET=utf8 " , " ) ENGINE= \\ 1 " , " SET FOREIGN_KEY_CHECKS=0; \n SET unique_checks=0; \n SET AUTOCOMMIT=0; " );
2015-08-12 09:30:43 -04:00
2017-01-18 17:33:38 -04:00
//replace DEFINER
$script = preg_replace ( '/DEFINER=[^*]*/' , '' , file_get_contents ( $filename ));
file_put_contents ( $filename , $script );
2016-03-03 12:09:38 -04:00
if ( ! $flag && ! is_null ( $flagFunction )) {
2015-05-29 14:42:29 -04:00
//Replace TYPE by ENGINE
2016-04-14 17:44:40 -04:00
if ( $versionBackupEngine == 1 ) {
$script = preg_replace ( $arrayRegExpEngineSearch , $arrayRegExpEngineReplace , file_get_contents ( $filename ));
file_put_contents ( $filename , $script . " \n COMMIT; " );
} else {
$arrayRegExpEngineSearch = array ( " / \ ) \ s*TYPE \ s*= \ s*(InnoDB)/i " , " / \ ) \ s*TYPE \ s*= \ s*(MyISAM)/i " );
$arrayRegExpEngineReplace = array ( " ) ENGINE= \\ 1 DEFAULT CHARSET=utf8 " , " ) ENGINE= \\ 1 " );
$script = preg_replace ( $arrayRegExpEngineSearch , $arrayRegExpEngineReplace , file_get_contents ( $filename ));
file_put_contents ( $filename , $script );
}
2015-08-12 09:30:43 -04:00
2016-03-03 12:09:38 -04:00
$aHost = explode ( ':' , $parameters [ 'dbHost' ]);
2015-05-25 17:44:23 -04:00
$dbHost = $aHost [ 0 ];
2016-03-03 12:09:38 -04:00
if ( isset ( $aHost [ 1 ])) {
2015-05-26 09:17:10 -04:00
$dbPort = $aHost [ 1 ];
$command = 'mysql'
2016-03-03 12:09:38 -04:00
. ' --host=' . $dbHost
. ' --port=' . $dbPort
. ' --user=' . $parameters [ 'dbUser' ]
2016-09-28 14:58:48 -04:00
. ' --password=' . escapeshellarg ( $parameters [ 'dbPass' ])
2016-03-03 12:09:38 -04:00
. ' --database=' . mysql_real_escape_string ( $database )
. ' --default_character_set utf8'
. ' --execute="SOURCE ' . $filename . '"' ;
} else {
2015-05-26 09:17:10 -04:00
$command = 'mysql'
2016-03-03 12:09:38 -04:00
. ' --host=' . $dbHost
. ' --user=' . $parameters [ 'dbUser' ]
2016-09-28 14:58:48 -04:00
. ' --password=' . escapeshellarg ( $parameters [ 'dbPass' ])
2016-03-03 12:09:38 -04:00
. ' --database=' . mysql_real_escape_string ( $database )
. ' --default_character_set utf8'
. ' --execute="SOURCE ' . $filename . '"' ;
2015-05-25 17:44:23 -04:00
}
2013-08-15 13:27:29 -04:00
shell_exec ( $command );
} else {
//If the safe mode of the server is actived
try {
mysql_select_db ( $database );
2013-08-21 16:59:33 -04:00
2015-05-22 10:07:44 -04:00
//Replace TYPE by ENGINE
2015-08-12 09:30:43 -04:00
$script = preg_replace ( $arrayRegExpEngineSearch , $arrayRegExpEngineReplace , file_get_contents ( $filename ));
2016-04-14 17:44:40 -04:00
if ( $versionBackupEngine == 1 ) {
$script = $script . " \n COMMIT; " ;
}
2015-08-12 09:30:43 -04:00
2013-10-28 13:53:03 -04:00
$lines = explode ( " \n " , $script );
2013-08-15 13:27:29 -04:00
$previous = null ;
2014-10-03 10:31:50 -04:00
$insert = false ;
2013-08-15 13:27:29 -04:00
foreach ( $lines as $j => $line ) {
// Remove comments from the script
$line = trim ( $line );
if ( strpos ( $line , " -- " ) === 0 ) {
$line = substr ( $line , 0 , strpos ( $line , " -- " ));
}
if ( empty ( $line )) {
continue ;
}
// Concatenate the previous line, if any, with the current
if ( $previous ) {
$line = $previous . " " . $line ;
}
$previous = null ;
2013-11-11 10:46:22 -04:00
2013-08-15 13:27:29 -04:00
// If the current line doesnt end with ; then put this line together
// with the next one, thus supporting multi-line statements.
if ( strrpos ( $line , " ; " ) != strlen ( $line ) - 1 ) {
$previous = $line ;
continue ;
}
$line = substr ( $line , 0 , strrpos ( $line , " ; " ));
2013-11-11 10:46:22 -04:00
if ( strrpos ( $line , " INSERT INTO " ) !== false ) {
2014-10-03 10:31:50 -04:00
$insert = true ;
2013-11-11 10:46:22 -04:00
if ( $insert ) {
$result = mysql_query ( " START TRANSACTION " );
$insert = false ;
}
$result = mysql_query ( $line );
continue ;
} else {
if ( ! $insert ) {
$result = mysql_query ( " COMMIT " );
$insert = true ;
}
}
2013-08-15 13:27:29 -04:00
$result = mysql_query ( $line );
if ( $result === false ) {
throw new Exception ( " Error when running script ' $filename ', line $j , query ' $line ': " . mysql_error ());
}
}
2013-11-11 10:46:22 -04:00
if ( ! $insert ) {
$result = mysql_query ( " COMMIT " );
}
2013-08-15 13:27:29 -04:00
} catch ( Exception $e ) {
CLI :: logging ( CLI :: error ( " Error: " . " There are problems running script ' $filename ': " . $e ));
2012-10-18 13:05:23 -04:00
}
}
2011-01-14 23:11:13 +00:00
}
2012-10-18 13:05:23 -04:00
2014-10-09 10:36:34 -04:00
public function executeScript ( $database , $filename , $parameters )
{
$this -> executeSQLScript ( $database , $filename , $parameters );
return true ;
}
2013-03-14 15:50:49 -04:00
static public function restoreLegacy ( $directory )
2012-10-18 13:05:23 -04:00
{
2013-03-14 15:50:49 -04:00
throw new Exception ( " Use gulliver to restore backups from old versions " );
2011-02-17 20:51:26 +00:00
}
2011-11-08 17:37:47 -04:00
2013-03-14 15:50:49 -04:00
static public function getBackupInfo ( $filename )
2012-10-18 13:05:23 -04:00
{
2013-03-14 15:50:49 -04:00
G :: LoadThirdParty ( 'pear/Archive' , 'Tar' );
$backup = new Archive_Tar ( $filename );
2012-10-18 13:05:23 -04:00
//Get a temporary directory in the upgrade directory
2013-03-14 15:50:49 -04:00
$tempDirectory = PATH_DATA . " upgrade/ " . basename ( tempnam ( __FILE__ , '' ));
mkdir ( $tempDirectory );
$metafiles = array ();
2012-10-18 13:05:23 -04:00
foreach ( $backup -> listContent () as $backupFile ) {
$filename = $backupFile [ " filename " ];
2016-03-03 12:09:38 -04:00
if ( strpos ( $filename , " / " ) === false && substr_compare ( $filename , " .meta " , - 5 , 5 , true ) === 0 ) {
2013-03-14 15:50:49 -04:00
if ( ! $backup -> extractList ( array ( $filename ), $tempDirectory )) {
throw new Exception ( " Could not extract backup " );
2012-10-18 13:05:23 -04:00
}
$metafiles [] = " $tempDirectory / $filename " ;
}
}
2011-02-17 20:51:26 +00:00
2013-03-14 15:50:49 -04:00
CLI :: logging ( " Found " . count ( $metafiles ) . " workspace(s) in backup \n " );
2011-02-17 20:51:26 +00:00
2012-10-18 13:05:23 -04:00
foreach ( $metafiles as $metafile ) {
2013-03-14 15:50:49 -04:00
$data = file_get_contents ( $metafile );
$workspaceData = G :: json_decode ( $data );
CLI :: logging ( " \n " );
2016-03-03 12:09:38 -04:00
workspaceTools :: printInfo (( array ) $workspaceData );
2012-10-18 13:05:23 -04:00
}
2013-03-14 15:50:49 -04:00
G :: rm_dir ( $tempDirectory );
2011-01-14 23:11:13 +00:00
}
2011-02-17 20:51:26 +00:00
2013-03-14 15:50:49 -04:00
static public function dirPerms ( $filename , $owner , $group , $perms )
2012-10-18 13:05:23 -04:00
{
2013-03-14 15:50:49 -04:00
$chown = @ chown ( $filename , $owner );
$chgrp = @ chgrp ( $filename , $group );
$chmod = @ chmod ( $filename , $perms );
2015-08-12 09:30:43 -04:00
2012-10-18 13:05:23 -04:00
if ( $chgrp === false || $chmod === false || $chown === false ) {
2016-03-03 12:09:38 -04:00
if ( strtoupper ( substr ( PHP_OS , 0 , 3 )) === 'WIN' ) {
2015-08-12 09:30:43 -04:00
exec ( " icacls \" " . $filename . " \" /grant Administrador:(D,WDAC) /T " , $res );
2013-10-22 12:34:08 -04:00
} else {
CLI :: logging ( CLI :: error ( " Failed to set permissions for $filename " ) . " \n " );
}
2012-10-18 13:05:23 -04:00
}
2013-03-14 15:50:49 -04:00
if ( is_dir ( $filename )) {
foreach ( array_merge ( glob ( $filename . " /* " ), glob ( $filename . " /.* " )) as $item ) {
if ( basename ( $item ) == " . " || basename ( $item ) == " .. " ) {
2012-10-18 13:05:23 -04:00
continue ;
}
2013-03-14 15:50:49 -04:00
workspaceTools :: dirPerms ( $item , $owner , $group , $perms );
2012-10-18 13:05:23 -04:00
}
}
2011-01-14 23:11:13 +00:00
}
2011-03-10 17:14:07 +00:00
2012-10-18 13:05:23 -04:00
/**
* restore an archive into a workspace
*
* Restores any database and files included in the backup , either as a new
* workspace , or overwriting a previous one
*
* @ param string $filename the backup filename
2017-02-16 12:41:25 -04:00
* @ param string $srcWorkspace name of the source workspace
* @ param string $dstWorkspace name of the destination workspace
* @ param string $overwrite if you need overwrite the database
* @ param string $lang for define the language
* @ param string $port of database if is empty take 3306
2012-10-18 13:05:23 -04:00
*/
2015-05-21 15:19:42 -04:00
static public function restore ( $filename , $srcWorkspace , $dstWorkspace = null , $overwrite = true , $lang = 'en' , $port = '' )
2012-10-18 13:05:23 -04:00
{
2013-03-14 15:50:49 -04:00
G :: LoadThirdParty ( 'pear/Archive' , 'Tar' );
$backup = new Archive_Tar ( $filename );
2012-10-18 13:05:23 -04:00
//Get a temporary directory in the upgrade directory
2013-03-14 15:50:49 -04:00
$tempDirectory = PATH_DATA . " upgrade/ " . basename ( tempnam ( __FILE__ , '' ));
2012-10-18 13:05:23 -04:00
$parentDirectory = PATH_DATA . " upgrade " ;
2013-03-14 15:50:49 -04:00
if ( is_writable ( $parentDirectory )) {
mkdir ( $tempDirectory );
2012-10-18 13:05:23 -04:00
} else {
2013-03-14 15:50:49 -04:00
throw new Exception ( " Could not create directory: " . $parentDirectory );
2012-10-18 13:05:23 -04:00
}
//Extract all backup files, including database scripts and workspace files
2013-03-14 15:50:49 -04:00
if ( ! $backup -> extract ( $tempDirectory )) {
throw new Exception ( " Could not extract backup " );
2012-10-18 13:05:23 -04:00
}
//Search for metafiles in the new standard (the old standard would contain
//txt files).
2013-03-14 15:50:49 -04:00
$metaFiles = glob ( $tempDirectory . " /*.meta " );
if ( empty ( $metaFiles )) {
$metaFiles = glob ( $tempDirectory . " /*.txt " );
if ( ! empty ( $metaFiles )) {
return workspaceTools :: restoreLegacy ( $tempDirectory );
2012-10-18 13:05:23 -04:00
} else {
2013-03-14 15:50:49 -04:00
throw new Exception ( " No metadata found in backup " );
2012-10-18 13:05:23 -04:00
}
} else {
2013-03-14 15:50:49 -04:00
CLI :: logging ( " Found " . count ( $metaFiles ) . " workspaces in backup: \n " );
2012-10-18 13:05:23 -04:00
foreach ( $metaFiles as $metafile ) {
2013-03-14 15:50:49 -04:00
CLI :: logging ( " -> " . basename ( $metafile ) . " \n " );
2012-10-18 13:05:23 -04:00
}
}
2013-03-14 15:50:49 -04:00
if ( count ( $metaFiles ) > 1 && ( ! isset ( $srcWorkspace ))) {
throw new Exception ( " Multiple workspaces in backup but no workspace specified to restore " );
2012-10-18 13:05:23 -04:00
}
2013-03-14 15:50:49 -04:00
if ( isset ( $srcWorkspace ) && ! in_array ( " $srcWorkspace .meta " , array_map ( BASENAME , $metaFiles ))) {
throw new Exception ( " Workspace $srcWorkspace not found in backup " );
2012-10-18 13:05:23 -04:00
}
2013-06-26 13:15:43 -04:00
2013-05-17 10:39:48 -04:00
$version = System :: getVersion ();
2016-03-03 12:09:38 -04:00
$pmVersion = ( preg_match ( " /^([ \ d \ .]+).* $ / " , $version , $arrayMatch )) ? $arrayMatch [ 1 ] : " " ; //Otherwise: Branch master
2015-08-12 09:30:43 -04:00
2013-05-17 10:39:48 -04:00
CLI :: logging ( CLI :: warning ( "
2015-07-21 15:55:20 -04:00
Warning : A workspace from a newer version of ProcessMaker can NOT be restored in an older version of
ProcessMaker . For example , restoring from v . 3.0 to v . 2.5 will not work . However , it may be possible
to restore a workspace from an older version to an newer version of ProcessMaker , although error
2015-08-12 09:30:43 -04:00
messages may be displayed during the restore process . " ) . " \n " );
2013-05-17 10:39:48 -04:00
2012-10-18 13:05:23 -04:00
foreach ( $metaFiles as $metaFile ) {
2016-08-05 12:51:13 -04:00
$metadata = preg_replace ( '/\r|\n/' , '' , file_get_contents ( $metaFile ));
$metadata = G :: json_decode ( preg_replace ( '/\s+/' , '' , $metadata ));
2012-10-18 13:05:23 -04:00
if ( $metadata -> version != 1 ) {
2013-03-14 15:50:49 -04:00
throw new Exception ( " Backup version { $metadata -> version } not supported " );
2012-10-18 13:05:23 -04:00
}
$backupWorkspace = $metadata -> WORKSPACE_NAME ;
2014-10-27 11:25:17 -04:00
2014-10-09 10:36:34 -04:00
if ( strpos ( $metadata -> DB_RBAC_NAME , 'rb_' ) === false ) {
$onedb = true ;
2014-10-30 17:32:31 -04:00
$oldDatabases = 1 ;
2014-10-09 10:36:34 -04:00
} else {
$onedb = false ;
2014-10-30 17:32:31 -04:00
$oldDatabases = 3 ;
2014-10-09 10:36:34 -04:00
}
2014-10-27 11:25:17 -04:00
2013-03-14 15:50:49 -04:00
if ( isset ( $dstWorkspace )) {
2012-10-18 13:05:23 -04:00
$workspaceName = $dstWorkspace ;
$createWorkspace = true ;
} else {
$workspaceName = $metadata -> WORKSPACE_NAME ;
$createWorkspace = false ;
}
2013-03-14 15:50:49 -04:00
if ( isset ( $srcWorkspace ) && strcmp ( $metadata -> WORKSPACE_NAME , $srcWorkspace ) != 0 ) {
CLI :: logging ( CLI :: warning ( " > Workspace $backupWorkspace found, but not restoring. " ) . " \n " );
2012-10-18 13:05:23 -04:00
continue ;
} else {
2013-03-14 15:50:49 -04:00
CLI :: logging ( " > Restoring " . CLI :: info ( $backupWorkspace ) . " to " . CLI :: info ( $workspaceName ) . " \n " );
2012-10-18 13:05:23 -04:00
}
2013-03-14 15:50:49 -04:00
$workspace = new workspaceTools ( $workspaceName );
2014-10-27 11:25:17 -04:00
2016-04-20 11:11:34 -04:00
if ( Installer :: isset_site ( $workspaceName )) {
2012-10-18 13:05:23 -04:00
if ( $overwrite ) {
2014-11-10 09:01:51 -04:00
if ( $workspace -> dbInfo [ 'DB_NAME' ] == $workspace -> dbInfo [ 'DB_RBAC_NAME' ]) {
2014-10-30 17:32:31 -04:00
$newDatabases = 1 ;
} else {
$newDatabases = 3 ;
}
if ( $newDatabases != $oldDatabases ) {
throw new Exception ( " We can't overwrite this workspace because it has a different amount of databases. Not only the 'source' but also the 'target' must have the same amount of databases. " );
}
2016-04-20 15:18:23 -04:00
2016-08-05 12:51:13 -04:00
if ( ! $workspace -> workspaceExists ()) {
throw new Exception ( 'We can not overwrite this workspace because the workspace ' . $workspaceName . ' does not exist please check the lower case and upper case.' );
2016-04-20 15:18:23 -04:00
}
2013-03-14 15:50:49 -04:00
CLI :: logging ( CLI :: warning ( " > Workspace $workspaceName already exist, overwriting! " ) . " \n " );
2012-10-18 13:05:23 -04:00
} else {
2013-03-14 15:50:49 -04:00
throw new Exception ( " Destination workspace already exist (use -o to overwrite) " );
2012-10-18 13:05:23 -04:00
}
}
2013-03-14 15:50:49 -04:00
if ( file_exists ( $workspace -> path )) {
G :: rm_dir ( $workspace -> path );
2012-10-18 13:05:23 -04:00
}
foreach ( $metadata -> directories as $dir ) {
2013-03-14 15:50:49 -04:00
CLI :: logging ( " +> Restoring directory ' $dir ' \n " );
2012-10-18 13:05:23 -04:00
2013-11-11 10:46:22 -04:00
if ( file_exists ( " $tempDirectory / $dir " . " /ee " )) {
2013-05-13 09:45:56 -04:00
G :: rm_dir ( " $tempDirectory / $dir " . " /ee " );
}
2013-11-11 10:46:22 -04:00
if ( file_exists ( " $tempDirectory / $dir " . " /plugin.singleton " )) {
2013-05-13 09:45:56 -04:00
G :: rm_dir ( " $tempDirectory / $dir " . " /plugin.singleton " );
2013-04-30 16:28:12 -04:00
}
2013-03-14 15:50:49 -04:00
if ( ! rename ( " $tempDirectory / $dir " , $workspace -> path )) {
throw new Exception ( " There was an error copying the backup files ( $tempDirectory / $dir ) to the workspace directory { $workspace -> path } . " );
2012-10-18 13:05:23 -04:00
}
}
2013-03-14 15:50:49 -04:00
CLI :: logging ( " > Changing file permissions \n " );
$shared_stat = stat ( PATH_DATA );
2015-08-12 09:30:43 -04:00
2012-10-18 13:05:23 -04:00
if ( $shared_stat !== false ) {
2013-03-14 15:50:49 -04:00
workspaceTools :: dirPerms ( $workspace -> path , $shared_stat [ 'uid' ], $shared_stat [ 'gid' ], $shared_stat [ 'mode' ]);
2012-10-18 13:05:23 -04:00
} else {
2013-03-14 15:50:49 -04:00
CLI :: logging ( CLI :: error ( " Could not get the shared folder permissions, not changing workspace permissions " ) . " \n " );
2012-10-18 13:05:23 -04:00
}
2013-03-14 15:50:49 -04:00
list ( $dbHost , $dbUser , $dbPass ) = @ explode ( SYSTEM_HASH , G :: decrypt ( HASH_INSTALLATION , SYSTEM_HASH ));
2016-03-03 12:09:38 -04:00
if ( $port != '' ) {
$dbHost = $dbHost . $port ; //127.0.0.1:3306
2015-05-21 15:19:42 -04:00
}
2016-03-03 12:09:38 -04:00
$aParameters = array ( 'dbHost' => $dbHost , 'dbUser' => $dbUser , 'dbPass' => $dbPass );
2015-08-12 09:30:43 -04:00
//Restore
if ( ! defined ( " SYS_SYS " )) {
define ( " SYS_SYS " , $workspaceName );
}
if ( ! defined ( " PATH_DATA_SITE " )) {
define ( " PATH_DATA_SITE " , PATH_DATA . " sites " . PATH_SEP . SYS_SYS . PATH_SEP );
}
2016-03-03 12:09:38 -04:00
$pmVersionWorkspaceToRestore = ( preg_match ( " /^([ \ d \ .]+).* $ / " , $metadata -> PM_VERSION , $arrayMatch )) ? $arrayMatch [ 1 ] : " " ;
2015-08-12 09:30:43 -04:00
2013-03-14 15:50:49 -04:00
CLI :: logging ( " > Connecting to system database in ' $dbHost ' \n " );
$link = mysql_connect ( $dbHost , $dbUser , $dbPass );
@ mysql_query ( " SET NAMES 'utf8'; " );
@ mysql_query ( " SET FOREIGN_KEY_CHECKS=0; " );
2015-08-12 09:30:43 -04:00
@ mysql_query ( " SET GLOBAL log_bin_trust_routine_creators = 1; " );
2013-03-14 15:50:49 -04:00
if ( ! $link ) {
throw new Exception ( 'Could not connect to system database: ' . mysql_error ());
2012-10-18 13:05:23 -04:00
}
2014-10-03 10:31:50 -04:00
2014-10-09 10:36:34 -04:00
$dbName = '' ;
$newDBNames = $workspace -> resetDBInfo ( $dbHost , $createWorkspace , $onedb );
2012-10-18 13:05:23 -04:00
foreach ( $metadata -> databases as $db ) {
2014-10-27 11:25:17 -04:00
if ( $dbName != $newDBNames [ $db -> name ]) {
2016-11-04 17:10:36 -04:00
$dbName = $dbUser = $newDBNames [ $db -> name ];
if ( isset ( $newDBNames [ 'DB_USER' ])){
$dbUser = $newDBNames [ 'DB_USER' ];
}
2014-11-05 12:02:02 -04:00
if ( mysql_select_db ( $dbName , $link )) {
2016-03-03 12:09:38 -04:00
if ( ! $overwrite ) {
2014-11-05 09:34:49 -04:00
throw new Exception ( " Destination Database already exist (use -o to overwrite) " );
}
}
2014-10-09 10:36:34 -04:00
CLI :: logging ( " +> Restoring database { $db -> name } to $dbName\n " );
2016-04-14 17:44:40 -04:00
$versionBackupEngine = ( isset ( $metadata -> backupEngineVersion )) ? $metadata -> backupEngineVersion : 1 ;
$workspace -> executeSQLScript ( $dbName , " $tempDirectory / { $db -> name } .sql " , $aParameters , $versionBackupEngine );
2017-02-14 15:09:57 -04:00
$workspace -> createDBUser ( $dbUser , ( $workspace -> dbGrantUserPassword != '' ? $workspace -> dbGrantUserPassword : $db -> pass ), " localhost " , $dbName );
$workspace -> createDBUser ( $dbUser , ( $workspace -> dbGrantUserPassword != '' ? $workspace -> dbGrantUserPassword : $db -> pass ), " % " , $dbName );
2014-10-09 10:36:34 -04:00
}
2012-10-18 13:05:23 -04:00
}
2016-04-14 17:44:40 -04:00
if (( $pmVersionWorkspaceToRestore != '' ) && ( version_compare ( $pmVersionWorkspaceToRestore . " " ,
$pmVersion . " " , " < " ) || $pmVersion == " " )
) {
2013-05-17 10:39:48 -04:00
$start = microtime ( true );
CLI :: logging ( " > Updating database... \n " );
2014-10-09 10:36:34 -04:00
$workspace -> upgradeDatabase ( $onedb );
2013-05-17 10:39:48 -04:00
$stop = microtime ( true );
2015-08-12 09:30:43 -04:00
CLI :: logging ( " <*> Database Upgrade Process took " . ( $stop - $start ) . " seconds. \n " );
2013-05-17 10:39:48 -04:00
}
2015-08-12 09:30:43 -04:00
$start = microtime ( true );
CLI :: logging ( " > Verify files enterprise old... \n " );
$workspace -> verifyFilesOldEnterprise ( $workspaceName );
$stop = microtime ( true );
CLI :: logging ( " <*> Verify took " . ( $stop - $start ) . " seconds. \n " );
2014-10-17 12:30:25 -04:00
$start = microtime ( true );
CLI :: logging ( " > Verify License Enterprise... \n " );
$workspace -> verifyLicenseEnterprise ( $workspaceName );
$stop = microtime ( true );
2015-08-12 09:30:43 -04:00
CLI :: logging ( " <*> Verify took " . ( $stop - $start ) . " seconds. \n " );
2014-10-17 12:30:25 -04:00
2015-08-12 09:30:43 -04:00
$start = microtime ( true );
CLI :: logging ( " > Check Mafe Requirements... \n " );
2015-05-10 17:16:34 -04:00
$workspace -> checkMafeRequirements ( $workspaceName , $lang );
2015-08-12 09:30:43 -04:00
$stop = microtime ( true );
CLI :: logging ( " <*> Check Mafe Requirements Process took " . ( $stop - $start ) . " seconds. \n " );
2016-04-14 17:44:40 -04:00
if (( $pmVersionWorkspaceToRestore != '' ) && ( version_compare ( $pmVersionWorkspaceToRestore . " " ,
$pmVersion . " " , " < " ) || $pmVersion == " " )
) {
2015-08-12 09:30:43 -04:00
$start = microtime ( true );
CLI :: logging ( " > Updating cache view... \n " );
$workspace -> upgradeCacheView ( true , true , $lang );
$stop = microtime ( true );
CLI :: logging ( " <*> Updating cache view Process took " . ( $stop - $start ) . " seconds. \n " );
} else {
$workspace -> upgradeTriggersOfTables ( true , $lang );
}
2015-05-10 17:16:34 -04:00
2016-08-05 12:51:13 -04:00
if ( $pmVersion == '' && strpos ( strtoupper ( $version ), 'BRANCH' )) {
2016-04-14 17:44:40 -04:00
$pmVersion = 'dev-version-backup' ;
}
2017-02-16 12:41:25 -04:00
//Move the labels of content to the corresponding table
$start = microtime ( true );
CLI :: logging ( " > Optimizing content data... \n " );
$workspace -> migrateContent ( $workspace -> name , $lang );
$stop = microtime ( true );
CLI :: logging ( " <*> Optimizing content data took " . ( $stop - $start ) . " seconds. \n " );
//Move the data of cases to the corresponding List
2015-05-14 16:15:20 -04:00
/*----------------------------------********---------------------------------*/
2017-02-16 12:41:25 -04:00
$start = microtime ( true );
CLI :: logging ( " > Updating List tables... \n " );
$workspace -> migrateList ( $workspace -> name , false , $lang );
$stop = microtime ( true );
CLI :: logging ( " <*> Updating List Process took " . ( $stop - $start ) . " seconds. \n " );
2015-05-14 16:15:20 -04:00
/*----------------------------------********---------------------------------*/
2013-06-26 13:15:43 -04:00
2017-02-16 12:41:25 -04:00
$start = microtime ( true );
CLI :: logging ( " > Updating Files Manager... \n " );
$workspace -> processFilesUpgrade ();
$stop = microtime ( true );
CLI :: logging ( " <*> Updating Files Manager took " . ( $stop - $start ) . " seconds. \n " );
//Populate the new fields for replace string UID to Interger ID
$start = microtime ( true );
CLI :: logging ( " > Migrating and populating indexing for APP_CACHE_VIEW... \n " );
$workspace -> migratePopulateIndexingACV ( $workspace -> name );
$stop = microtime ( true );
CLI :: logging ( " <*> Migrating an populating indexing for APP_CACHE_VIEW process took " . ( $stop - $start ) . " seconds. \n " );
2013-03-14 15:50:49 -04:00
mysql_close ( $link );
2012-10-18 13:05:23 -04:00
}
2011-03-10 17:14:07 +00:00
2013-03-14 15:50:49 -04:00
CLI :: logging ( " Removing temporary files \n " );
2010-12-20 15:26:23 +00:00
2013-03-14 15:50:49 -04:00
G :: rm_dir ( $tempDirectory );
2012-10-18 13:05:23 -04:00
2013-03-14 15:50:49 -04:00
CLI :: logging ( CLI :: info ( " Done restoring " ) . " \n " );
2012-10-18 13:05:23 -04:00
}
2013-06-26 13:15:43 -04:00
2013-06-26 14:54:37 -04:00
public static function hotfixInstall ( $file )
2013-06-26 13:15:43 -04:00
{
$result = array ();
2013-06-26 14:54:37 -04:00
$dirHotfix = PATH_DATA . " hotfixes " ;
2013-06-26 13:15:43 -04:00
$arrayPathInfo = pathinfo ( $file );
2016-03-03 12:09:38 -04:00
$f = ( $arrayPathInfo [ " dirname " ] == " . " ) ? $dirHotfix . PATH_SEP . $file : $file ;
2013-06-26 13:15:43 -04:00
2016-03-03 12:09:38 -04:00
$swv = 1 ;
2013-06-26 13:15:43 -04:00
$msgv = " " ;
2013-06-26 14:54:37 -04:00
if ( ! file_exists ( $dirHotfix )) {
G :: mk_dir ( $dirHotfix , 0777 );
2013-06-26 13:15:43 -04:00
}
if ( ! file_exists ( $f )) {
2016-03-03 12:09:38 -04:00
$swv = 0 ;
$msgv = $msgv . (( $msgv != " " ) ? " \n " : null ) . " - The file \" $f\ " does not exist " ;
2013-06-26 13:15:43 -04:00
}
if ( $arrayPathInfo [ " extension " ] != " tar " ) {
2016-03-03 12:09:38 -04:00
$swv = 0 ;
$msgv = $msgv . (( $msgv != " " ) ? " \n " : null ) . " - The file extension \" $file\ " is not \ " tar \" " ;
2013-06-26 13:15:43 -04:00
}
if ( $swv == 1 ) {
G :: LoadThirdParty ( " pear/Archive " , " Tar " );
//Extract
$tar = new Archive_Tar ( $f );
2013-11-06 17:06:53 -04:00
$swTar = $tar -> extractModify ( PATH_TRUNK , " processmaker " ); //true on success, false on error
2013-06-26 13:15:43 -04:00
if ( $swTar ) {
$result [ " status " ] = 1 ;
2013-06-26 15:24:18 -04:00
$result [ " message " ] = " - Hotfix installed successfully \" $f\ " " ;
2013-06-26 13:15:43 -04:00
} else {
$result [ " status " ] = 0 ;
$result [ " message " ] = " - Could not extract file \" $f\ " " ;
}
} else {
$result [ " status " ] = 0 ;
$result [ " message " ] = $msgv ;
}
return $result ;
}
2014-01-17 14:39:29 -04:00
2013-11-22 17:05:10 -04:00
public function backupLogFiles ()
{
2013-11-25 17:58:52 -04:00
$config = System :: getSystemConfiguration ();
2014-01-17 14:39:29 -04:00
2013-11-22 17:05:10 -04:00
clearstatcache ();
$path = PATH_DATA . " log " . PATH_SEP ;
$filePath = $path . " cron.log " ;
if ( file_exists ( $filePath )) {
$size = filesize ( $filePath );
2013-11-25 17:58:52 -04:00
/* $config['size_log_file'] has the value 5000000 -> approximately 5 megabytes */
if ( $size > $config [ 'size_log_file' ]) {
2013-11-22 17:05:10 -04:00
rename ( $filePath , $filePath . " .bak " );
}
}
}
2014-05-13 17:15:44 -04:00
public function checkMafeRequirements ( $workspace , $lang ) {
2014-10-03 10:31:50 -04:00
$this -> initPropel ( true );
2014-05-13 17:15:44 -04:00
$pmRestClient = OauthClientsPeer :: retrieveByPK ( 'x-pm-local-client' );
if ( empty ( $pmRestClient )) {
2015-05-10 17:16:34 -04:00
if ( ! is_file ( PATH_DATA . 'sites/' . $workspace . '/' . '.server_info' )) {
$_CSERVER = $_SERVER ;
unset ( $_CSERVER [ 'REQUEST_TIME' ]);
unset ( $_CSERVER [ 'REMOTE_PORT' ]);
$cput = serialize ( $_CSERVER );
file_put_contents ( PATH_DATA . 'sites/' . $workspace . '/' . '.server_info' , $cput );
}
2014-05-13 17:15:44 -04:00
if ( is_file ( PATH_DATA . 'sites/' . $workspace . '/' . '.server_info' )) {
$SERVER_INFO = file_get_contents ( PATH_DATA . 'sites/' . $workspace . '/' . '.server_info' );
$SERVER_INFO = unserialize ( $SERVER_INFO );
$envFile = PATH_CONFIG . 'env.ini' ;
$skin = 'neoclassic' ;
if ( file_exists ( $envFile ) ) {
$sysConf = System :: getSystemConfiguration ( $envFile );
$lang = $sysConf [ 'default_lang' ];
$skin = $sysConf [ 'default_skin' ];
}
$endpoint = sprintf (
'%s/sys%s/%s/%s/oauth2/grant' ,
2014-10-31 16:37:50 -04:00
isset ( $SERVER_INFO [ 'HTTP_ORIGIN' ]) ? $SERVER_INFO [ 'HTTP_ORIGIN' ] : '' ,
2014-05-13 17:15:44 -04:00
$workspace ,
$lang ,
$skin
);
$oauthClients = new OauthClients ();
$oauthClients -> setClientId ( 'x-pm-local-client' );
$oauthClients -> setClientSecret ( '179ad45c6ce2cb97cf1029e212046e81' );
$oauthClients -> setClientName ( 'PM Web Designer' );
$oauthClients -> setClientDescription ( 'ProcessMaker Web Designer App' );
$oauthClients -> setClientWebsite ( 'www.processmaker.com' );
$oauthClients -> setRedirectUri ( $endpoint );
$oauthClients -> save ();
} else {
eprintln ( " WARNING! No server info found! " , 'red' );
}
}
}
2014-09-25 16:55:16 -04:00
public function changeHashPassword ( $workspace , $response )
{
2014-09-22 09:58:50 -04:00
$this -> initPropel ( true );
2014-09-25 16:55:16 -04:00
G :: LoadClass ( " enterprise " );
2014-10-10 16:17:07 -04:00
$licensedFeatures = & PMLicensedFeatures :: getSingleton ();
2014-11-24 11:06:28 -04:00
/*----------------------------------********---------------------------------*/
2014-10-10 16:17:07 -04:00
if ( $licensedFeatures -> verifyfeature ( '95OY24wcXpEMzIyRmlNSnF0STNFSHJzMG9wYTJKekpLNmY2ZmRCeGtuZk5oUDloaUNhUGVjTDJBPT0=' )) {
enterpriseClass :: setHashPassword ( $response );
} else {
return false ;
}
2014-11-24 11:06:28 -04:00
/*----------------------------------********---------------------------------*/
2014-10-10 16:17:07 -04:00
return true ;
2014-09-22 09:58:50 -04:00
}
2014-09-26 13:00:16 -04:00
2014-10-17 12:30:25 -04:00
public function verifyFilesOldEnterprise ( $workspace )
2014-09-26 13:00:16 -04:00
{
$this -> initPropel ( true );
$pathBackup = PATH_DATA . 'backups' ;
if ( ! file_exists ( $pathBackup )) {
G :: mk_dir ( $pathBackup , 0777 );
}
$pathNewFile = PATH_DATA . 'backups' . PATH_SEP . 'enterpriseBackup' ;
$pathDirectoryEnterprise = PATH_CORE . 'plugins' . PATH_SEP . 'enterprise' ;
$pathFileEnterprise = PATH_CORE . 'plugins' . PATH_SEP . 'enterprise.php' ;
2014-10-02 18:07:57 -04:00
if ( ! file_exists ( $pathDirectoryEnterprise ) && ! file_exists ( $pathFileEnterprise )) {
2014-09-26 13:00:16 -04:00
CLI :: logging ( " Without changes... \n " );
return true ;
}
2014-09-29 11:38:08 -04:00
CLI :: logging ( " Migrating Enterprise Core version... \n " );
2014-09-26 13:00:16 -04:00
if ( ! file_exists ( $pathNewFile )) {
CLI :: logging ( " Creating folder in $pathNewFile\n " );
G :: mk_dir ( $newDiretory , 0777 );
}
$shared_stat = stat ( PATH_DATA );
if ( file_exists ( $pathDirectoryEnterprise )) {
2014-09-29 11:38:08 -04:00
CLI :: logging ( " Copying Enterprise Directory to $pathNewFile ... \n " );
2014-09-26 13:00:16 -04:00
if ( $shared_stat !== false ) {
workspaceTools :: dirPerms ( $pathDirectoryEnterprise , $shared_stat [ 'uid' ], $shared_stat [ 'gid' ], $shared_stat [ 'mode' ]);
} else {
2014-09-29 11:38:08 -04:00
CLI :: logging ( CLI :: error ( " Could not get shared folder permissions, workspace permissions couldn't be changed " ) . " \n " );
2014-09-26 13:00:16 -04:00
}
if ( G :: recursive_copy ( $pathDirectoryEnterprise , $pathNewFile . PATH_SEP . 'enterprise' )) {
CLI :: logging ( " Removing $pathDirectoryEnterprise ... \n " );
G :: rm_dir ( $pathDirectoryEnterprise );
} else {
2014-09-29 11:38:08 -04:00
CLI :: logging ( CLI :: error ( " Error: Failure to copy from $pathDirectoryEnterprise ... \n " ));
2014-09-26 13:00:16 -04:00
}
if ( file_exists ( $pathDirectoryEnterprise )) {
CLI :: logging ( CLI :: info ( " Remove manually $pathDirectoryEnterprise ... \n " ));
}
}
if ( file_exists ( $pathFileEnterprise )) {
2014-09-29 11:38:08 -04:00
CLI :: logging ( " Copying Enterprise.php file to $pathNewFile ... \n " );
2014-09-26 13:00:16 -04:00
if ( $shared_stat !== false ) {
workspaceTools :: dirPerms ( $pathFileEnterprise , $shared_stat [ 'uid' ], $shared_stat [ 'gid' ], $shared_stat [ 'mode' ]);
} else {
2014-09-29 11:38:08 -04:00
CLI :: logging ( CLI :: error ( " Could not get shared folder permissions, workspace permissions couldn't be changed " ) . " \n " );
2014-09-26 13:00:16 -04:00
}
CLI :: logging ( " Removing $pathFileEnterprise ... \n " );
copy ( $pathFileEnterprise , $pathNewFile . PATH_SEP . 'enterprise.php' );
2014-09-26 14:18:59 -04:00
G :: rm_dir ( $pathFileEnterprise );
2014-09-26 13:00:16 -04:00
if ( file_exists ( $pathFileEnterprise )) {
CLI :: logging ( CLI :: info ( " Remove manually $pathFileEnterprise ... \n " ));
}
}
}
2014-10-17 12:30:25 -04:00
2016-10-14 09:12:23 -04:00
/**
* @ param $workspace
*/
public function verifyLicenseEnterprise ( $workspace )
2014-10-17 12:30:25 -04:00
{
2016-10-14 09:12:23 -04:00
$this -> initPropel ( true );
2014-10-17 12:30:25 -04:00
$oCriteria = new Criteria ( 'workflow' );
$oCriteria -> add ( LicenseManagerPeer :: LICENSE_STATUS , 'ACTIVE' );
$oDataset = LicenseManagerPeer :: doSelectRS ( $oCriteria );
$oDataset -> setFetchmode ( ResultSet :: FETCHMODE_ASSOC );
if ( $oDataset -> next ()) {
$row = $oDataset -> getRow ();
2016-10-14 09:12:23 -04:00
$tr = LicenseManagerPeer :: retrieveByPK ( $row [ 'LICENSE_UID' ]);
$tr -> setLicensePath ( PATH_DATA_SITE . basename ( $row [ 'LICENSE_PATH' ]));
$tr -> setLicenseWorkspace ( $workspace );
$res = $tr -> save ();
2014-10-17 12:30:25 -04:00
}
}
2014-10-27 11:25:17 -04:00
/**
* Generate data for table APP_ASSIGN_SELF_SERVICE_VALUE
*
* return void
*/
public function appAssignSelfServiceValueTableGenerateData ()
{
try {
$this -> initPropel ( true );
$appAssignSelfServiceValue = new AppAssignSelfServiceValue ();
$appAssignSelfServiceValue -> generateData ();
} catch ( Exception $e ) {
throw $e ;
}
}
2014-11-19 16:47:22 -04:00
/**
* Get disabled code
*
2016-07-18 17:54:28 -04:00
* @ return array Returns an array with disabled code found , array empty otherwise
2014-11-19 16:47:22 -04:00
*/
public function getDisabledCode ()
{
try {
$this -> initPropel ( true );
G :: LoadClass ( " processes " );
$process = new Processes ();
//Return
2016-07-18 17:54:28 -04:00
return $process -> getDisabledCode ( null , $this -> name );
2014-11-19 16:47:22 -04:00
} catch ( Exception $e ) {
throw $e ;
}
}
2015-03-19 11:12:55 -04:00
2015-03-04 18:42:47 -04:00
/**
* Migrate all cases to New list
*
2015-08-12 09:30:43 -04:00
* @ param string $workSpace Workspace
* @ param bool $flagReinsert Flag that specifies the re - insertion
*
2016-09-02 13:14:03 -04:00
* @ return void
2015-03-04 18:42:47 -04:00
*/
2016-05-09 13:58:52 -04:00
public function migrateList ( $workSpace , $flagReinsert = false , $lang = 'en' )
2015-03-19 11:12:55 -04:00
{
2015-08-12 09:30:43 -04:00
$this -> initPropel ( true );
2016-09-02 13:14:03 -04:00
$flagListAll = $this -> listFirstExecution ( 'check' );
$flagListUnassigned = $this -> listFirstExecution ( 'check' , 'unassigned' );
2015-08-12 09:30:43 -04:00
2016-09-02 13:14:03 -04:00
if ( ! $flagReinsert && $flagListAll && $flagListUnassigned ) {
return ;
2015-04-13 17:43:35 -04:00
}
2015-08-12 09:30:43 -04:00
2016-09-02 13:14:03 -04:00
$arrayTable1 = [ 'ListInbox' , 'ListMyInbox' , 'ListCanceled' , 'ListParticipatedLast' , 'ListParticipatedHistory' , 'ListPaused' , 'ListCompleted' ];
$arrayTable2 = [ 'ListUnassigned' , 'ListUnassignedGroup' ];
$arrayTable = array_merge ( $arrayTable1 , $arrayTable2 );
2015-08-12 09:30:43 -04:00
if ( $flagReinsert ) {
//Delete all records
foreach ( $arrayTable as $value ) {
2016-09-02 13:14:03 -04:00
$tableName = $value . 'Peer' ;
2015-08-12 09:30:43 -04:00
$list = new $tableName ();
$list -> doDeleteAll ();
}
2016-09-02 13:14:03 -04:00
}
if ( ! $flagReinsert && ! $flagListAll ) {
foreach ( $arrayTable1 as $value ) {
$tableName = $value . 'Peer' ;
$list = new $tableName ();
if (( int )( $list -> doCount ( new Criteria ())) > 0 ) {
$flagListAll = true ;
break ;
}
}
}
2015-08-12 09:30:43 -04:00
2016-09-02 13:14:03 -04:00
if ( $flagReinsert || ! $flagListAll ) {
2016-05-09 13:58:52 -04:00
$this -> regenerateListCompleted ( $lang );
$this -> regenerateListCanceled ( $lang );
2016-09-02 13:14:03 -04:00
$this -> regenerateListMyInbox (); //This list require no translation
$this -> regenerateListInbox (); //This list require no translation
$this -> regenerateListParticipatedHistory (); //This list require no translation
$this -> regenerateListParticipatedLast (); //This list require no translation
$this -> regenerateListPaused (); //This list require no translation
2016-06-22 11:27:43 -04:00
}
2016-09-02 13:14:03 -04:00
if ( $flagReinsert || ! $flagListUnassigned ) {
$this -> regenerateListUnassigned (); //This list require no translation
2015-03-04 18:42:47 -04:00
}
2015-05-22 16:07:42 -04:00
2016-09-02 13:14:03 -04:00
$this -> listFirstExecution ( 'insert' );
$this -> listFirstExecution ( 'insert' , 'unassigned' );
2016-03-03 17:33:55 -04:00
}
2015-05-22 16:07:42 -04:00
2016-05-09 13:58:52 -04:00
public function regenerateListCanceled ( $lang = 'en' )
2016-03-03 17:33:55 -04:00
{
$this -> initPropel ( true );
$query = 'INSERT INTO ' . $this -> dbName . ' . LIST_CANCELED
( APP_UID ,
USR_UID ,
TAS_UID ,
PRO_UID ,
APP_NUMBER ,
APP_TITLE ,
APP_PRO_TITLE ,
APP_TAS_TITLE ,
APP_CANCELED_DATE ,
DEL_INDEX ,
DEL_PREVIOUS_USR_UID ,
DEL_CURRENT_USR_USERNAME ,
DEL_CURRENT_USR_FIRSTNAME ,
DEL_CURRENT_USR_LASTNAME ,
DEL_DELEGATE_DATE ,
DEL_INIT_DATE ,
DEL_DUE_DATE ,
DEL_PRIORITY )
SELECT
ACV . APP_UID ,
ACV . USR_UID ,
ACV . TAS_UID ,
ACV . PRO_UID ,
ACV . APP_NUMBER ,
C_APP . CON_VALUE AS APP_TITLE ,
C_PRO . CON_VALUE AS APP_PRO_TITLE ,
C_TAS . CON_VALUE AS APP_TAS_TITLE ,
NOW () AS APP_CANCELED_DATE ,
ACV . DEL_INDEX ,
PREV_AD . USR_UID AS DEL_PREVIOUS_USR_UID ,
USR . USR_USERNAME AS DEL_CURRENT_USR_USERNAME ,
USR . USR_FIRSTNAME AS DEL_CURRENT_USR_FIRSTNAME ,
USR . USR_LASTNAME AS DEL_CURRENT_USR_LASTNAME ,
AD . DEL_DELEGATE_DATE AS DEL_DELEGATE_DATE ,
AD . DEL_INIT_DATE AS DEL_INIT_DATE ,
AD . DEL_TASK_DUE_DATE AS DEL_DUE_DATE ,
ACV . DEL_PRIORITY
FROM
( '.$this->dbName.' . APP_CACHE_VIEW ACV
LEFT JOIN '.$this->dbName.' . CONTENT C_APP ON ACV . APP_UID = C_APP . CON_ID
AND C_APP . CON_CATEGORY = \ ' APP_TITLE\ '
2016-05-09 13:58:52 -04:00
AND C_APP . CON_LANG = \ '' . $lang . ' \ '
2016-03-03 17:33:55 -04:00
LEFT JOIN '.$this->dbName.' . CONTENT C_PRO ON ACV . PRO_UID = C_PRO . CON_ID
AND C_PRO . CON_CATEGORY = \ ' PRO_TITLE\ '
2016-05-09 13:58:52 -04:00
AND C_PRO . CON_LANG = \ '' . $lang . ' \ '
2016-03-03 17:33:55 -04:00
LEFT JOIN '.$this->dbName.' . CONTENT C_TAS ON ACV . TAS_UID = C_TAS . CON_ID
2016-05-09 13:58:52 -04:00
AND C_TAS . CON_CATEGORY = \ ' TAS_TITLE\ '
AND C_TAS . CON_LANG = \ '' . $lang . ' \ ' )
2016-03-03 17:33:55 -04:00
LEFT JOIN
( '.$this->dbName.' . APP_DELEGATION AD
INNER JOIN '.$this->dbName.' . APP_DELEGATION PREV_AD ON AD . APP_UID = PREV_AD . APP_UID
AND AD . DEL_PREVIOUS = PREV_AD . DEL_INDEX ) ON ACV . APP_UID = AD . APP_UID
AND ACV . DEL_INDEX = AD . DEL_INDEX
LEFT JOIN
'.$this->dbName.' . USERS USR ON ACV . USR_UID = USR . USR_UID
WHERE
ACV . APP_STATUS = \ ' CANCELLED\ '
AND ACV . DEL_LAST_INDEX = 1 ' ;
$con = Propel :: getConnection ( " workflow " );
$stmt = $con -> createStatement ();
$stmt -> executeQuery ( $query );
CLI :: logging ( " > Completed table LIST_CANCELED \n " );
}
2015-03-19 11:12:55 -04:00
2016-05-09 13:58:52 -04:00
public function regenerateListCompleted ( $lang = 'en' ){
2016-03-03 17:33:55 -04:00
$this -> initPropel ( true );
$query = 'INSERT INTO ' . $this -> dbName . ' . LIST_COMPLETED
( APP_UID ,
USR_UID ,
TAS_UID ,
PRO_UID ,
APP_NUMBER ,
APP_TITLE ,
APP_PRO_TITLE ,
APP_TAS_TITLE ,
APP_CREATE_DATE ,
APP_FINISH_DATE ,
DEL_INDEX ,
DEL_PREVIOUS_USR_UID ,
DEL_CURRENT_USR_USERNAME ,
DEL_CURRENT_USR_FIRSTNAME ,
DEL_CURRENT_USR_LASTNAME )
SELECT
ACV . APP_UID ,
ACV . USR_UID ,
ACV . TAS_UID ,
ACV . PRO_UID ,
ACV . APP_NUMBER ,
C_APP . CON_VALUE AS APP_TITLE ,
C_PRO . CON_VALUE AS APP_PRO_TITLE ,
C_TAS . CON_VALUE AS APP_TAS_TITLE ,
ACV . APP_CREATE_DATE ,
ACV . APP_FINISH_DATE ,
ACV . DEL_INDEX ,
PREV_AD . USR_UID AS DEL_PREVIOUS_USR_UID ,
USR . USR_USERNAME AS DEL_CURRENT_USR_USERNAME ,
USR . USR_FIRSTNAME AS DEL_CURRENT_USR_FIRSTNAME ,
USR . USR_LASTNAME AS DEL_CURRENT_USR_LASTNAME
FROM
( '.$this->dbName.' . APP_CACHE_VIEW ACV
LEFT JOIN '.$this->dbName.' . CONTENT C_APP ON ACV . APP_UID = C_APP . CON_ID
AND C_APP . CON_CATEGORY = \ ' APP_TITLE\ '
2016-05-09 13:58:52 -04:00
AND C_APP . CON_LANG = \ '' . $lang . ' \ '
2016-03-03 17:33:55 -04:00
LEFT JOIN '.$this->dbName.' . CONTENT C_PRO ON ACV . PRO_UID = C_PRO . CON_ID
AND C_PRO . CON_CATEGORY = \ ' PRO_TITLE\ '
2016-05-09 13:58:52 -04:00
AND C_PRO . CON_LANG = \ '' . $lang . ' \ '
2016-03-03 17:33:55 -04:00
LEFT JOIN '.$this->dbName.' . CONTENT C_TAS ON ACV . TAS_UID = C_TAS . CON_ID
2016-05-09 13:58:52 -04:00
AND C_TAS . CON_CATEGORY = \ ' TAS_TITLE\ '
AND C_TAS . CON_LANG = \ '' . $lang . ' \ ' )
2016-03-03 17:33:55 -04:00
LEFT JOIN
( '.$this->dbName.' . APP_DELEGATION AD
INNER JOIN '.$this->dbName.' . APP_DELEGATION PREV_AD ON AD . APP_UID = PREV_AD . APP_UID
AND AD . DEL_PREVIOUS = PREV_AD . DEL_INDEX ) ON ACV . APP_UID = AD . APP_UID
AND ACV . DEL_INDEX = AD . DEL_INDEX
LEFT JOIN
'.$this->dbName.' . USERS USR ON ACV . USR_UID = USR . USR_UID
WHERE
ACV . APP_STATUS = \ ' COMPLETED\ '
AND ACV . DEL_LAST_INDEX = 1 ' ;
$con = Propel :: getConnection ( " workflow " );
$stmt = $con -> createStatement ();
$stmt -> executeQuery ( $query );
CLI :: logging ( " > Completed table LIST_COMPLETED \n " );
}
2015-05-22 16:07:42 -04:00
2016-03-03 17:33:55 -04:00
public function regenerateListMyInbox (){
$this -> initPropel ( true );
$query = 'INSERT INTO ' . $this -> dbName . ' . LIST_MY_INBOX
( APP_UID ,
USR_UID ,
TAS_UID ,
PRO_UID ,
APP_NUMBER ,
APP_TITLE ,
APP_PRO_TITLE ,
APP_TAS_TITLE ,
APP_CREATE_DATE ,
APP_UPDATE_DATE ,
APP_FINISH_DATE ,
APP_STATUS ,
DEL_INDEX ,
DEL_PREVIOUS_USR_UID ,
DEL_PREVIOUS_USR_USERNAME ,
DEL_PREVIOUS_USR_FIRSTNAME ,
DEL_PREVIOUS_USR_LASTNAME ,
DEL_CURRENT_USR_UID ,
DEL_CURRENT_USR_USERNAME ,
DEL_CURRENT_USR_FIRSTNAME ,
DEL_CURRENT_USR_LASTNAME ,
DEL_DELEGATE_DATE ,
DEL_INIT_DATE ,
DEL_DUE_DATE ,
DEL_PRIORITY )
SELECT
ACV . APP_UID ,
ACV . USR_UID ,
ACV . TAS_UID ,
ACV . PRO_UID ,
ACV . APP_NUMBER ,
ACV . APP_TITLE ,
ACV . APP_PRO_TITLE ,
ACV . APP_TAS_TITLE ,
ACV . APP_CREATE_DATE ,
ACV . APP_UPDATE_DATE ,
ACV . APP_FINISH_DATE ,
ACV . APP_STATUS ,
ACV . DEL_INDEX ,
ACV . PREVIOUS_USR_UID AS DEL_PREVIOUS_USR_UID ,
PRE_USR . USR_USERNAME AS DEL_PREVIOUS_USR_USERNAME ,
PRE_USR . USR_FIRSTNAME AS DEL_PREVIOUS_USR_FIRSTNAME ,
PRE_USR . USR_LASTNAME AS DEL_PREVIOUS_USR_LASTNAME ,
ACV . USR_UID AS DEL_CURRENT_USR_UID ,
CUR_USR . USR_USERNAME AS DEL_CURRENT_USR_USERNAME ,
CUR_USR . USR_FIRSTNAME AS DEL_CURRENT_USR_FIRSTNAME ,
CUR_USR . USR_LASTNAME AS DEL_CURRENT_USR_LASTNAME ,
ACV . DEL_DELEGATE_DATE AS DEL_DELEGATE_DATE ,
ACV . DEL_INIT_DATE AS DEL_INIT_DATE ,
ACV . DEL_TASK_DUE_DATE AS DEL_DUE_DATE ,
ACV . DEL_PRIORITY
FROM
'.$this->dbName.' . APP_CACHE_VIEW ACV
LEFT JOIN
'.$this->dbName.' . USERS CUR_USR ON ACV . USR_UID = CUR_USR . USR_UID
LEFT JOIN
'.$this->dbName.' . USERS PRE_USR ON ACV . PREVIOUS_USR_UID = PRE_USR . USR_UID
WHERE ACV . DEL_INDEX = 1 ' ;
$con = Propel :: getConnection ( " workflow " );
$stmt = $con -> createStatement ();
$stmt -> executeQuery ( $query );
CLI :: logging ( " > Completed table LIST_MY_INBOX \n " );
}
2015-03-19 11:12:55 -04:00
2016-03-03 17:33:55 -04:00
public function regenerateListInbox (){
$this -> initPropel ( true );
$query = 'INSERT INTO ' . $this -> dbName . ' . LIST_INBOX
( APP_UID ,
DEL_INDEX ,
USR_UID ,
TAS_UID ,
PRO_UID ,
APP_NUMBER ,
APP_STATUS ,
APP_TITLE ,
APP_PRO_TITLE ,
APP_TAS_TITLE ,
APP_UPDATE_DATE ,
DEL_PREVIOUS_USR_UID ,
DEL_PREVIOUS_USR_USERNAME ,
DEL_PREVIOUS_USR_FIRSTNAME ,
DEL_PREVIOUS_USR_LASTNAME ,
DEL_DELEGATE_DATE ,
DEL_INIT_DATE ,
DEL_DUE_DATE ,
DEL_RISK_DATE ,
DEL_PRIORITY )
SELECT
ACV . APP_UID ,
ACV . DEL_INDEX ,
ACV . USR_UID ,
ACV . TAS_UID ,
ACV . PRO_UID ,
ACV . APP_NUMBER ,
ACV . APP_STATUS ,
ACV . APP_TITLE ,
ACV . APP_PRO_TITLE ,
ACV . APP_TAS_TITLE ,
ACV . APP_UPDATE_DATE ,
ACV . PREVIOUS_USR_UID AS DEL_PREVIOUS_USR_UID ,
USR . USR_USERNAME AS DEL_PREVIOUS_USR_USERNAME ,
USR . USR_FIRSTNAME AS DEL_PREVIOUS_USR_FIRSTNAME ,
USR . USR_LASTNAME AS DEL_PREVIOUS_USR_LASTNAME ,
ACV . DEL_DELEGATE_DATE AS DEL_DELEGATE_DATE ,
ACV . DEL_INIT_DATE AS DEL_INIT_DATE ,
ACV . DEL_TASK_DUE_DATE AS DEL_DUE_DATE ,
ACV . DEL_RISK_DATE AS DEL_RISK_DATE ,
ACV . DEL_PRIORITY
FROM
'.$this->dbName.' . APP_CACHE_VIEW ACV
LEFT JOIN
'.$this->dbName.' . USERS USR ON ACV . PREVIOUS_USR_UID = USR . USR_UID
WHERE
ACV . DEL_THREAD_STATUS = \ 'OPEN\'' ;
$con = Propel :: getConnection ( " workflow " );
$stmt = $con -> createStatement ();
$stmt -> executeQuery ( $query );
2015-03-04 18:42:47 -04:00
CLI :: logging ( " > Completed table LIST_INBOX \n " );
2016-03-03 17:33:55 -04:00
}
public function regenerateListParticipatedHistory (){
$this -> initPropel ( true );
$query = 'INSERT INTO ' . $this -> dbName . ' . LIST_PARTICIPATED_HISTORY
( APP_UID ,
DEL_INDEX ,
USR_UID ,
TAS_UID ,
PRO_UID ,
APP_NUMBER ,
APP_TITLE ,
APP_PRO_TITLE ,
APP_TAS_TITLE ,
DEL_PREVIOUS_USR_UID ,
DEL_PREVIOUS_USR_USERNAME ,
DEL_PREVIOUS_USR_FIRSTNAME ,
DEL_PREVIOUS_USR_LASTNAME ,
DEL_CURRENT_USR_USERNAME ,
DEL_CURRENT_USR_FIRSTNAME ,
DEL_CURRENT_USR_LASTNAME ,
DEL_DELEGATE_DATE ,
DEL_INIT_DATE ,
DEL_DUE_DATE ,
DEL_PRIORITY )
SELECT
ACV . APP_UID ,
ACV . DEL_INDEX ,
ACV . USR_UID ,
ACV . TAS_UID ,
ACV . PRO_UID ,
ACV . APP_NUMBER ,
ACV . APP_TITLE ,
ACV . APP_PRO_TITLE ,
ACV . APP_TAS_TITLE ,
ACV . PREVIOUS_USR_UID AS DEL_PREVIOUS_USR_UID ,
PRE_USR . USR_USERNAME AS DEL_PREVIOUS_USR_USERNAME ,
PRE_USR . USR_FIRSTNAME AS DEL_PREVIOUS_USR_FIRSTNAME ,
PRE_USR . USR_LASTNAME AS DEL_PREVIOUS_USR_LASTNAME ,
CUR_USR . USR_USERNAME AS DEL_CURRENT_USR_USERNAME ,
CUR_USR . USR_FIRSTNAME AS DEL_CURRENT_USR_FIRSTNAME ,
CUR_USR . USR_LASTNAME AS DEL_CURRENT_USR_LASTNAME ,
ACV . DEL_DELEGATE_DATE AS DEL_DELEGATE_DATE ,
ACV . DEL_INIT_DATE AS DEL_INIT_DATE ,
ACV . DEL_TASK_DUE_DATE AS DEL_DUE_DATE ,
ACV . DEL_PRIORITY
FROM
'.$this->dbName.' . APP_CACHE_VIEW ACV
LEFT JOIN
'.$this->dbName.' . USERS CUR_USR ON ACV . USR_UID = CUR_USR . USR_UID
LEFT JOIN
'.$this->dbName.' . USERS PRE_USR ON ACV . PREVIOUS_USR_UID = PRE_USR . USR_UID ' ;
$con = Propel :: getConnection ( " workflow " );
$stmt = $con -> createStatement ();
$stmt -> executeQuery ( $query );
2015-03-04 18:42:47 -04:00
CLI :: logging ( " > Completed table LIST_PARTICIPATED_HISTORY \n " );
2016-03-03 17:33:55 -04:00
}
2015-05-22 16:07:42 -04:00
2017-02-20 10:58:53 -04:00
public function regenerateListParticipatedLast ()
{
2016-03-03 17:33:55 -04:00
$this -> initPropel ( true );
2017-02-20 10:58:53 -04:00
$query = 'INSERT INTO ' . $this -> dbName . ' . LIST_PARTICIPATED_LAST
2016-03-03 17:33:55 -04:00
(
2017-02-20 10:58:53 -04:00
APP_UID ,
USR_UID ,
DEL_INDEX ,
TAS_UID ,
PRO_UID ,
APP_NUMBER ,
APP_TITLE ,
APP_PRO_TITLE ,
APP_TAS_TITLE ,
APP_STATUS ,
DEL_PREVIOUS_USR_UID ,
DEL_PREVIOUS_USR_USERNAME ,
DEL_PREVIOUS_USR_FIRSTNAME ,
DEL_PREVIOUS_USR_LASTNAME ,
DEL_CURRENT_USR_USERNAME ,
DEL_CURRENT_USR_FIRSTNAME ,
DEL_CURRENT_USR_LASTNAME ,
DEL_DELEGATE_DATE ,
DEL_INIT_DATE ,
DEL_DUE_DATE ,
DEL_CURRENT_TAS_TITLE ,
DEL_PRIORITY ,
DEL_THREAD_STATUS )
SELECT
2016-03-03 17:33:55 -04:00
ACV . APP_UID ,
ACV . USR_UID ,
ACV . DEL_INDEX ,
ACV . TAS_UID ,
ACV . PRO_UID ,
ACV . APP_NUMBER ,
ACV . APP_TITLE ,
ACV . APP_PRO_TITLE ,
ACV . APP_TAS_TITLE ,
ACV . APP_STATUS ,
2017-02-20 10:58:53 -04:00
DEL_PREVIOUS_USR_UID ,
IFNULL ( PRE_USR . USR_USERNAME , CUR_USR . USR_USERNAME ) AS DEL_PREVIOUS_USR_USERNAME ,
IFNULL ( PRE_USR . USR_FIRSTNAME , CUR_USR . USR_FIRSTNAME ) AS DEL_PREVIOUS_USR_USERNAME ,
IFNULL ( PRE_USR . USR_LASTNAME , CUR_USR . USR_LASTNAME ) AS DEL_PREVIOUS_USR_USERNAME ,
CUR_USR . USR_USERNAME AS DEL_CURRENT_USR_USERNAME ,
CUR_USR . USR_FIRSTNAME AS DEL_CURRENT_USR_FIRSTNAME ,
CUR_USR . USR_LASTNAME AS DEL_CURRENT_USR_LASTNAME ,
ACV . DEL_DELEGATE_DATE AS DEL_DELEGATE_DATE ,
ACV . DEL_INIT_DATE AS DEL_INIT_DATE ,
ACV . DEL_TASK_DUE_DATE AS DEL_DUE_DATE ,
ACV . APP_TAS_TITLE AS DEL_CURRENT_TAS_TITLE ,
2016-03-03 17:33:55 -04:00
ACV . DEL_PRIORITY ,
ACV . DEL_THREAD_STATUS
2017-02-20 10:58:53 -04:00
FROM
(
SELECT
CASE WHEN ACV1 . PREVIOUS_USR_UID = \ ' \ ' AND ACV1 . DEL_INDEX = 1
THEN ACV1 . USR_UID
ELSE ACV1 . PREVIOUS_USR_UID END AS DEL_PREVIOUS_USR_UID ,
ACV1 .*
FROM ' . $this->dbName . ' . APP_CACHE_VIEW ACV1
JOIN
( SELECT
ACV_INT . APP_UID ,
MAX ( ACV_INT . DEL_INDEX ) MAX_DEL_INDEX
FROM
' . $this->dbName . ' . APP_CACHE_VIEW ACV_INT
GROUP BY
ACV_INT . USR_UID ,
ACV_INT . APP_UID
) ACV2
ON ACV2 . APP_UID = ACV1 . APP_UID AND ACV2 . MAX_DEL_INDEX = ACV1 . DEL_INDEX
) ACV
LEFT JOIN ' . $this->dbName . ' . USERS PRE_USR ON ACV . PREVIOUS_USR_UID = PRE_USR . USR_UID
LEFT JOIN ' . $this->dbName . ' . USERS CUR_USR ON ACV . USR_UID = CUR_USR . USR_UID ' ;
$con = Propel :: getConnection ( " workflow " );
$stmt = $con -> createStatement ();
$stmt -> executeQuery ( $query );
CLI :: logging ( " > Inserted data into table LIST_PARTICIPATED_LAST \n " );
$query = 'UPDATE ' . $this -> dbName . ' . LIST_PARTICIPATED_LAST LPL , (
SELECT
TASK . TAS_TITLE ,
CUR_USER . APP_UID ,
USERS . USR_UID ,
USERS . USR_USERNAME ,
USERS . USR_FIRSTNAME ,
USERS . USR_LASTNAME
FROM (
SELECT
APP_UID ,
TAS_UID ,
DEL_INDEX ,
USR_UID
FROM ' . $this->dbName . ' . APP_DELEGATION
WHERE DEL_LAST_INDEX = 1
) CUR_USER
LEFT JOIN ' . $this->dbName . ' . USERS ON CUR_USER . USR_UID = USERS . USR_UID
LEFT JOIN ' . $this->dbName . ' . TASK ON CUR_USER . TAS_UID = TASK . TAS_UID ) USERS_VALUES
SET
LPL . DEL_CURRENT_USR_USERNAME = USERS_VALUES . USR_USERNAME ,
LPL . DEL_CURRENT_USR_FIRSTNAME = USERS_VALUES . USR_FIRSTNAME ,
LPL . DEL_CURRENT_USR_LASTNAME = USERS_VALUES . USR_LASTNAME ,
LPL . DEL_CURRENT_TAS_TITLE = USERS_VALUES . TAS_TITLE
WHERE LPL . APP_UID = USERS_VALUES . APP_UID ' ;
2016-03-03 17:33:55 -04:00
$con = Propel :: getConnection ( " workflow " );
$stmt = $con -> createStatement ();
2017-02-20 10:58:53 -04:00
CLI :: logging ( " > Updating the current users data on table LIST_PARTICIPATED_LAST \n " );
2016-03-03 17:33:55 -04:00
$stmt -> executeQuery ( $query );
CLI :: logging ( " > Completed table LIST_PARTICIPATED_LAST \n " );
}
2015-05-22 16:07:42 -04:00
2016-03-03 17:33:55 -04:00
public function regenerateListPaused (){
2015-03-04 18:42:47 -04:00
$delaycriteria = new Criteria ( " workflow " );
$delaycriteria -> addSelectColumn ( AppDelayPeer :: APP_UID );
$delaycriteria -> addSelectColumn ( AppDelayPeer :: PRO_UID );
$delaycriteria -> addSelectColumn ( AppDelayPeer :: APP_DEL_INDEX );
2017-02-10 17:11:14 -04:00
$delaycriteria -> addSelectColumn ( AppDelayPeer :: APP_DISABLE_ACTION_DATE );
2015-03-04 18:42:47 -04:00
$delaycriteria -> addSelectColumn ( AppCacheViewPeer :: APP_NUMBER );
2015-03-19 11:12:55 -04:00
$delaycriteria -> addSelectColumn ( AppCacheViewPeer :: USR_UID );
$delaycriteria -> addSelectColumn ( AppCacheViewPeer :: APP_STATUS );
$delaycriteria -> addSelectColumn ( AppCacheViewPeer :: TAS_UID );
$delaycriteria -> addJoin ( AppCacheViewPeer :: APP_UID , AppDelayPeer :: APP_UID . ' AND ' . AppCacheViewPeer :: DEL_INDEX . ' = ' . AppDelayPeer :: APP_DEL_INDEX , Criteria :: INNER_JOIN );
$delaycriteria -> add ( AppDelayPeer :: APP_DISABLE_ACTION_USER , " 0 " , CRITERIA :: EQUAL );
$delaycriteria -> add ( AppDelayPeer :: APP_TYPE , " PAUSE " , CRITERIA :: EQUAL );
2015-03-04 18:42:47 -04:00
$rsCriteria = AppDelayPeer :: doSelectRS ( $delaycriteria );
$rsCriteria -> setFetchmode ( ResultSet :: FETCHMODE_ASSOC );
2015-05-22 16:07:42 -04:00
2015-03-04 18:42:47 -04:00
while ( $rsCriteria -> next ()) {
$row = $rsCriteria -> getRow ();
2016-03-03 17:33:55 -04:00
$data = $row ;
$data [ " DEL_INDEX " ] = $row [ " APP_DEL_INDEX " ];
2017-02-10 17:11:14 -04:00
$data [ " APP_RESTART_DATE " ] = $row [ " APP_DISABLE_ACTION_DATE " ];
2016-03-03 17:33:55 -04:00
$listPaused = new ListPaused ();
$listPaused -> remove ( $row [ " APP_UID " ], $row [ " APP_DEL_INDEX " ], $data );
$listPaused -> setDeleted ( false );
$listPaused -> create ( $data );
2015-05-22 16:07:42 -04:00
}
2016-03-03 17:33:55 -04:00
CLI :: logging ( " > Completed table LIST_PAUSED \n " );
}
2015-03-09 16:14:02 -04:00
2016-06-22 11:27:43 -04:00
/*----------------------------------********---------------------------------*/
public function regenerateListUnassigned (){
$this -> initPropel ( true );
$truncate = 'TRUNCATE ' . $this -> dbName . '.LIST_UNASSIGNED' ;
//This executeQuery is very fast than Propel
$query = 'INSERT INTO ' . $this -> dbName . ' . LIST_UNASSIGNED
( APP_UID ,
DEL_INDEX ,
TAS_UID ,
PRO_UID ,
APP_NUMBER ,
APP_TITLE ,
APP_PRO_TITLE ,
APP_TAS_TITLE ,
DEL_PREVIOUS_USR_USERNAME ,
DEL_PREVIOUS_USR_FIRSTNAME ,
DEL_PREVIOUS_USR_LASTNAME ,
APP_UPDATE_DATE ,
DEL_PREVIOUS_USR_UID ,
DEL_DELEGATE_DATE ,
DEL_DUE_DATE ,
DEL_PRIORITY )
SELECT
ACV . APP_UID ,
ACV . DEL_INDEX ,
ACV . TAS_UID ,
ACV . PRO_UID ,
ACV . APP_NUMBER ,
ACV . APP_TITLE ,
ACV . APP_PRO_TITLE ,
ACV . APP_TAS_TITLE ,
USR . USR_USERNAME AS DEL_PREVIOUS_USR_USERNAME ,
USR . USR_FIRSTNAME AS DEL_PREVIOUS_USR_FIRSTNAME ,
USR . USR_LASTNAME AS DEL_PREVIOUS_USR_LASTNAME ,
ACV . APP_UPDATE_DATE ,
ACV . PREVIOUS_USR_UID AS DEL_PREVIOUS_USR_UID ,
ACV . DEL_DELEGATE_DATE AS DEL_DELEGATE_DATE ,
ACV . DEL_TASK_DUE_DATE AS DEL_DUE_DATE ,
ACV . DEL_PRIORITY
FROM
'.$this->dbName.' . APP_CACHE_VIEW ACV
LEFT JOIN
'.$this->dbName.' . USERS USR ON ACV . PREVIOUS_USR_UID = USR . USR_UID
WHERE
ACV . DEL_THREAD_STATUS = \ ' OPEN\ '
AND ACV . USR_UID = \ '\' ' ;
$con = Propel :: getConnection ( " workflow " );
$stmt = $con -> createStatement ();
$stmt -> executeQuery ( $truncate );
$stmt -> executeQuery ( $query );
CLI :: logging ( " > Completed table LIST_UNASSIGNED \n " );
}
/*----------------------------------********---------------------------------*/
2015-03-04 18:42:47 -04:00
/**
2015-05-22 16:07:42 -04:00
* This function checks if List tables are going to migrated
2015-03-04 18:42:47 -04:00
*
* return boolean value
*/
2016-06-22 11:27:43 -04:00
public function listFirstExecution ( $action , $list = 'all' ){
2015-03-04 18:42:47 -04:00
$this -> initPropel ( true );
switch ( $action ) {
2016-06-22 11:27:43 -04:00
case 'insert' :
2015-03-04 18:42:47 -04:00
$conf = new Configuration ();
2016-06-22 11:27:43 -04:00
if ( $list === 'all' ){
if ( ! ( $conf -> exists ( 'MIGRATED_LIST' , 'list' , 'list' , 'list' , 'list' ))) {
$data [ " CFG_UID " ] = 'MIGRATED_LIST' ;
$data [ " OBJ_UID " ] = 'list' ;
$data [ " CFG_VALUE " ] = 'true' ;
$data [ " PRO_UID " ] = 'list' ;
$data [ " USR_UID " ] = 'list' ;
$data [ " APP_UID " ] = 'list' ;
$conf -> create ( $data );
}
2015-03-04 18:42:47 -04:00
}
2016-06-22 11:27:43 -04:00
if ( $list === 'unassigned' ){
if ( ! ( $conf -> exists ( 'MIGRATED_LIST_UNASSIGNED' , 'list' , 'list' , 'list' , 'list' ))) {
$data [ " CFG_UID " ] = 'MIGRATED_LIST_UNASSIGNED' ;
$data [ " OBJ_UID " ] = 'list' ;
$data [ " CFG_VALUE " ] = 'true' ;
$data [ " PRO_UID " ] = 'list' ;
$data [ " USR_UID " ] = 'list' ;
$data [ " APP_UID " ] = 'list' ;
$conf -> create ( $data );
}
2015-03-04 18:42:47 -04:00
}
2016-06-22 11:27:43 -04:00
return true ;
2016-12-01 09:32:35 -05:00
break ;
2016-06-22 11:27:43 -04:00
case 'check' :
2016-12-01 09:32:35 -05:00
$criteria = new Criteria ( " workflow " );
$criteria -> addSelectColumn ( ConfigurationPeer :: CFG_UID );
if ( $list === 'all' ){
$criteria -> add ( ConfigurationPeer :: CFG_UID , " MIGRATED_LIST " , CRITERIA :: EQUAL );
}
if ( $list === 'unassigned' ){
$criteria -> add ( ConfigurationPeer :: CFG_UID , " MIGRATED_LIST_UNASSIGNED " , CRITERIA :: EQUAL );
}
$rsCriteria = AppCacheViewPeer :: doSelectRS ( $criteria );
$rsCriteria -> setFetchmode ( ResultSet :: FETCHMODE_ASSOC );
$aRows = array ();
while ( $rsCriteria -> next ()) {
$aRows [] = $rsCriteria -> getRow ();
}
if ( empty ( $aRows )){
return false ; //If is false continue with the migrated
} else {
return true ; //Stop
}
2015-03-04 18:42:47 -04:00
break ;
2016-06-22 11:27:43 -04:00
default :
2015-03-04 18:42:47 -04:00
return true ;
2016-06-22 11:27:43 -04:00
}
2015-05-22 16:07:42 -04:00
}
2015-06-01 14:15:53 -04:00
/**
* Verify feature
*
* @ param string $featureName Feature name
*
* return bool Return true if is valid the feature , false otherwise
*/
public function pmLicensedFeaturesVerifyFeature ( $featureName )
{
try {
$this -> initPropel ( true );
$flag = PMLicensedFeatures :: getSingleton () -> verifyfeature ( $featureName );
$this -> close ();
//Return
return $flag ;
} catch ( Exception $e ) {
throw $e ;
}
}
2015-07-21 15:55:20 -04:00
/**
* Process - Files upgrade
*
* return void
*/
public function processFilesUpgrade ()
{
try {
if ( ! defined ( " PATH_DATA_MAILTEMPLATES " )) {
define ( " PATH_DATA_MAILTEMPLATES " , PATH_DATA_SITE . " mailTemplates " . PATH_SEP );
}
if ( ! defined ( " PATH_DATA_PUBLIC " )) {
define ( " PATH_DATA_PUBLIC " , PATH_DATA_SITE . " public " . PATH_SEP );
}
$this -> initPropel ( true );
$filesManager = new \ProcessMaker\BusinessModel\FilesManager ();
$filesManager -> processFilesUpgrade ();
} catch ( Exception $e ) {
throw $e ;
}
}
2016-03-03 12:09:38 -04:00
2016-02-17 16:44:14 -04:00
/**
* Register system tables in a file
*
* return void
*/
public static function registerSystemTables ( $aSquema ){
//Register all tables
$sListTables = '' ;
foreach ( $aSquema as $key => $value ) {
$sListTables .= $key . '|' ;
}
$sysTablesIniFile = PATH_CONFIG . 'system-tables.ini' ;
$contents = file_put_contents ( $sysTablesIniFile , sprintf ( " %s '%s' \n " , " tables = " , $sListTables ) );
if ( $contents === null ) {
throw ( new Exception ( G :: LoadTranslation ( 'ID_FILE_NOT_WRITEABLE' , SYS_LANG , array ( $sysTablesIniFile ) ) ));
}
}
2016-03-03 12:09:38 -04:00
/**
* return void
*/
public function checkRbacPermissions (){
CLI :: logging ( " -> Verifying roles permissions in RBAC \n " );
//Update table RBAC permissions
Bootstrap :: LoadSystem ( 'rbac' );
$RBAC = & RBAC :: getSingleton ();
$RBAC -> initRBAC ();
$result = $RBAC -> verifyPermissions ();
if ( count ( $result ) > 1 ) {
foreach ( $result as $item ) {
CLI :: logging ( " $item ... \n " );
}
} else {
CLI :: logging ( " All roles permissions already updated \n " );
}
}
2016-06-22 11:27:43 -04:00
2016-04-01 16:43:37 -04:00
public function checkSequenceNumber ()
{
2016-04-18 22:27:14 -04:00
$criteria = new Criteria ( " workflow " );
$rsCriteria = AppSequencePeer :: doSelectRS ( $criteria );
$rsCriteria -> setFetchmode ( ResultSet :: FETCHMODE_ASSOC );
$rsCriteria -> next ();
$appSequenceRow = $rsCriteria -> getRow ();
if ( empty ( $appSequenceRow )) {
$sequenceInstance = SequencesPeer :: retrieveByPK ( " APP_NUMBER " );
$appSequenceInstance = new AppSequence ();
if ( ! is_null ( $sequenceInstance )) {
$sequenceFields = $sequenceInstance -> toArray ( BasePeer :: TYPE_FIELDNAME );
$appSequenceInstance -> updateSequenceNumber ( $sequenceFields [ 'SEQ_VALUE' ]);
} else {
$appSequenceInstance -> updateSequenceNumber ( 0 );
}
2016-04-01 16:43:37 -04:00
}
}
2016-03-03 17:33:55 -04:00
public function hasMissingUsers ()
{
$this -> initPropel ( true );
file_put_contents (
PATH_DATA . " /missing-users- " . $this -> name . " .txt " ,
" Missing Processes List. \n "
);
$criteria = new Criteria ( " workflow " );
$criteria -> addSelectColumn ( AppCacheViewPeer :: APP_UID );
$criteria -> addSelectColumn ( AppCacheViewPeer :: DEL_INDEX );
$criteria -> addSelectColumn ( AppCacheViewPeer :: USR_UID );
$criteria -> addJoinMC ( array (
array ( AppCacheViewPeer :: USR_UID , UsersPeer :: USR_UID )),
Criteria :: LEFT_JOIN
);
$criteria -> add ( UsersPeer :: USR_UID , null , Criteria :: ISNULL );
$rsCriteria = AppCacheViewPeer :: doSelectRS ( $criteria );
$rsCriteria -> setFetchmode ( ResultSet :: FETCHMODE_ASSOC );
$counter = 0 ;
while ( $rsCriteria -> next ()) {
$item = $rsCriteria -> getRow ();
$counter ++ ;
file_put_contents (
PATH_DATA . " /missing-users- " . $this -> name . " .txt " ,
" APP_UID:[ " . $item [ 'APP_UID' ] . " ] - DEL_INDEX[ " . $item [ 'DEL_INDEX' ] . " ] have relation " .
" with invalid or non-existent user user with " .
" id [ " . $item [ 'USR_UID' ] . " ] "
);
}
CLI :: logging ( " > Number of user related inconsistencies for workspace " . CLI :: info ( $this -> name ) . " : " . CLI :: info ( $counter ) . " \n " );
return ( $counter > 0 );
}
public function hasMissingTasks ()
{
$this -> initPropel ( true );
file_put_contents (
PATH_DATA . " /missing-tasks- " . $this -> name . " .txt " ,
" Missing Processes List \n "
);
$criteria = new Criteria ( " workflow " );
$criteria -> addSelectColumn ( AppCacheViewPeer :: APP_UID );
$criteria -> addSelectColumn ( AppCacheViewPeer :: DEL_INDEX );
$criteria -> addSelectColumn ( AppCacheViewPeer :: TAS_UID );
$criteria -> addJoinMC ( array (
array ( AppCacheViewPeer :: USR_UID , TaskPeer :: TAS_UID )),
Criteria :: LEFT_JOIN
);
$criteria -> add ( TaskPeer :: TAS_UID , null , Criteria :: ISNULL );
$rsCriteria = AppCacheViewPeer :: doSelectRS ( $criteria );
$rsCriteria -> setFetchmode ( ResultSet :: FETCHMODE_ASSOC );
$counter = 0 ;
while ( $rsCriteria -> next ()) {
$item = $rsCriteria -> getRow ();
file_put_contents (
PATH_DATA . " /missing-tasks- " . $this -> name . " .txt " ,
" APP_UID:[ " . $item [ 'APP_UID' ] . " ] - DEL_INDEX[ " . $item [ 'DEL_INDEX' ] . " ] have relation " .
" with invalid or non-existent task with " .
" id [ " . $item [ 'TAS_UID' ] . " ] "
);
}
CLI :: logging ( " > Number of task related inconsistencies for workspace " . CLI :: info ( $this -> name ) . " : " . CLI :: info ( $counter ) . " \n " );
return ( $counter > 0 );
}
public function hasMissingProcesses ()
{
$this -> initPropel ( true );
file_put_contents (
PATH_DATA . " /missing-processes- " . $this -> name . " .txt " ,
" Missing Processes List \n "
);
$criteria = new Criteria ( " workflow " );
$criteria -> addSelectColumn ( AppCacheViewPeer :: APP_UID );
$criteria -> addSelectColumn ( AppCacheViewPeer :: DEL_INDEX );
$criteria -> addSelectColumn ( AppCacheViewPeer :: PRO_UID );
$criteria -> addJoinMC ( array (
array ( AppCacheViewPeer :: USR_UID , ProcessPeer :: PRO_UID )),
Criteria :: LEFT_JOIN
);
$criteria -> add ( ProcessPeer :: PRO_UID , null , Criteria :: ISNULL );
$rsCriteria = AppCacheViewPeer :: doSelectRS ( $criteria );
$rsCriteria -> setFetchmode ( ResultSet :: FETCHMODE_ASSOC );
$counter = 0 ;
while ( $rsCriteria -> next ()) {
$item = $rsCriteria -> getRow ();
file_put_contents (
PATH_DATA . " /missing-processes- " . $this -> name . " .txt " ,
" APP_UID:[ " . $item [ 'APP_UID' ] . " ] - DEL_INDEX[ " . $item [ 'DEL_INDEX' ] . " ] have relation " .
" with invalid or non-existent process with " .
" id [ " . $item [ 'PRO_UID' ] . " ] "
);
}
CLI :: logging ( " > Number of processes related data inconsistencies for workspace " . CLI :: info ( $this -> name ) . " : " . CLI :: info ( $counter ) . " \n " );
return ( $counter > 0 );
}
public function hasMissingAppDelegations ()
{
$this -> initPropel ( true );
file_put_contents (
PATH_DATA . " /missing-app-delegation- " . $this -> name . " .txt " ,
" Missing AppDelegation List. \n "
);
$criteria = new Criteria ( " workflow " );
$criteria -> addSelectColumn ( AppCacheViewPeer :: APP_UID );
$criteria -> addSelectColumn ( AppCacheViewPeer :: DEL_INDEX );
$criteria -> addJoinMC ( array (
array ( AppCacheViewPeer :: APP_UID , AppCacheViewPeer :: DEL_INDEX ),
array ( AppDelegationPeer :: APP_UID , AppDelegationPeer :: DEL_INDEX )),
Criteria :: LEFT_JOIN
);
$criteria -> add ( AppDelegationPeer :: APP_UID , null , Criteria :: ISNULL );
$rsCriteria = AppCacheViewPeer :: doSelectRS ( $criteria );
$rsCriteria -> setFetchmode ( ResultSet :: FETCHMODE_ASSOC );
$counter = 0 ;
while ( $rsCriteria -> next ()) {
$item = $rsCriteria -> getRow ();
$counter ++ ;
file_put_contents (
PATH_DATA . " /missing-app-delegation- " . $this -> name . " .txt " ,
" APP_UID:[ " . $item [ 'APP_UID' ] . " ] - DEL_INDEX[ " . $item [ 'DEL_INDEX' ] . " ] have relation " .
" with invalid or non-existent process with " .
" id [ " . $item [ 'PRO_UID' ] . " ] "
);
}
CLI :: logging ( " > Number of delegations related data inconsistencies for workspace " . CLI :: info ( $this -> name ) . " : " . CLI :: info ( $counter ) . " \n " );
return ( $counter > 0 );
}
public function verifyMissingCancelled ()
{
$this -> initPropel ( true );
file_put_contents (
PATH_DATA . " /post-missing-cancelled- " . $this -> name . " .txt " ,
" Missing Cancelled List. \n "
);
$criteria = new Criteria ( " workflow " );
$criteria -> addSelectColumn ( AppCacheViewPeer :: APP_UID );
$criteria -> addSelectColumn ( AppCacheViewPeer :: DEL_INDEX );
$criteria -> addJoinMC ( array (
array ( AppCacheViewPeer :: APP_UID , ListCanceledPeer :: APP_UID ),
array ( AppCacheViewPeer :: DEL_INDEX , ListCanceledPeer :: DEL_INDEX )),
Criteria :: LEFT_JOIN
);
$criteria -> add ( AppCacheViewPeer :: APP_STATUS , 'CANCELLED' , Criteria :: EQUAL );
$criteria -> add ( AppCacheViewPeer :: DEL_LAST_INDEX , 1 , Criteria :: EQUAL );
$criteria -> add ( ListCanceledPeer :: APP_UID , null , Criteria :: ISNULL );
$rsCriteria = AppCacheViewPeer :: doSelectRS ( $criteria );
$rsCriteria -> setFetchmode ( ResultSet :: FETCHMODE_ASSOC );
$counter = 0 ;
while ( $rsCriteria -> next ()) {
$item = $rsCriteria -> getRow ();
$counter ++ ;
file_put_contents (
PATH_DATA . " /post-missing-cancelled- " . $this -> name . " .txt " ,
" [ " . $item [ 'APP_UID' ] . " ] has not been found "
);
}
CLI :: logging ( " > Number of missing cancelled cases for workspace " . CLI :: info ( $this -> name ) . " : " . CLI :: info ( $counter ) . " \n " );
}
public function verifyMissingCompleted ()
{
$this -> initPropel ( true );
file_put_contents (
PATH_DATA . " /post-missing-completed- " . $this -> name . " .txt " ,
" Missing Completed List. \n "
);
$criteria = new Criteria ( " workflow " );
$criteria -> addSelectColumn ( AppCacheViewPeer :: APP_UID );
$criteria -> addSelectColumn ( AppCacheViewPeer :: DEL_INDEX );
$criteria -> addJoinMC ( array (
array ( AppCacheViewPeer :: APP_UID , ListCompletedPeer :: APP_UID ),
array ( AppCacheViewPeer :: DEL_INDEX , ListCompletedPeer :: DEL_INDEX )),
Criteria :: LEFT_JOIN
);
$criteria -> add ( AppCacheViewPeer :: APP_STATUS , 'COMPLETED' , Criteria :: EQUAL );
$criteria -> add ( AppCacheViewPeer :: DEL_LAST_INDEX , 1 , Criteria :: EQUAL );
$criteria -> add ( ListCompletedPeer :: APP_UID , null , Criteria :: ISNULL );
$rsCriteria = AppCacheViewPeer :: doSelectRS ( $criteria );
$rsCriteria -> setFetchmode ( ResultSet :: FETCHMODE_ASSOC );
$counter = 0 ;
while ( $rsCriteria -> next ()) {
$item = $rsCriteria -> getRow ();
$counter ++ ;
file_put_contents (
PATH_DATA . " /post-missing-completed- " . $this -> name . " .txt " ,
" [ " . $item [ 'APP_UID' ] . " ] has not been found "
);
}
CLI :: logging ( " > Number of missing completed cases for workspace " . CLI :: info ( $this -> name ) . " : " . CLI :: info ( $counter ) . " \n " );
}
public function verifyMissingInbox ()
{
$this -> initPropel ( true );
file_put_contents (
PATH_DATA . " /post-missing-inbox- " . $this -> name . " .txt " ,
" Missing Inbox List. \n "
);
$criteria = new Criteria ( " workflow " );
$criteria -> addSelectColumn ( AppCacheViewPeer :: APP_UID );
$criteria -> addSelectColumn ( AppCacheViewPeer :: DEL_INDEX );
$criteria -> addJoinMC ( array (
array ( AppCacheViewPeer :: APP_UID , ListInboxPeer :: APP_UID ),
array ( AppCacheViewPeer :: DEL_INDEX , ListInboxPeer :: DEL_INDEX )),
Criteria :: LEFT_JOIN
);
$criteria -> add ( AppCacheViewPeer :: DEL_THREAD_STATUS , 'OPEN' , Criteria :: EQUAL );
$criteria -> add ( ListInboxPeer :: APP_UID , null , Criteria :: ISNULL );
$rsCriteria = AppCacheViewPeer :: doSelectRS ( $criteria );
$rsCriteria -> setFetchmode ( ResultSet :: FETCHMODE_ASSOC );
$counter = 0 ;
while ( $rsCriteria -> next ()) {
$item = $rsCriteria -> getRow ();
$counter ++ ;
file_put_contents (
PATH_DATA . " /post-missing-inbox- " . $this -> name . " .txt " ,
" [ " . $item [ 'APP_UID' ] . " ] has not been found "
);
}
CLI :: logging ( " > Number of missing inbox cases for workspace " . CLI :: info ( $this -> name ) . " : " . CLI :: info ( $counter ) . " \n " );
}
public function verifyMissingParticipatedHistory ()
{
$this -> initPropel ( true );
file_put_contents (
PATH_DATA . " /post-missing-participated-history- " . $this -> name . " .txt " ,
" Missing ParticipatedHistory List. \n "
);
$criteria = new Criteria ( " workflow " );
$criteria -> addSelectColumn ( AppCacheViewPeer :: APP_UID );
$criteria -> addSelectColumn ( AppCacheViewPeer :: DEL_INDEX );
$criteria -> addJoinMC ( array (
array ( AppCacheViewPeer :: APP_UID , ListParticipatedHistoryPeer :: APP_UID ),
array ( AppCacheViewPeer :: DEL_INDEX , ListParticipatedHistoryPeer :: DEL_INDEX )
2016-12-01 09:32:35 -05:00
),
2016-03-03 17:33:55 -04:00
Criteria :: LEFT_JOIN
);
$criteria -> add ( AppCacheViewPeer :: DEL_THREAD_STATUS , 'OPEN' , Criteria :: NOT_EQUAL );
$criteria -> add ( ListParticipatedHistoryPeer :: APP_UID , null , Criteria :: ISNULL );
$rsCriteria = AppCacheViewPeer :: doSelectRS ( $criteria );
$rsCriteria -> setFetchmode ( ResultSet :: FETCHMODE_ASSOC );
$counter = 0 ;
while ( $rsCriteria -> next ()) {
$item = $rsCriteria -> getRow ();
$counter ++ ;
file_put_contents (
PATH_DATA . " /post-missing-participated-history- " . $this -> name . " .txt " ,
" [ " . $item [ 'APP_UID' ] . " ] has not been found "
);
}
CLI :: logging ( " > Number of missing participated history entries for workspace " . CLI :: info ( $this -> name ) . " : " . CLI :: info ( $counter ) . " \n " );
}
public function verifyMissingParticipatedLast ()
{
$this -> initPropel ( true );
file_put_contents (
PATH_DATA . " /post-missing-participated-last- " . $this -> name . " .txt " ,
" Missing ParticipatedLast List. \n "
);
$criteria = new Criteria ( " workflow " );
$criteria -> addSelectColumn ( AppCacheViewPeer :: APP_UID );
$criteria -> addSelectColumn ( AppCacheViewPeer :: DEL_INDEX );
$criteria -> addJoinMC ( array (
array ( AppCacheViewPeer :: APP_UID , ListParticipatedLastPeer :: APP_UID ),
array ( AppCacheViewPeer :: DEL_INDEX , ListParticipatedLastPeer :: DEL_INDEX )
),
Criteria :: LEFT_JOIN
);
$criteria -> add ( AppCacheViewPeer :: DEL_THREAD_STATUS , 'OPEN' , Criteria :: NOT_EQUAL );
$criteria -> add ( ListParticipatedLastPeer :: APP_UID , null , Criteria :: ISNULL );
$rsCriteria = AppCacheViewPeer :: doSelectRS ( $criteria );
$rsCriteria -> setFetchmode ( ResultSet :: FETCHMODE_ASSOC );
$counter = 0 ;
while ( $rsCriteria -> next ()) {
$item = $rsCriteria -> getRow ();
$counter ++ ;
file_put_contents (
PATH_DATA . " /post-missing-participated-last- " . $this -> name . " .txt " ,
" [ " . $item [ 'APP_UID' ] . " ] has not been found "
);
}
CLI :: logging ( " > Number of missing participated last entries for workspace " . CLI :: info ( $this -> name ) . " : " . CLI :: info ( $counter ) . " \n " );
}
public function verifyMissingMyInbox ()
{
$this -> initPropel ( true );
file_put_contents (
PATH_DATA . " /post-missing-my-inbox- " . $this -> name . " .txt " ,
" Missing MyInbox List. \n "
);
$criteria = new Criteria ( " workflow " );
$criteria -> addSelectColumn ( AppCacheViewPeer :: APP_UID );
$criteria -> addSelectColumn ( AppCacheViewPeer :: DEL_INDEX );
$criteria -> addJoinMC ( array (
array ( AppCacheViewPeer :: APP_UID , ListMyInboxPeer :: APP_UID ),
array ( AppCacheViewPeer :: DEL_INDEX , ListMyInboxPeer :: DEL_INDEX )
),
Criteria :: LEFT_JOIN
);
$criteria -> add ( AppCacheViewPeer :: DEL_INDEX , 1 , Criteria :: EQUAL );
$criteria -> add ( ListMyInboxPeer :: APP_UID , null , Criteria :: ISNULL );
$rsCriteria = AppCacheViewPeer :: doSelectRS ( $criteria );
$rsCriteria -> setFetchmode ( ResultSet :: FETCHMODE_ASSOC );
$counter = 0 ;
while ( $rsCriteria -> next ()) {
$item = $rsCriteria -> getRow ();
$counter ++ ;
file_put_contents (
PATH_DATA . " /post-missing-my-inbox- " . $this -> name . " .txt " ,
" [ " . $item [ 'APP_UID' ] . " ] has not been found "
);
}
CLI :: logging ( " > Number of missing my inbox entries for workspace " . CLI :: info ( $this -> name ) . " : " . CLI :: info ( $counter ) . " \n " );
}
public function verifyMissingUnassigned ()
{
$this -> initPropel ( true );
file_put_contents (
PATH_DATA . " /post-missing-unassigned- " . $this -> name . " .txt " ,
" Missing MissingUnassigned List. \n "
);
$criteria = new Criteria ( " workflow " );
$criteria -> addSelectColumn ( AppCacheViewPeer :: APP_UID );
$criteria -> addSelectColumn ( AppCacheViewPeer :: DEL_INDEX );
$criteria -> addJoinMC ( array (
array ( AppCacheViewPeer :: APP_UID , ListUnassignedPeer :: APP_UID ),
array ( AppCacheViewPeer :: DEL_INDEX , ListUnassignedPeer :: DEL_INDEX )
),
Criteria :: LEFT_JOIN
);
$criteria -> add ( AppCacheViewPeer :: USR_UID , '' , Criteria :: EQUAL );
$criteria -> add ( ListUnassignedPeer :: APP_UID , null , Criteria :: ISNULL );
$rsCriteria = AppCacheViewPeer :: doSelectRS ( $criteria );
$rsCriteria -> setFetchmode ( ResultSet :: FETCHMODE_ASSOC );
$counter = 0 ;
while ( $rsCriteria -> next ()) {
$item = $rsCriteria -> getRow ();
$counter ++ ;
file_put_contents (
PATH_DATA . " /post-missing-unassigned- " . $this -> name . " .txt " ,
" [ " . $item [ 'APP_UID' ] . " ] has not been found "
);
}
CLI :: logging ( " > Number of unassigned cases for workspace " . CLI :: info ( $this -> name ) . " : " . CLI :: info ( $counter ) . " \n " );
}
public function verifyListData ( $type )
{
switch ( $type ) {
case 'LIST_CANCELLED' :
$response = $this -> verifyMissingCancelled ();
break ;
case 'LIST_COMPLETED' :
$response = $this -> verifyMissingCompleted ();
break ;
case 'LIST_INBOX' :
$response = $this -> verifyMissingInbox ();
break ;
case 'LIST_PARTICIPATED_HISTORY' :
$response = $this -> verifyMissingParticipatedHistory ();
break ;
case 'LIST_PARTICIPATED_LAST' :
$response = $this -> verifyMissingParticipatedLast ();
break ;
case 'LIST_MY_INBOX' :
$response = $this -> verifyMissingMyInbox ();
break ;
case 'LIST_PAUSED' :
// The list implementation needs to be reestructured in order to
// properly validate the list consistency, currently we are maintaining the
// current LIST_PAUSED implementation.
$response = '' ;
break ;
case 'LIST_UNASSIGNED' :
$response = $this -> verifyMissingUnassigned ();
break ;
case 'LIST_UNASSIGNED_GROUP' :
// There is still no need to validate this list since is not being
// populated until the logic has been defined
$response = '' ;
break ;
default :
$response = '' ;
break ;
}
return $response ;
}
2016-07-22 10:59:13 -04:00
2016-12-01 09:32:35 -05:00
public function migrateContent ( $workspace , $lang = SYS_LANG )
{
2016-07-20 11:48:10 -04:00
if (( ! class_exists ( 'Memcache' ) || ! class_exists ( 'Memcached' )) && ! defined ( 'MEMCACHED_ENABLED' )) {
define ( 'MEMCACHED_ENABLED' , false );
}
$this -> initPropel ( true );
$conf = new Configuration ();
2016-12-01 09:32:35 -05:00
$blackList = array ();
if ( $bExist = $conf -> exists ( 'MIGRATED_CONTENT' , 'content' )){
$oConfig = $conf -> load ( 'MIGRATED_CONTENT' , 'content' );
$blackList = $oConfig [ 'CFG_VALUE' ] == 'true' ? array ( 'Groupwf' , 'Process' , 'Department' , 'Task' , 'InputDocument' , 'Application' ) : unserialize ( $oConfig [ 'CFG_VALUE' ]);
2016-07-20 11:48:10 -04:00
}
2016-12-01 09:32:35 -05:00
$blackList = $this -> migrateContentRun ( $workspace , $lang , $blackList );
$data [ " CFG_UID " ] = 'MIGRATED_CONTENT' ;
$data [ " OBJ_UID " ] = 'content' ;
$data [ " CFG_VALUE " ] = serialize ( $blackList );
$data [ " PRO_UID " ] = '' ;
$data [ " USR_UID " ] = '' ;
$data [ " APP_UID " ] = '' ;
$conf -> create ( $data );
2016-07-20 11:48:10 -04:00
}
2016-07-07 14:25:04 -04:00
/**
* Migrate this workspace table Content .
2016-07-20 11:48:10 -04:00
*
2016-07-07 14:25:04 -04:00
* @ param $className
* @ param $fields
2016-07-20 11:48:10 -04:00
* @ param mixed | string $lang
2016-07-07 14:25:04 -04:00
* @ throws Exception
*/
2016-07-20 11:48:10 -04:00
public function migrateContentWorkspace ( $className , $fields , $lang = SYS_LANG )
2016-07-07 14:25:04 -04:00
{
try {
$this -> initPropel ( true );
$fieldUidName = $fields [ 'uid' ];
$oCriteria = new Criteria ();
$oCriteria -> clearSelectColumns ();
$oCriteria -> addAsColumn ( $fieldUidName , ContentPeer :: CON_ID );
2016-12-01 09:32:35 -05:00
$oCriteria -> addSelectColumn ( ContentPeer :: CON_PARENT );
2016-07-07 14:25:04 -04:00
$oCriteria -> addSelectColumn ( ContentPeer :: CON_CATEGORY );
$oCriteria -> addSelectColumn ( ContentPeer :: CON_VALUE );
$oCriteria -> add ( ContentPeer :: CON_CATEGORY , $fields [ 'fields' ], Criteria :: IN );
2016-07-20 11:48:10 -04:00
$oCriteria -> add ( ContentPeer :: CON_LANG , $lang );
2016-07-07 14:25:04 -04:00
$oDataset = ContentPeer :: doSelectRS ( $oCriteria );
$oDataset -> setFetchmode ( ResultSet :: FETCHMODE_ASSOC );
$methods = $fields [ 'methods' ];
while ( $oDataset -> next ()) {
$row = $oDataset -> getRow ();
$fieldName = $row [ 'CON_CATEGORY' ];
$fieldName = isset ( $fields [ 'alias' ]) && isset ( $fields [ 'alias' ][ $fieldName ]) ? $fields [ 'alias' ][ $fieldName ] : $fieldName ;
unset ( $row [ 'CON_CATEGORY' ]);
2016-12-01 09:32:35 -05:00
$row [ $fieldName ] = $row [ 'CON_VALUE' ];
2016-07-07 14:25:04 -04:00
unset ( $row [ 'CON_VALUE' ]);
$oTable = new $className ();
2016-12-01 09:32:35 -05:00
$that = array ( $oTable , $methods [ 'exists' ]);
$params = array ( $row [ $fieldUidName ]);
if ( isset ( $row [ 'CON_PARENT' ]) && $row [ 'CON_PARENT' ] != '' ){
array_push ( $params , $row [ 'CON_PARENT' ]);
$fieldName = isset ( $fields [ 'alias' ]) && isset ( $fields [ 'alias' ][ 'CON_PARENT' ]) ? $fields [ 'alias' ][ 'CON_PARENT' ] : 'CON_PARENT' ;
$row [ $fieldName ] = $row [ 'CON_PARENT' ];
}
unset ( $row [ 'CON_PARENT' ]);
if ( call_user_func_array ( $that , $params )){
if ( isset ( $methods [ 'update' ])){
$fn = $methods [ 'update' ];
$fn ( $row );
} else {
$oTable -> update ( $row );
}
2016-07-07 14:25:04 -04:00
}
}
2016-12-01 09:32:35 -05:00
$classNamePeer = class_exists ( $className . 'Peer' ) ? $className . 'Peer' : $fields [ 'peer' ];
2016-07-20 11:48:10 -04:00
CLI :: logging ( " |--> Add content data in table " . $classNamePeer :: TABLE_NAME . " \n " );
2016-07-07 14:25:04 -04:00
} catch ( Exception $e ) {
throw ( $e );
}
}
2016-07-20 11:48:10 -04:00
2016-12-01 09:32:35 -05:00
/**
* Migration
*
* @ param $workspace
* @ param mixed | string $lang
* @ return array
*/
public function migrateContentRun ( $workspace , $lang = SYS_LANG , $blackList = array ())
{
2016-07-20 11:48:10 -04:00
if (( ! class_exists ( 'Memcache' ) || ! class_exists ( 'Memcached' )) && ! defined ( 'MEMCACHED_ENABLED' )) {
define ( 'MEMCACHED_ENABLED' , false );
}
$content = array (
'Groupwf' => array (
'uid' => 'GRP_UID' ,
'fields' => array ( 'GRP_TITLE' ),
'methods' => array ( 'exists' => 'GroupwfExists' )
),
'Process' => array (
'uid' => 'PRO_UID' ,
'fields' => array ( 'PRO_TITLE' , 'PRO_DESCRIPTION' ),
'methods' => array ( 'exists' => 'exists' )
),
'Department' => array (
'uid' => 'DEP_UID' ,
'fields' => array ( 'DEPO_TITLE' ),
'alias' => array ( 'DEPO_TITLE' => 'DEP_TITLE' ),
'methods' => array ( 'exists' => 'existsDepartment' )
),
'Task' => array (
'uid' => 'TAS_UID' ,
'fields' => array ( 'TAS_TITLE' , 'TAS_DESCRIPTION' , 'TAS_DEF_TITLE' , 'TAS_DEF_SUBJECT_MESSAGE' , 'TAS_DEF_PROC_CODE' , 'TAS_DEF_MESSAGE' , 'TAS_DEF_DESCRIPTION' ),
'methods' => array ( 'exists' => 'taskExists' )
),
'InputDocument' => array (
'uid' => 'INP_DOC_UID' ,
'fields' => array ( 'INP_DOC_TITLE' , 'INP_DOC_DESCRIPTION' ),
'methods' => array ( 'exists' => 'InputExists' )
),
'Application' => array (
'uid' => 'APP_UID' ,
'fields' => array ( 'APP_TITLE' , 'APP_DESCRIPTION' ),
'methods' => array ( 'exists' => 'exists' )
2016-12-01 09:32:35 -05:00
),
'AppDocument' => array (
'uid' => 'APP_DOC_UID' ,
'alias' => array ( 'CON_PARENT' => 'DOC_VERSION' ),
'fields' => array ( 'APP_DOC_TITLE' , 'APP_DOC_COMMENT' , 'APP_DOC_FILENAME' ),
'methods' => array ( 'exists' => 'exists' )
),
'Dynaform' => array (
'uid' => 'DYN_UID' ,
'fields' => array ( 'DYN_TITLE' , 'DYN_DESCRIPTION' ),
'methods' => array ( 'exists' => 'exists' )
),
'OutputDocument' => array (
'uid' => 'OUT_DOC_UID' ,
'fields' => array ( 'OUT_DOC_TITLE' , 'OUT_DOC_DESCRIPTION' , 'OUT_DOC_FILENAME' , 'OUT_DOC_TEMPLATE' ),
'methods' => array ( 'exists' => 'OutputExists' )
),
'ReportTable' => array (
'uid' => 'REP_TAB_UID' ,
'fields' => array ( 'REP_TAB_TITLE' ),
'methods' => array ( 'exists' => 'reportTableExists' , 'update' => function ( $row ) {
$oRepTab = \ReportTablePeer :: retrieveByPK ( $row [ 'REP_TAB_UID' ]);
$oRepTab -> fromArray ( $row , BasePeer :: TYPE_FIELDNAME );
if ( $oRepTab -> validate ()) {
$result = $oRepTab -> save ();
}
})
),
'Triggers' => array (
'uid' => 'TRI_UID' ,
'fields' => array ( 'TRI_TITLE' , 'TRI_DESCRIPTION' ),
'methods' => array ( 'exists' => 'TriggerExists' )
),
'\ProcessMaker\BusinessModel\WebEntryEvent' => array (
'uid' => 'WEE_UID' ,
'fields' => array ( 'WEE_TITLE' , 'WEE_DESCRIPTION' ),
'methods' => array ( 'exists' => 'exists' , 'update' => function ( $row ) {
$webEntry = \WebEntryEventPeer :: retrieveByPK ( $row [ 'WEE_UID' ]);
$webEntry -> fromArray ( $row , BasePeer :: TYPE_FIELDNAME );
if ( $webEntry -> validate ()) {
$result = $webEntry -> save ();
}
}),
'peer' => 'WebEntryEventPeer'
2016-07-20 11:48:10 -04:00
)
);
2016-12-01 09:32:35 -05:00
2016-07-20 11:48:10 -04:00
foreach ( $content as $className => $fields ) {
2016-12-01 09:32:35 -05:00
if ( ! in_array ( $className , $blackList )) {
$this -> migrateContentWorkspace ( $className , $fields , $lang );
$blackList [] = $className ;
}
2016-07-20 11:48:10 -04:00
}
2016-12-01 09:32:35 -05:00
return $blackList ;
2016-07-20 11:48:10 -04:00
}
2016-07-22 10:59:13 -04:00
2016-08-29 11:06:44 -04:00
public function cleanTokens ( $workspace , $lang = SYS_LANG )
{
$this -> initPropel ( true );
$oCriteria = new Criteria ();
$oCriteria -> add ( OauthAccessTokensPeer :: ACCESS_TOKEN , 0 , Criteria :: NOT_EQUAL );
$accessToken = OauthAccessTokensPeer :: doDelete ( $oCriteria );
CLI :: logging ( " |--> Clean data in table " . OauthAccessTokensPeer :: TABLE_NAME . " rows " . $accessToken . " \n " );
$oCriteria = new Criteria ();
$oCriteria -> add ( OauthRefreshTokensPeer :: REFRESH_TOKEN , 0 , Criteria :: NOT_EQUAL );
$refreshToken = OauthRefreshTokensPeer :: doDelete ( $oCriteria );
CLI :: logging ( " |--> Clean data in table " . OauthRefreshTokensPeer :: TABLE_NAME . " rows " . $refreshToken . " \n " );
}
2016-06-14 13:43:49 -04:00
public function migrateIteeToDummytask ( $workspaceName ){
$this -> initPropel ( true );
$arraySystemConfiguration = System :: getSystemConfiguration ( '' , '' , $workspaceName );
2016-09-09 11:09:02 -04:00
\G :: LoadClass ( " configuration " );
$conf = new Configurations ();
\G :: $sysSys = $workspaceName ;
\G :: $pathDataSite = PATH_DATA . " sites " . PATH_SEP . \G :: $sysSys . PATH_SEP ;
\G :: $pathDocument = PATH_DATA . 'sites' . DIRECTORY_SEPARATOR . $workspaceName . DIRECTORY_SEPARATOR . 'files' ;
\G :: $memcachedEnabled = $arraySystemConfiguration [ 'memcached' ];
\G :: $pathDataPublic = \G :: $pathDataSite . " public " . PATH_SEP ;
\G :: $sysSkin = $conf -> getConfiguration ( 'SKIN_CRON' , '' );
if ( is_file ( \G :: $pathDataSite . PATH_SEP . " .server_info " )) {
$serverInfo = file_get_contents ( \G :: $pathDataSite . PATH_SEP . " .server_info " );
$serverInfo = unserialize ( $serverInfo );
$envHost = $serverInfo [ " SERVER_NAME " ];
$envPort = ( $serverInfo [ " SERVER_PORT " ] . " " != " 80 " ) ? " : " . $serverInfo [ " SERVER_PORT " ] : " " ;
if ( ! empty ( $envPort ) && strpos ( $envHost , $envPort ) === false ) {
$envHost = $envHost . $envPort ;
}
\G :: $httpHost = $envHost ;
2016-07-22 15:21:09 -04:00
}
2016-06-14 13:43:49 -04:00
//Search All process
$oCriteria = new Criteria ( " workflow " );
$oCriteria -> addSelectColumn ( ProcessPeer :: PRO_UID );
$oCriteria -> addSelectColumn ( ProcessPeer :: PRO_ITEE );
$oCriteria -> add ( ProcessPeer :: PRO_ITEE , '0' , Criteria :: EQUAL );
$rsCriteria = ProcessPeer :: doSelectRS ( $oCriteria );
$rsCriteria -> setFetchmode ( ResultSet :: FETCHMODE_ASSOC );
$message = " -> Migrating the Intermediate Email Event \n " ;
CLI :: logging ( $message );
while ( $rsCriteria -> next ()) {
$row = $rsCriteria -> getRow ();
$prj_uid = $row [ 'PRO_UID' ];
$bpmnProcess = new Process ();
if ( $bpmnProcess -> isBpmnProcess ( $prj_uid )){
$project = new \ProcessMaker\Project\Adapter\BpmnWorkflow ();
$diagram = $project -> getStruct ( $prj_uid );
$res = $project -> updateFromStruct ( $prj_uid , $diagram );
$bpmnProcess -> setProUid ( $prj_uid );
$oProcess = new Process ();
$aProcess [ 'PRO_UID' ] = $prj_uid ;
$aProcess [ 'PRO_ITEE' ] = '1' ;
if ( $oProcess -> processExists ( $prj_uid )) {
$oProcess -> update ( $aProcess );
}
$message = " Process updated " . $bpmnProcess -> getProTitle () . " \n " ;
CLI :: logging ( $message );
}
}
$message = " Migrating Itee Done \n " ;
CLI :: logging ( $message );
}
2016-08-13 13:52:07 -04:00
public function upgradeConfiguration ()
{
G :: LoadClass ( " configuration " );
$conf = new Configurations ();
$conf -> aConfig = 'neoclassic' ;
$conf -> saveConfig ( 'SKIN_CRON' , '' );
}
2016-08-18 12:21:29 -04:00
public function upgradeAuditLog ( $workspace ){
G :: LoadClass ( " configuration " );
$conf = new Configurations ();
if ( ! $conf -> exists ( 'AUDIT_LOG' , 'log' )) {
CLI :: logging ( " > Updating Auditlog Config \n " );
$oServerConf = & serverConf :: getSingleton ();
$sAudit = $oServerConf -> getAuditLogProperty ( 'AL_OPTION' , $workspace );
$conf -> aConfig = ( $sAudit == 1 ) ? 'true' : 'false' ;
$conf -> saveConfig ( 'AUDIT_LOG' , 'log' );
}
}
2016-12-08 17:02:13 -05:00
public function migrateSelfServiceRecordsRun ( $workspace ) {
// Initializing
$this -> initPropel ( true );
// Get datat to migrate
$criteria = new Criteria ( " workflow " );
$criteria -> addSelectColumn ( AppAssignSelfServiceValuePeer :: ID );
$criteria -> addSelectColumn ( AppAssignSelfServiceValuePeer :: GRP_UID );
$criteria -> add ( AppAssignSelfServiceValuePeer :: GRP_UID , '' , Criteria :: NOT_EQUAL );
$rsCriteria = AppAssignSelfServiceValuePeer :: doSelectRS ( $criteria );
$rsCriteria -> setFetchmode ( ResultSet :: FETCHMODE_ASSOC );
// Migrating data
CLI :: logging ( " -> Migrating Self-Service by Value Cases \n " );
while ( $rsCriteria -> next ()) {
$row = $rsCriteria -> getRow ();
$temp = unserialize ( $row [ 'GRP_UID' ]);
if ( is_array ( $temp )) {
foreach ( $temp as $groupUid ) {
if ( $groupUid != '' ) {
$appAssignSelfServiceValueGroup = new AppAssignSelfServiceValueGroup ();
$appAssignSelfServiceValueGroup -> setId ( $row [ 'ID' ]);
$appAssignSelfServiceValueGroup -> setGrpUid ( $groupUid );
$appAssignSelfServiceValueGroup -> save ();
}
}
} else {
if ( $temp != '' ) {
$appAssignSelfServiceValueGroup = new AppAssignSelfServiceValueGroup ();
$appAssignSelfServiceValueGroup -> setId ( $row [ 'ID' ]);
$appAssignSelfServiceValueGroup -> setGrpUid ( $temp );
$appAssignSelfServiceValueGroup -> save ();
}
}
CLI :: logging ( " Migrating Record " . $row [ 'ID' ] . " \n " );
}
// Updating processed records to empty
$con = Propel :: getConnection ( 'workflow' );
$criteriaSet = new Criteria ( " workflow " );
$criteriaSet -> add ( AppAssignSelfServiceValuePeer :: GRP_UID , '' );
BasePeer :: doUpdate ( $criteria , $criteriaSet , $con );
CLI :: logging ( " Migrating Self-Service by Value Cases Done \n " );
}
2017-01-10 17:51:08 -04:00
public function migratePopulateIndexingACV ( $workspace ) {
// Migrating and populating new indexes
2017-02-13 14:50:48 -04:00
CLI :: logging ( " -> Migrating an populating indexing for avoiding the use of table APP_CACHE_VIEW Start \n " );
2017-01-10 17:51:08 -04:00
// Initializing
$this -> initPropel ( true );
$con = Propel :: getConnection ( AppDelegationPeer :: DATABASE_NAME );
// Populating APP_DELEGATION.APP_NUMBER
CLI :: logging ( " -> Populating APP_DELEGATION.APP_NUMBER \n " );
$con -> begin ();
$stmt = $con -> createStatement ();
$rs = $stmt -> executeQuery ( " UPDATE APP_DELEGATION AS AD
INNER JOIN (
SELECT APPLICATION . APP_UID , APPLICATION . APP_NUMBER
FROM APPLICATION
) AS APP
ON ( AD . APP_UID = APP . APP_UID )
SET AD . APP_NUMBER = APP . APP_NUMBER
WHERE AD . APP_NUMBER = 0 " );
$con -> commit ();
// Populating APP_DELEGATION.USR_ID
CLI :: logging ( " -> Populating APP_DELEGATION.USR_ID \n " );
$con -> begin ();
$stmt = $con -> createStatement ();
$rs = $stmt -> executeQuery ( " UPDATE APP_DELEGATION AS AD
INNER JOIN (
SELECT USERS . USR_UID , USERS . USR_ID
FROM USERS
) AS USR
ON ( AD . USR_UID = USR . USR_UID )
SET AD . USR_ID = USR . USR_ID
WHERE AD . USR_ID = 0 " );
$con -> commit ();
// Populating APP_DELEGATION.PRO_ID
CLI :: logging ( " -> Populating APP_DELEGATION.PRO_ID \n " );
$con -> begin ();
$stmt = $con -> createStatement ();
$rs = $stmt -> executeQuery ( " UPDATE APP_DELEGATION AS AD
INNER JOIN (
SELECT PROCESS . PRO_UID , PROCESS . PRO_ID
FROM PROCESS
) AS PRO
ON ( AD . PRO_UID = PRO . PRO_UID )
SET AD . PRO_ID = PRO . PRO_ID
WHERE AD . PRO_ID = 0 " );
$con -> commit ();
// Populating APP_DELEGATION.TAS_ID
CLI :: logging ( " -> Populating APP_DELEGATION.TAS_ID \n " );
$con -> begin ();
$stmt = $con -> createStatement ();
$rs = $stmt -> executeQuery ( " UPDATE APP_DELEGATION AS AD
INNER JOIN (
SELECT TASK . TAS_UID , TASK . TAS_ID
FROM TASK
) AS TAS
ON ( AD . TAS_UID = TAS . TAS_UID )
SET AD . TAS_ID = TAS . TAS_ID
WHERE AD . TAS_ID = 0 " );
$con -> commit ();
2017-02-13 15:54:25 -04:00
// Populating APPLICATION.APP_STATUS_ID
2017-01-10 17:51:08 -04:00
CLI :: logging ( " -> Populating APPLICATION.APP_STATUS_ID \n " );
$con -> begin ();
$stmt = $con -> createStatement ();
$rs = $stmt -> executeQuery ( " UPDATE APPLICATION
SET APP_STATUS_ID = ( case
when APP_STATUS = 'DRAFT' then 1
when APP_STATUS = 'TO_DO' then 2
when APP_STATUS = 'COMPLETED' then 3
when APP_STATUS = 'CANCELLED' then 4
end )
WHERE APP_STATUS in ( 'DRAFT' , 'TO_DO' , 'COMPLETED' , 'CANCELLED' ) AND
APP_STATUS_ID = 0 " );
$con -> commit ();
2017-02-13 14:50:48 -04:00
CLI :: logging ( " -> Migrating And Populating Indexing for avoiding the use of table APP_CACHE_VIEW Done \n " );
2017-02-20 11:15:23 -04:00
// Populating PRO_ID, USR_ID
2017-02-20 13:21:22 -04:00
CLI :: logging ( " -> Populating PRO_ID, USR_ID at LIST_* \n " );
2017-02-20 11:15:23 -04:00
$con -> begin ();
$stmt = $con -> createStatement ();
2017-02-21 16:25:17 -04:00
foreach ( workspaceTools :: $populateIdsQueries as $query ) {
$stmt -> executeQuery ( $query );
}
2017-02-20 11:15:23 -04:00
$con -> commit ();
2017-02-20 17:37:03 -04:00
CLI :: logging ( " -> Populating PRO_ID, USR_ID at LIST_* Done \n " );
2017-01-10 17:51:08 -04:00
}
2017-03-09 18:24:34 -04:00
/**
* It populates the WEB_ENTRY table for the classic processes , this procedure
* is done to verify the execution of php files generated when the WebEntry
* is configured .
* @ param type $workSpace
*/
public function updatingWebEntryClassicModel ( $workSpace , $force = false )
{
//We obtain from the configuration the list of proUids obtained so that
//we do not go through again.
$cfgUid = 'UPDATING_ROWS_WEB_ENTRY' ;
$objUid = 'blackList' ;
$blackList = [];
$conf = new Configuration ();
$ifExists = $conf -> exists ( $cfgUid , $objUid );
if ( $ifExists ) {
$oConfig = $conf -> load ( $cfgUid , $objUid );
$blackList = unserialize ( $oConfig [ 'CFG_VALUE' ]);
}
//The following query returns all the classic processes that do not have
//a record in the WEB_ENTRY table.
$oCriteria = new Criteria ( " workflow " );
$oCriteria -> addSelectColumn ( ProcessPeer :: PRO_UID );
$oCriteria -> addSelectColumn ( BpmnProcessPeer :: PRJ_UID );
$oCriteria -> addJoin ( ProcessPeer :: PRO_UID , BpmnProcessPeer :: PRJ_UID , Criteria :: LEFT_JOIN );
$oCriteria -> addJoin ( ProcessPeer :: PRO_UID , WebEntryPeer :: PRO_UID , Criteria :: LEFT_JOIN );
$oCriteria -> add ( BpmnProcessPeer :: PRJ_UID , null , Criteria :: EQUAL );
$oCriteria -> add ( WebEntryPeer :: PRO_UID , null , Criteria :: EQUAL );
if ( $force === false ) {
$oCriteria -> add ( ProcessPeer :: PRO_UID , $blackList , Criteria :: NOT_IN );
}
$rsCriteria = ProcessPeer :: doSelectRS ( $oCriteria );
$rsCriteria -> setFetchmode ( ResultSet :: FETCHMODE_ASSOC );
$process = new Process ();
while ( $rsCriteria -> next ()) {
$row = $rsCriteria -> getRow ();
$proUid = $row [ 'PRO_UID' ];
if ( ! in_array ( $proUid , $blackList )) {
$blackList [] = $proUid ;
}
$path = PATH_DATA . " sites " . PATH_SEP . $this -> name . PATH_SEP . " public " . PATH_SEP . $proUid ;
if ( is_dir ( $path )) {
$dir = opendir ( $path );
while ( $fileName = readdir ( $dir )) {
if ( $fileName !== " . " && $fileName !== " .. " && strpos ( $fileName , " wsClient.php " ) === false && strpos ( $fileName , " Post.php " ) === false
) {
CLI :: logging ( " Verifying if file: " . $fileName . " is a web entry \n " );
$step = new Criteria ( " workflow " );
$step -> addSelectColumn ( StepPeer :: PRO_UID );
$step -> addSelectColumn ( StepPeer :: TAS_UID );
$step -> addSelectColumn ( StepPeer :: STEP_TYPE_OBJ );
$step -> addSelectColumn ( StepPeer :: STEP_UID_OBJ );
$step -> add ( StepPeer :: STEP_TYPE_OBJ , " DYNAFORM " , Criteria :: EQUAL );
$step -> add ( StepPeer :: PRO_UID , $proUid , Criteria :: EQUAL );
$stepRs = StepPeer :: doSelectRS ( $step );
$stepRs -> setFetchmode ( ResultSet :: FETCHMODE_ASSOC );
while ( $stepRs -> next ()) {
$row1 = $stepRs -> getRow ();
$content = file_get_contents ( $path . " / " . $fileName );
if ( strpos ( $content , $proUid . " / " . $row1 [ " STEP_UID_OBJ " ]) !== false ) {
//The default user admin is set. This task is
//carried out by the system administrator.
$userUid = " 00000000000000000000000000000001 " ;
//save data in table WEB_ENTRY
$arrayData = [
" PRO_UID " => $proUid ,
" DYN_UID " => $row1 [ " STEP_UID_OBJ " ],
" TAS_UID " => $row1 [ " TAS_UID " ],
" WE_DATA " => $fileName ,
" USR_UID " => $userUid ,
" WE_CREATE_USR_UID " => $userUid ,
" WE_UPDATE_USR_UID " => $userUid
];
$webEntry = new \ProcessMaker\BusinessModel\WebEntry ();
$webEntry -> createClassic ( $arrayData );
}
}
}
}
}
}
//The list of proUids obtained is saved in the configuration so that it
//does not go through again.
$data = [
" CFG_UID " => $cfgUid ,
" OBJ_UID " => $objUid ,
" CFG_VALUE " => serialize ( $blackList ),
" PRO_UID " => '' ,
" USR_UID " => '' ,
" APP_UID " => ''
];
if ( $ifExists ) {
$conf -> update ( $data );
} else {
$conf -> create ( $data );
}
}
2017-01-10 17:51:08 -04:00
2010-12-02 23:34:41 +00:00
}