2010-12-02 23:34:41 +00:00
< ? php
/**
* pakeGulliver . php
2011-01-27 11:04:13 +00:00
* @ package gulliver . bin . tasks
2011-12-06 19:05:40 -04:00
*
2010-12-02 23:34:41 +00:00
* ProcessMaker Open Source Edition
2011-01-27 11:04:13 +00:00
* Copyright ( C ) 2004 - 2011 Colosa Inc .
2010-12-02 23:34:41 +00:00
*
* 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 .
2011-12-06 19:05:40 -04:00
*
*
2010-12-02 23:34:41 +00:00
*/
//dont work mb_internal_encoding('UTF-8');
2017-08-04 09:32:25 -04:00
use ProcessMaker\Plugins\PluginRegistry ;
2011-01-17 15:09:57 +00:00
2010-12-02 23:34:41 +00:00
pake_desc ( 'gulliver version' );
pake_task ( 'version' , 'project_exists' );
pake_desc ( " create poedit file for system labels \n args: [<lang-id> [<country-id> [verbose]]] " );
pake_task ( 'create-poedit-file' , 'project_exists' );
pake_desc ( " generate a unit test file for an existing class \n args: <class-filename> " );
pake_task ( 'generate-unit-test-class' , 'project_exists' );
pake_desc ( " build new plugin \n args: <name> " );
pake_task ( 'new-plugin' , 'project_exists' );
2014-10-09 14:16:08 -04:00
pake_desc ( " Update the plugin attributes in all workspaces \n args: <plugin-name> " );
pake_task ( " update-plugin-attributes " , " project_exists " );
2014-12-23 17:22:42 -04:00
/*----------------------------------********---------------------------------*/
2014-11-19 16:47:22 -04:00
pake_desc ( " Check disabled code in plugins \n args: [enterprise-plugin|custom-plugin|all|<plugin-name>] " );
pake_task ( " check-plugin-disabled-code " , " project_exists " );
2014-12-23 17:22:42 -04:00
/*----------------------------------********---------------------------------*/
2014-11-19 16:47:22 -04:00
2010-12-02 23:34:41 +00:00
pake_desc ( " pack plugin in .tar file \n args: <plugin> " );
pake_task ( 'pack-plugin' , 'project_exists' );
pake_desc ( " generate basic CRUD files for an existing class \n args: <class-name> <table-name> <plugin-name> " );
pake_task ( 'propel-build-crud' , 'project_exists' );
2015-01-07 16:47:21 -04:00
/*----------------------------------********---------------------------------*/
2010-12-02 23:34:41 +00:00
pake_desc ( " check standard code \n args: <directory> " );
2017-12-04 13:25:35 +00:00
pake_task ( 'check-standard-code' , 'project_exists' );
2015-01-07 16:47:21 -04:00
/*----------------------------------********---------------------------------*/
2010-12-02 23:34:41 +00:00
2011-01-27 11:04:13 +00:00
/**
* Function run_version
* access public
*/
2017-12-04 13:25:35 +00:00
function run_version ( $task , $args )
{
printf ( " Gulliver version %s \n " , pakeColor :: colorize ( trim ( file_get_contents ( PATH_GULLIVER . 'VERSION' )), 'INFO' ));
exit ( 0 );
2010-12-02 23:34:41 +00:00
}
2017-12-04 13:25:35 +00:00
function isUTF8 ( $str )
{
if ( $str === mb_convert_encoding ( mb_convert_encoding ( $str , " UTF-32 " , " UTF-8 " ), " UTF-8 " , " UTF-32 " )) {
return true ;
} else {
return false ;
}
2010-12-02 23:34:41 +00:00
}
2017-12-04 13:25:35 +00:00
function strip_quotes ( $text )
{
if ( ! isUTF8 ( $text )) {
$text = utf8_encode ( $text );
}
return str_replace ( '"' , " " , $text );
2010-12-02 23:34:41 +00:00
}
// function for the prompt data read in windows
2017-12-04 13:25:35 +00:00
function prompt_win ( $text )
{
print $text ;
flush ();
ob_flush ();
$read = trim ( fgets ( STDIN ));
return $read ;
2010-12-02 23:34:41 +00:00
}
2017-12-04 13:25:35 +00:00
function prompt ( $text )
{
if ( ! ( PHP_OS == " WINNT " )) {
printf ( " $text %s " , pakeColor :: colorize ( ':' , 'INFO' ));
# 4092 max on win32 fopen
2011-12-06 19:05:40 -04:00
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
//$fp=fopen("php://stdin", "r");
$fp = fopen ( " /dev/tty " , " r " );
$in = fgets ( $fp , 4094 );
fclose ( $fp );
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
# strip newline
( PHP_OS == " WINNT " ) ? ( $read = str_replace ( " \r \n " , " " , $in )) : ( $read = str_replace ( " \n " , " " , $in ));
} else {
$read = prompt_win ( $text );
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
return $read ;
2010-12-02 23:34:41 +00:00
}
2017-12-04 13:25:35 +00:00
function query_sql_file ( $file , $connection )
{
$report = array (
2011-12-06 19:05:40 -04:00
'SQL_FILE' => $file ,
2017-12-04 13:25:35 +00:00
'errors' => array (),
2011-12-06 19:05:40 -04:00
'querys' => 0
2010-12-02 23:34:41 +00:00
);
2017-12-04 13:25:35 +00:00
$content = @ fread ( @ fopen ( $file , " rt " ), @ filesize ( $file ));
if ( ! $content ) {
$report [ 'errors' ] = " Error reading SQL " ;
return $report ;
2010-12-02 23:34:41 +00:00
}
2017-12-04 13:25:35 +00:00
$ret = array ();
for ( $i = 0 ; $i < strlen ( $content ) - 1 ; $i ++ ) {
if ( $content [ $i ] == " ; " ) {
if ( $content [ $i + 1 ] == " \n " ) {
$ret [] = substr ( $content , 0 , $i );
$content = substr ( $content , $i + 1 );
$i = 0 ;
}
}
2010-12-02 23:34:41 +00:00
}
2017-12-04 13:25:35 +00:00
$report [ 'querys' ] = count ( $ret );
foreach ( $ret as $qr ) {
$re = mysqli_query ( $connection , $qr );
if ( ! $re ) {
$report [ 'errors' ][] = " Query error: " . mysqli_error ( $connection );
}
}
return $report ;
2010-12-02 23:34:41 +00:00
}
2017-12-04 13:25:35 +00:00
function createPngLogo ( $filePng , $text )
{
$im = imagecreatetruecolor ( 162 , 50 );
$orange = imagecolorallocate ( $im , 140 , 120 , 0 );
$white = imagecolorallocate ( $im , 255 , 255 , 255 );
$black = imagecolorallocate ( $im , 0 , 0 , 0 );
$grey = imagecolorallocate ( $im , 100 , 100 , 100 );
$yellow = imagecolorallocatealpha ( $im , 255 , 255 , 10 , 95 );
$red = imagecolorallocatealpha ( $im , 255 , 10 , 10 , 95 );
$blue = imagecolorallocatealpha ( $im , 10 , 10 , 255 , 95 );
$transparent = imagecolorallocatealpha ( $im , 0 , 0 , 0 , 127 );
imagefill ( $im , 0 , 0 , $white );
imagestring ( $im , 4 , 50 , 14 , $text , $orange );
// drawing 3 overlapped circle
imagefilledellipse ( $im , 25 , 20 , 27 , 25 , $yellow );
imagefilledellipse ( $im , 15 , 30 , 27 , 25 , $red );
imagefilledellipse ( $im , 30 , 30 , 27 , 25 , $blue );
imagefill ( $im , 0 , 0 , $transparent );
imagesavealpha ( $im , true );
imagepng ( $im , $filePng );
$aux = explode ( PATH_SEP , $filePng );
$auxName = $aux [ count ( $aux ) - 2 ] . PATH_SEP . $aux [ count ( $aux ) - 1 ];
$iSize = filesize ( $filePng );
printf ( " saved %s bytes in file %s [%s] \n " , pakeColor :: colorize ( $iSize , 'INFO' ), pakeColor :: colorize ( $auxName , 'INFO' ), pakeColor :: colorize ( $aux [ count ( $aux ) - 1 ], 'INFO' ));
2010-12-02 23:34:41 +00:00
}
2017-12-04 13:25:35 +00:00
function run_generate_unit_test_class ( $task , $args )
{
//the class filename in the first argument
$class = $args [ 0 ];
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
//try to find the class in classes directory
$classFilename = PATH_CORE . 'classes' . PATH_SEP . 'class.' . $args [ 0 ] . '.php' ;
if ( file_exists ( $classFilename )) {
printf ( " class found in %s \n " , pakeColor :: colorize ( $classFilename , 'INFO' ));
} else {
printf ( " class %s not found \n " , pakeColor :: colorize ( $class , 'ERROR' ));
exit ( 0 );
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
include ( 'test' . PATH_SEP . 'bootstrap' . PATH_SEP . 'unit.php' );
2017-08-02 16:06:56 -04:00
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
require_once ( $classFilename );
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
$unitFilename = PATH_GULLIVER_HOME . 'bin' . PATH_SEP . 'tasks' . PATH_SEP . 'templates' . PATH_SEP . 'unitTest.tpl' ;
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
$smarty = new Smarty ();
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
$smarty -> template_dir = PATH_GULLIVER . 'bin' . PATH_SEP . 'tasks' ;
$smarty -> compile_dir = PATH_SMARTY_C ;
$smarty -> cache_dir = PATH_SMARTY_CACHE ;
$smarty -> config_dir = PATH_THIRDPARTY . 'smarty/configs' ;
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
printf ( " using unit file in %s \n " , pakeColor :: colorize ( $unitFilename , 'INFO' ));
$smarty -> assign ( 'className' , ucwords ( $class ));
$smarty -> assign ( 'classFile' , $class );
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
//get the method list
$reflect = new ReflectionClass ( $class );
$methods = array ();
$testItems = 0 ;
foreach ( $reflect -> getMethods () as $reflectmethod ) {
$params = '' ;
foreach ( $reflectmethod -> getParameters () as $key => $row ) {
if ( $params != '' ) {
$params .= ', ' ;
}
$params .= '$' . $row -> name ;
}
$testItems ++ ;
$methods [ $reflectmethod -> getName ()] = $params ;
2010-12-02 23:34:41 +00:00
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
$smarty -> assign ( 'methods' , $methods );
$smarty -> assign ( 'testItems' , ( count ( $methods ) * 2 ) + 3 );
$smarty -> assign ( 'cantMethods' , count ( $methods ));
// $smarty->assign('llave', '{' );
2011-12-06 19:05:40 -04:00
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
// fetch smarty output
$content = $smarty -> fetch ( $unitFilename );
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
//saving the content in the output file
if ( defined ( 'MAIN_POFILE' ) && MAIN_POFILE != '' ) {
$unitFilename = PATH_CORE . 'test' . PATH_SEP . 'unit' . PATH_SEP . MAIN_POFILE . PATH_SEP . 'class' . ucwords ( $class ) . 'Test.php' ;
} else {
$unitFilename = PATH_CORE . 'test' . PATH_SEP . 'unit' . PATH_SEP . 'class' . ucwords ( $class ) . 'Test.php' ;
}
printf ( " creating unit file in %s \n " , pakeColor :: colorize ( $unitFilename , 'INFO' ));
$fp = fopen ( $unitFilename , 'w' );
fprintf ( $fp , $content );
fclose ( $fp );
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
exit ( 0 );
2010-12-02 23:34:41 +00:00
}
2017-12-04 13:25:35 +00:00
function convertPhpName ( $f )
{
$upper = true ;
$res = '' ;
for ( $i = 0 ; $i < strlen ( $f ); $i ++ ) {
$car = substr ( $f , $i , 1 );
if ( $car == '_' ) {
$upper = true ;
} else {
if ( $upper ) {
$res .= strtoupper ( $car );
$upper = false ;
} else {
$res .= strtolower ( $car );
}
}
2010-12-02 23:34:41 +00:00
}
2017-12-04 13:25:35 +00:00
return $res ;
2010-12-02 23:34:41 +00:00
}
2017-12-04 13:25:35 +00:00
function copyPluginFile ( $tplName , $fName , $class )
{
$pluginOutDirectory = PATH_OUTTRUNK . " plugins " . PATH_SEP . $class . PATH_SEP ;
$pluginFilename = $pluginOutDirectory . $fName ;
2014-10-09 14:16:08 -04:00
2017-12-04 13:25:35 +00:00
$fileTpl = PATH_GULLIVER_HOME . 'bin' . PATH_SEP . 'tasks' . PATH_SEP . 'templates' . PATH_SEP . $tplName . '.tpl' ;
$content = file_get_contents ( $fileTpl );
$iSize = file_put_contents ( $pluginFilename , $content );
printf ( " saved %s bytes in file %s \n " , pakeColor :: colorize ( $iSize , 'INFO' ), pakeColor :: colorize ( $tplName , 'INFO' ));
2010-12-02 23:34:41 +00:00
}
2013-01-15 10:05:30 -04:00
function savePluginFile ( $fName , $tplName , $class , $tableName , $fields = null , $utf8 = false )
{
2017-12-04 13:25:35 +00:00
$pluginOutDirectory = PATH_OUTTRUNK . " plugins " . PATH_SEP . $class . PATH_SEP ;
$pluginFilename = $pluginOutDirectory . $fName ;
$pluginTpl = PATH_GULLIVER_HOME . 'bin' . PATH_SEP . 'tasks' . PATH_SEP . 'templates' . PATH_SEP . $tplName . '.tpl' ;
$template = new TemplatePower ( $pluginTpl );
$template -> prepare ();
$template -> assign ( 'className' , $class );
$template -> assign ( 'tableName' , $tableName );
$template -> assign ( 'menuId' , 'ID_' . strtoupper ( $class ));
if ( is_array ( $fields )) {
foreach ( $fields as $block => $data ) {
$template -> gotoBlock ( " _ROOT " );
if ( is_array ( $data )) {
foreach ( $data as $rowId => $row ) {
$template -> newBlock ( $block );
foreach ( $row as $key => $val ) {
$template -> assign ( $key , $val );
}
}
} else {
$template -> assign ( $block , $data );
}
2010-12-02 23:34:41 +00:00
}
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
$content = $template -> getOutputContent ();
$iSize = file_put_contents ( $pluginFilename , $content );
2013-01-15 10:05:30 -04:00
if ( $utf8 ) {
//add BOM utf-8
2017-12-04 13:25:35 +00:00
$fp = fopen ( $pluginFilename , " wb " );
fwrite ( $fp , pack ( " CCC " , 0xef , 0xbb , 0xbf ) . $content );
2013-01-15 10:05:30 -04:00
fclose ( $fp );
}
2017-12-04 13:25:35 +00:00
printf ( " saved %s bytes in file %s [%s] \n " , pakeColor :: colorize ( $iSize , 'INFO' ), pakeColor :: colorize ( $fName , 'INFO' ), pakeColor :: colorize ( $tplName , 'INFO' ));
2010-12-02 23:34:41 +00:00
}
2017-12-04 13:25:35 +00:00
function run_generate_crud ( $task , $args )
{
ini_set ( 'display_errors' , 'on' );
ini_set ( 'error_reporting' , E_ERROR );
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
// the environment for poedit always is Development
define ( 'G_ENVIRONMENT' , G_DEV_ENV );
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
//the class filename in the first argument
if ( ! isset ( $args [ 0 ])) {
printf ( " Error: %s \n " , pakeColor :: colorize ( 'you must specify a valid classname ' , 'ERROR' ));
exit ( 0 );
}
$class = $args [ 0 ];
//second parameter is the table name, by default is the same classname in uppercase.
$tableName = isset ( $args [ 1 ]) ? $args [ 1 ] : strtoupper ( $class );
//try to find the class in classes directory
$classFilename = PATH_CORE . 'classes' . PATH_SEP . 'model' . PATH_SEP . $args [ 0 ] . '.php' ;
if ( file_exists ( $classFilename )) {
printf ( " class found in %s \n " , pakeColor :: colorize ( $classFilename , 'INFO' ));
} else {
printf ( " class %s not found \n " , pakeColor :: colorize ( $class , 'ERROR' ));
exit ( 0 );
}
2017-08-02 16:06:56 -04:00
2017-12-04 13:25:35 +00:00
require_once ( $classFilename );
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
Propel :: init ( PATH_CORE . " config/databases.php " );
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
$configuration = Propel :: getConfiguration ();
$connectionDSN = $configuration [ 'datasources' ][ 'workflow' ][ 'connection' ];
printf ( " using DSN Connection %s \n " , pakeColor :: colorize ( $connectionDSN , 'INFO' ));
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
$dirs = explode ( PATH_SEP , PATH_HOME );
print_r ( $dirs );
$projectName = $dirs [ count ( $dirs ) - 1 ];
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
// if ( strlen ( trim( $projectName) ) == 0 ) {
// printf("Project name not found \n", pakeColor::colorize( $class, 'ERROR'));
// exit (0);
// }
2011-12-06 19:05:40 -04:00
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
// printf("using Project Name %s \n", pakeColor::colorize( $projectName, 'INFO'));
2011-12-06 19:05:40 -04:00
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
// $pluginDirectory = PATH_PLUGINS . $class;
// $pluginOutDirectory = PATH_OUTTRUNK . 'plugins' . PATH_SEP . $class;
//
// G::verifyPath ( $pluginOutDirectory, true );
// G::verifyPath ( $pluginOutDirectory. PATH_SEP . $class, $pluginDirectory );
2011-12-06 19:05:40 -04:00
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
//G::verifyPath ( $pluginDirectory, true );
2010-12-02 23:34:41 +00:00
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
// //main php file
// savePluginFile ( $class . '.php', 'pluginMainFile', $class, $tableName );
2011-12-06 19:05:40 -04:00
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
//menu
savePluginFile ( $class . PATH_SEP . 'menu' . $class . '.php' , 'pluginMenu' , $class , $tableName );
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
//default list
savePluginFile ( $class . PATH_SEP . $class . 'List.php' , 'pluginList' , $class , $tableName );
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
//parse the schema file in order to get Table definition
$schemaFile = PATH_CORE . 'config' . PATH_SEP . 'schema.xml' ;
$xmlContent = file_get_contents ( $schemaFile );
$s = simplexml_load_file ( $schemaFile );
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
//default xmlform
//load the $fields array with fields data for an xmlform.
$fields = array ();
foreach ( $s -> table as $key => $table ) {
if ( $table [ 'name' ] == $tableName ) {
foreach ( $table -> column as $kc => $column ) {
//print $column['name'] . ' ' .$column['type'] . ' ' .$column['size'] . ' ' .$column['required'] . ' ' .$column['primaryKey'];
//print "\n";
$maxlength = $column [ 'size' ];
$size = ( $maxlength > 60 ) ? 60 : $maxlength ;
$type = $column [ 'type' ];
$field = array (
2011-12-06 19:05:40 -04:00
'name' => $column [ 'name' ],
'type' => $type ,
'size' => $size ,
'maxlength' => $maxlength
2010-12-02 23:34:41 +00:00
);
2017-12-04 13:25:35 +00:00
$fields [ 'fields' ][] = $field ;
}
}
}
savePluginFile ( $class . PATH_SEP . $class . '.xml' , 'pluginXmlform' , $class , $tableName , $fields );
die ();
//xmlform for list
//load the $fields array with fields data for PagedTable xml.
$fields = array ();
$primaryKey = '' ;
foreach ( $s -> table as $key => $table ) {
if ( $table [ 'name' ] == $tableName ) {
foreach ( $table -> column as $kc => $column ) {
//print $column['name'] . ' ' .$column['type'] . ' ' .$column['size'] . ' ' .$column['required'] . ' ' .$column['primaryKey'];
//print "\n";
$size = ( $column [ 'size' ] > 30 ) ? 30 : $column [ 'size' ];
$type = $column [ 'type' ];
if ( $column [ 'primaryKey' ]) {
if ( $primaryKey == '' ) {
$primaryKey .= '@@' . $column [ 'name' ];
} else {
$primaryKey .= '|@@' . $column [ 'name' ];
}
}
$field = array (
2011-12-06 19:05:40 -04:00
'name' => $column [ 'name' ],
'type' => $type ,
'size' => $size
2010-12-02 23:34:41 +00:00
);
2017-12-04 13:25:35 +00:00
$fields [ 'fields' ][] = $field ;
}
}
}
$fields [ 'primaryKey' ] = $primaryKey ;
savePluginFile ( $class . PATH_SEP . $class . 'List.xml' , 'pluginXmlformList' , $class , $tableName , $fields );
//default edit
$fields = array ();
$index = 0 ;
$keylist = '' ;
foreach ( $s -> table as $key => $table ) {
if ( $table [ 'name' ] == $tableName ) {
foreach ( $table -> column as $kc => $column ) {
$name = $column [ 'name' ];
$phpName = convertPhpName ( $name );
$field = array (
2011-12-06 19:05:40 -04:00
'name' => $name ,
'phpName' => $phpName ,
'index' => $index ++
2010-12-02 23:34:41 +00:00
);
2017-12-04 13:25:35 +00:00
if ( $column [ 'primaryKey' ]) {
if ( $keylist == '' ) {
$keylist .= '$' . $phpName ;
} else {
$keylist .= ', $' . $phpName ;
}
$fields [ 'keys' ][] = $field ;
//$index++;
}
$fields [ 'fields' ][] = $field ;
$fields [ 'fields2' ][] = $field ;
}
2010-12-02 23:34:41 +00:00
}
2017-12-04 13:25:35 +00:00
}
$fields [ 'keylist' ] = $keylist ;
savePluginFile ( $class . PATH_SEP . $class . 'Edit.php' , 'pluginEdit' , $class , $tableName , $fields );
savePluginFile ( $class . PATH_SEP . $class . 'Save.php' , 'pluginSave' , $class , $tableName , $fields );
if ( ! PHP_OS == " WINNT " ) {
printf ( " creting symlinks %s \n " , pakeColor :: colorize ( $pluginDirectory , 'INFO' ));
symlink ( $pluginOutDirectory . PATH_SEP . $class . '.php' , PATH_PLUGINS . $class . '.php' );
symlink ( $pluginOutDirectory . PATH_SEP . $class , $pluginDirectory );
}
exit ( 0 );
2010-12-02 23:34:41 +00:00
}
2017-12-04 13:25:35 +00:00
function addTarFolder ( $tar , $pathBase , $pluginHome )
{
$aux = explode ( PATH_SEP , $pathBase );
//print $aux[count($aux) -2 ] . "\n";
if ( $aux [ count ( $aux ) - 2 ] == '.svn' ) {
return ;
}
if ( $handle = opendir ( $pathBase )) {
while ( false !== ( $file = readdir ( $handle ))) {
if ( is_file ( $pathBase . $file )) {
//print "file $file \n";
$tar -> addModify ( $pathBase . $file , '' , $pluginHome );
}
if ( is_dir ( $pathBase . $file ) && $file != '..' && $file != '.' ) {
//print "dir $pathBase$file \n";
addTarFolder ( $tar , $pathBase . $file . PATH_SEP , $pluginHome );
}
}
closedir ( $handle );
2010-12-02 23:34:41 +00:00
}
}
2017-08-11 17:36:23 -04:00
function run_pack_plugin ( $task , $args )
{
ini_set ( 'display_errors' , 'on' );
ini_set ( 'error_reporting' , E_ERROR );
2011-12-06 19:05:40 -04:00
2017-08-11 17:36:23 -04:00
// the environment for poedit always is Development
define ( 'G_ENVIRONMENT' , G_DEV_ENV );
2011-12-06 19:05:40 -04:00
2017-08-11 17:36:23 -04:00
//the plugin name in the first argument
if ( ! isset ( $args [ 0 ])) {
printf ( " Error: %s \n " , pakeColor :: colorize ( 'you must specify a valid name for the plugin' , 'ERROR' ));
exit ( 0 );
}
$pluginName = $args [ 0 ];
2011-12-06 19:05:40 -04:00
2017-08-11 17:36:23 -04:00
$pluginHome = PATH_OUTTRUNK . 'plugins' . PATH_SEP . $pluginName ;
//verify if plugin exists,
$pluginClassFilename = PATH_PLUGINS . $pluginName . PATH_SEP . 'class.' . $pluginName . '.php' ;
$pluginFilename = PATH_PLUGINS . $pluginName . '.php' ;
if ( ! is_file ( $pluginClassFilename )) {
printf ( " The plugin %s does not exist in this file %s \n " , pakeColor :: colorize ( $pluginName , 'ERROR' ), pakeColor :: colorize ( $pluginClassFilename , 'INFO' ));
die ();
}
2017-08-02 16:06:56 -04:00
2017-08-11 17:36:23 -04:00
if ( ! file_exists ( $pluginFilename )) {
printf ( " Error: %s \n " , pakeColor :: colorize ( 'you must specify a valid name for the plugin' , 'ERROR' ));
exit ( 0 );
}
2011-12-06 19:05:40 -04:00
2017-08-11 17:36:23 -04:00
if ( preg_match_all ( '/->iVersion(.*)=(.*);/i' , file_get_contents ( $pluginFilename ), $result )) {
$version = trim ( $result [ 2 ][ 0 ], ' "' );
} else {
$version = 1 ;
}
$fileTar = $pluginHome . PATH_SEP . $pluginName . '-' . $version . '.tar' ;
2017-08-02 16:06:56 -04:00
2017-08-11 17:36:23 -04:00
$tar = new Archive_Tar ( $fileTar );
$tar -> _compress = false ;
2011-12-06 19:05:40 -04:00
2017-08-11 17:36:23 -04:00
$pathBase = $pluginHome . PATH_SEP . $pluginName . PATH_SEP ;
$tar -> createModify ( $pluginHome . PATH_SEP . $pluginName . '.php' , '' , $pluginHome );
addTarFolder ( $tar , $pathBase , $pluginHome );
$aFiles = $tar -> listContent ();
2011-12-06 19:05:40 -04:00
2017-08-11 17:36:23 -04:00
foreach ( $aFiles as $key => $val ) {
printf ( " %6d %s \n " , $val [ 'size' ], pakeColor :: colorize ( $val [ 'filename' ], 'INFO' ));
}
printf ( " File created in %s \n " , pakeColor :: colorize ( $fileTar , 'INFO' ));
$filesize = sprintf ( " %5.2f " , filesize ( $fileTar ) / 1024 );
printf ( " Filesize %s Kb \n " , pakeColor :: colorize ( $filesize , 'INFO' ));
2010-12-02 23:34:41 +00:00
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
function run_new_plugin ( $task , $args )
{
ini_set ( 'display_errors' , 'on' );
ini_set ( 'error_reporting' , E_ERROR );
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
// the environment for poedit always is Development
define ( 'G_ENVIRONMENT' , G_DEV_ENV );
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
//the plugin name in the first argument
if ( ! isset ( $args [ 0 ])) {
printf ( " Error: %s \n " , pakeColor :: colorize ( 'you must specify a valid name for the plugin' , 'ERROR' ));
exit ( 0 );
}
$pluginName = $args [ 0 ];
Propel :: init ( PATH_CORE . " config/databases.php " );
$configuration = Propel :: getConfiguration ();
$connectionDSN = $configuration [ 'datasources' ][ 'workflow' ][ 'connection' ];
printf ( " using DSN Connection %s \n " , pakeColor :: colorize ( $connectionDSN , 'INFO' ));
$pluginDirectory = PATH_PLUGINS . $pluginName ;
$pluginOutDirectory = PATH_OUTTRUNK . 'plugins' . PATH_SEP . $pluginName ;
$pluginHome = PATH_OUTTRUNK . 'plugins' . PATH_SEP . $pluginName . PATH_SEP . $pluginName ;
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
//verify if plugin exists, and then ask for overwrite
$pluginClassFilename = PATH_PLUGINS . $pluginName . PATH_SEP . 'class.' . $pluginName . '.php' ;
if ( is_file ( $pluginClassFilename )) {
printf ( " The plugin %s exists in this file %s \n " , pakeColor :: colorize ( $pluginName , 'ERROR' ), pakeColor :: colorize ( $pluginClassFilename , 'INFO' ));
$overwrite = strtolower ( prompt ( 'Do you want to create a new plugin? [Y/n]' ));
if ( $overwrite == 'n' ) {
die ();
}
}
printf ( " creating plugin directory %s \n " , pakeColor :: colorize ( $pluginOutDirectory , 'INFO' ));
G :: verifyPath ( $pluginOutDirectory , true );
G :: verifyPath ( $pluginHome . PATH_SEP . 'classes' , true );
G :: verifyPath ( $pluginHome . PATH_SEP . 'public_html' , true );
G :: verifyPath ( $pluginHome . PATH_SEP . 'config' , true );
G :: verifyPath ( $pluginHome . PATH_SEP . 'data' , true );
//config
savePluginFile ( $pluginName . PATH_SEP . " setup.xml " , " pluginSetup.xml " , $pluginName , $pluginName );
savePluginFile ( $pluginName . PATH_SEP . " messageShow.xml " , " pluginMessageShow.xml " , $pluginName , $pluginName );
savePluginFile ( $pluginName . PATH_SEP . 'config' . PATH_SEP . 'schema.xml' , 'pluginSchema.xml' , $pluginName , $pluginName );
savePluginFile ( $pluginName . PATH_SEP . 'config' . PATH_SEP . 'propel.ini' , 'pluginPropel.ini' , $pluginName , $pluginName );
savePluginFile ( $pluginName . PATH_SEP . 'config' . PATH_SEP . 'propel.mysql.ini' , 'pluginPropel.mysql.ini' , $pluginName , $pluginName );
//create a logo to use instead the Workspace logo
$changeLogo = strtolower ( prompt ( 'Change system logo [y/N]' ));
$fields = array ();
$fields [ 'phpClassName' ] = $pluginName ;
if ( $changeLogo == 'y' ) {
$filePng = $pluginHome . PATH_SEP . 'public_html' . PATH_SEP . $pluginName . '.png' ;
createPngLogo ( $filePng , $pluginName );
$fields [ 'changeLogo' ][] = array (
2011-12-06 19:05:40 -04:00
'className' => $pluginName
2010-12-02 23:34:41 +00:00
);
2017-12-04 13:25:35 +00:00
}
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
//Menu
$menu = strtolower ( prompt ( 'Create an example Page [Y/n]' ));
$swMenu = 0 ;
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
if ( $menu == 'y' ) {
$fields [ 'menu' ][] = array (
2011-12-06 19:05:40 -04:00
'className' => $pluginName
2010-12-02 23:34:41 +00:00
);
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
savePluginFile ( $pluginName . PATH_SEP . 'menu' . $pluginName . '.php' , 'pluginMenu' , $pluginName , $pluginName , $fields , true );
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
savePluginFile ( $pluginName . PATH_SEP . $pluginName . " Application.php " , " pluginApplication.php " , $pluginName , $pluginName , null , true );
savePluginFile ( $pluginName . PATH_SEP . $pluginName . " Application.html " , " pluginApplication.html " , $pluginName , $pluginName , null , true );
savePluginFile ( $pluginName . PATH_SEP . $pluginName . " Application.js " , " pluginApplication.js " , $pluginName , $pluginName , null , true );
savePluginFile ( $pluginName . PATH_SEP . $pluginName . " ApplicationAjax.php " , " pluginApplicationAjax.php " , $pluginName , $pluginName );
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
$swMenu = 1 ;
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
//Menu cases
$menuCases = strtolower ( prompt ( " Create new option in the menu of cases [Y/n] " ));
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
if ( $menuCases == " y " ) {
$fields [ " menuCases " ][] = array (
2011-12-06 19:05:40 -04:00
" className " => $pluginName
);
2017-12-04 13:25:35 +00:00
savePluginFile ( $pluginName . PATH_SEP . " menuCases " . $pluginName . " .php " , " pluginMenuCases " , $pluginName , $pluginName , $fields , true );
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
if ( $swMenu == 0 ) {
savePluginFile ( $pluginName . PATH_SEP . $pluginName . " Application.php " , " pluginApplication.php " , $pluginName , $pluginName , null , true );
savePluginFile ( $pluginName . PATH_SEP . $pluginName . " Application.html " , " pluginApplication.html " , $pluginName , $pluginName , null , true );
savePluginFile ( $pluginName . PATH_SEP . $pluginName . " Application.js " , " pluginApplication.js " , $pluginName , $pluginName , null , true );
savePluginFile ( $pluginName . PATH_SEP . $pluginName . " ApplicationAjax.php " , " pluginApplicationAjax.php " , $pluginName , $pluginName , null , true );
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
savePluginFile ( $pluginName . PATH_SEP . $pluginName . " Application2.php " , " pluginApplication2.php " , $pluginName , $pluginName , null , true );
savePluginFile ( $pluginName . PATH_SEP . $pluginName . " Application2.html " , " pluginApplication2.html " , $pluginName , $pluginName , null , true );
savePluginFile ( $pluginName . PATH_SEP . $pluginName . " Application2.js " , " pluginApplication2.js " , $pluginName , $pluginName , null , true );
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
savePluginFile ( $pluginName . PATH_SEP . $pluginName . " Application3.php " , " pluginApplication3.php " , $pluginName , $pluginName , null , true );
savePluginFile ( $pluginName . PATH_SEP . $pluginName . " Application3.html " , " pluginApplication3.html " , $pluginName , $pluginName , null , true );
savePluginFile ( $pluginName . PATH_SEP . $pluginName . " Application3.js " , " pluginApplication3.js " , $pluginName , $pluginName , null , true );
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
//RBAC features
$classNameUpperCase = strtoupper ( $pluginName );
//Create a new Permission a new role
$newPermission = strtolower ( prompt ( " Create the Role 'PROCESSMAKER_ $classNameUpperCase ' and \n the Permission 'PM_ $classNameUpperCase ' [y/N] " ));
$swRole = 0 ;
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
if ( $newPermission == 'y' ) {
$fields [ 'createPermission' ][] = array (
2011-12-06 19:05:40 -04:00
'className' => $classNameUpperCase
2010-12-02 23:34:41 +00:00
);
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
$swRole = 1 ;
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
//Redirect
if ( $swRole == 1 ) {
$redirect = strtolower ( prompt ( " Create a Redirect Login for the Role 'PROCESSMAKER_ $classNameUpperCase ' [y/N] " ));
if ( $redirect == 'y' ) {
$fields [ 'redirectLogin' ][] = array (
2011-12-06 19:05:40 -04:00
'className' => $classNameUpperCase
);
2017-12-04 13:25:35 +00:00
}
2011-12-06 19:05:40 -04:00
}
2017-12-04 13:25:35 +00:00
//External step
$externalStep = strtolower ( prompt ( 'Create external step for Processmaker [y/N]' ));
if ( $externalStep == 'y' ) {
$fields [ 'externalStep' ][] = array (
2011-12-06 19:05:40 -04:00
'className' => $pluginName ,
'GUID' => G :: generateUniqueID ()
2010-12-02 23:34:41 +00:00
);
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
savePluginFile ( $pluginName . PATH_SEP . " step " . $pluginName . " Application.php " , " pluginStepApplication.php " , $pluginName , $pluginName , null , true );
savePluginFile ( $pluginName . PATH_SEP . " step " . $pluginName . " Application.html " , " pluginStepApplication.html " , $pluginName , $pluginName , null , true );
savePluginFile ( $pluginName . PATH_SEP . " step " . $pluginName . " Application.js " , " pluginStepApplication.js " , $pluginName , $pluginName , null , true );
savePluginFile ( $pluginName . PATH_SEP . " step " . $pluginName . " ApplicationAjax.php " , " pluginStepApplicationAjax.php " , $pluginName , $pluginName , null , true );
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
//Dashboards
$dashboard = strtolower ( prompt ( " Create an element for the Processmaker Dashboards [y/N] " ));
if ( $dashboard == " y " ) {
$fields [ " dashboard " ][] = array (
2012-03-27 09:45:10 -04:00
" className " => $pluginName
);
2014-10-09 14:16:08 -04:00
2017-12-04 13:25:35 +00:00
$fields [ " dashboardAttribute " ] = " private \$ dashletsUids; " ;
$fields [ " dashboardAttributeValue " ] = "
2012-03-27 09:45:10 -04:00
\ $this -> dashletsUids = array (
array ( \ " DAS_UID \" => \" " . G :: GenerateUniqueId () . " \" ,
\ " DAS_CLASS \" => \" dashlet " . $pluginName . " \" ,
\ " DAS_TITLE \" => \" Dashlet $pluginName\ " ,
\ " DAS_DESCRIPTION \" => \" Dashlet $pluginName\ " ,
\ " DAS_VERSION \" => \" 1.0 \" ,
\ " DAS_CREATE_DATE \" => date( \" Y-m-d \" ),
\ " DAS_UPDATE_DATE \" => date( \" Y-m-d \" ))
);
" ;
2017-12-04 13:25:35 +00:00
$fields [ " dashboardSetup " ] = " \$ this->registerDashlets(); " ;
$fields [ " dashboardEnable " ] = " \$ this->dashletInsert(); " ;
$fields [ " dashboardDisable " ] = " \$ this->dashletDelete(); " ;
2014-10-09 14:16:08 -04:00
2017-12-04 13:25:35 +00:00
G :: verifyPath ( $pluginHome . PATH_SEP . " views " , true );
2014-10-09 14:16:08 -04:00
2017-12-04 13:25:35 +00:00
savePluginFile ( $pluginName . PATH_SEP . " classes " . PATH_SEP . " class.dashlet " . $pluginName . " .php " , " pluginDashletClass.php " , $pluginName , $pluginName );
copyPluginFile ( " pluginDashlet.html " , $pluginName . PATH_SEP . " views " . PATH_SEP . " dashlet " . $pluginName . " .html " , $pluginName , null , true );
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
//$report = strtolower(prompt('Create a Report for Processmaker [y/N]'));
//if( $report == 'y' ) {
// $fields['report'][] = array (
// 'className' => $pluginName
// );
// savePluginFile($pluginName . PATH_SEP . 'report.xml', 'pluginReport.xml', $pluginName, $pluginName, $fields);
//}
$report = strtolower ( prompt ( 'Create a PmFunction Class for extending Processmaker [y/N]' ));
if ( $report == 'y' ) {
$fields [ 'PmFunction' ][] = array (
2011-12-06 19:05:40 -04:00
'className' => $pluginName
2010-12-02 23:34:41 +00:00
);
2017-12-04 13:25:35 +00:00
savePluginFile ( $pluginName . PATH_SEP . 'classes' . PATH_SEP . 'class.pmFunctions.php' , 'class.pmFunctions.php' , $pluginName , $pluginName , $fields );
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
//main php file
savePluginFile ( $pluginName . '.php' , 'pluginMainFile' , $pluginName , $pluginName , $fields );
savePluginFile ( $pluginName . PATH_SEP . 'class.' . $pluginName . '.php' , 'pluginClass' , $pluginName , $pluginName , $fields );
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
if ( ! PHP_OS == " WINNT " ) {
printf ( " creating symlinks %s \n " , pakeColor :: colorize ( $pluginDirectory , 'INFO' ));
symlink ( $pluginOutDirectory . PATH_SEP . $pluginName . '.php' , PATH_PLUGINS . $pluginName . '.php' );
symlink ( $pluginOutDirectory . PATH_SEP . $pluginName , $pluginDirectory );
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
exit ( 0 );
2010-12-02 23:34:41 +00:00
}
2017-12-04 13:25:35 +00:00
function run_create_poedit_file ( $task , $args )
{
// the environment for poedit always is Development
define ( 'G_ENVIRONMENT' , G_DEV_ENV );
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
//the output language .po file
$lgOutId = isset ( $args [ 0 ]) ? $args [ 0 ] : 'en' ;
$countryOutId = isset ( $args [ 1 ]) ? strtoupper ( $args [ 1 ]) : 'US' ;
$verboseFlag = isset ( $args [ 2 ]) ? $args [ 2 ] == true : false ;
2017-08-02 16:06:56 -04:00
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
Propel :: init ( PATH_CORE . " config/databases.php " );
$configuration = Propel :: getConfiguration ();
$connectionDSN = $configuration [ 'datasources' ][ 'propel' ][ 'connection' ];
printf ( " using DSN Connection %s \n " , pakeColor :: colorize ( $connectionDSN , 'INFO' ));
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
printf ( " checking Language table \n " );
$c = new Criteria ();
$c -> add ( LanguagePeer :: LAN_ENABLED , " 1 " );
$c -> addor ( LanguagePeer :: LAN_ENABLED , " 0 " );
$languages = LanguagePeer :: doSelect ( $c );
$langs = array ();
$lgIndex = 0 ;
$findLang = false ;
$langDir = 'english' ;
$langId = 'en' ;
foreach ( $languages as $rowid => $row ) {
$lgIndex ++ ;
$langs [ $row -> getLanId ()] = $row -> getLanName ();
if ( $lgOutId != '' && $lgOutId == $row -> getLanId ()) {
$findLang = true ;
$langDir = strtolower ( $row -> getLanName ());
$langId = $row -> getLanId ();
}
2010-12-02 23:34:41 +00:00
}
2017-12-04 13:25:35 +00:00
printf ( " read %s entries from language table \n " , pakeColor :: colorize ( $lgIndex , 'INFO' ));
printf ( " checking iso_country table \n " );
$c = new Criteria ();
$c -> add ( IsoCountryPeer :: IC_UID , null , Criteria :: ISNOTNULL );
$countries = IsoCountryPeer :: doSelect ( $c );
$countryIndex = 0 ;
$findCountry = false ;
$countryDir = 'UNITED STATES' ;
$countryId = 'US' ;
foreach ( $countries as $rowid => $row ) {
$countryIndex ++ ;
if ( $countryOutId != '' && $countryOutId == $row -> getICUid ()) {
$findCountry = true ;
$countryDir = strtoupper ( $row -> getICName ());
$countryId = $row -> getICUid ();
}
2010-12-02 23:34:41 +00:00
}
2017-12-04 13:25:35 +00:00
printf ( " read %s entries from iso_country table \n " , pakeColor :: colorize ( $countryIndex , 'INFO' ));
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
if ( $findLang == false && $lgOutId != '' ) {
printf ( " %s \n " , pakeColor :: colorize ( " ' $lgOutId ' is not a valid language " , 'ERROR' ));
die ();
} else {
printf ( " language: %s \n " , pakeColor :: colorize ( $langDir , 'INFO' ));
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
if ( $findCountry == false && $countryOutId != '' ) {
printf ( " %s \n " , pakeColor :: colorize ( " ' $countryOutId ' is not a valid country " , 'ERROR' ));
die ();
} else {
printf ( " country: [%s] %s \n " , pakeColor :: colorize ( $countryId , 'INFO' ), pakeColor :: colorize ( $countryDir , 'INFO' ));
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
if ( $findCountry && $countryId != '' ) {
$poeditOutFile = PATH_CORE . 'content' . PATH_SEP . 'translations' . PATH_SEP . $langDir . PATH_SEP . MAIN_POFILE . '.' . $langId . '_' . $countryId . '.po' ;
2010-12-02 23:34:41 +00:00
} else {
2017-12-04 13:25:35 +00:00
$poeditOutFile = PATH_CORE . 'content' . PATH_SEP . 'translations' . PATH_SEP . $langDir . PATH_SEP . MAIN_POFILE . '.' . $langId . '.po' ;
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
printf ( " poedit file: %s \n " , pakeColor :: colorize ( $poeditOutFile , 'INFO' ));
$poeditOutPathInfo = pathinfo ( $poeditOutFile );
G :: verifyPath ( $poeditOutPathInfo [ 'dirname' ], true );
$lf = " \n " ;
$fp = fopen ( $poeditOutFile , 'w' );
fprintf ( $fp , " msgid \" \" \n " );
fprintf ( $fp , " msgstr \" \" \n " );
fprintf ( $fp , " \" Project-Id-Version: %s \\ n \" \n " , PO_SYSTEM_VERSION );
fprintf ( $fp , " \" POT-Creation-Date: \\ n \" \n " );
fprintf ( $fp , " \" PO-Revision-Date: %s \\ n \" \n " , date ( 'Y-m-d H:i+0100' ));
fprintf ( $fp , " \" Last-Translator: Fernando Ontiveros<fernando@colosa.com> \\ n \" \n " );
fprintf ( $fp , " \" Language-Team: Colosa Developers Team <developers@colosa.com> \\ n \" \n " );
fprintf ( $fp , " \" MIME-Version: 1.0 \\ n \" \n " );
fprintf ( $fp , " \" Content-Type: text/plain; charset=utf-8 \\ n \" \n " );
fprintf ( $fp , " \" Content-Transfer_Encoding: 8bit \\ n \" \n " );
fprintf ( $fp , " \" X-Poedit-Language: %s \\ n \" \n " , ucwords ( $langDir ));
fprintf ( $fp , " \" X-Poedit-Country: %s \\ n \" \n " , $countryDir );
fprintf ( $fp , " \" X-Poedit-SourceCharset: utf-8 \\ n \" \n " );
printf ( " checking translation table \n " );
$c = new Criteria ();
$c -> add ( TranslationPeer :: TRN_LANG , " en " );
$translation = TranslationPeer :: doSelect ( $c );
$trIndex = 0 ;
$trError = 0 ;
$langIdOut = $langId ; //the output language, later we'll include the country too.
$arrayLabels = array ();
foreach ( $translation as $rowid => $row ) {
$keyid = 'TRANSLATION/' . $row -> getTrnCategory () . '/' . $row -> getTrnId ();
if ( trim ( $row -> getTrnValue ()) == '' ) {
printf ( " warning the key %s is empty. \n " , pakeColor :: colorize ( $keyid , 'ERROR' ));
$trError ++ ;
} else {
$trans = TranslationPeer :: retrieveByPK ( $row -> getTrnCategory (), $row -> getTrnId (), $langIdOut );
if ( is_null ( $trans )) {
$msgStr = $row -> getTrnValue ();
} else {
$msgStr = $trans -> getTrnValue ();
}
$msgid = $row -> getTrnValue ();
if ( in_array ( $msgid , $arrayLabels )) {
$newMsgid = '[' . $row -> getTrnCategory () . '/' . $row -> getTrnId () . '] ' . $msgid ;
printf ( " duplicated key %s is renamed to %s. \n " , pakeColor :: colorize ( $msgid , 'ERROR' ), pakeColor :: colorize ( $newMsgid , 'INFO' ));
$trError ++ ;
$msgid = $newMsgid ;
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
$arrayLabels [] = $msgid ;
sort ( $arrayLabels );
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
$trIndex ++ ;
fprintf ( $fp , " \n " );
fprintf ( $fp , " #: %s \n " , $keyid );
//fprintf ( $fp, "#, php-format \n" );
fprintf ( $fp , " # %s \n " , strip_quotes ( $keyid ));
fprintf ( $fp , " msgid \" %s \" \n " , strip_quotes ( $msgid ));
fprintf ( $fp , " msgstr \" %s \" \n " , strip_quotes ( $msgStr ));
}
2010-12-02 23:34:41 +00:00
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
printf ( " checking xmlform \n " );
printf ( " using directory %s \n " , pakeColor :: colorize ( PATH_XMLFORM , 'INFO' ));
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
$filter = new InputFilter ();
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
$langIdOut = $langId ; //the output language, later we'll include the country too.
$exceptionFields = array (
2011-12-06 19:05:40 -04:00
'javascript' ,
'hidden' ,
'phpvariable' ,
'private' ,
'toolbar' ,
'xmlmenu' ,
'toolbutton' ,
'cellmark' ,
'grid'
2010-12-02 23:34:41 +00:00
);
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
$xmlfiles = pakeFinder :: type ( 'file' ) -> name ( '*.xml' ) -> in ( PATH_XMLFORM );
$xmlIndex = 0 ;
$xmlError = 0 ;
$fieldsIndexTotal = 0 ;
$exceptIndexTotal = 0 ;
foreach ( $xmlfiles as $xmlfileComplete ) {
$xmlIndex ++ ;
$xmlfile = str_replace ( PATH_XMLFORM , '' , $xmlfileComplete );
//english version of dynaform
$form = new Form ( $xmlfile , '' , 'en' );
$englishLabel = array ();
foreach ( $form -> fields as $nodeName => $node ) {
if ( trim ( $node -> label ) != '' ) {
$englishLabel [ $node -> name ] = $node -> label ;
}
2010-12-02 23:34:41 +00:00
}
2017-12-04 13:25:35 +00:00
unset ( $form -> fields );
unset ( $form -> tree );
unset ( $form );
//in this second pass, we are getting the target language labels
$form = new Form ( $xmlfile , '' , $langIdOut );
$fieldsIndex = 0 ;
$exceptIndex = 0 ;
foreach ( $form -> fields as $nodeName => $node ) {
if ( is_object ( $node ) && isset ( $englishLabel [ $node -> name ])) {
$msgid = trim ( $englishLabel [ $node -> name ]);
$node -> label = trim ( str_replace ( chr ( 10 ), '' , $node -> label ));
} else {
$msgid = '' ;
}
if ( trim ( $msgid ) != '' && ! in_array ( $node -> type , $exceptionFields )) {
//$msgid = $englishLabel [ $node->name ];
$keyid = $xmlfile . '?' . $node -> name ;
if ( in_array ( $msgid , $arrayLabels )) {
$newMsgid = '[' . $keyid . '] ' . $msgid ;
if ( $verboseFlag ) {
printf ( " duplicated key %s is renamed to %s. \n " , pakeColor :: colorize ( $msgid , 'ERROR' ), pakeColor :: colorize ( $newMsgid , 'INFO' ));
}
$xmlError ++ ;
$msgid = $newMsgid ;
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
$arrayLabels [] = $msgid ;
sort ( $arrayLabels );
$comment1 = $xmlfile ;
$comment2 = $node -> type . ' - ' . $node -> name ;
fprintf ( $fp , " \n " );
fprintf ( $fp , " #: %s \n " , $keyid );
// fprintf ( $fp, "#, php-format \n" );
fprintf ( $fp , " # %s \n " , strip_quotes ( $comment1 ));
fprintf ( $fp , " # %s \n " , strip_quotes ( $comment2 ));
fprintf ( $fp , " msgid \" %s \" \n " , strip_quotes ( $msgid ));
fprintf ( $fp , " msgstr \" %s \" \n " , strip_quotes ( $node -> label ));
//fprintf ( $fp, "msgstr \"%s\" \n", strip_quotes( utf8_encode( trim($node->label) ) ));
$fieldsIndex ++ ;
$fieldsIndexTotal ++ ;
} else {
$xmlfile = $filter -> xssFilterHard ( $xmlfile );
$exceptionFields = $filter -> xssFilterHard ( $exceptionFields );
if ( is_object ( $node ) && ! in_array ( $node -> type , $exceptionFields )) {
if ( isset ( $node -> value ) && strpos ( $node -> value , 'G::LoadTranslation' ) !== false ) {
$exceptIndex ++ ;
//print ($node->value);
} else {
$node -> name = $filter -> xssFilterHard ( $node -> name );
$node -> type = $filter -> xssFilterHard ( $node -> type );
printf ( " Error: xmlform %s has no english definition for %s [%s] \n " , pakeColor :: colorize ( $xmlfile , 'ERROR' ), pakeColor :: colorize ( $node -> name , 'INFO' ), pakeColor :: colorize ( $node -> type , 'INFO' ));
$xmlError ++ ;
}
} else {
$exceptIndex ++ ;
if ( $verboseFlag ) {
$node -> name = $filter -> xssFilterHard ( $node -> name );
$node -> type = $filter -> xssFilterHard ( $node -> type );
printf ( " %s %s in %s \n " , $node -> type , pakeColor :: colorize ( $node -> name , 'INFO' ), pakeColor :: colorize ( $xmlfile , 'INFO' ));
}
}
}
2010-12-02 23:34:41 +00:00
}
2017-12-04 13:25:35 +00:00
unset ( $form -> fields );
unset ( $form -> tree );
unset ( $form );
printf ( " xmlform: %s has %s fields and %s exceptions \n " , pakeColor :: colorize ( $xmlfile , 'INFO' ), pakeColor :: colorize ( $fieldsIndex , 'INFO' ), pakeColor :: colorize ( $exceptIndex , 'INFO' ));
$exceptIndexTotal += $exceptIndex ;
2010-12-02 23:34:41 +00:00
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
fclose ( $fp );
printf ( " added %s entries from translation table \n " , pakeColor :: colorize ( $trIndex , 'INFO' ));
printf ( " added %s entries from %s xmlforms \n " , pakeColor :: colorize ( $fieldsIndexTotal , 'INFO' ), pakeColor :: colorize ( $xmlIndex , 'INFO' ));
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
if ( $trError > 0 ) {
printf ( " there are %s errors in tranlation table \n " , pakeColor :: colorize ( $trError , 'ERROR' ));
}
if ( $xmlError > 0 ) {
printf ( " there are %s errors and %s exceptions in xmlforms \n " , pakeColor :: colorize ( $xmlError , 'ERROR' ), pakeColor :: colorize ( $exceptIndexTotal , 'ERROR' ));
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
exit ( 0 );
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
//to do: leer los html templates
2010-12-02 23:34:41 +00:00
}
2017-12-04 13:25:35 +00:00
function create_file_from_tpl ( $tplName , $newFilename , $fields = null )
{
global $pathHome ;
global $projectName ;
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
$httpdTpl = PATH_GULLIVER_HOME . 'bin' . PATH_SEP . 'tasks' . PATH_SEP . 'templates' . PATH_SEP . $tplName . '.tpl' ;
if ( substr ( $newFilename , 0 , 1 ) == PATH_SEP ) {
$httpFilename = $newFilename ;
} else {
$httpFilename = $pathHome . PATH_SEP . $newFilename ;
}
$template = new TemplatePower ( $httpdTpl );
$template -> prepare ();
$template -> assignGlobal ( 'pathHome' , $pathHome );
$template -> assignGlobal ( 'projectName' , $projectName );
$template -> assignGlobal ( 'rbacProjectName' , strtoupper ( $projectName ));
$template -> assignGlobal ( 'siglaProjectName' , substr ( strtoupper ( $projectName ), 0 , 3 ));
$template -> assignGlobal ( 'propel.output.dir' , '{propel.output.dir}' );
if ( is_array ( $fields )) {
foreach ( $fields as $block => $data ) {
$template -> gotoBlock ( " _ROOT " );
if ( is_array ( $data )) {
foreach ( $data as $rowId => $row ) {
$template -> newBlock ( $block );
foreach ( $row as $key => $val ) {
if ( is_array ( $val )) {
// $template->newBlock( $key );
foreach ( $val as $key2 => $val2 ) {
if ( is_array ( $val2 )) {
$template -> newBlock ( $key );
foreach ( $val2 as $key3 => $val3 ) {
$template -> assign ( $key3 , $val3 );
}
}
}
} else {
$template -> assign ( $key , $val );
}
}
2010-12-02 23:34:41 +00:00
}
2017-12-04 13:25:35 +00:00
} else {
$template -> assign ( $block , $data );
}
2010-12-02 23:34:41 +00:00
}
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
$content = $template -> getOutputContent ();
$iSize = file_put_contents ( $httpFilename , $content );
printf ( " saved %s bytes in file %s \n " , pakeColor :: colorize ( $iSize , 'INFO' ), pakeColor :: colorize ( $tplName , 'INFO' ));
2010-12-02 23:34:41 +00:00
}
2017-12-04 13:25:35 +00:00
function copy_file_from_tpl ( $tplName , $newFilename )
{
global $pathHome ;
global $projectName ;
$httpdTpl = PATH_GULLIVER_HOME . 'bin' . PATH_SEP . 'tasks' . PATH_SEP . 'templates' . PATH_SEP . $tplName . '.tpl' ;
$httpFilename = $pathHome . PATH_SEP . $newFilename ;
$content = file_get_contents ( $httpdTpl );
$iSize = file_put_contents ( $httpFilename , $content );
printf ( " saved %s bytes in file %s \n " , pakeColor :: colorize ( $iSize , 'INFO' ), pakeColor :: colorize ( $tplName , 'INFO' ));
2010-12-02 23:34:41 +00:00
}
2017-12-04 13:25:35 +00:00
function copy_file ( $newFilename )
{
global $pathHome ;
$httpdTpl = PATH_HOME . $newFilename ;
$httpFilename = $pathHome . PATH_SEP . $newFilename ;
$content = file_get_contents ( $httpdTpl );
$iSize = file_put_contents ( $httpFilename , $content );
printf ( " saved %s bytes in file %s \n " , pakeColor :: colorize ( $iSize , 'INFO' ), pakeColor :: colorize ( $newFilename , 'INFO' ));
2010-12-02 23:34:41 +00:00
}
2017-12-04 13:25:35 +00:00
function fieldToLabel ( $field )
{
$aux = substr ( $field , 4 );
$res = $aux [ 0 ];
for ( $i = 1 ; $i < strlen ( $aux ); $i ++ ) {
if ( $aux [ $i ] == '_' ) {
$res .= " " . $aux [ ++ $i ];
} else {
$res .= strtolower ( $aux [ $i ]);
}
}
return $res ;
2010-12-02 23:34:41 +00:00
}
2017-12-04 13:25:35 +00:00
function fieldToLabelOption ( $field )
{
$aux = $field ;
$res = $aux [ 0 ];
for ( $i = 1 ; $i < strlen ( $aux ); $i ++ ) {
if ( $aux [ $i ] == '_' ) {
$res .= " " . $aux [ ++ $i ];
} else {
$res .= strtolower ( $aux [ $i ]);
}
}
return $res ;
2010-12-02 23:34:41 +00:00
}
2017-12-04 13:25:35 +00:00
function run_propel_build_crud ( $task , $args )
{
ini_set ( 'display_errors' , 'on' );
ini_set ( 'error_reporting' , E_ERROR );
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
// the environment for poedit always is Development
define ( 'G_ENVIRONMENT' , G_DEV_ENV );
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
printf ( " Arguments: %s \n " , pakeColor :: colorize ( './gulliver propel-build-crud <class-name> <table-name> <plugin-name> ' , 'INFO' ));
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
//the class filename in the first argument
if ( ! isset ( $args [ 0 ])) {
printf ( " Error: %s \n " , pakeColor :: colorize ( 'you must specify a valid classname ' , 'ERROR' ));
exit ( 0 );
}
$class = $args [ 0 ];
$phpClass = $class ;
$phpClass [ 0 ] = strtolower ( $phpClass [ 0 ]);
$tableName = $class [ 0 ];
for ( $i = 1 ; $i < strlen ( $class ); $i ++ ) {
if ( $class [ $i ] >= 'a' ) {
$tableName .= strtoupper ( $class [ $i ]);
} else {
$tableName .= " _ " . $class [ $i ];
}
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
//second parameter is the table name, by default is the same classname in uppercase.
if ( isset ( $args [ 1 ])) {
$tableName = $args [ 1 ];
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
$pluginName = '' ;
if ( isset ( $args [ 2 ])) {
$pluginName = $args [ 2 ];
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
//try to find the class in classes directory
$classFilename = PATH_CORE . 'classes' . PATH_SEP . 'model' . PATH_SEP . $args [ 0 ] . '.php' ;
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
//try to find in the plugis directory, assuming there are a class in the plugin
if ( $pluginName != '' ) {
$classFilename = PATH_PLUGINS . $pluginName . PATH_SEP . 'classes' . PATH_SEP . 'model' . PATH_SEP . $args [ 0 ] . '.php' ;
set_include_path ( PATH_PLUGINS . $pluginName . PATH_SEPARATOR . get_include_path ());
printf ( " using plugin : %s \n " , pakeColor :: colorize ( $pluginName , 'ERROR' ));
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
if ( file_exists ( $classFilename )) {
printf ( " class found in %s \n " , pakeColor :: colorize ( $classFilename , 'INFO' ));
} else {
printf ( " class %s not found \n " , pakeColor :: colorize ( $class , 'ERROR' ));
exit ( 0 );
}
printf ( " TableName : %s \n " , pakeColor :: colorize ( $tableName , 'INFO' ));
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
require_once ( $classFilename );
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
global $G_ENVIRONMENTS ;
$aux = explode ( PATH_SEP , PATH_HOME );
$projectName = $aux [ count ( $aux ) - 2 ];
define ( 'PATH_SHARED' , PATH_SEP . 'shared' . PATH_SEP . $projectName . '_data' . PATH_SEP );
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
$dbFile = PATH_SHARED . 'sites' . PATH_SEP . $projectName . PATH_SEP . 'db.php' ;
if ( ! file_exists ( $dbFile )) {
$dbFile = PATH_GULLIVER_HOME . 'bin' . PATH_SEP . 'tasks' . PATH_SEP . 'templates' . PATH_SEP . 'db.php.tpl' ;
}
printf ( " searching db file in : %s \n " , pakeColor :: colorize ( $dbFile , 'INFO' ));
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
$G_ENVIRONMENTS [ 'DEVELOPMENT' ][ 'dbfile' ] = $dbFile ;
Propel :: init ( PATH_CORE . " config/databases.php " );
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
$configuration = Propel :: getConfiguration ();
$connectionDSN = $configuration [ 'datasources' ][ 'workflow' ][ 'connection' ];
printf ( " using DSN Connection %s \n " , pakeColor :: colorize ( $connectionDSN , 'INFO' ));
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
if ( $pluginName != '' ) {
$xmlformPath = PATH_PLUGINS . $pluginName . PATH_SEP ;
$methodsPath = PATH_PLUGINS . $pluginName . PATH_SEP . $phpClass . PATH_SEP ;
$corePath = PATH_PLUGINS . $pluginName . PATH_SEP ;
} else {
$xmlformPath = PATH_CORE . 'xmlform' . PATH_SEP . $phpClass . PATH_SEP ;
$methodsPath = PATH_CORE . 'methods' . PATH_SEP . $phpClass . PATH_SEP ;
$corePath = PATH_CORE ;
}
G :: mk_dir ( $xmlformPath );
G :: mk_dir ( $methodsPath );
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
$fields [ 'className' ] = $class ;
$fields [ 'phpClassName' ] = $phpClass ;
$fields [ 'tableName' ] = $tableName ;
$fields [ 'projectName' ] = $projectName ;
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
//1. MENU
if ( $pluginName == '' ) {
create_file_from_tpl ( 'pluginMenu' , PATH_CORE . 'menus' . PATH_SEP . $phpClass . " .php " , $fields );
}
//else {
// create_file_from_tpl ( 'pluginMenu', $corePath. $phpClass. ".php", $fields );
//}
2011-12-06 19:05:40 -04:00
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
//2. si existe menu welcome, aqade la opcion
if ( $pluginName == '' ) {
if ( ! file_exists ( PATH_CORE . 'menus' . PATH_SEP . " welcome.php " )) {
$fp = fopen ( PATH_CORE . 'menus' . PATH_SEP . " welcome.php " , " w " );
fwrite ( $fp , " <?php \n " );
fclose ( $fp );
}
$content = file_get_contents ( PATH_CORE . 'menus' . PATH_SEP . " welcome.php " );
if ( strpos ( $content , $phpClass . " .php " ) == false ) {
$fp = fopen ( PATH_CORE . 'menus' . PATH_SEP . " welcome.php " , " a " );
fwrite ( $fp , " require_once ( ' " . $phpClass . " .php' ); \n " );
fclose ( $fp );
}
2010-12-02 23:34:41 +00:00
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
//parse the schema file in order to get Table definition
$schemaFile = PATH_CORE . 'config' . PATH_SEP . 'schema.xml' ;
if ( $pluginName != '' ) {
$schemaFile = PATH_PLUGINS . $pluginName . PATH_SEP . 'config' . PATH_SEP . 'schema.xml' ;
2010-12-02 23:34:41 +00:00
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
printf ( " using schemaFile %s \n " , pakeColor :: colorize ( $schemaFile , 'INFO' ));
$xmlContent = file_get_contents ( $schemaFile );
$s = simplexml_load_file ( $schemaFile );
//default xmlform
//load the $fields array with fields data for an xmlform.
$fields = array ();
foreach ( $s -> table as $key => $table ) {
if ( $table [ 'name' ] == $tableName ) {
foreach ( $table -> column as $kc => $column ) {
$valuesOpt = null ;
if ( isset ( $table -> validator )) {
foreach ( $table -> validator as $kc => $validator ) {
if ( $validator [ 'column' ] == $column [ 'name' ]) {
foreach ( $validator -> rule as $kr => $rule ) {
if ( $rule [ 'name' ] == 'validValues' ) {
$valuesOpt = explode ( '|' , $rule [ 'value' ]);
}
}
}
}
}
// print "\033[1;34m "; print_r ( $values);
//print $column['name'] . ' ' .$column['type'] . ' ' .$column['size'] . ' ' .$column['required'] . ' ' .$column['primaryKey'];
//print_r ( $column); print "\n";
$maxlength = isset ( $column [ 'size' ]) ? $column [ 'size' ] : 25 ;
$size = ( $maxlength > 60 ) ? 60 : $maxlength ;
$values = null ;
if ( isset ( $valuesOpt )) {
$type = 'dropdown' ;
foreach ( $valuesOpt as $key => $val ) {
$values [] = array (
2011-12-06 19:05:40 -04:00
'value' => $val ,
'label' => fieldToLabelOption ( $val )
2010-12-02 23:34:41 +00:00
);
2017-12-04 13:25:35 +00:00
}
} else {
switch ( $column [ 'type' ]) {
2010-12-02 23:34:41 +00:00
case 'TIMESTAMP' :
$type = 'date' ;
break ;
case 'LONGVARCHAR' :
$type = 'textarea' ;
break ;
default :
$type = 'text' ;
}
2017-12-04 13:25:35 +00:00
}
if ( isset ( $column [ 'label' ])) {
$label = $column [ 'label' ];
} else {
$label = fieldToLabel ( $column [ 'name' ]);
}
$field = array (
2011-12-06 19:05:40 -04:00
'name' => $column [ 'name' ],
'className' => $class ,
'type' => $type ,
'size' => $size ,
'maxlength' => $maxlength ,
'label' => $label ,
'values' => $values
2010-12-02 23:34:41 +00:00
);
2017-12-04 13:25:35 +00:00
$fields [ 'fields' ][] = $field ;
if ( ! $column [ 'primaryKey' ]) {
$fields [ 'onlyFields' ][] = $field ;
} else {
$fields [ 'keys' ][] = $field ;
}
}
2010-12-02 23:34:41 +00:00
}
2017-12-04 13:25:35 +00:00
}
$fields [ 'className' ] = $class ;
$fields [ 'phpClassName' ] = $phpClass ;
$fields [ 'projectName' ] = $projectName ;
$fields [ 'firstKey' ] = $fields [ 'keys' ][ 0 ][ 'name' ];
$fields [ 'phpFolderName' ] = $phpClass ;
if ( $pluginName != '' ) {
$fields [ 'plugin' ][] = array (
2011-12-06 19:05:40 -04:00
'pluginName' => $pluginName
2010-12-02 23:34:41 +00:00
);
2017-12-04 13:25:35 +00:00
$fields [ 'phpFolderName' ] = $pluginName ;
}
create_file_from_tpl ( 'pluginXmlform' , $xmlformPath . $phpClass . " .xml " , $fields );
create_file_from_tpl ( 'pluginXmlformEdit' , $xmlformPath . $phpClass . " Edit.xml " , $fields );
create_file_from_tpl ( 'pluginXmlformDelete' , $xmlformPath . $phpClass . " Delete.xml " , $fields );
create_file_from_tpl ( 'pluginList' , $methodsPath . $phpClass . " List.php " , $fields );
//xmlform for list
//load the $fields array with fields data for PagedTable xml.
$fields = array ();
$onlyFields = array ();
$primaryKey = '' ;
foreach ( $s -> table as $key => $table ) {
if ( $table [ 'name' ] == $tableName ) {
foreach ( $table -> column as $kc => $column ) {
//print $column['name'] . ' ' .$column['type'] . ' ' .$column['size'] . ' ' .$column['required'] . ' ' .$column['primaryKey'];
//print "\n";
$size = ( $column [ 'size' ] > 40 ) ? 40 * 3 : $column [ 'size' ] * 3 ;
$type = $column [ 'type' ];
$label = fieldToLabel ( $column [ 'name' ]);
if ( $column [ 'primaryKey' ]) {
if ( $primaryKey == '' ) {
$primaryKey .= '@!' . $column [ 'name' ];
} else {
$primaryKey .= '|@!' . $column [ 'name' ];
}
if ( isset ( $column [ 'label' ])) {
$label = $column [ 'label' ];
} else {
$label = fieldToLabel ( $column [ 'name' ]);
}
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
$field = array (
2011-12-06 19:05:40 -04:00
'name' => $column [ 'name' ],
'type' => $type ,
'size' => $size ,
'label' => $label
2010-12-02 23:34:41 +00:00
);
2017-12-04 13:25:35 +00:00
$fields [ 'fields' ][] = $field ;
if ( ! $column [ 'primaryKey' ]) {
if ( $column [ 'type' ] != 'LONGVARCHAR' ) {
$fields [ 'onlyFields' ][] = $field ;
}
} else {
$fields [ 'keys' ][] = $field ;
}
}
2010-12-02 23:34:41 +00:00
}
2017-12-04 13:25:35 +00:00
}
$fields [ 'primaryKey' ] = $primaryKey ;
$fields [ 'className' ] = $class ;
$fields [ 'phpClassName' ] = $phpClass ;
$fields [ 'phpFolderName' ] = $phpClass ;
if ( $pluginName != '' ) {
$fields [ 'phpFolderName' ] = $pluginName ;
}
$fields [ 'projectName' ] = $projectName ;
$fields [ 'tableName' ] = $tableName ;
create_file_from_tpl ( 'pluginXmlformList' , $xmlformPath . $phpClass . " List.xml " , $fields );
create_file_from_tpl ( 'pluginXmlformOptions' , $xmlformPath . $phpClass . " Options.xml " , $fields );
//default edit
$fields = array ();
$index = 0 ;
$keylist = '' ;
foreach ( $s -> table as $key => $table ) {
if ( $table [ 'name' ] == $tableName ) {
foreach ( $table -> column as $kc => $column ) {
$name = $column [ 'name' ];
$phpName = convertPhpName ( $name );
$field = array (
2011-12-06 19:05:40 -04:00
'name' => $name ,
'phpName' => $phpName ,
'index' => $index ++
2010-12-02 23:34:41 +00:00
);
2017-12-04 13:25:35 +00:00
if ( $column [ 'primaryKey' ]) {
if ( $keylist == '' ) {
$keylist .= '$' . $phpName ;
} else {
$keylist .= ', $' . $phpName ;
}
$fields [ 'keys' ][] = $field ;
}
$fields [ 'fields' ][] = $field ;
if ( ! $column [ 'primaryKey' ]) {
$fields [ 'onlyFields' ][] = $field ;
}
$fields [ 'fields2' ][] = $field ;
}
2010-12-02 23:34:41 +00:00
}
2017-12-04 13:25:35 +00:00
}
$fields [ 'keylist' ] = $keylist ;
$fields [ 'phpClassName' ] = $phpClass ;
$fields [ 'phpFolderName' ] = $phpClass ;
$fields [ 'className' ] = $class ;
$fields [ 'tableName' ] = $tableName ;
$fields [ 'projectName' ] = $projectName ;
if ( $pluginName != '' ) {
$fields [ 'plugin' ][] = array (
2011-12-06 19:05:40 -04:00
'pluginName' => $pluginName
2010-12-02 23:34:41 +00:00
);
2017-12-04 13:25:35 +00:00
$fields [ 'phpFolderName' ] = $pluginName ;
}
//savePluginFile ( $class . PATH_SEP . $class . 'Edit.php', 'pluginEdit', $class, $tableName, $fields );
//savePluginFile ( $class . PATH_SEP . $class . 'Save.php', 'pluginSave', $class, $tableName, $fields );
create_file_from_tpl ( 'pluginEdit' , $methodsPath . $phpClass . " Edit.php " , $fields );
create_file_from_tpl ( 'pluginSave' , $methodsPath . $phpClass . " Save.php " , $fields );
create_file_from_tpl ( 'pluginNew' , $methodsPath . $phpClass . " New.php " , $fields );
create_file_from_tpl ( 'pluginDelete' , $methodsPath . $phpClass . " Delete.php " , $fields );
create_file_from_tpl ( 'pluginDeleteExec' , $methodsPath . $phpClass . " DeleteExec.php " , $fields );
exit ( 0 );
2010-12-02 23:34:41 +00:00
}
//////////////////////////// backup and restore functions ///////////////////////////////////
2017-12-04 13:25:35 +00:00
function backupAddTarFolder ( $tar , $pathBase , $pluginHome )
{
$empty = true ;
print " " . str_replace ( $pluginHome , '' , $pathBase ) . " \n " ;
if ( $handle = opendir ( $pathBase )) {
while ( false !== ( $file = readdir ( $handle ))) {
if ( is_file ( $pathBase . $file )) {
$empty = false ;
$tar -> addModify ( array ( $pathBase . $file ), '' , $pluginHome );
}
if ( is_dir ( $pathBase . $file ) && $file != '..' && $file != '.' ) {
//print "dir $pathBase$file \n";
backupAddTarFolder ( $tar , $pathBase . $file . PATH_SEP , $pluginHome );
$empty = false ;
}
}
closedir ( $handle );
}
if ( $empty /*&& $pathBase . $file != $pluginHome */ ) {
2010-12-02 23:34:41 +00:00
$tar -> addModify ( array ( $pathBase . $file ), '' , $pluginHome );
}
}
2017-12-04 13:25:35 +00:00
function getSysInfo ()
{
if ( file_exists ( PATH_METHODS . 'login/version-pmos.php' )) {
include ( PATH_METHODS . 'login/version-pmos.php' );
} else {
define ( 'PM_VERSION' , 'Development Version' );
}
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
$ipe = explode ( " " , $_SERVER [ 'SSH_CONNECTION' ]);
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
if ( getenv ( 'HTTP_CLIENT_IP' )) {
$ip = getenv ( 'HTTP_CLIENT_IP' );
} elseif ( getenv ( 'HTTP_X_FORWARDED_FOR' )) {
$ip = getenv ( 'HTTP_X_FORWARDED_FOR' );
} else {
$ip = getenv ( 'REMOTE_ADDR' );
}
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
/* For distros with the lsb_release , this returns a one - line description of
* the distro name , such as " CentOS release 5.3 (Final) " or " Ubuntu 10.10 "
*/
$distro = exec ( " lsb_release -d -s 2> /dev/null " );
2010-12-16 20:36:29 +00:00
2017-12-04 13:25:35 +00:00
/* For distros without lsb_release , we look for * release ( such as
* redhat - release , gentoo - release , SuSE - release , etc ) or * version ( such as
* debian_version , slackware - version , etc )
*/
2010-12-16 20:36:29 +00:00
if ( empty ( $distro )) {
2017-12-04 13:25:35 +00:00
foreach ( glob ( " /etc/*release " ) as $filename ) {
$distro = trim ( file_get_contents ( $filename ));
if ( ! empty ( $distro )) {
break ;
}
}
if ( empty ( $distro )) {
foreach ( glob ( " /etc/*version " ) as $filename ) {
$distro = trim ( file_get_contents ( $filename ));
if ( ! empty ( $distro )) {
break ;
}
}
}
2010-12-16 20:36:29 +00:00
}
2017-12-04 13:25:35 +00:00
/* CentOS returns a string with quotes, remove them! */
$distro = trim ( $distro , " \" " );
2010-12-16 20:36:29 +00:00
2017-12-04 13:25:35 +00:00
$distro .= " ( " . PHP_OS . " ) " ;
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
$Fields = array ();
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
$Fields [ 'SYSTEM' ] = $distro ;
$Fields [ 'PHP' ] = phpversion ();
$Fields [ 'PM_VERSION' ] = PM_VERSION ;
$Fields [ 'SERVER_ADDR' ] = lookup ( $ipe [ 2 ]);
$Fields [ 'IP' ] = lookup ( $ipe [ 0 ]);
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
return $Fields ;
2010-12-02 23:34:41 +00:00
}
/*
** function get_infoOnPM
** information about workspace
*/
2017-12-04 13:25:35 +00:00
function get_infoOnPM ( $workspace )
{
$infoPM = array ();
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
$Fields = getSysInfo ();
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
$Fields [ 'WORKSPACE_NAME' ] = $workspace ;
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
if ( defined ( " DB_HOST " )) {
$dbNetView = new Net ( DB_HOST );
$dbNetView -> loginDbServer ( DB_USER , DB_PASS );
2017-08-02 16:06:56 -04:00
2017-12-04 13:25:35 +00:00
$dbConns = new DbConnections ( '' );
$availdb = '' ;
foreach ( $dbConns -> getDbServicesAvailables () as $key => $val ) {
if ( $availdb != '' ) {
$availdb .= ', ' ;
}
$availdb .= $val [ 'name' ];
}
try {
$sMySQLVersion = $dbNetView -> getDbServerVersion ( 'mysql' );
} catch ( Exception $oException ) {
$sMySQLVersion = 'Unknown' ;
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
$Fields [ 'DATABASE' ] = $dbNetView -> dbName ( DB_ADAPTER ) . ' (Version ' . $sMySQLVersion . ')' ;
$Fields [ 'DATABASE_SERVER' ] = DB_HOST ;
$Fields [ 'DATABASE_NAME' ] = DB_NAME ;
$Fields [ 'AVAILABLE_DB' ] = $availdb ;
} else {
$Fields [ 'DATABASE' ] = " Not defined " ;
$Fields [ 'DATABASE_SERVER' ] = $info_db [ 'adap' ];
$Fields [ 'DATABASE_NAME' ] = " Not defined " ;
$Fields [ 'AVAILABLE_DB' ] = " Not defined " ;
2010-12-02 23:34:41 +00:00
}
2017-12-04 13:25:35 +00:00
$info_db = get_DirDB ( $workspace );
$Fields [ 'MYSQL_DATA_DIR' ] = $info_db [ 'datadir' ];
$Fields [ 'PLUGINS_LIST' ] = get_plugins ();
$Fields [ 'DB_ADAPTER' ] = $info_db [ 'DB_ADAPTER' ];
$Fields [ 'DB_HOST' ] = $info_db [ 'DB_HOST' ];
$Fields [ 'DB_NAME' ] = $info_db [ 'DB_NAME' ];
$Fields [ 'DB_USER' ] = $info_db [ 'DB_USER' ];
$Fields [ 'DB_PASS' ] = $info_db [ 'DB_PASS' ];
$Fields [ 'DB_RBAC_HOST' ] = $info_db [ 'DB_RBAC_HOST' ];
$Fields [ 'DB_RBAC_NAME' ] = $info_db [ 'DB_RBAC_NAME' ];
$Fields [ 'DB_RBAC_USER' ] = $info_db [ 'DB_RBAC_USER' ];
$Fields [ 'DB_RBAC_PASS' ] = $info_db [ 'DB_RBAC_PASS' ];
$Fields [ 'DB_REPORT_HOST' ] = $info_db [ 'DB_REPORT_HOST' ];
$Fields [ 'DB_REPORT_NAME' ] = $info_db [ 'DB_REPORT_NAME' ];
$Fields [ 'DB_REPORT_USER' ] = $info_db [ 'DB_REPORT_USER' ];
$Fields [ 'DB_REPORT_PASS' ] = $info_db [ 'DB_REPORT_PASS' ];
$infoPM = $Fields ;
return $infoPM ;
2010-12-02 23:34:41 +00:00
}
2017-12-04 13:25:35 +00:00
function printMetadata ( $fields )
{
printf ( " %20s %s \n " , 'Workspace Name' , pakeColor :: colorize ( $fields [ 'WORKSPACE_NAME' ], 'INFO' ));
printf ( " %20s %s \n " , 'System' , pakeColor :: colorize ( $fields [ 'SYSTEM' ], 'INFO' ));
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
printf ( " %20s %s \n " , 'ProcessMaker Version' , pakeColor :: colorize ( $fields [ 'PM_VERSION' ], 'INFO' ));
printf ( " %20s %s \n " , 'PHP Version' , pakeColor :: colorize ( $fields [ 'PHP' ], 'INFO' ));
printf ( " %20s %s \n " , 'Server Address' , pakeColor :: colorize ( $fields [ 'SERVER_ADDR' ], 'INFO' ));
printf ( " %20s %s \n " , 'Client IP Address' , pakeColor :: colorize ( $fields [ 'IP' ], 'INFO' ));
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
printf ( " %20s %s \n " , 'MySql Version' , pakeColor :: colorize ( $fields [ 'DATABASE' ], 'INFO' ));
printf ( " %20s %s \n " , 'MySql Data Directory' , pakeColor :: colorize ( $fields [ 'MYSQL_DATA_DIR' ], 'INFO' ));
printf ( " %20s %s \n " , 'Available Databases' , pakeColor :: colorize ( $fields [ 'AVAILABLE_DB' ], 'INFO' ));
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
printf ( " %20s %s \n " , 'Plugins' , pakeColor :: colorize ( '' , 'INFO' ));
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
foreach ( $fields [ 'PLUGINS_LIST' ] as $k => $v ) {
printf ( " %20s %s \n " , ' -' , pakeColor :: colorize ( $v , 'INFO' ));
}
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
$wfDsn = $fields [ 'DB_ADAPTER' ] . '://' . $fields [ 'DB_USER' ] . ':' . $fields [ 'DB_PASS' ] . '@' . $fields [ 'DB_HOST' ] . '/' . $fields [ 'DB_NAME' ];
$rbDsn = $fields [ 'DB_ADAPTER' ] . '://' . $fields [ 'DB_RBAC_USER' ] . ':' . $fields [ 'DB_RBAC_PASS' ] . '@' . $fields [ 'DB_RBAC_HOST' ] . '/' . $fields [ 'DB_RBAC_NAME' ];
$rpDsn = $fields [ 'DB_ADAPTER' ] . '://' . $fields [ 'DB_REPORT_USER' ] . ':' . $fields [ 'DB_REPORT_PASS' ] . '@' . $fields [ 'DB_REPORT_HOST' ] . '/' . $fields [ 'DB_REPORT_NAME' ];
printf ( " %20s %s \n " , 'Workflow Database' , pakeColor :: colorize ( $wfDsn , 'INFO' ));
printf ( " %20s %s \n " , 'RBAC Database' , pakeColor :: colorize ( $rbDsn , 'INFO' ));
printf ( " %20s %s \n " , 'Report Database' , pakeColor :: colorize ( $rpDsn , 'INFO' ));
2010-12-02 23:34:41 +00:00
}
2017-12-04 13:25:35 +00:00
function get_plugins ()
{
$dir = PATH_PLUGINS ;
$filesArray = array ();
if ( file_exists ( $dir )) {
if ( $handle = opendir ( $dir )) {
while ( false !== ( $file = readdir ( $handle ))) {
if (( $file != " . " ) && ( $file != " .. " ) && ( $file != " .svn " )) {
if ( ! strpos ( $file , " .php " )) {
$filesArray [] = $file ;
}
}
}
closedir ( $handle );
2010-12-02 23:34:41 +00:00
}
}
2017-12-04 13:25:35 +00:00
sort ( $filesArray , SORT_STRING );
return $filesArray ;
2010-12-02 23:34:41 +00:00
}
2017-12-04 13:25:35 +00:00
function lookup ( $target )
{
global $ntarget ;
$msg = $target . ' => ' ;
//if( eregi('[a-zA-Z]', $target) )
if ( preg_match ( '[a-zA-Z]' , $target )) { //Made compatible to PHP 5.3
2010-12-02 23:34:41 +00:00
$ntarget = gethostbyname ( $target );
2017-12-04 13:25:35 +00:00
} else {
$ntarget = gethostbyaddr ( $target );
}
$msg .= $ntarget ;
return ( $msg );
2010-12-02 23:34:41 +00:00
}
2017-12-04 13:25:35 +00:00
function run_workspace_backup ( $task , $args )
{
throw new Exception ( " Gulliver backup is no longer supported, use processmaker command-line instead. " );
try {
ini_set ( 'display_errors' , 'on' );
ini_set ( 'error_reporting' , E_ERROR );
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
// the environment for poedit always is Development
define ( 'G_ENVIRONMENT' , G_DEV_ENV );
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
/* Look for -c and --compress in arguments */
$compress = array_search ( '-c' , $args );
if ( $compress === false ) {
$compress = array_search ( '--compress' , $args );
}
if ( $compress !== false ) {
unset ( $args [ $compress ]);
/* We need to reorder the args if we removed the compress switch */
$args = array_values ( $args );
$compress = true ;
}
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
/* Look for -c and --compress in arguments */
$overwrite = array_search ( '-o' , $args );
if ( $overwrite === false ) {
$overwrite = array_search ( '--overwrite' , $args );
}
if ( $overwrite !== false ) {
unset ( $args [ $overwrite ]);
/* We need to reorder the args if we removed the compress switch */
$args = array_values ( $args );
$overwrite = true ;
}
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
if ( array_search ( 'compress' , $args )) {
echo pakeColor :: colorize ( " Compress is no longer an option, check if this is what you want \n " , 'ERROR' );
}
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
if ( count ( $args ) > 2 || count ( $args ) == 0 ) {
throw ( new Exception ( 'wrong arguments specified' ));
}
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
$workspace = $args [ 0 ];
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
/* Use system gzip if not in Windows */
if ( $compress && strtolower ( reset ( explode ( ' ' , php_uname ( 's' )))) != " windows " ) {
/* Find the system gzip */
exec ( " whereis -b gzip " , $whereisGzip );
$gzipPaths = explode ( ' ' , $whereisGzip [ 0 ]);
if ( isset ( $gzipPaths [ 1 ])) {
$gzipPath = $gzipPaths [ 1 ];
}
if ( isset ( $gzipPath )) {
echo " Using system gzip in $gzipPath\n " ;
}
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
if ( isset ( $args [ 1 ])) {
$fileTar = $args [ 1 ];
/* Check if the second argument is an absolute filename . If it is , use
* it as the backup filename . Otherwise , use it as a filename relative
* to the backups directory . This makes migration from previous versions
* easier , which always expects a relative filename , while still accepting
* absolute filenames .
*/
if ( dirname ( $fileTar ) == '.' ) {
printf ( " Using %s as root. Use an absolute filename to change it. \n " , pakeColor :: colorize ( PATH_TRUNK . 'backups' , 'INFO' ));
G :: mk_dir ( PATH_DATA . 'backups' );
$fileTar = PATH_DATA . 'backups' . PATH_SEP . $fileTar . '.tar' ;
if ( $compress ) {
$fileTar .= '.gz' ;
}
}
printf ( " Backing up workspace %s to %s \n " , pakeColor :: colorize ( $workspace , 'INFO' ), pakeColor :: colorize ( $fileTar , 'INFO' ));
if ( ! $overwrite && file_exists ( $fileTar )) {
$overwrite = strtolower ( prompt ( 'Backup file already exists, do you want to overwrite? [Y/n]' ));
if ( array_search ( trim ( $overwrite ), array ( " y " , " " )) === false ) {
die ();
}
$overwrite = true ;
}
} else {
G :: mk_dir ( PATH_DATA . 'backups' );
$fileBase = PATH_DATA . 'backups' . PATH_SEP . $workspace . '.tar' ;
$fileTar = $fileBase ;
if ( $compress ) {
$fileTar .= '.gz' ;
}
printf ( " Backing up workspace %s to %s \n " , pakeColor :: colorize ( $workspace , 'INFO' ), pakeColor :: colorize ( $fileTar , 'INFO' ));
/* To avoid confusion, we remove both .tar and .tar.gz */
if ( ! $overwrite && ( file_exists ( $fileBase ) || file_exists ( $fileBase . '.gz' ))) {
$overwrite = strtolower ( prompt ( 'Backup file already exists, do you want to overwrite? [Y/n]' ));
if ( array_search ( trim ( $overwrite ), array ( " y " , " " )) === false ) {
die ();
}
$overwrite = true ;
}
if ( file_exists ( $fileBase )) {
unlink ( $fileBase );
}
if ( file_exists ( $fileBase . " .gz " )) {
unlink ( $fileBase . '.gz' );
}
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
/* Remove the backup file before backing up . Previous versions didn ' t do
* this , so backup files would increase indefinetely as new data was
* appended to the tar file instead of replaced .
*/
if ( file_exists ( $fileTar )) {
unlink ( $fileTar );
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
/* If using the system gzip, create the tar using a temporary filename */
if ( isset ( $gzipPath )) {
$gzipFinal = $fileTar ;
$fileTar = tempnam ( __FILE__ , '' );
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
$aSerializeData = get_infoOnPM ( $workspace );
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
$dbFile = PATH_DB . $workspace . PATH_SEP . 'db.php' ;
if ( ! file_exists ( $dbFile )) {
throw ( new Exception ( " Invalid workspace, the db file does not exist, $dbFile " ));
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
$dbOpt = @ explode ( SYSTEM_HASH , G :: decrypt ( HASH_INSTALLATION , SYSTEM_HASH ));
$oDbMaintainer = new DataBaseMaintenance ( $dbOpt [ 0 ], $dbOpt [ 1 ], $dbOpt [ 2 ]);
try {
$oDbMaintainer -> connect ( " mysql " );
} catch ( Exception $e ) {
echo " Problems contacting the database with the administrator user \n " ;
echo " The response was: { $e -> getMessage () } \n " ;
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
require_once ( $dbFile );
Propel :: init ( PATH_CORE . " config/databases.php " );
$configuration = Propel :: getConfiguration ();
$connectionDSN = $configuration [ 'datasources' ][ 'workflow' ][ 'connection' ];
printf ( " using DSN Connection %s \n " , pakeColor :: colorize ( $connectionDSN , 'INFO' ));
$con = Propel :: getConnection ( 'workflow' );
$sql = " show variables like 'datadir' " ;
$stmt = $con -> createStatement ();
$rs = $stmt -> executeQuery ( $sql , ResultSet :: FETCHMODE_ASSOC );
$rs -> next ();
$row = $rs -> getRow ();
if ( ! is_array ( $row )) {
throw ( new Exception ( " unable to execute query in database " ));
}
$dataDir = $row [ 'Value' ];
if ( $dataDir [ count ( $dataDir ) - 1 ] == '/' ) {
$dataDir = substr ( $dataDir , count ( $dataDir ) - 1 );
}
2010-12-20 14:13:30 +00:00
2017-12-04 13:25:35 +00:00
printf ( " MySQL data dir %s \n " , pakeColor :: colorize ( $dataDir , 'INFO' ));
$sql = " SELECT VERSION(); " ;
$stmt = $con -> createStatement ();
$rs = $stmt -> executeQuery ( $sql , ResultSet :: FETCHMODE_NUM );
$rs -> next ();
$row = $rs -> getRow ();
$mysqlVersion = $row [ 0 ];
$aSerializeData [ 'DATABASE' ] = $mysqlVersion ;
//new db restore rotines, by Erik <erik@colosa.com> on May 17th, 2010
//set the temporal directory for all tables into wf, rb, and rp databases
$tmpDir = G :: sys_get_temp_dir () . PATH_SEP . 'pmDbBackup' . PATH_SEP ;
//create the db maintenance temporal dir
G :: mk_dir ( $tmpDir );
$fileMetadata = $tmpDir . 'metadata.txt' ;
$sMetadata = file_put_contents ( $fileMetadata , serialize ( $aSerializeData ));
if ( $sMetadata === false ) {
throw new Exception ( " Metadata file could not be written " );
}
2010-12-20 14:13:30 +00:00
2011-12-06 19:05:40 -04:00
2017-08-02 16:06:56 -04:00
2017-12-04 13:25:35 +00:00
$tar = new Archive_Tar ( $fileTar );
if ( ! isset ( $gzipPath )) {
$tar -> _compress = $compress ;
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
$pathSharedBase = PATH_DATA . 'sites' . PATH_SEP . $workspace . PATH_SEP ;
printf ( " copying folder: %s \n " , pakeColor :: colorize ( $pathSharedBase , 'INFO' ));
backupAddTarFolder ( $tar , $pathSharedBase , PATH_DATA . 'sites' );
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
backupAddTarFolder ( $tar , $fileMetadata , dirname ( $fileMetadata ));
unlink ( $fileMetadata );
$aFiles = $tar -> listContent ();
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
$total = 0 ;
foreach ( $aFiles as $key => $val ) {
// printf( " %6d %s \n", $val['size'], pakeColor::colorize( $val['filename'], 'INFO') );
$total += $val [ 'size' ];
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
/* If using system gzip , compress the temporary tar to the original
* filename .
*/
if ( isset ( $gzipPath )) {
exec ( " gzip -c \" $fileTar\ " > $gzipFinal " , $output , $ret );
if ( $ret != 0 ) {
/* The error message is in stderr, which should be displayed already */
echo pakeColor :: colorize ( " Error compressing backup " , " ERROR " ) . " \n " ;
die ( 1 );
}
unlink ( $fileTar );
$fileTar = $gzipFinal ;
}
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
printMetadata ( $aSerializeData );
printf ( " %20s %s \n " , 'Backup File' , pakeColor :: colorize ( $fileTar , 'INFO' ));
printf ( " %20s %s \n " , 'Files in Backup' , pakeColor :: colorize ( count ( $aFiles ), 'INFO' ));
printf ( " %20s %s \n " , 'Total Filesize' , pakeColor :: colorize ( sprintf ( " %5.2f MB " , $total / 1024 / 1024 ), 'INFO' ));
printf ( " %20s %s \n " , 'Backup Filesize' , pakeColor :: colorize ( sprintf ( " %5.2f MB " , filesize ( $fileTar ) / 1024 / 1024 ), 'INFO' ));
} catch ( Exception $e ) {
printf ( " Error: %s \n " , pakeColor :: colorize ( $e -> getMessage (), 'ERROR' ));
exit ( 0 );
2010-12-02 23:34:41 +00:00
}
}
/**
* Parse and get the database parameters from a dns connection
* dsn sample mysql :// wf_os : w9j14dkf5v0m @ localhost : 3306 / wf_os ? encoding = utf8
2011-12-06 19:05:40 -04:00
*
2010-12-02 23:34:41 +00:00
* @ author Erik A . O . < erik @ colosa . com , erik @ gmail . com >
*/
2017-12-04 13:25:35 +00:00
function getDataBaseConfiguration ( $dsn )
{
$dsn = trim ( $dsn );
$tmp = explode ( ':' , $dsn );
$tmp2 = str_replace ( '//' , '' , $tmp [ 1 ]);
$result [ " user " ] = $tmp2 ;
$tmp2 = explode ( '@' , $tmp [ 2 ]);
$result [ " passwd " ] = $tmp2 [ 0 ];
$result [ " host " ] = $tmp2 [ 1 ];
$tmp2 = explode ( '?' , $tmp [ 3 ]);
$tmp2 = explode ( '/' , $tmp2 [ 0 ]);
$result [ " port " ] = $tmp2 [ 0 ];
$result [ " dbname " ] = $tmp2 [ 1 ];
return $result ;
2010-12-02 23:34:41 +00:00
}
2017-12-04 13:25:35 +00:00
function updateDBCallback ( $matches )
{
global $updateDBCallbackData ;
/* 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
*/
$dbPrefix = array (
2010-12-02 23:34:41 +00:00
'DB_NAME' => 'wf_' ,
'DB_USER' => 'wf_' ,
'DB_RBAC_NAME' => 'rb_' ,
'DB_RBAC_USER' => 'rb_' ,
'DB_REPORT_NAME' => 'rp_' ,
'DB_REPORT_USER' => 'rp_' );
2017-12-04 13:25:35 +00:00
$key = $matches [ 'key' ];
$value = $matches [ 'value' ];
if ( array_search ( $key , array ( 'DB_HOST' , 'DB_RBAC_HOST' , 'DB_REPORT_HOST' )) !== false ) {
/* Change the database hostname for these keys */
$value = $updateDBCallbackData [ 'new_host' ];
} elseif ( array_key_exists ( $key , $dbPrefix )) {
if ( $updateDBCallbackData [ 'change_workspace' ]) {
/* Change the database name to the new workspace , following the standard
* of prefix ( either wf_ , rp_ , rb_ ) and the workspace name .
*/
$value = $dbPrefix [ $key ] . $updateDBCallbackData [ 'target_workspace' ];
}
}
$updateDBCallbackData [ 'config' ][ $key ] = $value ;
return $matches [ 1 ] . $value . $matches [ 4 ];
2010-12-02 23:34:41 +00:00
}
2017-12-04 13:25:35 +00:00
function updateDBfile ( $directory , $targetWorkspace , $dbNewHost , $changeWorkspace )
{
if ( count ( explode ( " : " , $dbNewHost )) < 2 ) {
$dbNewHost .= ':3306' ;
}
/* Workaround to send variables to updateDBCallback callback */
$GLOBALS [ 'updateDBCallbackData' ] = array (
2010-12-02 23:34:41 +00:00
" new_host " => $dbNewHost ,
" change_workspace " => $changeWorkspace ,
" target_workspace " => $targetWorkspace ,
" config " => array ()
);
2017-12-04 13:25:35 +00:00
global $updateDBCallbackData ;
$dbfile = $directory . PATH_SEP . 'db.php' ;
if ( file_exists ( $dbfile )) {
$sDbFile = file_get_contents ( $dbfile );
/* 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>.*?)(' * \ ) *;.*)/ " ,
2010-12-02 23:34:41 +00:00
updateDBCallback ,
2017-12-04 13:25:35 +00:00
$sDbFile
);
file_put_contents ( $dbfile , $sNewDbFile );
return $updateDBCallbackData [ 'config' ];
}
2010-12-02 23:34:41 +00:00
}
2017-12-04 13:25:35 +00:00
function restoreDB ( $dbHost , $dbMaintainer , $dbOldName , $dbName , $dbUser , $dbPass , $tempDirectory , $overwrite )
{
printf ( " Restoring database %s to %s \n " , $dbOldName , pakeColor :: colorize ( $dbName , 'INFO' ));
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
/* Check if the hostname is local (localhost or 127.0.0.1) */
$islocal = ( strcmp ( substr ( $dbHost , 0 , strlen ( 'localhost' )), 'localhost' ) === 0 ) ||
( strcmp ( substr ( $dbHost , 0 , strlen ( '127.0.0.1' )), '127.0.0.1' ) === 0 );
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
$dbMaintainer -> connect ( 'mysql' );
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
$result = $dbMaintainer -> query ( " SELECT * FROM `user` WHERE user=' $dbUser ' AND password=PASSWORD(' { $dbPass } ') " );
if ( ! isset ( $result [ 0 ])) { //the user doesn't exist
$dbHostPerm = $islocal ? " localhost " : " % " ;
$dbMaintainer -> query ( " INSERT INTO user VALUES(' $dbHostPerm ',' $dbUser ',PASSWORD(' { $dbPass } '),'Y','Y','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','','','','',0,0,0,0); " );
}
$dbMaintainer -> query ( " GRANT ALL PRIVILEGES ON ` $dbUser `.* TO $dbName @'localhost' IDENTIFIED BY ' { $dbPass } ' WITH GRANT OPTION " );
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
if ( $overwrite ) {
$dbMaintainer -> createDb ( $dbName , true );
} else {
$dbMaintainer -> createDb ( $dbName );
}
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
$dbMaintainer -> connect ( $dbName );
$dbMaintainer -> setTempDir ( $tempDirectory . PATH_SEP . $dbOldName . PATH_SEP );
$dbMaintainer -> restoreFromSql ( $dbMaintainer -> getTempDir () . $dbOldName . '.sql' );
$dbMaintainer -> restoreAllData ( 'sql' );
2010-12-02 23:34:41 +00:00
}
2017-12-04 13:25:35 +00:00
function workspaceRestore ( $backupFilename , $targetWorkspace , $overwrite )
{
$tempDirectory = tempnam ( __FILE__ , '' );
if ( file_exists ( $tempDirectory )) {
unlink ( $tempDirectory );
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
if ( file_exists ( $tempDirectory )) {
G :: rm_dir ( $tempDirectory );
}
G :: mk_dir ( $tempDirectory );
2011-12-06 19:05:40 -04:00
2017-08-02 16:06:56 -04:00
2017-12-04 13:25:35 +00:00
$tar = new Archive_Tar ( $backupFilename );
$res = $tar -> extract ( $tempDirectory );
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
$metadataFilename = $tempDirectory . PATH_SEP . 'metadata.txt' ;
2010-12-02 23:34:41 +00:00
if ( ! file_exists ( $metadataFilename )) {
2017-12-04 13:25:35 +00:00
/* Look for legacy backups , where metadata was stored as a file with the
* workspace name , such as workflow . txt
* This means the backup filename must be the same as the metadata file .
*/
$info = pathinfo ( $backupFilename );
/* Check if it ' s a compressed backup , in which case we need to remove
* both the gz and the tar extensions .
*/
if ( $info [ 'extension' ] == " gz " ) {
$info = pathinfo ( basename ( $backupFilename , '.' . $info [ 'extension' ]));
}
$wsNameFromTar = basename ( $backupFilename , '.' . $info [ 'extension' ]);
$metadataFilename = $tempDirectory . PATH_SEP . $wsNameFromTar . '.txt' ;
if ( ! file_exists ( $metadataFilename )) {
throw ( new Exception ( " Metadata file was not found in backup " ));
}
2010-12-02 23:34:41 +00:00
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
$metadata = unserialize ( file_get_contents ( $metadataFilename ));
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
$backupWorkspace = $metadata [ 'WORKSPACE_NAME' ];
$changeWorkspace = ( isset ( $targetWorkspace ));
if ( ! $changeWorkspace ) {
$targetWorkspace = $backupWorkspace ;
} else {
echo " Restoring from workspace: " . pakeColor :: colorize ( $backupWorkspace , 'INFO' ) . " \n " ;
}
echo " Restoring to workspace: " . pakeColor :: colorize ( $targetWorkspace , 'INFO' ) . " \n " ;
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
//moving the site files
$backupWorkspaceDir = $tempDirectory . PATH_SEP . $backupWorkspace ;
$targetWorkspaceDir = PATH_DATA . 'sites' . PATH_SEP . $targetWorkspace ;
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
if ( ! $overwrite && file_exists ( $targetWorkspaceDir )) {
$overwrite = strtolower ( prompt ( 'Workspace already exists, do you want to overwrite? [Y/n]' ));
if ( array_search ( trim ( $overwrite ), array ( " y " , " " )) === false ) {
die ();
}
$overwrite = true ;
}
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
printf ( " Moving files to %s \n " , pakeColor :: colorize ( $targetWorkspaceDir , 'INFO' ));
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
/* We already know we will be overwriting the new workspace if we reach this
* point , so remove the workspace directory if it exists .
*/
if ( file_exists ( $targetWorkspaceDir )) {
G :: rm_dir ( $targetWorkspaceDir );
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
if ( ! rename ( $backupWorkspaceDir , $targetWorkspaceDir )) {
throw ( new Exception ( " There was an error moving from $backupWorkspaceDir to $targetWorkspaceDir " ));
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
$dbOpt = @ explode ( SYSTEM_HASH , G :: decrypt ( HASH_INSTALLATION , SYSTEM_HASH ));
$dbHostname = $dbOpt [ 0 ];
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
/* TODO: Check if database exists after updateDBfile */
$config = updateDBfile ( $targetWorkspaceDir , $targetWorkspace , $dbHostname , $changeWorkspace );
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
$oDbMaintainer = new DataBaseMaintenance ( $dbOpt [ 0 ], $dbOpt [ 1 ], $dbOpt [ 2 ]);
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
$dbName = $config [ 'DB_NAME' ];
$dbUser = $config [ 'DB_USER' ];
$dbPass = $config [ 'DB_PASS' ];
restoreDB ( $dbHostname , $oDbMaintainer , $metadata [ 'DB_NAME' ], $dbName , $dbUser , $dbPass , $tempDirectory , $overwrite );
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
$dbName = $config [ 'DB_RBAC_NAME' ];
$dbUser = $config [ 'DB_RBAC_USER' ];
$dbPass = $config [ 'DB_RBAC_PASS' ];
restoreDB ( $dbHostname , $oDbMaintainer , $metadata [ 'DB_RBAC_NAME' ], $dbName , $dbUser , $dbPass , $tempDirectory , $overwrite );
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
$dbName = $config [ 'DB_REPORT_NAME' ];
$dbUser = $config [ 'DB_REPORT_USER' ];
$dbPass = $config [ 'DB_REPORT_PASS' ];
restoreDB ( $dbHostname , $oDbMaintainer , $metadata [ 'DB_REPORT_NAME' ], $dbName , $dbUser , $dbPass , $tempDirectory , $overwrite );
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
echo " \n " ;
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
$wsInfo = getSysInfo ();
$wsInfo [ 'WORKSPACE_NAME' ] = $targetWorkspace ;
$wsInfo = array_merge ( $wsInfo , $config );
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
printInfoSites ( $metadata , $wsInfo );
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
return true ;
2010-12-02 23:34:41 +00:00
}
2017-12-04 13:25:35 +00:00
function get_DirDB ( $workspace )
{
$dbFile = PATH_DB . $workspace . PATH_SEP . 'db.php' ;
if ( ! file_exists ( $dbFile )) {
throw ( new Exception ( " the db file does not exist, $dbFile " ));
}
require_once ( $dbFile );
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
Propel :: init ( PATH_CORE . " config/databases.php " );
$configuration = Propel :: getConfiguration ();
$connectionDSN = $configuration [ 'datasources' ][ 'workflow' ][ 'connection' ];
// printf("using DSN Connection %s \n", pakeColor::colorize( $connectionDSN, 'INFO'));
$con = Propel :: getConnection ( 'workflow' );
$sql = " show variables like 'datadir' " ;
$stmt = $con -> createStatement ();
$rs = $stmt -> executeQuery ( $sql , ResultSet :: FETCHMODE_ASSOC );
$rs -> next ();
$row = $rs -> getRow ();
if ( ! is_array ( $row )) {
throw ( new Exception ( " unable to execute query in database " ));
}
$dataDir = $row [ 'Value' ];
if ( $dataDir [ count ( $dataDir ) - 1 ] == '/' ) {
$dataDir = substr ( $dataDir , count ( $dataDir ) - 1 );
}
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
$info_db = array ();
$info_db [ 'conx' ] = $configuration [ 'datasources' ][ 'workflow' ][ 'connection' ];
$info_db [ 'adap' ] = $configuration [ 'datasources' ][ 'workflow' ][ 'adapter' ];
$info_db [ 'datadir' ] = $dataDir ;
$info_db [ 'DB_ADAPTER' ] = DB_ADAPTER ;
$info_db [ 'DB_HOST' ] = DB_HOST ;
$info_db [ 'DB_NAME' ] = DB_NAME ;
$info_db [ 'DB_USER' ] = DB_USER ;
$info_db [ 'DB_PASS' ] = DB_PASS ;
$info_db [ 'DB_RBAC_HOST' ] = DB_RBAC_HOST ;
$info_db [ 'DB_RBAC_NAME' ] = DB_RBAC_NAME ;
$info_db [ 'DB_RBAC_USER' ] = DB_RBAC_USER ;
$info_db [ 'DB_RBAC_PASS' ] = DB_RBAC_PASS ;
$info_db [ 'DB_REPORT_HOST' ] = DB_REPORT_HOST ;
$info_db [ 'DB_REPORT_NAME' ] = DB_REPORT_NAME ;
$info_db [ 'DB_REPORT_USER' ] = DB_REPORT_USER ;
$info_db [ 'DB_REPORT_PASS' ] = DB_REPORT_PASS ;
return $info_db ;
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
function printInfoSites ( $aSitebck , $aSiterestared )
{
printf ( " %25s %s \n " , 'Workspace Name Backup' , pakeColor :: colorize ( $aSitebck [ 'WORKSPACE_NAME' ], 'INFO' ));
printf ( " %25s %s \n " , 'Workspace Name Restored' , pakeColor :: colorize ( $aSiterestared [ 'WORKSPACE_NAME' ], 'INFO' ));
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
printf ( " %25s %s \n " , 'System Backup' , pakeColor :: colorize ( $aSitebck [ 'SYSTEM' ], 'INFO' ));
printf ( " %25s %s \n " , 'System Restored' , pakeColor :: colorize ( $aSiterestared [ 'SYSTEM' ], 'INFO' ));
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
printf ( " %25s %s \n " , 'PM Version Backup' , pakeColor :: colorize ( $aSitebck [ 'PM_VERSION' ], 'INFO' ));
printf ( " %25s %s \n " , 'PM Version Restored' , pakeColor :: colorize ( $aSiterestared [ 'PM_VERSION' ], 'INFO' ));
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
printf ( " %25s %s \n " , 'PHP Version Backup' , pakeColor :: colorize ( $aSitebck [ 'PHP' ], 'INFO' ));
printf ( " %25s %s \n " , 'PHP Version Restored' , pakeColor :: colorize ( $aSiterestared [ 'PHP' ], 'INFO' ));
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
//printf( "%25s %s \n", 'Server Address', pakeColor::colorize( $aSitebck['SERVER_ADDR'], 'INFO') );
//printf( "%25s %s \n", 'Client IP Address', pakeColor::colorize( $aSitebck['IP'], 'INFO') );
2010-12-02 23:34:41 +00:00
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
//printf( "%25s %s \n", 'MySql Version', pakeColor::colorize( $aSitebck['DATABASE'], 'INFO') );
//printf( "%25s %s \n", 'MySql Version', pakeColor::colorize( $aSiterestared['DATABASE'], 'INFO') );
2010-12-02 23:34:41 +00:00
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
//printf( "%25s %s \n", 'MySql Data Directory', pakeColor::colorize( $aSitebck['MYSQL_DATA_DIR'], 'INFO') );
//printf( "%25s %s \n", 'MySql Data Directory', pakeColor::colorize( $aSiterestared['MYSQL_DATA_DIR'], 'INFO') );
2010-12-02 23:34:41 +00:00
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
//printf( "%25s %s \n", 'Available Databases', pakeColor::colorize( $aSitebck['AVAILABLE_DB'], 'INFO') );
2010-12-02 23:34:41 +00:00
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
/* printf ( " %20s %s \n " , 'Plugins' , pakeColor :: colorize ( '' , 'INFO' ) );
foreach ( $aSitebck [ 'PLUGINS_LIST' ] as $k => $v ){
printf ( " %20s %s \n " , ' -' , pakeColor :: colorize ( $v , 'INFO' ) );
} */
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
$wfDsn = $aSiterestared [ 'DB_ADAPTER' ] . '://' . $aSiterestared [ 'DB_USER' ] . ':' . $aSiterestared [ 'DB_PASS' ] . '@' . $aSiterestared [ 'DB_HOST' ] . '/' . $aSiterestared [ 'DB_NAME' ];
$rbDsn = $aSiterestared [ 'DB_ADAPTER' ] . '://' . $aSiterestared [ 'DB_RBAC_USER' ] . ':' . $aSiterestared [ 'DB_RBAC_PASS' ] . '@' . $aSiterestared [ 'DB_RBAC_HOST' ] . '/' . $aSiterestared [ 'DB_RBAC_NAME' ];
$rpDsn = $aSiterestared [ 'DB_ADAPTER' ] . '://' . $aSiterestared [ 'DB_REPORT_USER' ] . ':' . $aSiterestared [ 'DB_REPORT_PASS' ] . '@' . $aSiterestared [ 'DB_REPORT_HOST' ] . '/' . $aSiterestared [ 'DB_REPORT_NAME' ];
printf ( " %25s %s \n " , 'Workflow Database' , pakeColor :: colorize ( $wfDsn , 'INFO' ));
printf ( " %25s %s \n " , 'RBAC Database' , pakeColor :: colorize ( $rbDsn , 'INFO' ));
printf ( " %25s %s \n " , 'Report Database' , pakeColor :: colorize ( $rpDsn , 'INFO' ));
2011-12-06 19:05:40 -04:00
}
2010-12-02 23:34:41 +00:00
global $aFiles ;
2017-12-04 13:25:35 +00:00
function checkFileStandardCode ( $file )
{
global $aFiles ;
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
if ( strpos ( $file , 'workflow/engine/classes/model/om/' ) !== false ) {
return ;
}
if ( strpos ( $file , 'workflow/engine/classes/model/map/' ) !== false ) {
return ;
}
if ( substr ( $file , - 4 ) == '.gif' ) {
return ;
}
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
$rootFolder = str_replace ( PATH_TRUNK , '' , $file );
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
$data = file_get_contents ( $file );
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
$bTabs = false ;
if ( strpos ( $data , " \t " ) !== false ) {
$bTabs = true ;
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
$bUtf8 = false ;
if ( strpos ( $data , " \xff " ) !== false || strpos ( $data , " \x00 " ) !== false ) {
//isUTF8
$bUtf8 = true ;
}
if ( filesize ( $file ) != strlen ( $data )) {
$bUtf8 = true ;
}
2011-12-06 19:05:40 -04:00
2017-12-04 13:25:35 +00:00
$bDos = false ;
if ( strpos ( $data , " \x0D " ) !== false ) {
$bDos = true ;
}
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
if ( $bUtf8 || $bTabs || $bDos ) {
$aFiles [] = array ( 'file' => $rootFolder , 'tab' => $bTabs , 'utf' => $bUtf8 , 'dos' => $bDos );
}
2010-12-02 23:34:41 +00:00
}
2014-12-23 17:22:42 -04:00
/*----------------------------------********---------------------------------*/
/* function checkFolderStandardCode ( $folder , $bSubFolders ) {
2010-12-02 23:34:41 +00:00
global $aFiles ;
2017-12-04 13:25:35 +00:00
$rootFolder = str_replace ( PATH_TRUNK , '' , $folder );
2010-12-02 23:34:41 +00:00
//printf("%s \n", pakeColor::colorize($rootFolder, 'INFO'));
if ( $handle = opendir ( $folder )) {
while ( false !== ( $file = readdir ( $handle ))) {
2011-12-06 19:05:40 -04:00
2010-12-02 23:34:41 +00:00
if ( substr ( $file , 0 , 1 ) !== '.' ) {
2017-12-04 13:25:35 +00:00
if ( is_file ( $folder . '/' . $file ) ) {
2010-12-02 23:34:41 +00:00
checkFileStandardCode ( $folder . '/' . $file );
2011-12-06 19:05:40 -04:00
}
2010-12-02 23:34:41 +00:00
if ( is_dir ( $folder . '/' . $file ) && $bSubFolders ) {
2017-12-04 13:25:35 +00:00
checkFolderStandardCode ( $folder . '/' . $file , $bSubFolders );
2010-12-02 23:34:41 +00:00
}
2011-12-06 19:05:40 -04:00
}
2010-12-02 23:34:41 +00:00
}
}
2014-12-23 17:22:42 -04:00
} */
/*----------------------------------********---------------------------------*/
2011-12-06 19:05:40 -04:00
2014-12-23 17:22:42 -04:00
/*----------------------------------********---------------------------------*/
2017-12-04 13:25:35 +00:00
function run_check_standard_code ( $task , $options )
{
global $aFiles ;
$aFiles = array ();
if ( ! isset ( $options [ 0 ])) {
$folder = PATH_TRUNK . 'classes' ;
} else {
$folder = PATH_TRUNK . $options [ 0 ];
}
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
if ( ! isset ( $options [ 1 ])) {
$bSubFolders = false ;
} else {
$bSubFolders = strtolower ( $options [ 1 ]) == 'true' ;
}
2010-12-02 23:34:41 +00:00
2017-12-04 13:25:35 +00:00
printf ( " checking folder %s \n " , pakeColor :: colorize ( $folder , 'INFO' ));
checkFolderStandardCode ( $folder , $bSubFolders );
sort ( $aFiles );
foreach ( $aFiles as $key => $val ) {
printf (
" %s %s %s %s \n " ,
pakeColor :: colorize ( $val [ 'tab' ] ? 'tab' : ' ' , 'INFO' ),
2011-12-06 19:05:40 -04:00
pakeColor :: colorize ( $val [ 'utf' ] ? 'utf' : ' ' , 'INFO' ),
2017-12-04 13:25:35 +00:00
pakeColor :: colorize ( $val [ 'dos' ] ? 'dos' : ' ' , 'INFO' ),
$val [ 'file' ]
);
}
2010-12-02 23:34:41 +00:00
}
2014-12-23 17:22:42 -04:00
/*----------------------------------********---------------------------------*/
2014-10-09 14:16:08 -04:00
function run_update_plugin_attributes ( $task , $args )
{
try {
//Verify data
if ( ! isset ( $args [ 0 ])) {
throw new Exception ( " Error: You must specify the name of a plugin " );
}
//Set variables
$pluginName = $args [ 0 ];
2017-08-14 17:00:41 -04:00
// virtual SYS_SYS for cache
2017-10-06 17:21:21 -04:00
$sys_sys = uniqid ();
define ( 'SYS_SYS' , $sys_sys );
2017-10-10 12:33:25 -04:00
config ([ " system.workspace " => $sys_sys ]);
2017-08-14 15:58:34 -04:00
foreach ( PmSystem :: listWorkspaces () as $value ) {
\ProcessMaker\Util\Cnn :: connect ( $value -> name );
//Update plugin attributes
$pmPluginRegistry = PluginRegistry :: newInstance ();
$pmPluginRegistry -> updatePluginAttributesInAllWorkspaces ( $value -> name , $pluginName );
}
2014-10-09 14:16:08 -04:00
echo " Done! \n " ;
} catch ( Exception $e ) {
2017-08-14 15:58:34 -04:00
error_log ( $e -> getMessage () . " \n " );
2014-10-09 14:16:08 -04:00
}
}
2014-11-19 16:47:22 -04:00
function run_check_plugin_disabled_code ( $task , $args )
{
try {
//Set variables
2017-08-14 15:58:34 -04:00
$option = ( isset ( $args [ 0 ])) ? trim ( $args [ 0 ]) : " " ;
2014-11-19 16:47:22 -04:00
$option2 = strtoupper ( $option );
switch ( $option2 ) {
case " ENTERPRISE-PLUGIN " :
break ;
case " CUSTOM-PLUGIN " :
case " ALL " :
case " " :
break ;
default :
//PLUGIN-NAME
$option2 = " PLUGIN-NAME " ;
break ;
}
if ( is_dir ( PATH_PLUGINS )) {
if ( $dirh = opendir ( PATH_PLUGINS )) {
$arrayData = array ();
while (( $file = readdir ( $dirh )) !== false ) {
if ( preg_match ( " /^.+ \ .php $ / " , $file )) {
$pluginName = str_replace ( " .php " , " " , $file );
if ( is_file ( PATH_PLUGINS . $pluginName . " .php " ) && is_dir ( PATH_PLUGINS . $pluginName )) {
2016-07-14 12:16:12 -04:00
if ( preg_match (
2017-08-14 15:58:34 -04:00
'/^.*class\s+' . $pluginName . 'Plugin\s+extends\s+(\w*)\s*\{.*$/i' ,
str_replace ([ " \n " , " \r " , " \t " ], ' ' , file_get_contents ( PATH_PLUGINS . $pluginName . '.php' )),
$arrayMatch
)
2016-07-14 12:16:12 -04:00
) {
2014-11-26 14:42:25 -04:00
$pluginParentClassName = $arrayMatch [ 1 ];
switch ( $option2 ) {
case " ENTERPRISE-PLUGIN " :
if ( $pluginParentClassName == " enterprisePlugin " ) {
$arrayData [] = $pluginName ;
}
break ;
case " CUSTOM-PLUGIN " :
case " ALL " :
case " " :
if ( $pluginParentClassName == " PMPlugin " ) {
$arrayData [] = $pluginName ;
}
break ;
default :
//PLUGIN-NAME
if ( $pluginName == $option ) {
$arrayData [] = $pluginName ;
}
break ;
}
2014-11-19 16:47:22 -04:00
}
}
}
}
closedir ( $dirh );
//Verify data
if ( $option2 == " PLUGIN-NAME " && count ( $arrayData ) == 0 ) {
throw new Exception ( " Error: The plugin does not exist " );
}
//Check disabled code
if ( count ( $arrayData ) > 0 ) {
2016-07-18 17:54:28 -04:00
$cs = new CodeScanner ( true );
2014-11-19 16:47:22 -04:00
$strFoundDisabledCode = " " ;
foreach ( $arrayData as $value ) {
$pluginName = $value ;
$arrayFoundDisabledCode = array_merge ( $cs -> checkDisabledCode ( " FILE " , PATH_PLUGINS . $pluginName . " .php " ), $cs -> checkDisabledCode ( " PATH " , PATH_PLUGINS . $pluginName ));
2015-06-01 14:15:53 -04:00
if ( ! empty ( $arrayFoundDisabledCode )) {
2017-08-14 15:58:34 -04:00
$strFoundDisabledCode .= (( $strFoundDisabledCode != " " ) ? " \n \n " : " " ) . " > " . $pluginName ;
2014-11-19 16:47:22 -04:00
foreach ( $arrayFoundDisabledCode as $key2 => $value2 ) {
$strCodeAndLine = " " ;
foreach ( $value2 as $key3 => $value3 ) {
2017-08-14 15:58:34 -04:00
$strCodeAndLine .= (( $strCodeAndLine != " " ) ? " , " : " " ) . $key3 . " (Lines " . implode ( " , " , $value3 ) . " ) " ;
2014-11-19 16:47:22 -04:00
}
$strFoundDisabledCode .= " \n - " . str_replace ( PATH_PLUGINS , " " , $key2 ) . " : " . $strCodeAndLine ;
}
}
}
if ( $strFoundDisabledCode != " " ) {
echo " The next plugins have the following unwanted code (this code should be removed): \n \n " . $strFoundDisabledCode . " \n \n " ;
} else {
echo " The plugin(s) it's OK \n \n " ;
}
}
}
}
echo " Done! \n " ;
} catch ( Exception $e ) {
2017-08-14 15:58:34 -04:00
error_log ( $e -> getMessage () . " \n " );
2014-11-19 16:47:22 -04:00
}
}