Several improvements to the installer (show correct status, keep a log file and stop on database errors).

This commit is contained in:
Alexandre Rosenfeld
2011-02-22 22:09:00 +00:00
parent a6070e2883
commit ad4a86c055
3 changed files with 162 additions and 117 deletions

View File

@@ -169,72 +169,31 @@ class Installer
if($this->options['advanced']['ao_db_drop']===true) { if($this->options['advanced']['ao_db_drop']===true) {
/* Drop databases */ /* Drop databases */
$q = "DROP DATABASE IF EXISTS ".$wf; $this->run_query("DROP DATABASE IF EXISTS ".$wf, "Drop database $wf");
$ac = @mysql_query($q,$this->connection_database); $this->run_query("DROP DATABASE IF EXISTS ".$rb, "Drop database $rb");
$this->log($q.": => ".((!$ac)?mysql_error():"OK")."\n"); $this->run_query("DROP DATABASE IF EXISTS ".$rp, "Drop database $rp");
$q = "DROP DATABASE IF EXISTS ".$rb;
$ac = @mysql_query($q,$this->connection_database);
$this->log($q.": => ".((!$ac)?mysql_error():"OK")."\n");
$q = "DROP DATABASE IF EXISTS ".$rp;
$ac = @mysql_query($q,$this->connection_database);
$this->log($q.": => ".((!$ac)?mysql_error():"OK")."\n");
} }
$q = "CREATE DATABASE IF NOT EXISTS ".$wf." DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci"; $this->run_query("CREATE DATABASE IF NOT EXISTS ".$wf." DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci",
$ac = @mysql_query($q,$this->connection_database); "Create database $wf");
$this->log($q.": => ".((!$ac)?mysql_error():"OK")."\n"); $this->run_query("CREATE DATABASE IF NOT EXISTS ".$rb." DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci",
"Create database $rb");
$q = "CREATE DATABASE IF NOT EXISTS ".$rb." DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci"; $this->run_query("CREATE DATABASE IF NOT EXISTS ".$rp." DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci",
$ac = @mysql_query($q,$this->connection_database); "Create database $rp");
$this->log($q.": => ".((!$ac)?mysql_error():"OK")."\n");
/* report DB begin */
$q = "CREATE DATABASE IF NOT EXISTS ".$rp." DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci";
$ac = @mysql_query($q,$this->connection_database);
$this->log($q.": => ".((!$ac)?mysql_error():"OK")."\n");
/* report DB end */
if($this->cc_status==1) { if($this->cc_status==1) {
if($islocal) { $host = ($islocal) ? "localhost" : "%";
$priv_wf = "GRANT ALL PRIVILEGES ON `".$wf."`.* TO ".$wf."@'localhost' IDENTIFIED BY '".$this->options['password']."' WITH GRANT OPTION"; $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");
else { $this->run_query("GRANT ALL PRIVILEGES ON `$rb`.* TO $rb@'$host' IDENTIFIED BY '{$this->options['password']}' WITH GRANT OPTION",
$priv_wf = "GRANT ALL PRIVILEGES ON `".$wf."`.* TO ".$wf."@'%' 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",
$ac = @mysql_query($priv_wf,$this->connection_database); "Grant privileges for user $rp on database $rp");
$this->log($priv_wf.": => ".((!$ac)?mysql_error():"OK")."\n");
if($islocal) {
$priv_rb = "GRANT ALL PRIVILEGES ON `".$rb."`.* TO ".$rb."@'localhost' IDENTIFIED BY '".$this->options['password']."' WITH GRANT OPTION";
}
else {
$priv_rb = "GRANT ALL PRIVILEGES ON `".$rb."`.* TO ".$rb."@'%' IDENTIFIED BY '".$this->options['password']."' WITH GRANT OPTION";
}
$ac = @mysql_query($priv_rb,$this->connection_database);
$this->log($priv_rb.": => ".((!$ac)?mysql_error():"OK")."\n");
/* report DB begin */
if($islocal) {
$priv_rp = "GRANT ALL PRIVILEGES ON `".$rp."`.* TO ".$rp."@'localhost' IDENTIFIED BY '".$this->options['password']."' WITH GRANT OPTION";
}
else {
$priv_rp = "GRANT ALL PRIVILEGES ON `".$rp."`.* TO ".$rp."@'%' IDENTIFIED BY '".$this->options['password']."' WITH GRANT OPTION";
}
$ac = @mysql_query($priv_rp,$this->connection_database);
$this->log($priv_rp.": => ".((!$ac)?mysql_error():"OK")."\n");
/* report DB end */
} }
/* Dump schema workflow && data */ /* Dump schema workflow && data */
$this->log("Importing database schema\n"); $this->log("Importing database schema:\n");
$myPortA = explode(":",$this->options['database']['hostname']); $myPortA = explode(":",$this->options['database']['hostname']);
if(count($myPortA)<2) { if(count($myPortA)<2) {
$myPortA[1]="3306"; $myPortA[1]="3306";
@@ -245,18 +204,18 @@ class Installer
mysql_select_db($wf,$this->connection_database); mysql_select_db($wf,$this->connection_database);
$pws = PATH_WORKFLOW_MYSQL_DATA.$schema; $pws = PATH_WORKFLOW_MYSQL_DATA.$schema;
$qws = $this->query_sql_file(PATH_WORKFLOW_MYSQL_DATA.$schema,$this->connection_database); $qws = $this->query_sql_file(PATH_WORKFLOW_MYSQL_DATA.$schema,$this->connection_database);
$this->log($qws); $this->log($qws, isset($qws['errors']));
$qwv = $this->query_sql_file(PATH_WORKFLOW_MYSQL_DATA.$values,$this->connection_database); $qwv = $this->query_sql_file(PATH_WORKFLOW_MYSQL_DATA.$values,$this->connection_database);
$this->log($qwv); $this->log($qwv, isset($qwv['errors']));
/* Dump schema rbac && data */ /* Dump schema rbac && data */
$pws = PATH_RBAC_MYSQL_DATA.$schema; $pws = PATH_RBAC_MYSQL_DATA.$schema;
mysql_select_db($rb,$this->connection_database); mysql_select_db($rb,$this->connection_database);
$qrs = $this->query_sql_file(PATH_RBAC_MYSQL_DATA.$schema,$this->connection_database); $qrs = $this->query_sql_file(PATH_RBAC_MYSQL_DATA.$schema,$this->connection_database);
$this->log($qrs); $this->log($qrs, isset($qrs['errors']));
$qrv = $this->query_sql_file(PATH_RBAC_MYSQL_DATA.$values,$this->connection_database); $qrv = $this->query_sql_file(PATH_RBAC_MYSQL_DATA.$values,$this->connection_database);
$this->log($qrv); $this->log($qrv, isset($qrv['errors']));
$path_site = $this->options['path_data']."/sites/".$this->options['name']."/"; $path_site = $this->options['path_data']."/sites/".$this->options['name']."/";
$db_file = $path_site."db.php"; $db_file = $path_site."db.php";
@@ -284,9 +243,9 @@ class Installer
"define ('DB_REPORT_PASS', '". (($this->cc_status==1)?$this->options['password']:$this->options['database']['password']) . "' );\n" . "define ('DB_REPORT_PASS', '". (($this->cc_status==1)?$this->options['password']:$this->options['database']['password']) . "' );\n" .
"?>"; "?>";
$fp = @fopen($db_file, "w"); $fp = @fopen($db_file, "w");
$this->log("Creating: ".$db_file." => ".((!$fp)?$fp:"OK")."\n"); $this->log("Create: ".$db_file." => ".((!$fp)?$fp:"OK")."\n", $fp === FALSE);
$ff = @fputs( $fp, $db_text, strlen($db_text)); $ff = @fputs( $fp, $db_text, strlen($db_text));
$this->log("Write: ".$db_file." => ".((!$ff)?$ff:"OK")."\n"); $this->log("Write: ".$db_file." => ".((!$ff)?$ff:"OK")."\n", $ff === FALSE);
fclose( $fp ); fclose( $fp );
$this->set_admin(); $this->set_admin();
@@ -302,14 +261,26 @@ class Installer
public function set_admin() public function set_admin()
{ {
mysql_select_db($this->wf_site_name,$this->connection_database); mysql_select_db($this->wf_site_name,$this->connection_database);
$q = 'UPDATE USERS SET USR_USERNAME = \''.mysql_escape_string($this->options['admin']['username']).'\', `USR_PASSWORD` = \''.md5($this->options['admin']['password']).'\' WHERE `USR_UID` = \'00000000000000000000000000000001\' LIMIT 1'; $this->run_query('UPDATE USERS SET USR_USERNAME = \''.mysql_escape_string($this->options['admin']['username']).'\', `USR_PASSWORD` = \''.md5($this->options['admin']['password']).'\' WHERE `USR_UID` = \'00000000000000000000000000000001\' LIMIT 1',
$ac = @mysql_query($q,$this->connection_database); "Add 'admin' user in ProcessMaker (wf)");
$this->log("Set workflow USERNAME:PASSWORD => ".((!$ac)?mysql_error():"OK")."\n");
mysql_select_db($this->rbac_site_name,$this->connection_database); mysql_select_db($this->rbac_site_name,$this->connection_database);
$q = 'UPDATE USERS SET USR_USERNAME = \''.mysql_escape_string($this->options['admin']['username']).'\', `USR_PASSWORD` = \''.md5($this->options['admin']['password']).'\' WHERE `USR_UID` = \'00000000000000000000000000000001\' LIMIT 1'; $this->run_query('UPDATE USERS SET USR_USERNAME = \''.mysql_escape_string($this->options['admin']['username']).'\', `USR_PASSWORD` = \''.md5($this->options['admin']['password']).'\' WHERE `USR_UID` = \'00000000000000000000000000000001\' LIMIT 1',
$ac = @mysql_query($q,$this->connection_database); "Add 'admin' user in ProcessMaker (rb)");
$this->log("Set rbac USERNAME:PASSWORD => ".((!$ac)?mysql_error():"OK")."\n"); }
/**
* Run a mysql query on the current database and take care of logging and
* error handling.
*
* @param string $query SQL command
* @param string $description Description to log instead of $query
*/
private function run_query($query, $description = NULL) {
$result = @mysql_query($query, $this->connection_database);
$error = ($result) ? false : mysql_error();
$this->log(($description ? $description : $query) . " => " . (($error) ? $error : "OK") . "\n",
$error);
} }
/** /**
@@ -323,7 +294,6 @@ class Installer
{ {
$report = array( $report = array(
'SQL_FILE' => $file, 'SQL_FILE' => $file,
'errors' => array(),
'queries' => 0 'queries' => 0
); );
@@ -342,6 +312,8 @@ class Installer
/* Make sure we have a query to execute, then execute it */ /* Make sure we have a query to execute, then execute it */
if (trim($qr) != "") { if (trim($qr) != "") {
if(!@mysql_query($qr, $connection)) { if(!@mysql_query($qr, $connection)) {
if (!array_key_exists('errors', $report))
$report['errors'] = array();
$report['errors'][] = "Error in query ".$i.": ".mysql_error(); $report['errors'][] = "Error in query ".$i.": ".mysql_error();
} else { } else {
$report['queries'] += 1; $report['queries'] += 1;
@@ -570,9 +542,11 @@ class Installer
* @param string $text * @param string $text
* @return void * @return void
*/ */
public function log($text) public function log($text, $failed = NULL)
{ {
array_push($this->report,$text); array_push($this->report,$text);
if ($failed)
throw new Exception($text);
} }
} }
?> ?>

View File

@@ -578,27 +578,21 @@ var installer=function()
this.table = document.createElement("table"); this.table = document.createElement("table");
this.table.className="inst_table"; this.table.className="inst_table";
var success = (rpc.xmlhttp.status == 200);
var tr = this.table.insertRow(-1); var tr = this.table.insertRow(-1);
var tdtitle = tr.insertCell(0); var tdtitle = tr.insertCell(0);
tdtitle.innerHTML="Directories"; tdtitle.innerHTML="Status";
tdtitle.className="app_grid_title___gray title"; tdtitle.className="app_grid_title___gray title";
var tr = this.table.insertRow(-1); var tr = this.table.insertRow(-1);
var td0 = tr.insertCell(0); var td0 = tr.insertCell(0);
td0.innerHTML="SUCCESS"; td0.innerHTML=(success) ? "Success" : "Failed (Check log below)";
td0.className="tdOk"; td0.className=(success) ? "tdOk" : "tdFailed";
var tr = this.table.insertRow(-1);
var tdtitle = tr.insertCell(0);
tdtitle.innerHTML="New Workspace";
tdtitle.className="app_grid_title___gray title";
var tr = this.table.insertRow(-1);
var td0 = tr.insertCell(0);
td0.innerHTML="SUCCESS";
td0.className="tdOk";
this.options.target.appendChild(this.table); this.options.target.appendChild(this.table);
if (success) {
var tr = this.table.insertRow(-1); var tr = this.table.insertRow(-1);
var tdS = tr.insertCell(0); var tdS = tr.insertCell(0);
tdS.colSpan = 2; tdS.colSpan = 2;
@@ -618,6 +612,8 @@ var installer=function()
tdS.appendChild(document.createElement("br")); tdS.appendChild(document.createElement("br"));
tdS.appendChild(document.createElement("br")); tdS.appendChild(document.createElement("br"));
}
var tr = this.table.insertRow(-1); var tr = this.table.insertRow(-1);
var tdtitle = tr.insertCell(0); var tdtitle = tr.insertCell(0);
tdtitle.innerHTML="Installation Log"; tdtitle.innerHTML="Installation Log";

View File

@@ -201,6 +201,8 @@ else if($action==="install")
*5.2 Install plugins *5.2 Install plugins
* */ * */
require_once 'Log.php';
$sp = "/"; $sp = "/";
$dir_data = $dataClient->path_data; $dir_data = $dataClient->path_data;
//$dir_compiled = $dataClient->path_compiled; //$dir_compiled = $dataClient->path_compiled;
@@ -212,6 +214,15 @@ else if($action==="install")
@mkdir($dir_data."sites",0777,true); @mkdir($dir_data."sites",0777,true);
@mkdir($dir_compiled,0777,true); @mkdir($dir_compiled,0777,true);
$logFile = "{$dir_data}install.log";
$display = Log::singleton('display', '', 'INSTALLER', array('lineFormat' => "%{message}"));
$file = Log::singleton('file', $logFile, 'INSTALLER');
global $logger;
$logger = Log::singleton('composite');
$logger->addChild($display);
$logger->addChild($file);
$create_db ="create-db.sql"; $create_db ="create-db.sql";
$schema ="schema.sql"; $schema ="schema.sql";
@@ -222,6 +233,8 @@ else if($action==="install")
$siteName="workflow"; $siteName="workflow";
$p1 = (isset($dataClient->ao_admin_pass1))?$dataClient->ao_admin_pass1:'admin'; $p1 = (isset($dataClient->ao_admin_pass1))?$dataClient->ao_admin_pass1:'admin';
$p2 = (isset($dataClient->ao_admin_pass2))?$dataClient->ao_admin_pass2:'admin'; $p2 = (isset($dataClient->ao_admin_pass2))?$dataClient->ao_admin_pass2:'admin';
try {
$s = $inst->create_site(Array( $s = $inst->create_site(Array(
'name' =>'workflow', 'name' =>'workflow',
'path_data'=>$dataClient->path_data, 'path_data'=>$dataClient->path_data,
@@ -240,24 +253,41 @@ else if($action==="install")
'password'=>$dataClient->mysqlP 'password'=>$dataClient->mysqlP
) )
),true); ),true);
$installError = (!$s['created']);
} catch (Exception $e) {
$installError = ($e->getMessage() ? $e->getMessage() : true);
}
if ($installError)
header('HTTP', true, 500);
/* Status is used in the Windows installer, do not change this */ /* Status is used in the Windows installer, do not change this */
print_r("Status: ".($s['created'] ? 'SUCCESS':'FAILED')."\n\n"); print_r("Status: ".(($installError) ? 'FAILED':'SUCCESS')."\n\n");
print_r("Installation arguments:\n");
print_r($dataClient); $file->log("Status: ".(($installError) ? 'FAILED':'SUCCESS'));
print_r("\n"); $display->log("This log is also avaliable in $logFile");
if (!$s['created']) {
$installArgs = (array)$dataClient;
$hiddenFields = array('mysqlP', 'ao_admin_pass1', 'ao_admin_pass2');
foreach ($installArgs as $arg => $param)
if (in_array($arg, $hiddenFields))
$installArgs[$arg] = "********";
$logger->log("Installation arguments\n" . neat_r(array($installArgs)));
if ($installError !== false && isset($s) && !$s['created']) {
/* On a failed install, $inst->report is blank because the /* On a failed install, $inst->report is blank because the
* installation didnt occured at all. So we use the test report * installation didnt occured at all. So we use the test report
* instead. * instead.
*/ */
print_r("Installation report:\n"); $logger->log("Installation report\n" . neat_r(array($s['result'])));
print_r($s['result']);
die(); die();
} }
print_r("Installation report:\n"); $logger->log("Installation report\n" . neat_r(array($inst->report)));
print_r($inst->report);
if ($installError)
die();
$sh=md5(filemtime(PATH_GULLIVER."/class.g.php")); $sh=md5(filemtime(PATH_GULLIVER."/class.g.php"));
$h=G::encrypt($dataClient->mysqlH.$sh.$dataClient->mysqlU.$sh.$dataClient->mysqlP.$sh.$inst->cc_status,$sh); $h=G::encrypt($dataClient->mysqlH.$sh.$dataClient->mysqlU.$sh.$dataClient->mysqlP.$sh.$inst->cc_status,$sh);
@@ -273,23 +303,68 @@ else if($action==="install")
/* Update languages */ /* Update languages */
$update = file_get_contents("http://".$_SERVER['SERVER_NAME'].":".$_SERVER['SERVER_PORT']."/sysworkflow/en/green/tools/updateTranslation"); $update = file_get_contents("http://".$_SERVER['SERVER_NAME'].":".$_SERVER['SERVER_PORT']."/sysworkflow/en/green/tools/updateTranslation");
print_r("Update language => ".((!$update)?$update:"OK")."\n"); $logger->log("Update language => ".((!$update)?$update:"OK"));
/* Heartbeat Enable/Disable */ /* Heartbeat Enable/Disable */
if(!isset($dataClient->heartbeatEnabled)) $dataClient->heartbeatEnabled=true; if(!isset($dataClient->heartbeatEnabled)) $dataClient->heartbeatEnabled=true;
$update = file_get_contents("http://".$_SERVER['SERVER_NAME'].":".$_SERVER['SERVER_PORT']."/sysworkflow/en/green/install/heartbeatStatus?status=".$dataClient->heartbeatEnabled); $update = file_get_contents("http://".$_SERVER['SERVER_NAME'].":".$_SERVER['SERVER_PORT']."/sysworkflow/en/green/install/heartbeatStatus?status=".$dataClient->heartbeatEnabled);
print_r("Heartbeat Status => ".str_replace("<br>","\n",$update)."\n"); $logger->log("Heartbeat Status => ".str_replace("<br>","\n",$update));
/* Autoinstall Process */ /* Autoinstall Process */
$update = file_get_contents("http://".$_SERVER['SERVER_NAME'].":".$_SERVER['SERVER_PORT']."/sysworkflow/en/green/install/autoinstallProcesses"); $update = file_get_contents("http://".$_SERVER['SERVER_NAME'].":".$_SERVER['SERVER_PORT']."/sysworkflow/en/green/install/autoinstallProcesses");
if (trim(str_replace("<br>","",$update)) == "") if (trim(str_replace("<br>","",$update)) == "")
$update = "Nothing to do."; $update = "Nothing to do.";
print_r("Process AutoInstall => ".str_replace("<br>","\n",$update)."\n"); $logger->log("Process AutoInstall => ".str_replace("<br>","\n",$update));
/* Autoinstall Plugins */ /* Autoinstall Plugins */
$update = file_get_contents("http://".$_SERVER['SERVER_NAME'].":".$_SERVER['SERVER_PORT']."/sysworkflow/en/green/install/autoinstallPlugins"); $update = file_get_contents("http://".$_SERVER['SERVER_NAME'].":".$_SERVER['SERVER_PORT']."/sysworkflow/en/green/install/autoinstallPlugins");
if (trim(str_replace("<br>","",$update)) == "") if (trim(str_replace("<br>","",$update)) == "")
$update = "Nothing to do."; $update = "Nothing to do.";
print_r("Plugin AutoInstall => ".str_replace("<br>","\n",$update)."\n"); $logger->log("Plugin AutoInstall => ".str_replace("<br>","\n",$update));
}
/*
neat_r works like print_r but with much less visual clutter.
By Jake Lodwick. Copy freely.
*/
function neat_r($arr, $return = false) {
$out = array();
$oldtab = " ";
$newtab = " ";
$lines = explode("\n", print_r($arr, true));
foreach ($lines as $line) {
//remove numeric indexes like "[0] =>" unless the value is an array
//if (substr($line, -5) != "Array") {
$line = preg_replace("/^(\s*)\[[0-9]+\] => /", "$1", $line, 1);
//}
//garbage symbols
foreach (array(
"Array" => "",
"[" => "",
"]" => "",
//" =>" => ":",
) as $old => $new) {
$out = str_replace($old, $new, $out);
}
//garbage lines
if (in_array(trim($line), array("Array", "(", ")", ""))) continue;
//indents
$indent = "";
$indents = floor((substr_count($line, $oldtab) - 1) / 2);
if ($indents > 0) { for ($i = 0; $i < $indents; $i++) { $indent .= $newtab; } }
$out[] = $indent . trim($line);
}
$out = implode("\n", $out);
if ($return == true) return $out;
return $out;
} }
?> ?>