2015-04-01 18:01:40 -04:00
< ? php
2011-01-22 12:20:08 +00:00
/**
2011-01-27 15:04:37 +00:00
* cliWorkspaces . php
*
* ProcessMaker Open Source Edition
* Copyright ( C ) 2011 Colosa Inc .
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation , either version 3 of the
* License , or ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU Affero General Public License for more details .
*
* You should have received a copy of the GNU Affero General Public License
* along with this program . If not , see < http :// www . gnu . org / licenses />.
*
* For more information , contact Colosa Inc , 2566 Le Jeune Rd . ,
* Coral Gables , FL , 33134 , USA , or email info @ colosa . com .
*
* @ author Alexandre Rosenfeld < alexandre @ colosa . com >
2011-01-22 12:20:08 +00:00
* @ package workflow - engine - bin - tasks
2011-01-28 14:16:58 +00:00
*/
2010-12-16 20:36:29 +00:00
2011-01-27 15:04:37 +00:00
CLI :: taskName ( 'info' );
CLI :: taskDescription ( <<< EOT
2011-02-02 16:32:22 +00:00
Print information about the current system and any specified workspaces .
If no workspace is specified , show information about all available workspaces
2011-01-27 15:04:37 +00:00
EOT
);
CLI :: taskArg ( 'workspace-name' , true , true );
2014-03-17 11:54:09 -04:00
CLI :: taskRun ( " run_info " );
2011-01-27 15:04:37 +00:00
CLI :: taskName ( 'workspace-backup' );
CLI :: taskDescription ( <<< EOT
2015-07-20 12:02:33 -04:00
Backup the specified workspace to a file .
2011-01-27 15:04:37 +00:00
2015-07-20 12:02:33 -04:00
BACKUP - FILE is the backup filename which will be created . If it contains
slashes , it will be treated as a path and filename , either absolute or relative .
Otherwise , it will be treated as a filename inside the " shared/backups " directory .
If no BACKUP - FILE is specified , it will use the workspace name as the filename .
2011-01-27 15:04:37 +00:00
A backup archive will contain all information about the specified workspace
2011-02-02 16:32:22 +00:00
so that it can be restored later . The archive includes a database dump and
all the workspace files .
2011-01-27 15:04:37 +00:00
EOT
);
CLI :: taskArg ( 'workspace' , false );
CLI :: taskArg ( 'backup-file' , true );
2015-08-05 22:41:55 -04:00
CLI :: taskOpt ( " filesize " , " Split the backup file in multiple files which are compressed. The maximum size of these files is set to MAX-SIZE in megabytes. If MAX-SIZE is not set, then it is 1000 megabytes by default. It may be necessary to use this option if using a 32 bit Linux/UNIX system which limits its maximum file size to 2GB. This option does not work on Windows systems. " , " s: " , " filesize= " );
2014-03-17 11:54:09 -04:00
CLI :: taskRun ( " run_workspace_backup " );
2011-01-27 15:04:37 +00:00
CLI :: taskName ( 'workspace-restore' );
CLI :: taskDescription ( <<< EOT
2015-07-20 12:02:33 -04:00
Restore a workspace from a backup file
2011-01-27 15:04:37 +00:00
2011-02-02 16:32:22 +00:00
BACKUP - FILE is the backup filename . If it contains slashes , it will be
treated as a path and filename , either absolute or relative . Otherwise , it
will be treated as a filename inside the 'shared/backups' directory .
2011-01-27 15:04:37 +00:00
2011-02-02 16:32:22 +00:00
Specify the WORKSPACE to restore to a different workspace name . Otherwise ,
it will restore to the same workspace name as the original backup .
2011-01-27 15:04:37 +00:00
EOT
);
CLI :: taskArg ( 'backup-file' , false );
CLI :: taskArg ( 'workspace' , true );
2011-02-17 20:51:26 +00:00
CLI :: taskOpt ( " overwrite " , " If a workspace already exists, overwrite it. " , " o " , " overwrite " );
2015-07-20 12:02:33 -04:00
CLI :: taskOpt ( " info " , " Show information about backup file, but do not restore any workspaces. " , " i " );
CLI :: taskOpt ( " multiple " , " Restore from multiple compressed backup files which are numbered. " , " m " );
CLI :: taskOpt ( " workspace " , " Specify which workspace to restore if multiple workspaces are present in the backup file.
Ex : - wworkflow . " ,
2015-08-05 22:41:55 -04:00
" w: " , " workspace= " );
CLI :: taskOpt ( " lang " , " Specify the language which will be used to rebuild the case cache list. If this option isn't included, then 'en' (English) will be used by default. " , " l: " , " lang= " );
CLI :: taskOpt ( " port " , " Specify the port number used by MySQL. If not specified, then the port 3306 will be used by default. " , " p: " );
2014-03-17 11:54:09 -04:00
CLI :: taskRun ( " run_workspace_restore " );
2011-01-27 15:04:37 +00:00
CLI :: taskName ( 'cacheview-repair' );
CLI :: taskDescription ( <<< EOT
2011-02-02 16:32:22 +00:00
Create and populate the APP_CACHE_VIEW table
2011-01-27 15:04:37 +00:00
2011-02-02 16:32:22 +00:00
Specify the workspaces whose cases cache should be repaired . If no workspace
is specified , then the cases will be repaired on all available workspaces .
2011-01-27 15:04:37 +00:00
In order to improve the performance , ProcessMaker includes a cache of cases
in the table APP_CACHE_VIEW . This table must be in sync with the database
2011-02-02 16:32:22 +00:00
to present the correct information in the cases inbox . This command will
create the table and populate it with the right information . This only needs
to be used after upgrading ProcessMaker or if the cases inbox is out of sync .
2011-01-27 15:04:37 +00:00
EOT
);
CLI :: taskArg ( 'workspace' , true , true );
2015-08-05 22:41:55 -04:00
CLI :: taskOpt ( " lang " , " Specify the language to rebuild the case cache list. If not specified, then 'en' (English) will be used by default. \n Ex: -lfr (French) Ex: --lang=zh-CN (Mainland Chinese) " , " l: " , " lang= " );
2014-03-17 11:54:09 -04:00
CLI :: taskRun ( " run_cacheview_upgrade " );
2011-01-27 15:04:37 +00:00
CLI :: taskName ( 'database-upgrade' );
CLI :: taskDescription ( <<< EOT
2011-02-02 16:32:22 +00:00
Upgrade or repair the database schema to match the latest version
2011-01-27 15:04:37 +00:00
2015-07-20 12:02:33 -04:00
Specify the workspaces whose database schema should be upgraded or repaired .
2011-02-02 16:32:22 +00:00
If no workspace is specified , then the database schema will be upgraded or
repaired on all available workspaces .
2011-01-27 15:04:37 +00:00
2015-07-20 12:02:33 -04:00
This command will read the system schema and attempt to modify the workspaces
tables to match this new schema . Use this command to fix corrupted database
2011-02-02 16:32:22 +00:00
schemas or after ProcessMaker has been upgraded , so the database schemas will
2015-07-20 12:02:33 -04:00
be changed to match the new ProcessMaker code .
2011-01-27 15:04:37 +00:00
EOT
);
CLI :: taskArg ( 'workspace' , true , true );
2014-03-17 11:54:09 -04:00
CLI :: taskRun ( " run_database_upgrade " );
2011-01-27 15:04:37 +00:00
CLI :: taskName ( 'plugins-database-upgrade' );
CLI :: taskDescription ( <<< EOT
2011-02-02 16:32:22 +00:00
Upgrade or repair the database schema for plugins to match the latest version
2011-01-27 15:04:37 +00:00
2015-07-20 12:02:33 -04:00
Specify the workspaces whose database schema should be upgraded or repaired
2011-02-02 16:32:22 +00:00
for plugins . If no workspace is specified , then the database schema will be
upgraded or repaired on all available workspaces .
2011-01-27 15:04:37 +00:00
2015-07-20 12:02:33 -04:00
This is the same as database - upgrade but it works with schemas provided
by plugins . This is useful if plugins are installed that include
database schemas .
2011-01-27 15:04:37 +00:00
EOT
);
CLI :: taskArg ( 'workspace' , true , true );
2014-03-17 11:54:09 -04:00
CLI :: taskRun ( " run_plugins_database_upgrade " );
2011-01-27 15:04:37 +00:00
CLI :: taskName ( 'workspace-upgrade' );
CLI :: taskDescription ( <<< EOT
2015-07-20 12:02:33 -04:00
Upgrade the specified workspace ( s ) .
2011-01-27 15:04:37 +00:00
2011-02-02 16:32:22 +00:00
If no workspace is specified , the command will be run in all workspaces . More
than one workspace can be specified .
2011-11-08 17:37:47 -04:00
2015-07-20 12:02:33 -04:00
This command is a shortcut to execute all the upgrade commands for workspaces .
2011-02-02 16:32:22 +00:00
Upgrading a workspace will make it correspond to the current version of
ProcessMaker .
Use this command to upgrade workspaces individually , otherwise use the
2015-07-20 12:02:33 -04:00
'processmaker upgrade' command to upgrade the entire system .
2011-01-27 15:04:37 +00:00
EOT
);
CLI :: taskArg ( 'workspace-name' , true , true );
2014-03-17 11:54:09 -04:00
CLI :: taskRun ( " run_workspace_upgrade " );
2011-01-27 15:04:37 +00:00
CLI :: taskName ( 'translation-repair' );
CLI :: taskDescription ( <<< EOT
2011-02-02 16:32:22 +00:00
Upgrade or repair translations for the specified workspace ( s ) .
2011-01-27 15:04:37 +00:00
2011-02-02 16:32:22 +00:00
If no workspace is specified , the command will be run in all workspaces . More
than one workspace can be specified .
2011-11-08 17:37:47 -04:00
2011-01-27 15:04:37 +00:00
This command will go through each language installed in ProcessMaker and
2015-07-20 12:02:33 -04:00
update the translations for the workspace ( s ) to match the current version of
2011-02-02 16:32:22 +00:00
ProcessMaker .
2011-01-27 15:04:37 +00:00
EOT
);
CLI :: taskArg ( 'workspace-name' , true , true );
2014-03-17 11:54:09 -04:00
CLI :: taskRun ( " run_translation_upgrade " );
2011-01-27 15:04:37 +00:00
2013-06-25 14:36:02 -04:00
CLI :: taskName ( 'migrate-cases-folders' );
2013-06-25 13:50:38 -04:00
CLI :: taskDescription ( <<< EOT
2013-06-25 14:36:02 -04:00
Migrating cases folders of the workspaces
2013-06-25 13:50:38 -04:00
2013-06-25 14:36:02 -04:00
Specify the WORKSPACE to migrate from a existing workspace .
2013-06-25 13:50:38 -04:00
EOT
);
//CLI::taskArg('workspace', true);
2015-07-20 12:02:33 -04:00
CLI :: taskOpt ( " workspace " , " Select the workspace whose case folders will be migrated, if multiple workspaces are present in the server. \n Ex: -wworkflow. Ex: --workspace=workflow " ,
2015-08-05 22:41:55 -04:00
" w: " , " workspace= " );
2014-03-17 11:54:09 -04:00
CLI :: taskRun ( " runStructureDirectories " );
2013-06-25 13:50:38 -04:00
2014-10-27 11:25:17 -04:00
CLI :: taskName ( " database-generate-self-service-by-value " );
CLI :: taskDescription ( <<< EOT
2014-11-19 16:47:22 -04:00
Generate or upgrade the table " self-service by value " .
2014-10-27 11:25:17 -04:00
2015-07-20 12:02:33 -04:00
This command populates the table " self-service by value " for cases whose
task is defined with " Self Service Value Based Assignment " in " Assignment
Rules " .
2014-10-27 11:25:17 -04:00
If no workspace is specified , the command will be run in all workspaces . More
than one workspace can be specified .
EOT
);
CLI :: taskArg ( " workspace-name " , true , true );
CLI :: taskRun ( " run_database_generate_self_service_by_value " );
2015-01-06 16:57:38 -04:00
/*----------------------------------********---------------------------------*/
2014-11-19 16:47:22 -04:00
CLI :: taskName ( " check-workspace-disabled-code " );
CLI :: taskDescription ( <<< EOT
Check disabled code for the specified workspace ( s ) .
2015-07-20 12:02:33 -04:00
This command checks the disabled code in the specified workspace ( s ) .
2014-11-19 16:47:22 -04:00
2015-07-20 12:02:33 -04:00
If no workspace is specified , the command will be run in all workspaces .
More than one workspace can be specified .
2014-11-19 16:47:22 -04:00
EOT
);
CLI :: taskArg ( " workspace-name " , true , true );
CLI :: taskRun ( " run_check_workspace_disabled_code " );
2015-03-04 18:42:47 -04:00
CLI :: taskName ( 'migrate-new-cases-lists' );
CLI :: taskDescription ( <<< EOT
Migrating the list cases schema to match the latest version
Specify the WORKSPACE to migrate from a existing workspace .
If no workspace is specified , then the tables schema will be upgraded or
migrate on all available workspaces .
EOT
);
CLI :: taskArg ( 'workspace' , true , true );
CLI :: taskRun ( " run_migrate_new_cases_lists " );
2015-01-06 16:57:38 -04:00
/*----------------------------------********---------------------------------*/
2014-11-19 16:47:22 -04:00
2011-01-28 14:16:58 +00:00
/**
* Function run_info
* access public
*/
2011-01-27 15:04:37 +00:00
function run_info ( $args , $opts ) {
2011-02-02 16:32:22 +00:00
$workspaces = get_workspaces_from_args ( $args );
2011-01-27 15:04:37 +00:00
workspaceTools :: printSysInfo ();
2010-12-16 20:36:29 +00:00
foreach ( $workspaces as $workspace ) {
echo " \n " ;
$workspace -> printMetadata ( false );
}
}
2011-01-27 15:04:37 +00:00
function run_workspace_upgrade ( $args , $opts ) {
2015-03-17 15:25:49 -04:00
G :: LoadSystem ( 'inputfilter' );
$filter = new InputFilter ();
$opts = $filter -> xssFilterHard ( $opts );
$args = $filter -> xssFilterHard ( $args );
2010-12-16 20:36:29 +00:00
$workspaces = get_workspaces_from_args ( $args );
2011-02-02 15:42:12 +00:00
$first = true ;
2013-05-17 10:39:48 -04:00
$lang = array_key_exists ( " lang " , $opts ) ? $opts [ 'lang' ] : 'en' ;
2010-12-16 20:36:29 +00:00
foreach ( $workspaces as $workspace ) {
try {
2013-05-17 10:39:48 -04:00
$workspace -> upgrade ( $first , false , $workspace -> name , $lang );
2011-02-02 15:42:12 +00:00
$first = false ;
2010-12-16 20:36:29 +00:00
} catch ( Exception $e ) {
2011-02-24 23:32:57 +00:00
echo " Errors upgrading workspace " . CLI :: info ( $workspace -> name ) . " : " . CLI :: error ( $e -> getMessage ()) . " \n " ;
2010-12-16 20:36:29 +00:00
}
}
}
2011-01-27 15:04:37 +00:00
function run_translation_upgrade ( $args , $opts ) {
2015-03-17 15:25:49 -04:00
G :: LoadSystem ( 'inputfilter' );
$filter = new InputFilter ();
$opts = $filter -> xssFilterHard ( $opts );
$args = $filter -> xssFilterHard ( $args );
2010-12-16 20:36:29 +00:00
$workspaces = get_workspaces_from_args ( $args );
2011-02-02 15:42:12 +00:00
$first = true ;
2010-12-16 20:36:29 +00:00
foreach ( $workspaces as $workspace ) {
try {
echo " Upgrading translation for " . pakeColor :: colorize ( $workspace -> name , " INFO " ) . " \n " ;
2011-02-02 15:42:12 +00:00
$workspace -> upgradeTranslation ( $first );
$first = false ;
2010-12-16 20:36:29 +00:00
} catch ( Exception $e ) {
2011-02-24 23:32:57 +00:00
echo " Errors upgrading translation of workspace " . CLI :: info ( $workspace -> name ) . " : " . CLI :: error ( $e -> getMessage ()) . " \n " ;
2010-12-16 20:36:29 +00:00
}
}
}
2011-01-27 15:04:37 +00:00
function run_cacheview_upgrade ( $args , $opts ) {
2015-03-17 15:25:49 -04:00
G :: LoadSystem ( 'inputfilter' );
$filter = new InputFilter ();
$opts = $filter -> xssFilterHard ( $opts );
$args = $filter -> xssFilterHard ( $args );
2010-12-16 20:36:29 +00:00
$workspaces = get_workspaces_from_args ( $args );
2013-05-17 10:39:48 -04:00
$lang = array_key_exists ( " lang " , $opts ) ? $opts [ 'lang' ] : 'en' ;
2010-12-16 20:36:29 +00:00
foreach ( $workspaces as $workspace ) {
try {
echo " Upgrading cache view for " . pakeColor :: colorize ( $workspace -> name , " INFO " ) . " \n " ;
2013-05-17 10:39:48 -04:00
$workspace -> upgradeCacheView ( true , false , $lang );
2010-12-16 20:36:29 +00:00
} catch ( Exception $e ) {
2015-05-10 17:16:34 -04:00
echo " Errors upgrading cache view of workspace " . CLI :: info ( $workspace -> name ) . " : " . CLI :: error ( $e -> getMessage ()) . " \n " ;
2010-12-16 20:36:29 +00:00
}
}
}
2011-01-27 15:04:37 +00:00
function run_plugins_database_upgrade ( $args , $opts ) {
2010-12-17 14:35:56 +00:00
$workspaces = get_workspaces_from_args ( $args );
foreach ( $workspaces as $workspace ) {
try {
2011-02-24 23:32:57 +00:00
CLI :: logging ( " Upgrading plugins database for " . CLI :: info ( $workspace -> name ) . " \n " );
2010-12-17 14:35:56 +00:00
$workspace -> upgradePluginsDatabase ();
} catch ( Exception $e ) {
2011-02-24 23:32:57 +00:00
CLI :: logging ( " Errors upgrading plugins database: " . CLI :: error ( $e -> getMessage ()));
2010-12-17 14:35:56 +00:00
}
}
}
2011-01-27 15:04:37 +00:00
function run_database_export ( $args , $opts ) {
2010-12-16 20:36:29 +00:00
if ( count ( $args ) < 2 )
throw new Exception ( " Please provide a workspace name and a directory for export " );
$workspace = new workspaceTools ( $args [ 0 ]);
$workspace -> exportDatabase ( $args [ 1 ]);
}
2011-01-27 15:04:37 +00:00
function run_database_import ( $args , $opts ) {
2010-12-16 20:36:29 +00:00
throw new Exception ( " Not implemented " );
}
2011-01-27 15:04:37 +00:00
function run_database_upgrade ( $args , $opts ) {
2010-12-16 20:36:29 +00:00
database_upgrade ( " upgrade " , $args );
}
2011-01-27 15:04:37 +00:00
function run_database_check ( $args , $opts ) {
2010-12-16 20:36:29 +00:00
database_upgrade ( " check " , $args );
}
2015-03-04 18:42:47 -04:00
function run_migrate_new_cases_lists ( $args , $opts ) {
migrate_new_cases_lists ( " migrate " , $args );
}
2010-12-16 20:36:29 +00:00
function database_upgrade ( $command , $args ) {
2015-03-17 15:25:49 -04:00
G :: LoadSystem ( 'inputfilter' );
$filter = new InputFilter ();
$command = $filter -> xssFilterHard ( $command );
$args = $filter -> xssFilterHard ( $args );
2010-12-16 20:36:29 +00:00
$workspaces = get_workspaces_from_args ( $args );
$checkOnly = ( strcmp ( $command , " check " ) == 0 );
foreach ( $workspaces as $workspace ) {
2015-06-05 15:44:28 -04:00
if ( ! defined ( " SYS_SYS " )) {
define ( " SYS_SYS " , $workspace -> name );
}
if ( ! defined ( " PATH_DATA_SITE " )) {
define ( " PATH_DATA_SITE " , PATH_DATA . " sites " . PATH_SEP . SYS_SYS . PATH_SEP );
}
2010-12-16 20:36:29 +00:00
if ( $checkOnly )
2011-06-29 10:46:47 -04:00
print_r ( " Checking database in " . pakeColor :: colorize ( $workspace -> name , " INFO " ) . " \n " );
2010-12-16 20:36:29 +00:00
else
2011-06-29 10:46:47 -04:00
print_r ( " Upgrading database in " . pakeColor :: colorize ( $workspace -> name , " INFO " ) . " \n " );
2015-05-22 16:07:42 -04:00
2010-12-16 20:36:29 +00:00
try {
2011-01-10 14:14:31 +00:00
$changes = $workspace -> upgradeDatabase ( $checkOnly );
2010-12-16 20:36:29 +00:00
if ( $changes != false ) {
if ( $checkOnly ) {
echo " > " . pakeColor :: colorize ( " Run upgrade " , " INFO " ) . " \n " ;
echo " Tables (add = " . count ( $changes [ 'tablesToAdd' ]);
echo " , alter = " . count ( $changes [ 'tablesToAlter' ]) . " ) " ;
echo " - Indexes (add = " . count ( $changes [ 'tablesWithNewIndex' ]) . " " ;
echo " , alter = " . count ( $changes [ 'tablesToAlterIndex' ]) . " ) \n " ;
} else {
2011-11-08 17:37:47 -04:00
echo " -> Schema fixed \n " ;
2010-12-16 20:36:29 +00:00
}
} else {
echo " > OK \n " ;
}
} catch ( Exception $e ) {
2011-06-29 10:46:47 -04:00
echo " > Error: " . CLI :: error ( $e -> getMessage ()) . " \n " ;
2010-12-16 20:36:29 +00:00
}
}
}
function delete_app_from_table ( $con , $tableName , $appUid , $col = " APP_UID " ) {
$stmt = $con -> createStatement ();
$sql = " DELETE FROM " . $tableName . " WHERE " . $col . " =' " . $appUid . " ' " ;
$rs = $stmt -> executeQuery ( $sql , ResultSet :: FETCHMODE_NUM );
}
2011-01-27 15:04:37 +00:00
function run_drafts_clean ( $args , $opts ) {
2010-12-16 20:36:29 +00:00
echo " Cleaning drafts \n " ;
2011-11-08 17:37:47 -04:00
2010-12-16 20:36:29 +00:00
if ( count ( $args ) < 1 )
throw new Exception ( " Please specify a workspace name " );
$workspace = $args [ 0 ];
2011-11-08 17:37:47 -04:00
2010-12-16 20:36:29 +00:00
if ( ! file_exists ( PATH_DB . $workspace . '/db.php' )) {
throw new Exception ( 'Could not find workspace ' . $workspace );
}
$allDrafts = false ;
if ( count ( $args ) < 2 ) {
echo " Cases older them this much days will be deleted (ENTER for all): " ;
$days = rtrim ( fgets ( STDIN ), " \n " );
if ( $days == " " ) {
$allDrafts = true ;
}
} else {
$days = $args [ 1 ];
if ( strcmp ( $days , " all " ) == 0 ) {
$allDrafts = true ;
}
}
if ( ! $allDrafts && ( ! is_numeric ( $days ) || intval ( $days ) <= 0 )) {
throw new Exception ( " Days value is not valid: " . $days );
}
if ( $allDrafts )
echo " Removing all drafts \n " ;
else
echo " Removing drafts older than " . $days . " days \n " ;
/* Load the configuration from the workspace */
require_once ( PATH_DB . $workspace . '/db.php' );
require_once ( PATH_THIRDPARTY . 'propel/Propel.php' );
PROPEL :: Init ( PATH_METHODS . 'dbConnections/rootDbConnections.php' );
$con = Propel :: getConnection ( " root " );
$stmt = $con -> createStatement ();
if ( ! $allDrafts )
$dateSql = " AND DATE_SUB(CURDATE(),INTERVAL " . $days . " DAY) >= APP_CREATE_DATE " ;
else
$dateSql = " " ;
/* Search for all the draft cases */
$sql = " SELECT APP_UID FROM APPLICATION WHERE APP_STATUS='DRAFT' " . $dateSql ;
$appRows = $stmt -> executeQuery ( $sql , ResultSet :: FETCHMODE_ASSOC );
/* Tables to remove the cases from */
$tables = array (
" APPLICATION " ,
" APP_DELEGATION " ,
" APP_CACHE_VIEW " ,
" APP_THREAD " ,
" APP_DOCUMENT " ,
" APP_EVENT " ,
" APP_HISTORY " ,
" APP_MESSAGE "
);
echo " Found " . $appRows -> getRecordCount () . " cases to remove " ;
foreach ( $appRows as $row ) {
echo " . " ;
$appUid = $row [ 'APP_UID' ];
foreach ( $tables as $table ) {
delete_app_from_table ( $con , $table , $appUid );
}
delete_app_from_table ( $con , " CONTENT " , $appUid , " CON_ID " );
if ( file_exists ( PATH_DB . $workspace . '/files/' . $appUid )) {
echo " \n Removing files from " . $appUid . " \n " ;
G :: rm_dir ( PATH_DB . $workspace . '/files/' . $appUid );
}
}
echo " \n " ;
}
2011-01-27 15:04:37 +00:00
function run_workspace_backup ( $args , $opts ) {
2014-10-10 15:09:26 -04:00
$workspaces = array ();
if ( sizeof ( $args ) > 2 ) {
$filename = array_pop ( $args );
foreach ( $args as $arg ) {
$workspaces [] = new workspaceTools ( $arg );
}
} else if ( sizeof ( $args ) > 0 ) {
$workspace = new workspaceTools ( $args [ 0 ]);
$workspaces [] = $workspace ;
if ( sizeof ( $args ) == 2 ) {
$filename = $args [ 1 ];
} else {
$filename = " { $workspace -> name } .tar " ;
}
} else {
throw new Exception ( " No workspace specified for backup " );
2011-01-27 15:04:37 +00:00
}
2013-02-18 11:09:37 -04:00
2014-10-10 15:09:26 -04:00
foreach ( $workspaces as $workspace ) {
if ( ! $workspace -> workspaceExists ()) {
throw new Exception ( " Workspace ' { $workspace -> name } ' not found " );
2014-10-27 11:25:17 -04:00
}
2014-10-10 15:09:26 -04:00
}
2014-10-27 11:25:17 -04:00
2014-10-10 15:09:26 -04:00
//If this is a relative path, put the file in the backups directory
if ( strpos ( $filename , " / " ) === false && strpos ( $filename , '\\' ) === false ){
$filename = PATH_DATA . " backups/ $filename " ;
}
CLI :: logging ( " Backing up to $filename\n " );
$filesize = array_key_exists ( " filesize " , $opts ) ? $opts [ 'filesize' ] : - 1 ;
if ( $filesize >= 0 ) {
if ( ! Bootstrap :: isLinuxOs ()) {
2012-10-15 14:36:26 -04:00
CLI :: error ( " This is not a Linux enviroment, cannot use this filesize [-s] feature. \n " );
return ;
2014-10-10 15:09:26 -04:00
}
$multipleBackup = new multipleFilesBackup ( $filename , $filesize ); //if filesize is 0 the default size will be took
//using new method
foreach ( $workspaces as $workspace ) {
$multipleBackup -> addToBackup ( $workspace );
}
$multipleBackup -> letsBackup ();
} else {
//ansient method to backup into one large file
$backup = workspaceTools :: createBackup ( $filename );
2011-02-17 20:51:26 +00:00
2014-10-10 15:09:26 -04:00
foreach ( $workspaces as $workspace ) {
$workspace -> backup ( $backup );
}
}
2011-02-17 20:51:26 +00:00
CLI :: logging ( " \n " );
2014-10-10 15:09:26 -04:00
workspaceTools :: printSysInfo ();
foreach ( $workspaces as $workspace ) {
CLI :: logging ( " \n " );
$workspace -> printMetadata ( false );
}
2011-01-10 14:14:31 +00:00
}
2011-01-27 15:04:37 +00:00
function run_workspace_restore ( $args , $opts ) {
2015-06-29 13:57:30 -04:00
if ( sizeof ( $args ) > 0 ) {
2013-02-18 11:09:37 -04:00
2015-06-29 13:57:30 -04:00
$filename = $args [ 0 ];
2013-02-18 11:09:37 -04:00
2015-06-29 13:57:30 -04:00
G :: verifyPath ( PATH_DATA . 'upgrade' , true );
if ( strpos ( $filename , " / " ) === false && strpos ( $filename , '\\' ) === false ) {
$filename = PATH_DATA . " backups/ $filename " ;
if ( ! file_exists ( $filename ) && substr_compare ( $filename , " .tar " , - 4 , 4 , true ) != 0 )
$filename .= " .tar " ;
2012-10-15 14:36:26 -04:00
}
2015-06-29 13:57:30 -04:00
$info = array_key_exists ( " info " , $opts );
$lang = array_key_exists ( " lang " , $opts ) ? $opts [ 'lang' ] : 'en' ;
$port = array_key_exists ( " port " , $opts ) ? $opts [ 'port' ] : '' ;
if ( $info ) {
workspaceTools :: getBackupInfo ( $filename );
} else {
CLI :: logging ( " Restoring from $filename\n " );
$workspace = array_key_exists ( " workspace " , $opts ) ? $opts [ 'workspace' ] : NULL ;
$overwrite = array_key_exists ( " overwrite " , $opts );
$multiple = array_key_exists ( " multiple " , $opts );
$dstWorkspace = isset ( $args [ 1 ]) ? $args [ 1 ] : null ;
if ( ! empty ( $multiple )){
if ( ! Bootstrap :: isLinuxOs ()){
CLI :: error ( " This is not a Linux enviroment, cannot use this multiple [-m] feature. \n " );
return ;
}
multipleFilesBackup :: letsRestore ( $filename , $workspace , $dstWorkspace , $overwrite );
}
else {
$anotherExtention = " .* " ; //if there are files with and extra extention: e.g. <file>.tar.number
$multiplefiles = glob ( $filename . $anotherExtention ); // example: //shared/workflow_data/backups/myWorkspace.tar.*
if ( count ( $multiplefiles ) > 0 )
{
CLI :: error ( " Processmaker found these files: . \n " );
foreach ( $multiplefiles as $index => $value ){
CLI :: logging ( $value . " \n " );
}
CLI :: error ( " Please, you should use -m parameter to restore them. \n " );
return ;
}
workspaceTools :: restore ( $filename , $workspace , $dstWorkspace , $overwrite , $lang , $port );
}
2012-10-15 14:36:26 -04:00
}
2015-06-29 13:57:30 -04:00
} else {
throw new Exception ( " No workspace specified for restore " );
2011-02-17 20:51:26 +00:00
}
2011-01-14 23:11:13 +00:00
}
2013-06-25 13:50:38 -04:00
function runStructureDirectories ( $command , $args ) {
$workspaces = get_workspaces_from_args ( $command );
$count = count ( $workspaces );
$errors = false ;
$countWorkspace = 0 ;
foreach ( $workspaces as $index => $workspace ) {
try {
$countWorkspace ++ ;
CLI :: logging ( " Updating workspaces ( $countWorkspace / $count ): " . CLI :: info ( $workspace -> name ) . " \n " );
$workspace -> updateStructureDirectories ( $workspace -> name );
$workspace -> close ();
} catch ( Exception $e ) {
CLI :: logging ( " Errors upgrading workspace " . CLI :: info ( $workspace -> name ) . " : " . CLI :: error ( $e -> getMessage ()) . " \n " );
$errors = true ;
}
}
}
2014-10-27 11:25:17 -04:00
function run_database_generate_self_service_by_value ( $args , $opts )
{
2015-03-17 15:25:49 -04:00
G :: LoadSystem ( 'inputfilter' );
$filter = new InputFilter ();
$opts = $filter -> xssFilterHard ( $opts );
$args = $filter -> xssFilterHard ( $args );
2014-10-27 11:25:17 -04:00
try {
$arrayWorkspace = get_workspaces_from_args ( $args );
foreach ( $arrayWorkspace as $value ) {
$workspace = $value ;
try {
echo " Generating the table \" self-service by value \" for " . pakeColor :: colorize ( $workspace -> name , " INFO " ) . " \n " ;
$workspace -> appAssignSelfServiceValueTableGenerateData ();
} catch ( Exception $e ) {
echo " Errors generating the table \" self-service by value \" of workspace " . CLI :: info ( $workspace -> name ) . " : " . CLI :: error ( $e -> getMessage ()) . " \n " ;
}
2014-11-19 16:47:22 -04:00
echo " \n " ;
2014-10-27 11:25:17 -04:00
}
2014-11-19 16:47:22 -04:00
echo " Done! \n " ;
} catch ( Exception $e ) {
echo CLI :: error ( $e -> getMessage ()) . " \n " ;
}
}
2015-01-06 16:57:38 -04:00
/*----------------------------------********---------------------------------*/
2014-11-19 16:47:22 -04:00
function run_check_workspace_disabled_code ( $args , $opts )
{
try {
$arrayWorkspace = get_workspaces_from_args ( $args );
foreach ( $arrayWorkspace as $value ) {
$workspace = $value ;
2015-06-01 14:15:53 -04:00
if ( ! defined ( " SYS_SYS " )) {
define ( " SYS_SYS " , $workspace -> name );
}
if ( ! defined ( " PATH_DATA_SITE " )) {
define ( " PATH_DATA_SITE " , PATH_DATA . " sites " . PATH_SEP . SYS_SYS . PATH_SEP );
}
if ( ! $workspace -> pmLicensedFeaturesVerifyFeature ( " B0oWlBLY3hHdWY0YUNpZEtFQm5CeTJhQlIwN3IxMEkwaG4= " )) {
throw new Exception ( " Error: This command cannot be used because your license does not include it. " );
}
2014-11-19 16:47:22 -04:00
echo " > Workspace: " . $workspace -> name . " \n " ;
try {
$arrayFoundDisabledCode = $workspace -> getDisabledCode ();
2015-06-01 14:15:53 -04:00
if ( ! empty ( $arrayFoundDisabledCode )) {
2014-11-19 16:47:22 -04:00
$strFoundDisabledCode = " " ;
foreach ( $arrayFoundDisabledCode as $value2 ) {
$arrayProcessData = $value2 ;
$strFoundDisabledCode .= ( $strFoundDisabledCode != " " ) ? " \n " : " " ;
$strFoundDisabledCode .= " Process: " . $arrayProcessData [ " processTitle " ] . " \n " ;
$strFoundDisabledCode .= " Triggers: \n " ;
foreach ( $arrayProcessData [ " triggers " ] as $value3 ) {
$arrayTriggerData = $value3 ;
$strCodeAndLine = " " ;
foreach ( $arrayTriggerData [ " disabledCode " ] as $key4 => $value4 ) {
$strCodeAndLine .= (( $strCodeAndLine != " " ) ? " , " : " " ) . $key4 . " (Lines " . implode ( " , " , $value4 ) . " ) " ;
}
$strFoundDisabledCode .= " - " . $arrayTriggerData [ " triggerTitle " ] . " : " . $strCodeAndLine . " \n " ;
}
}
echo $strFoundDisabledCode . " \n " ;
} else {
echo " The workspace it's OK \n \n " ;
}
} catch ( Exception $e ) {
echo " Errors to check disabled code: " . CLI :: error ( $e -> getMessage ()) . " \n \n " ;
}
2015-06-01 14:15:53 -04:00
$workspace -> close ();
2014-11-19 16:47:22 -04:00
}
echo " Done! \n " ;
2014-10-27 11:25:17 -04:00
} catch ( Exception $e ) {
echo CLI :: error ( $e -> getMessage ()) . " \n " ;
}
}
2015-03-04 18:42:47 -04:00
2015-05-22 16:07:42 -04:00
function migrate_new_cases_lists ( $command , $args ) {
2015-03-04 18:42:47 -04:00
$workspaces = get_workspaces_from_args ( $args );
$checkOnly = ( strcmp ( $command , " migrate " ) == 0 );
foreach ( $workspaces as $workspace ) {
if ( $checkOnly ){
print_r ( " Checking database in " . pakeColor :: colorize ( $workspace -> name , " INFO " ) . " \n " );
} else {
print_r ( " Upgrading database in " . pakeColor :: colorize ( $workspace -> name , " INFO " ) . " \n " );
}
try {
$ws = $workspace -> name ;
$sContent = file_get_contents ( PATH_DB . $ws . PATH_SEP . 'db.php' );
if ( strpos ( $sContent , 'rb_' )) {
$workspace -> onedb = false ;
} else {
$workspace -> onedb = true ;
}
//check if is the tables List are empty
$changes = $workspace -> listFirstExecution ( 'check' );
if ( $workspace -> onedb && $changes != true ) {
$workspace -> migrateList ( $workspace -> name );
2015-05-22 16:07:42 -04:00
}
2015-03-04 18:42:47 -04:00
if ( $changes ) {
if ( $checkOnly ) {
2015-03-06 09:59:42 -04:00
echo " -> List tables are done \n " ;
2015-05-22 16:07:42 -04:00
}
2015-03-04 18:42:47 -04:00
} else {
echo " > List tables are done \n " ;
}
} catch ( Exception $e ) {
echo " > Error: " . CLI :: error ( $e -> getMessage ()) . " \n " ;
}
}
}
2015-06-01 14:15:53 -04:00
/*----------------------------------********---------------------------------*/