/** * Upgrade the AppCacheView table to the latest system version. * * This recreates the table and populates with data. * * @param bool $checkOnly only check if the upgrade is needed if true * @param string $lang not currently used */ public function upgradeCacheView($fill = true) { $this->initPropel(true); $lang = "en"; require_once 'classes/model/AppCacheView.php'; //check the language, if no info in config about language, the default is 'en' G::loadClass('configuration'); $oConf = new Configurations(); $oConf->loadConfig($x, 'APP_CACHE_VIEW_ENGINE', '', '', '', ''); $appCacheViewEngine = $oConf->aConfig; //setup the appcacheview object, and the path for the sql files $appCache = new AppCacheView(); $appCache->setPathToAppCacheFiles(PATH_METHODS . 'setup' . PATH_SEP . 'setupSchemas' . PATH_SEP); $userGrants = $appCache->checkGrantsForUser(false); $currentUser = $userGrants['user']; $currentUserIsSuper = $userGrants['super']; //if user does not have the SUPER privilege we need to use the root user and grant the SUPER priv. to normal user. if (!$currentUserIsSuper) { $appCache->checkGrantsForUser(true); $appCache->setSuperForUser($currentUser); $currentUserIsSuper = true; } CLI::logging("-> Creating table\n"); //now check if table APPCACHEVIEW exists, and it have correct number of fields, etc. $res = $appCache->checkAppCacheView(); CLI::logging("-> Creating triggers\n"); //now check if we have the triggers installed $triggers = array(); $triggers[] = $appCache->triggerAppDelegationInsert($lang, $checkOnly); $triggers[] = $appCache->triggerAppDelegationUpdate($lang, $checkOnly); $triggers[] = $appCache->triggerApplicationUpdate($lang, $checkOnly); $triggers[] = $appCache->triggerApplicationDelete($lang, $checkOnly); $triggers[] = $appCache->triggerContentUpdate($lang, $checkOnly); if ($fill) { CLI::logging("-> Rebuild Cache View\n"); //build using the method in AppCacheView Class $res = $appCache->fillAppCacheView($lang); //set status in config table $confParams = array('LANG' => $lang, 'STATUS' => 'active'); } $oConf->aConfig = $confParams; $oConf->saveConfig('APP_CACHE_VIEW_ENGINE', '', '', ''); // removing casesList configuration records. TODO: removing these lines that resets all the configurations records $oCriteria = new Criteria(); $oCriteria->add(ConfigurationPeer::CFG_UID, "casesList"); $oCriteria->add(ConfigurationPeer::OBJ_UID, array("todo", "draft", "sent", "unassigned", "paused", "cancelled"), Criteria::NOT_IN); ConfigurationPeer::doDelete($oCriteria); // end of reset }
$lang = 'en'; try { //setup the appcacheview object, and the path for the sql files $appCache = new AppCacheView(); $appCache->setPathToAppCacheFiles(PATH_METHODS . 'setup' . PATH_SEP . 'setupSchemas' . PATH_SEP); //APP_DELEGATION INSERT $res = $appCache->triggerAppDelegationInsert($lang, true); //$result->info[] = array ('name' => 'Trigger APP_DELEGATION INSERT', 'value'=> $res); //APP_DELEGATION Update $res = $appCache->triggerAppDelegationUpdate($lang, true); //$result->info[] = array ('name' => 'Trigger APP_DELEGATION UPDATE', 'value'=> $res); //APPLICATION UPDATE $res = $appCache->triggerApplicationUpdate($lang, true); //$result->info[] = array ('name' => 'Trigger APPLICATION UPDATE', 'value'=> $res); //APPLICATION DELETE $res = $appCache->triggerApplicationDelete($lang, true); //$result->info[] = array ('name' => 'Trigger APPLICATION DELETE', 'value'=> $res); //CONTENT UPDATE $res = $appCache->triggerContentUpdate($lang, true); //$result->info[] = array("name" => "Trigger CONTENT UPDATE", "value" => $res); //build using the method in AppCacheView Class $res = $appCache->fillAppCacheView($lang); //$result->info[] = array ('name' => 'build APP_CACHE_VIEW', 'value'=> $res); //set status in config table $confParams = array('LANG' => $lang, 'STATUS' => 'active'); $conf->aConfig = $confParams; $conf->saveConfig('APP_CACHE_VIEW_ENGINE', '', '', ''); $response = new StdClass(); $result->success = true; $result->msg = "Completed successfully"; echo G::json_encode($result);
/** * Upgrade the AppCacheView table to the latest system version. * * This recreates the table and populates with data. * * @param bool $checkOnly only check if the upgrade is needed if true * @param string $lang not currently used */ public function upgradeCacheView($fill = true, $checkOnly = false, $lang = "en") { $this->initPropel(true); //require_once ('classes/model/AppCacheView.php'); //check the language, if no info in config about language, the default is 'en' G::LoadClass("configuration"); $oConf = new Configurations(); $oConf->loadConfig($x, 'APP_CACHE_VIEW_ENGINE', '', '', '', ''); $appCacheViewEngine = $oConf->aConfig; //setup the appcacheview object, and the path for the sql files $appCache = new AppCacheView(); $appCache->setPathToAppCacheFiles(PATH_METHODS . 'setup' . PATH_SEP . 'setupSchemas' . PATH_SEP); $userGrants = $appCache->checkGrantsForUser(false); $currentUser = $userGrants['user']; $currentUserIsSuper = $userGrants['super']; //if user does not have the SUPER privilege we need to use the root user and grant the SUPER priv. to normal user. if (!$currentUserIsSuper) { $appCache->checkGrantsForUser(true); $appCache->setSuperForUser($currentUser); $currentUserIsSuper = true; } CLI::logging("-> Creating tables \n"); //now check if table APPCACHEVIEW exists, and it have correct number of fields, etc. $res = $appCache->checkAppCacheView(); CLI::logging("-> Update DEL_LAST_INDEX field in APP_DELEGATION table \n"); //Update APP_DELEGATION.DEL_LAST_INDEX data $res = $appCache->updateAppDelegationDelLastIndex($lang, $checkOnly); CLI::logging("-> Verifying roles permissions in RBAC \n"); //Update table RBAC permissions Bootstrap::LoadSystem( 'rbac' ); $RBAC = & RBAC::getSingleton(); $RBAC->initRBAC(); $result = $RBAC->verifyPermissions(); if (count($result) > 1) { foreach ($result as $item) { CLI::logging(" $item... \n"); } } else { CLI::logging(" All roles permissions already updated \n"); } CLI::logging("-> Creating triggers\n"); //now check if we have the triggers installed $triggers = array(); $triggers[] = $appCache->triggerAppDelegationInsert($lang, $checkOnly); $triggers[] = $appCache->triggerAppDelegationUpdate($lang, $checkOnly); $triggers[] = $appCache->triggerApplicationUpdate($lang, $checkOnly); $triggers[] = $appCache->triggerApplicationDelete($lang, $checkOnly); $triggers[] = $appCache->triggerSubApplicationInsert($lang, $checkOnly); $triggers[] = $appCache->triggerContentUpdate($lang, $checkOnly); if ($fill) { CLI::logging("-> Rebuild Cache View with language $lang...\n"); //build using the method in AppCacheView Class $res = $appCache->fillAppCacheView($lang); } //set status in config table $confParams = Array('LANG' => $lang, 'STATUS' => 'active'); $oConf->aConfig = $confParams; $oConf->saveConfig('APP_CACHE_VIEW_ENGINE', '', '', ''); // removing casesList configuration records. TODO: removing these lines that resets all the configurations records $oCriteria = new Criteria(); $oCriteria->add(ConfigurationPeer::CFG_UID, "casesList"); $oCriteria->add(ConfigurationPeer::OBJ_UID, array("todo", "draft", "sent", "unassigned", "paused", "cancelled"), Criteria::NOT_IN); ConfigurationPeer::doDelete($oCriteria); // end of reset //close connection if (substr(PHP_OS, 0, 3) != 'WIN') { $connection = Propel::getConnection( 'workflow' ); $sql_sleep = "SELECT * FROM information_schema.processlist WHERE command = 'Sleep' and user = SUBSTRING_INDEX(USER(),'@',1) and db = DATABASE() ORDER BY id;"; $stmt_sleep = $connection->createStatement(); $rs_sleep = $stmt_sleep->executeQuery( $sql_sleep, ResultSet::FETCHMODE_ASSOC ); while ($rs_sleep->next()) { $row_sleep = $rs_sleep->getRow(); $oStatement_sleep = $connection->prepareStatement( "kill ". $row_sleep['ID'] ); $oStatement_sleep->executeQuery(); } $sql_query = "SELECT * FROM information_schema.processlist WHERE user = SUBSTRING_INDEX(USER(),'@',1) and db = DATABASE() and time > 0 ORDER BY id;"; $stmt_query = $connection->createStatement(); $rs_query = $stmt_query->executeQuery( $sql_query, ResultSet::FETCHMODE_ASSOC ); while ($rs_query->next()) { $row_query = $rs_query->getRow(); $oStatement_query = $connection->prepareStatement( "kill ". $row_query['ID'] ); $oStatement_query->executeQuery(); } } }
public function createMySQLWorkspace () { G::LoadSystem('inputfilter'); $filter = new InputFilter(); ini_set( 'max_execution_time', '0' ); $info = new StdClass(); $info->result = false; $info->message = ''; $info->canRedirect = true; $db_hostname = trim( $_REQUEST['db_hostname'] ); $db_port = trim( $_REQUEST['db_port'] ); $db_port = $filter->validateInput($db_port); $db_username = trim( $_REQUEST['db_username'] ); $db_username = $filter->validateInput($db_username); $db_password = trim( $_REQUEST['db_password'] ); $db_password = $filter->validateInput($db_password); $wf = trim( $_REQUEST['wfDatabase'] ); $rb = trim( $_REQUEST['wfDatabase'] ); $rp = trim( $_REQUEST['wfDatabase'] ); $workspace = trim( $_REQUEST['workspace'] ); $pathConfig = trim( $_REQUEST['pathConfig'] ); $pathLanguages = trim( $_REQUEST['pathLanguages'] ); $pathPlugins = trim( $_REQUEST['pathPlugins'] ); $pathShared = trim( $_REQUEST['pathShared'] ); $pathXmlforms = trim( $_REQUEST['pathXmlforms'] ); $adminPassword = trim( $_REQUEST['adminPassword'] ); $adminPassword = $filter->validateInput($adminPassword); $adminUsername = trim( $_REQUEST['adminUsername'] ); $adminUsername = $filter->validateInput($adminUsername); $deleteDB = ($_REQUEST['deleteDB'] == 'true'); $userLogged = (isset($_REQUEST['userLogged']) ? ($_REQUEST['userLogged'] == 'true') : false); $userLogged = $filter->validateInput($userLogged); if (substr( $pathShared, - 1 ) != '/') { $pathShared .= '/'; } $this->installLog( '-------------------------------------------' ); $this->installLog( G::LoadTranslation('ID_CREATING_WORKSPACE', SYS_LANG, Array($workspace))); try { $db_host = ($db_port != '' && $db_port != 3306) ? $db_hostname . ':' . $db_port : $db_hostname; $db_host = $filter->validateInput($db_host); $db_username = $filter->validateInput($db_username); $db_password = $filter->validateInput($db_password); $this->link = @mysql_connect( $db_host, $db_username, $db_password ); $this->installLog( G::LoadTranslation('ID_CONNECT_TO_SERVER', SYS_LANG, Array($db_hostname, $db_port, $db_username ) )); if ($deleteDB) { $q = sprintf( 'DROP DATABASE IF EXISTS %s;', $wf, $wf ); $this->mysqlQuery( $q ); } // CREATE databases wf_workflow, rb_workflow and rp_workflow $q = sprintf( 'CREATE DATABASE IF NOT EXISTS %s;', $wf, $wf ); $this->mysqlQuery( $q ); // CREATE users and GRANT Privileges $wf_workpace = $wf; $rb_workpace = $wf; $rp_workpace = $wf; if (!$userLogged) { $wfPass = G::generate_password( 12 ); $this->setGrantPrivilegesMySQL( $wf, $wfPass, $wf, $db_hostname ); $this->setGrantPrivilegesMySQL( $rb, $wfPass, $wf, $db_hostname ); $this->setGrantPrivilegesMySQL( $rp, $wfPass, $wf, $db_hostname ); } else { $wfPass = $db_password; $rbPass = $db_password; $rpPass = $db_password; $wf = $db_username; $rb = $db_username; $rp = $db_username; } // Generate the db.php file and folders $pathSharedSites = $pathShared; $path_site = $pathShared . "/sites/" . $workspace . "/"; $db_file = $path_site . "db.php"; @mkdir( $path_site, 0777, true ); @mkdir( $path_site . "files/", 0777, true ); @mkdir( $path_site . "mailTemplates/", 0777, true ); @mkdir( $path_site . "public/", 0777, true ); @mkdir( $path_site . "reports/", 0777, true ); @mkdir( $path_site . "xmlForms", 0777, true ); $dbText = "<?php\n"; $dbText .= sprintf( "// Processmaker configuration\n" ); $dbText .= sprintf( " define ('DB_ADAPTER', '%s' );\n", 'mysql' ); $dbText .= sprintf( " define ('DB_HOST', '%s' );\n", $db_host ); $dbText .= sprintf( " define ('DB_NAME', '%s' );\n", $wf_workpace ); $dbText .= sprintf( " define ('DB_USER', '%s' );\n", $wf ); $dbText .= sprintf( " define ('DB_PASS', '%s' );\n", $wfPass ); $dbText .= sprintf( " define ('DB_RBAC_HOST', '%s' );\n", $db_host ); $dbText .= sprintf( " define ('DB_RBAC_NAME', '%s' );\n", $wf_workpace ); $dbText .= sprintf( " define ('DB_RBAC_USER', '%s' );\n", $wf ); $dbText .= sprintf( " define ('DB_RBAC_PASS', '%s' );\n", $wfPass ); $dbText .= sprintf( " define ('DB_REPORT_HOST', '%s' );\n", $db_host ); $dbText .= sprintf( " define ('DB_REPORT_NAME', '%s' );\n", $wf_workpace ); $dbText .= sprintf( " define ('DB_REPORT_USER', '%s' );\n", $wf ); $dbText .= sprintf( " define ('DB_REPORT_PASS', '%s' );\n", $wfPass ); if (defined('PARTNER_FLAG') || isset($_REQUEST['PARTNER_FLAG'])) { $dbText .= "\n"; $dbText .= " define ('PARTNER_FLAG', " . ((defined('PARTNER_FLAG')) ? PARTNER_FLAG : ((isset($_REQUEST['PARTNER_FLAG'])) ? $_REQUEST['PARTNER_FLAG']:'false')) . ");\n"; if ($this->systemName != '') { $dbText .= " define ('SYSTEM_NAME', '" . $this->systemName . "');\n"; } } $this->installLog( G::LoadTranslation('ID_CREATING', SYS_LANG, Array($db_file) )); file_put_contents( $db_file, $dbText ); // Generate the databases.php file $databases_file = $path_site . 'databases.php'; $dbData = sprintf( "\$dbAdapter = '%s';\n", 'mysql' ); $dbData .= sprintf( "\$dbHost = '%s';\n", $db_host ); $dbData .= sprintf( "\$dbName = '%s';\n", $wf_workpace ); $dbData .= sprintf( "\$dbUser = '******';\n", $wf ); $dbData .= sprintf( "\$dbPass = '******';\n", $wfPass ); $dbData .= sprintf( "\$dbRbacHost = '%s';\n", $db_host ); $dbData .= sprintf( "\$dbRbacName = '%s';\n", $wf_workpace ); $dbData .= sprintf( "\$dbRbacUser = '******';\n", $wf ); $dbData .= sprintf( "\$dbRbacPass = '******';\n", $wfPass ); $dbData .= sprintf( "\$dbReportHost = '%s';\n", $db_host ); $dbData .= sprintf( "\$dbReportName = '%s';\n", $wf_workpace ); $dbData .= sprintf( "\$dbReportUser = '******';\n", $wf ); $dbData .= sprintf( "\$dbReportPass = '******';\n", $wfPass ); $databasesText = str_replace( '{dbData}', $dbData, @file_get_contents( PATH_HOME . 'engine/templates/installer/databases.tpl' ) ); $this->installLog( G::LoadTranslation('ID_CREATING', SYS_LANG, Array($databases_file) )); file_put_contents( $databases_file, $databasesText ); // Execute scripts to create and populates databases $query = sprintf( "USE %s;", $wf_workpace ); $this->mysqlQuery( $query ); $this->mysqlFileQuery( PATH_RBAC_HOME . 'engine/data/mysql/schema.sql' ); $this->mysqlFileQuery( PATH_RBAC_HOME . 'engine/data/mysql/insert.sql' ); $query = sprintf( "USE %s;", $wf_workpace ); $this->mysqlQuery( $query ); $this->mysqlFileQuery( PATH_HOME . 'engine/data/mysql/schema.sql' ); $this->mysqlFileQuery( PATH_HOME . 'engine/data/mysql/insert.sql' ); if (defined('PARTNER_FLAG') || isset($_REQUEST['PARTNER_FLAG'])) { $this->setPartner(); //$this->setConfiguration(); } // Create the triggers if (file_exists( PATH_HOME . 'engine/methods/setup/setupSchemas/triggerAppDelegationInsert.sql' ) && file_exists( PATH_HOME . 'engine/methods/setup/setupSchemas/triggerAppDelegationUpdate.sql' ) && file_exists( PATH_HOME . 'engine/methods/setup/setupSchemas/triggerApplicationUpdate.sql' ) && file_exists( PATH_HOME . 'engine/methods/setup/setupSchemas/triggerApplicationDelete.sql' ) && file_exists( PATH_HOME . 'engine/methods/setup/setupSchemas/triggerContentUpdate.sql' )) { $this->mysqlQuery( @file_get_contents( PATH_HOME . 'engine/methods/setup/setupSchemas/triggerAppDelegationInsert.sql' ) ); $this->mysqlQuery( @file_get_contents( PATH_HOME . 'engine/methods/setup/setupSchemas/triggerAppDelegationUpdate.sql' ) ); $this->mysqlQuery( @file_get_contents( PATH_HOME . 'engine/methods/setup/setupSchemas/triggerApplicationUpdate.sql' ) ); $this->mysqlQuery( @file_get_contents( PATH_HOME . 'engine/methods/setup/setupSchemas/triggerApplicationDelete.sql' ) ); $this->mysqlQuery(@file_get_contents(PATH_HOME . "engine/methods/setup/setupSchemas/triggerSubApplicationInsert.sql")); $this->mysqlQuery( @file_get_contents( PATH_HOME . 'engine/methods/setup/setupSchemas/triggerContentUpdate.sql' ) ); $this->mysqlQuery( "INSERT INTO `CONFIGURATION` ( `CFG_UID`, `CFG_VALUE` ) VALUES ( 'APP_CACHE_VIEW_ENGINE', '" . mysql_real_escape_string( serialize( array ('LANG' => 'en','STATUS' => 'active' ) ) ) . "' )" ); $this->mysqlQuery("INSERT INTO EMAIL_SERVER(MESS_UID, MESS_ENGINE) VALUES('" . \ProcessMaker\Util\Common::generateUID() . "', 'MAIL')"); } // Change admin user $query = sprintf( "USE %s;", $wf_workpace ); $this->mysqlQuery( $query ); $query = sprintf( "UPDATE USERS SET USR_USERNAME = '******', USR_LASTNAME = '%s', USR_PASSWORD = '******' WHERE USR_UID = '00000000000000000000000000000001' ", $adminUsername, $adminUsername, G::encryptOld( $adminPassword ) ); $this->mysqlQuery( $query ); $query = sprintf( "UPDATE RBAC_USERS SET USR_USERNAME = '******', USR_LASTNAME = '%s', USR_PASSWORD = '******' WHERE USR_UID = '00000000000000000000000000000001' ", $adminUsername, $adminUsername, G::encryptOld( $adminPassword ) ); $this->mysqlQuery( $query ); // Write the paths_installed.php file (contains all the information configured so far) if (! file_exists( FILE_PATHS_INSTALLED )) { $sh = G::encryptOld( filemtime( PATH_GULLIVER . '/class.g.php' ) ); $h = G::encrypt( $db_hostname . $sh . $db_username . $sh . $db_password, $sh ); $dbText = "<?php\n"; $dbText .= sprintf( " define('PATH_DATA', '%s');\n", $pathShared ); $dbText .= sprintf( " define('PATH_C', '%s');\n", $pathShared . 'compiled/' ); $dbText .= sprintf( " define('HASH_INSTALLATION', '%s');\n", $h ); $dbText .= sprintf( " define('SYSTEM_HASH', '%s');\n", $sh ); $this->installLog( G::LoadTranslation('ID_CREATING', SYS_LANG, Array(FILE_PATHS_INSTALLED) )); file_put_contents( FILE_PATHS_INSTALLED, $dbText ); } /** * AppCacheView Build */ define( 'HASH_INSTALLATION', $h ); define( 'SYSTEM_HASH', $sh ); define( 'PATH_DB', $pathShared . 'sites' . PATH_SEP ); define( 'SYS_SYS', $workspace ); require_once ("propel/Propel.php"); Propel::init( PATH_CORE . "config/databases.php" ); $con = Propel::getConnection( 'workflow' ); require_once ('classes/model/AppCacheView.php'); $lang = 'en'; //setup the appcacheview object, and the path for the sql files $appCache = new AppCacheView(); $appCache->setPathToAppCacheFiles( PATH_METHODS . 'setup' . PATH_SEP . 'setupSchemas' . PATH_SEP ); //Update APP_DELEGATION.DEL_LAST_INDEX data $res = $appCache->updateAppDelegationDelLastIndex($lang, true); //APP_DELEGATION INSERT $res = $appCache->triggerAppDelegationInsert( $lang, true ); //APP_DELEGATION Update $res = $appCache->triggerAppDelegationUpdate( $lang, true ); //APPLICATION UPDATE $res = $appCache->triggerApplicationUpdate( $lang, true ); //APPLICATION DELETE $res = $appCache->triggerApplicationDelete( $lang, true ); //SUB_APPLICATION INSERT $res = $appCache->triggerSubApplicationInsert($lang, false); //CONTENT UPDATE $res = $appCache->triggerContentUpdate( $lang, true ); //build using the method in AppCacheView Class $res = $appCache->fillAppCacheView( $lang ); //end AppCacheView Build //erik: for new env conf handling G::loadClass( 'system' ); $envFile = PATH_CONFIG . 'env.ini'; // getting configuration from env.ini $sysConf = System::getSystemConfiguration( $envFile ); $langUri = 'en'; if (isset($sysConf['default_lang'])) { $langUri = $sysConf['default_lang']; } $skinUri = 'neoclassic'; if (isset($sysConf['default_skin'])) { $skinUri = $sysConf['default_skin']; } $updatedConf['default_lang'] = $langUri; $updatedConf['default_skin'] = $skinUri; $info->uri = PATH_SEP . 'sys' . $_REQUEST['workspace'] . PATH_SEP . $langUri . PATH_SEP . $skinUri . PATH_SEP . 'login' . PATH_SEP . 'login'; //register PMDesigner Client $http = (G::is_https() == true) ? 'https' : 'http'; $host = $_SERVER['SERVER_NAME'] . ($_SERVER['SERVER_PORT'] != '80' ? ':' . $_SERVER['SERVER_PORT'] : ''); $endpoint = sprintf( '%s://%s/sys%s/%s/%s/oauth2/grant', $http, $host, $workspace, $langUri, $skinUri ); // inserting the outh_client if (!$userLogged) { $query = sprintf( "USE %s;", $wf ); } else { $query = sprintf( "USE %s;", trim( $_REQUEST['wfDatabase']) ); } $this->mysqlQuery( $query ); $query = ( "INSERT INTO OAUTH_CLIENTS (CLIENT_ID,CLIENT_SECRET,CLIENT_NAME,CLIENT_DESCRIPTION,CLIENT_WEBSITE,REDIRECT_URI,USR_UID ) VALUES ('x-pm-local-client','179ad45c6ce2cb97cf1029e212046e81','PM Web Designer','ProcessMaker Web Designer App','www.processmaker.com','" . $endpoint . "','00000000000000000000000000000001' )"); $this->mysqlQuery( $query ); $indexFileUpdated = true; if (defined('PARTNER_FLAG') || isset($_REQUEST['PARTNER_FLAG'])) { $this->buildParternExtras($adminUsername, $adminPassword, $_REQUEST['workspace'], $langUri, $skinUri); } else { try { G::update_php_ini( $envFile, $updatedConf ); } catch (Exception $e) { $info->result = false; $info->message = G::LoadTranslation('ID_PROCESSMAKER_WRITE_CONFIG_INDEX', SYS_LANG, Array($envFile)); $info->message .= G::LoadTranslation('ID_PROCESSMAKER_UI_NOT_INSTALL'); $this->installLog( G::LoadTranslation('ID_INSTALL_BUT_ERROR', SYS_LANG, Array('env.ini'))); return $info; } try { // update the main index file $indexFileUpdated = System::updateIndexFile(array('lang' => 'en','skin' => $updatedConf['default_skin'])); } catch (Exception $e) { $info->result = false; $info->message = G::LoadTranslation('ID_PROCESSMAKER_WRITE_CONFIG_INDEX', SYS_LANG, Array(PATH_HTML . "index.html.")); $info->message .= G::LoadTranslation('ID_PROCESSMAKER_UI_NOT_INSTALL'); $this->installLog( G::LoadTranslation('ID_INSTALL_BUT_ERROR', SYS_LANG, Array('index.html'))); return $info; } } $this->installLog( G::LoadTranslation('ID_INDEX_FILE_UPDATED', SYS_LANG, Array($indexFileUpdated, $sysConf['default_lang'],$sysConf['default_skin']))); $this->installLog( G::LoadTranslation('ID_INSTALL_SUCESS') ); $info->result = true; $info->message = G::LoadTranslation('ID_INSTALL_SUCESS'); $info->messageFinish = G::LoadTranslation('ID_PROCESSMAKER_SUCCESS_INSTALLED', SYS_LANG, Array($workspace));; } catch (Exception $e) { $info->canRedirect = false; $info->result = false; $info->message = $e->getMessage(); } return $info; }
/** * Upgrade the AppCacheView table to the latest system version. * * This recreates the table and populates with data. * * @param bool $checkOnly only check if the upgrade is needed if true * @param string $lang not currently used */ public function upgradeCacheView($fill = true, $checkOnly = false, $lang = "en") { $this->initPropel(true); //require_once ('classes/model/AppCacheView.php'); //check the language, if no info in config about language, the default is 'en' G::LoadClass("configuration"); $oConf = new Configurations(); $oConf->loadConfig($x, 'APP_CACHE_VIEW_ENGINE', '', '', '', ''); $appCacheViewEngine = $oConf->aConfig; //setup the appcacheview object, and the path for the sql files $appCache = new AppCacheView(); $appCache->setPathToAppCacheFiles(PATH_METHODS . 'setup' . PATH_SEP . 'setupSchemas' . PATH_SEP); $userGrants = $appCache->checkGrantsForUser(false); $currentUser = $userGrants['user']; $currentUserIsSuper = $userGrants['super']; //if user does not have the SUPER privilege we need to use the root user and grant the SUPER priv. to normal user. if (!$currentUserIsSuper) { $appCache->checkGrantsForUser(true); $appCache->setSuperForUser($currentUser); $currentUserIsSuper = true; } CLI::logging("-> Creating table\n"); //now check if table APPCACHEVIEW exists, and it have correct number of fields, etc. $res = $appCache->checkAppCacheView(); CLI::logging("-> Update DEL_LAST_INDEX field in APP_DELEGATION table\n"); //Update APP_DELEGATION.DEL_LAST_INDEX data $res = $appCache->updateAppDelegationDelLastIndex($lang, $checkOnly); CLI::logging("-> Verifying roles permissions in RBAC \n"); //Update table RBAC permissions Bootstrap::LoadSystem('rbac'); $RBAC =& RBAC::getSingleton(); $RBAC->initRBAC(); $result = $RBAC->verifyPermissions(); if (count($result) > 1) { foreach ($result as $item) { CLI::logging(" {$item}... \n"); } } else { CLI::logging(" All roles permissions already updated \n"); } CLI::logging("-> Creating triggers\n"); //now check if we have the triggers installed $triggers = array(); $triggers[] = $appCache->triggerAppDelegationInsert($lang, $checkOnly); $triggers[] = $appCache->triggerAppDelegationUpdate($lang, $checkOnly); $triggers[] = $appCache->triggerApplicationUpdate($lang, $checkOnly); $triggers[] = $appCache->triggerApplicationDelete($lang, $checkOnly); $triggers[] = $appCache->triggerSubApplicationInsert($lang, $checkOnly); $triggers[] = $appCache->triggerContentUpdate($lang, $checkOnly); if ($fill) { CLI::logging("-> Rebuild Cache View with language {$lang}...\n"); //build using the method in AppCacheView Class $res = $appCache->fillAppCacheView($lang); //set status in config table $confParams = array('LANG' => $lang, 'STATUS' => 'active'); } $oConf->aConfig = $confParams; $oConf->saveConfig('APP_CACHE_VIEW_ENGINE', '', '', ''); // removing casesList configuration records. TODO: removing these lines that resets all the configurations records $oCriteria = new Criteria(); $oCriteria->add(ConfigurationPeer::CFG_UID, "casesList"); $oCriteria->add(ConfigurationPeer::OBJ_UID, array("todo", "draft", "sent", "unassigned", "paused", "cancelled"), Criteria::NOT_IN); ConfigurationPeer::doDelete($oCriteria); // end of reset }
public function createMySQLWorkspace() { ini_set('max_execution_time', '0'); $info->result = false; $info->message = ''; $info->canRedirect = true; $db_hostname = trim($_REQUEST['db_hostname']); $db_port = trim($_REQUEST['db_port']); $db_username = trim($_REQUEST['db_username']); $db_password = trim($_REQUEST['db_password']); $wf = trim($_REQUEST['wfDatabase']); $rb = trim($_REQUEST['rbDatabase']); $rp = trim($_REQUEST['rpDatabase']); $workspace = trim($_REQUEST['workspace']); $pathConfig = trim($_REQUEST['pathConfig']); $pathLanguages = trim($_REQUEST['pathLanguages']); $pathPlugins = trim($_REQUEST['pathPlugins']); $pathShared = trim($_REQUEST['pathShared']); $pathXmlforms = trim($_REQUEST['pathXmlforms']); $adminPassword = trim($_REQUEST['adminPassword']); $adminUsername = trim($_REQUEST['adminUsername']); $deleteDB = $_REQUEST['deleteDB'] == 'true'; if (substr($pathShared, -1) != '/') { $pathShared .= '/'; } $this->installLog('-------------------------------------------'); $this->installLog(sprintf("Creating workspace '%s' ", $workspace)); try { $db_host = $db_port != '' && $db_port != 3306 ? $db_hostname . ':' . $db_port : $db_hostname; $this->link = @mysql_connect($db_host, $db_username, $db_password); $this->installLog(sprintf("Connected to server %s:%d using user: '******' ", $db_hostname, $db_port, $db_username)); if ($deleteDB) { $q = sprintf('DROP DATABASE IF EXISTS %s;', $wf, $wf); $this->mysqlQuery($q); $q = sprintf('DROP DATABASE IF EXISTS %s;', $rb, $rb); $this->mysqlQuery($q); $q = sprintf('DROP DATABASE IF EXISTS %s;', $rp, $rp); $this->mysqlQuery($q); } // CREATE databases wf_workflow, rb_workflow and rp_workflow $q = sprintf('CREATE DATABASE IF NOT EXISTS %s;', $wf, $wf); $this->mysqlQuery($q); $q = sprintf('CREATE DATABASE IF NOT EXISTS %s;', $rb, $rb); $this->mysqlQuery($q); $q = sprintf('CREATE DATABASE IF NOT EXISTS %s;', $rp, $rp); $this->mysqlQuery($q); // CREATE users and GRANT Privileges $wfPass = G::generate_password(12); $rbPass = G::generate_password(12); $rpPass = G::generate_password(12); $this->setGrantPrivilegesMySQL($wf, $wfPass, $wf, $db_hostname); $this->setGrantPrivilegesMySQL($rb, $rbPass, $rb, $db_hostname); $this->setGrantPrivilegesMySQL($rp, $rpPass, $rp, $db_hostname); // Generate the db.php file and folders $path_site = $pathShared . "/sites/" . $workspace . "/"; $db_file = $path_site . "db.php"; @mkdir($path_site, 0777, true); @mkdir($path_site . "files/", 0777, true); @mkdir($path_site . "mailTemplates/", 0777, true); @mkdir($path_site . "public/", 0777, true); @mkdir($path_site . "reports/", 0777, true); @mkdir($path_site . "xmlForms", 0777, true); $dbText = "<?php\n"; $dbText .= sprintf("// Processmaker configuration\n"); $dbText .= sprintf(" define ('DB_ADAPTER', '%s' );\n", 'mysql'); $dbText .= sprintf(" define ('DB_HOST', '%s' );\n", $db_host); $dbText .= sprintf(" define ('DB_NAME', '%s' );\n", $wf); $dbText .= sprintf(" define ('DB_USER', '%s' );\n", $wf); $dbText .= sprintf(" define ('DB_PASS', '%s' );\n", $wfPass); $dbText .= sprintf(" define ('DB_RBAC_HOST', '%s' );\n", $db_host); $dbText .= sprintf(" define ('DB_RBAC_NAME', '%s' );\n", $rb); $dbText .= sprintf(" define ('DB_RBAC_USER', '%s' );\n", $rb); $dbText .= sprintf(" define ('DB_RBAC_PASS', '%s' );\n", $rbPass); $dbText .= sprintf(" define ('DB_REPORT_HOST', '%s' );\n", $db_host); $dbText .= sprintf(" define ('DB_REPORT_NAME', '%s' );\n", $rp); $dbText .= sprintf(" define ('DB_REPORT_USER', '%s' );\n", $rp); $dbText .= sprintf(" define ('DB_REPORT_PASS', '%s' );\n", $rpPass); $this->installLog("Creating: " . $db_file); file_put_contents($db_file, $dbText); // Generate the databases.php file $databases_file = $path_site . 'databases.php'; $dbData = sprintf("\$dbAdapter = '%s';\n", 'mysql'); $dbData .= sprintf("\$dbHost = '%s';\n", $db_host); $dbData .= sprintf("\$dbName = '%s';\n", $wf); $dbData .= sprintf("\$dbUser = '******';\n", $wf); $dbData .= sprintf("\$dbPass = '******';\n", $wfPass); $dbData .= sprintf("\$dbRbacHost = '%s';\n", $db_host); $dbData .= sprintf("\$dbRbacName = '%s';\n", $rb); $dbData .= sprintf("\$dbRbacUser = '******';\n", $rb); $dbData .= sprintf("\$dbRbacPass = '******';\n", $rbPass); $dbData .= sprintf("\$dbReportHost = '%s';\n", $db_host); $dbData .= sprintf("\$dbReportName = '%s';\n", $rp); $dbData .= sprintf("\$dbReportUser = '******';\n", $rp); $dbData .= sprintf("\$dbReportPass = '******';\n", $rpPass); $databasesText = str_replace('{dbData}', $dbData, @file_get_contents(PATH_HOME . 'engine/templates/installer/databases.tpl')); $this->installLog('Creating: ' . $databases_file); file_put_contents($databases_file, $databasesText); // Execute scripts to create and populates databases $query = sprintf("USE %s;", $rb); $this->mysqlQuery($query); $this->mysqlFileQuery(PATH_RBAC_HOME . 'engine/data/mysql/schema.sql'); $this->mysqlFileQuery(PATH_RBAC_HOME . 'engine/data/mysql/insert.sql'); $query = sprintf("USE %s;", $wf); $this->mysqlQuery($query); $this->mysqlFileQuery(PATH_HOME . 'engine/data/mysql/schema.sql'); $this->mysqlFileQuery(PATH_HOME . 'engine/data/mysql/insert.sql'); // Create the triggers if (file_exists(PATH_HOME . 'engine/methods/setup/setupSchemas/triggerAppDelegationInsert.sql') && file_exists(PATH_HOME . 'engine/methods/setup/setupSchemas/triggerAppDelegationUpdate.sql') && file_exists(PATH_HOME . 'engine/methods/setup/setupSchemas/triggerApplicationUpdate.sql') && file_exists(PATH_HOME . 'engine/methods/setup/setupSchemas/triggerApplicationDelete.sql') && file_exists(PATH_HOME . 'engine/methods/setup/setupSchemas/triggerContentUpdate.sql')) { $this->mysqlQuery(@file_get_contents(PATH_HOME . 'engine/methods/setup/setupSchemas/triggerAppDelegationInsert.sql')); $this->mysqlQuery(@file_get_contents(PATH_HOME . 'engine/methods/setup/setupSchemas/triggerAppDelegationUpdate.sql')); $this->mysqlQuery(@file_get_contents(PATH_HOME . 'engine/methods/setup/setupSchemas/triggerApplicationUpdate.sql')); $this->mysqlQuery(@file_get_contents(PATH_HOME . 'engine/methods/setup/setupSchemas/triggerApplicationDelete.sql')); $this->mysqlQuery(@file_get_contents(PATH_HOME . 'engine/methods/setup/setupSchemas/triggerContentUpdate.sql')); $this->mysqlQuery("INSERT INTO `CONFIGURATION` (\n `CFG_UID`,\n `CFG_VALUE`\n )\n VALUES (\n 'APP_CACHE_VIEW_ENGINE',\n '" . mysql_real_escape_string(serialize(array('LANG' => 'en', 'STATUS' => 'active'))) . "'\n )"); } // Change admin user $query = sprintf("USE %s;", $wf); $this->mysqlQuery($query); $query = sprintf("UPDATE USERS SET USR_USERNAME = '******', USR_PASSWORD = '******' WHERE USR_UID = '00000000000000000000000000000001' ", $adminUsername, md5($adminPassword)); $this->mysqlQuery($query); $query = sprintf("USE %s;", $rb); $this->mysqlQuery($query); $query = sprintf("UPDATE USERS SET USR_USERNAME = '******', USR_PASSWORD = '******' WHERE USR_UID = '00000000000000000000000000000001' ", $adminUsername, md5($adminPassword)); $this->mysqlQuery($query); // Write the paths_installed.php file (contains all the information configured so far) if (!file_exists(FILE_PATHS_INSTALLED)) { $sh = md5(filemtime(PATH_GULLIVER . '/class.g.php')); $h = G::encrypt($db_hostname . $sh . $db_username . $sh . $db_password, $sh); $dbText = "<?php\n"; $dbText .= sprintf(" define('PATH_DATA', '%s');\n", $pathShared); $dbText .= sprintf(" define('PATH_C', '%s');\n", $pathShared . 'compiled/'); $dbText .= sprintf(" define('HASH_INSTALLATION', '%s');\n", $h); $dbText .= sprintf(" define('SYSTEM_HASH', '%s');\n", $sh); $this->installLog("Creating: " . FILE_PATHS_INSTALLED); file_put_contents(FILE_PATHS_INSTALLED, $dbText); } /** * AppCacheView Build */ define('HASH_INSTALLATION', $h); define('SYSTEM_HASH', $sh); define('PATH_DB', $pathShared . 'sites' . PATH_SEP); define('SYS_SYS', 'workflow'); require_once "propel/Propel.php"; Propel::init(PATH_CORE . "config/databases.php"); $con = Propel::getConnection('workflow'); require_once 'classes/model/AppCacheView.php'; $lang = 'en'; //setup the appcacheview object, and the path for the sql files $appCache = new AppCacheView(); $appCache->setPathToAppCacheFiles(PATH_METHODS . 'setup' . PATH_SEP . 'setupSchemas' . PATH_SEP); //APP_DELEGATION INSERT $res = $appCache->triggerAppDelegationInsert($lang, true); //APP_DELEGATION Update $res = $appCache->triggerAppDelegationUpdate($lang, true); //APPLICATION UPDATE $res = $appCache->triggerApplicationUpdate($lang, true); //APPLICATION DELETE $res = $appCache->triggerApplicationDelete($lang, true); //CONTENT UPDATE $res = $appCache->triggerContentUpdate($lang, true); //build using the method in AppCacheView Class $res = $appCache->fillAppCacheView($lang); //end AppCacheView Build //erik: for new env conf handling G::loadClass('system'); $envFile = PATH_CONFIG . 'env.ini'; //writting for new installtions to use the new skin 'uxmind' with new Front End ExtJs Based $updatedConf['default_skin'] = 'uxmodern'; $info->uri = '/sys' . $_REQUEST['workspace'] . '/en/uxmodern/main/login'; try { G::update_php_ini($envFile, $updatedConf); } catch (Exception $e) { $info->result = false; $info->message = "ProcessMaker couldn't write on configuration file: {$envFile}.<br/>"; $info->message .= "The new ProcessMaker UI couldn't be applied on installation, you can enable it after from Admin->System settings."; $this->installLog("Installed but with error, couldn't update env.ini"); return $info; } // getting configuration from env.ini $sysConf = System::getSystemConfiguration($envFile); try { // update the main index file $indexFileUpdated = System::updateIndexFile(array('lang' => 'en', 'skin' => $updatedConf['default_skin'])); } catch (Exception $e) { $info->result = false; $info->message = "ProcessMaker couldn't write on configuration file: " . PATH_HTML . "index.html.<br/>"; $info->message .= "The new ProcessMaker UI couldn't be applied on installation, you can enable it after from Admin->System settings."; $this->installLog("Installed but with error, couldn't update index.html"); return $info; } $this->installLog("Index File updated {$indexFileUpdated} with lang: {$sysConf['default_lang']}, skin: {$sysConf['default_skin']} "); $this->installLog("Install completed Succesfully"); $info->result = true; $info->message = 'Succesfully OK'; } catch (Exception $e) { $info->canRedirect = false; $info->result = false; $info->message = $e->getMessage(); } return $info; }
/** * Upgrade triggers of tables (Database) * * @param bool $flagRecreate Recreate * @param string $language Language * * return void */ private function upgradeTriggersOfTables($flagRecreate, $language) { try { $appCacheView = new AppCacheView(); $appCacheView->setPathToAppCacheFiles(PATH_METHODS . "setup" . PATH_SEP . "setupSchemas" . PATH_SEP); $result = $appCacheView->triggerAppDelegationInsert($language, $flagRecreate); $result = $appCacheView->triggerAppDelegationUpdate($language, $flagRecreate); $result = $appCacheView->triggerApplicationUpdate($language, $flagRecreate); $result = $appCacheView->triggerApplicationDelete($language, $flagRecreate); $result = $appCacheView->triggerSubApplicationInsert($language, $flagRecreate); $result = $appCacheView->triggerContentUpdate($language, $flagRecreate); } catch (Exception $e) { throw $e; } }