/** * make_site * * @return array $test */ private function make_site() { $test = $this->create_site_test(); if ($test["created"] == true || $this->options["advanced"]["ao_db_drop"] == true) { /* Check if the hostname is local (localhost or 127.0.0.1) */ $islocal = (strcmp(substr($this->options['database']['hostname'], 0, strlen('localhost')), 'localhost') === 0) || (strcmp(substr($this->options['database']['hostname'], 0, strlen('127.0.0.1')), '127.0.0.1') === 0); $this->wf_site_name = $wf = $this->options['advanced']['ao_db_wf']; $this->rbac_site_name = $rb = $this->options['advanced']['ao_db_rb']; $this->report_site_name = $rp = $this->options['advanced']['ao_db_rp']; $schema = "schema.sql"; $values = "insert.sql"; if ($this->options['advanced']['ao_db_drop'] === true) { //Delete workspace directory if exists //Drop databases $this->run_query("DROP DATABASE IF EXISTS " . $wf, "Drop database $wf"); } $this->run_query("CREATE DATABASE IF NOT EXISTS " . $wf . " DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci", "Create database $wf"); if ($this->cc_status == 1) { $host = ($islocal) ? "localhost" : "%"; $this->run_query("GRANT ALL PRIVILEGES ON `$wf`.* TO $wf@'$host' IDENTIFIED BY '{$this->options['password']}' WITH GRANT OPTION", "Grant privileges for user $wf on database $wf"); } /* Dump schema workflow && data */ $this->log("Import database schema:\n"); $myPortA = explode(":", $this->options['database']['hostname']); if (count($myPortA) < 2) { $myPortA[1] = "3306"; } $myPort = $myPortA[1]; $this->options['database']['hostname'] = $myPortA[0]; mysql_select_db($wf, $this->connection_database); $pws = PATH_WORKFLOW_MYSQL_DATA . $schema; $qws = $this->query_sql_file(PATH_WORKFLOW_MYSQL_DATA . $schema, $this->connection_database); $this->log($qws, isset($qws['errors'])); $qwv = $this->query_sql_file(PATH_WORKFLOW_MYSQL_DATA . $values, $this->connection_database); $this->log($qwv, isset($qwv['errors'])); $http = (G::is_https() == true) ? 'https' : 'http'; $lang = defined( 'SYS_LANG' ) ? SYS_LANG : 'en'; $host = $_SERVER['SERVER_NAME'] . ($_SERVER['SERVER_PORT'] != '80' ? ':' . $_SERVER['SERVER_PORT'] : ''); $workspace = $this->options['name']; $endpoint = sprintf( '%s://%s/sys%s/%s/%s/oauth2/grant', $http, $host, $workspace, $lang, SYS_SKIN ); // inserting the outh_client $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->run_query( $query ); /* Dump schema rbac && data */ $pws = PATH_RBAC_MYSQL_DATA . $schema; mysql_select_db($rb, $this->connection_database); $qrs = $this->query_sql_file(PATH_RBAC_MYSQL_DATA . $schema, $this->connection_database); $this->log($qrs, isset($qrs['errors'])); $qrv = $this->query_sql_file(PATH_RBAC_MYSQL_DATA . $values, $this->connection_database); $this->log($qrv, isset($qrv['errors'])); mysql_select_db($wf, $this->connection_database); require_once ("propel/Propel.php"); require_once ('classes/model/AppCacheView.php'); $appCache = new AppCacheView(); $appCache->setPathToAppCacheFiles(PATH_METHODS . 'setup/setupSchemas/'); $triggers = $appCache->getTriggers("en"); $this->log("Create 'cases list cache' triggers"); foreach ($triggers as $triggerName => $trigger) { $this->run_query($trigger, "-> Trigger $triggerName"); } $path_site = $this->options['path_data'] . "/sites/" . $this->options['name'] . "/"; $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); $db_text = "<?php\n" . "// Processmaker configuration\n" . "define ('DB_ADAPTER', 'mysql' );\n" . "define ('DB_HOST', '" . $this->options['database']['hostname'] . ":" . $myPort . "' );\n" . "define ('DB_NAME', '" . $wf . "' );\n" . "define ('DB_USER', '" . (($this->cc_status == 1) ? $wf : $this->options['database']['username']) . "' );\n" . "define ('DB_PASS', '" . (($this->cc_status == 1) ? $this->options['password'] : $this->options['database']['password']) . "' );\n" . "define ('DB_RBAC_HOST', '" . $this->options['database']['hostname'] . ":" . $myPort . "' );\n" . "define ('DB_RBAC_NAME', '" . $rb . "' );\n" . "define ('DB_RBAC_USER', '" . (($this->cc_status == 1) ? $rb : $this->options['database']['username']) . "' );\n" . "define ('DB_RBAC_PASS', '" . (($this->cc_status == 1) ? $this->options['password'] : $this->options['database']['password']) . "' );\n" . "define ('DB_REPORT_HOST', '" . $this->options['database']['hostname'] . ":" . $myPort . "' );\n" . "define ('DB_REPORT_NAME', '" . $rp . "' );\n" . "define ('DB_REPORT_USER', '" . (($this->cc_status == 1) ? $rp : $this->options['database']['username']) . "' );\n" . "define ('DB_REPORT_PASS', '" . (($this->cc_status == 1) ? $this->options['password'] : $this->options['database']['password']) . "' );\n"; if (defined('PARTNER_FLAG') || isset($_REQUEST['PARTNER_FLAG'])) { $db_text .= "define ('PARTNER_FLAG', " . ((defined('PARTNER_FLAG') && PARTNER_FLAG != '') ? PARTNER_FLAG : ((isset($_REQUEST['PARTNER_FLAG'])) ? $_REQUEST['PARTNER_FLAG']:'false')) . ");\n"; if (defined('SYSTEM_NAME')) { $db_text .= " define ('SYSTEM_NAME', '" . SYSTEM_NAME . "');\n"; } } $db_text .="?>"; $fp = @fopen($db_file, "w"); $this->log("Create: " . $db_file . " => " . ((!$fp) ? $fp : "OK") . "\n", $fp === false); $ff = @fputs($fp, $db_text, strlen($db_text)); $this->log("Write: " . $db_file . " => " . ((!$ff) ? $ff : "OK") . "\n", $ff === false); fclose($fp); $this->setPartner(); $this->setAdmin(); $querySql = "INSERT INTO EMAIL_SERVER(MESS_UID, MESS_ENGINE) VALUES('" . \ProcessMaker\Util\Common::generateUID() . "', 'MAIL')"; $this->run_query($querySql); } return $test; }
/** * make_site * * @return array $test */ private function make_site() { $test = $this->create_site_test(); if ($test["created"] == true || $this->options["advanced"]["ao_db_drop"] == true) { /* Check if the hostname is local (localhost or 127.0.0.1) */ $islocal = strcmp(substr($this->options['database']['hostname'], 0, strlen('localhost')), 'localhost') === 0 || strcmp(substr($this->options['database']['hostname'], 0, strlen('127.0.0.1')), '127.0.0.1') === 0; $this->wf_site_name = $wf = $this->options['advanced']['ao_db_wf']; $this->rbac_site_name = $rb = $this->options['advanced']['ao_db_rb']; $this->report_site_name = $rp = $this->options['advanced']['ao_db_rp']; $schema = "schema.sql"; $values = "insert.sql"; if ($this->options['advanced']['ao_db_drop'] === true) { //Delete workspace directory if exists //Drop databases $this->run_query("DROP DATABASE IF EXISTS " . $wf, "Drop database {$wf}"); $this->run_query("DROP DATABASE IF EXISTS " . $rb, "Drop database {$rb}"); $this->run_query("DROP DATABASE IF EXISTS " . $rp, "Drop database {$rp}"); } $this->run_query("CREATE DATABASE IF NOT EXISTS " . $wf . " DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci", "Create database {$wf}"); $this->run_query("CREATE DATABASE IF NOT EXISTS " . $rb . " DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci", "Create database {$rb}"); $this->run_query("CREATE DATABASE IF NOT EXISTS " . $rp . " DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci", "Create database {$rp}"); if ($this->cc_status == 1) { $host = $islocal ? "localhost" : "%"; $this->run_query("GRANT ALL PRIVILEGES ON `{$wf}`.* TO {$wf}@'{$host}' IDENTIFIED BY '{$this->options['password']}' WITH GRANT OPTION", "Grant privileges for user {$wf} on database {$wf}"); $this->run_query("GRANT ALL PRIVILEGES ON `{$rb}`.* TO {$rb}@'{$host}' IDENTIFIED BY '{$this->options['password']}' WITH GRANT OPTION", "Grant privileges for user {$rb} on database {$rb}"); $this->run_query("GRANT ALL PRIVILEGES ON `{$rp}`.* TO {$rp}@'{$host}' IDENTIFIED BY '{$this->options['password']}' WITH GRANT OPTION", "Grant privileges for user {$rp} on database {$rp}"); } /* Dump schema workflow && data */ $this->log("Import database schema:\n"); $myPortA = explode(":", $this->options['database']['hostname']); if (count($myPortA) < 2) { $myPortA[1] = "3306"; } $myPort = $myPortA[1]; $this->options['database']['hostname'] = $myPortA[0]; mysql_select_db($wf, $this->connection_database); $pws = PATH_WORKFLOW_MYSQL_DATA . $schema; $qws = $this->query_sql_file(PATH_WORKFLOW_MYSQL_DATA . $schema, $this->connection_database); $this->log($qws, isset($qws['errors'])); $qwv = $this->query_sql_file(PATH_WORKFLOW_MYSQL_DATA . $values, $this->connection_database); $this->log($qwv, isset($qwv['errors'])); /* Dump schema rbac && data */ $pws = PATH_RBAC_MYSQL_DATA . $schema; mysql_select_db($rb, $this->connection_database); $qrs = $this->query_sql_file(PATH_RBAC_MYSQL_DATA . $schema, $this->connection_database); $this->log($qrs, isset($qrs['errors'])); $qrv = $this->query_sql_file(PATH_RBAC_MYSQL_DATA . $values, $this->connection_database); $this->log($qrv, isset($qrv['errors'])); mysql_select_db($wf, $this->connection_database); require_once "propel/Propel.php"; require_once 'classes/model/AppCacheView.php'; $appCache = new AppCacheView(); $appCache->setPathToAppCacheFiles(PATH_METHODS . 'setup/setupSchemas/'); $triggers = $appCache->getTriggers("en"); $this->log("Create 'cases list cache' triggers"); foreach ($triggers as $triggerName => $trigger) { $this->run_query($trigger, "-> Trigger {$triggerName}"); } $path_site = $this->options['path_data'] . "/sites/" . $this->options['name'] . "/"; $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); $db_text = "<?php\n" . "// Processmaker configuration\n" . "define ('DB_ADAPTER', 'mysql' );\n" . "define ('DB_HOST', '" . $this->options['database']['hostname'] . ":" . $myPort . "' );\n" . "define ('DB_NAME', '" . $wf . "' );\n" . "define ('DB_USER', '" . ($this->cc_status == 1 ? $wf : $this->options['database']['username']) . "' );\n" . "define ('DB_PASS', '" . ($this->cc_status == 1 ? $this->options['password'] : $this->options['database']['password']) . "' );\n" . "define ('DB_RBAC_HOST', '" . $this->options['database']['hostname'] . ":" . $myPort . "' );\n" . "define ('DB_RBAC_NAME', '" . $rb . "' );\n" . "define ('DB_RBAC_USER', '" . ($this->cc_status == 1 ? $rb : $this->options['database']['username']) . "' );\n" . "define ('DB_RBAC_PASS', '" . ($this->cc_status == 1 ? $this->options['password'] : $this->options['database']['password']) . "' );\n" . "define ('DB_REPORT_HOST', '" . $this->options['database']['hostname'] . ":" . $myPort . "' );\n" . "define ('DB_REPORT_NAME', '" . $rp . "' );\n" . "define ('DB_REPORT_USER', '" . ($this->cc_status == 1 ? $rp : $this->options['database']['username']) . "' );\n" . "define ('DB_REPORT_PASS', '" . ($this->cc_status == 1 ? $this->options['password'] : $this->options['database']['password']) . "' );\n"; if (defined('PARTNER_FLAG') || isset($_REQUEST['PARTNER_FLAG'])) { $db_text .= "define ('PARTNER_FLAG', " . (defined('PARTNER_FLAG') ? PARTNER_FLAG : (isset($_REQUEST['PARTNER_FLAG']) ? $_REQUEST['PARTNER_FLAG'] : 'false')) . ");\n"; if (defined('SYSTEM_NAME')) { $db_text .= " define ('SYSTEM_NAME', '" . SYSTEM_NAME . "');\n"; } } $db_text .= "?>"; $fp = @fopen($db_file, "w"); $this->log("Create: " . $db_file . " => " . (!$fp ? $fp : "OK") . "\n", $fp === false); $ff = @fputs($fp, $db_text, strlen($db_text)); $this->log("Write: " . $db_file . " => " . (!$ff ? $ff : "OK") . "\n", $ff === false); fclose($fp); $this->setPartner(); $this->setAdmin(); } return $test; }