Upgrade improvements (faster checksum, fix database upgrade, prompt on checksum failure).
This commit is contained in:
@@ -47,6 +47,18 @@ function error($message) {
|
|||||||
return pakeColor::colorize($message, "ERROR");
|
return pakeColor::colorize($message, "ERROR");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function prompt($message) {
|
||||||
|
echo "$message";
|
||||||
|
$handle = fopen ("php://stdin","r");
|
||||||
|
$line = fgets($handle);
|
||||||
|
return $line;
|
||||||
|
}
|
||||||
|
|
||||||
|
function question($message) {
|
||||||
|
$input = strtolower(prompt("$message [Y/n] "));
|
||||||
|
return (array_search(trim($input), array("y", "")) !== false);
|
||||||
|
}
|
||||||
|
|
||||||
function logging($message, $filename = NULL) {
|
function logging($message, $filename = NULL) {
|
||||||
static $log_file = NULL;
|
static $log_file = NULL;
|
||||||
if (isset($filename)) {
|
if (isset($filename)) {
|
||||||
|
|||||||
@@ -11,6 +11,10 @@ function run_upgrade($command, $args) {
|
|||||||
$checksum = System::verifyChecksum();
|
$checksum = System::verifyChecksum();
|
||||||
if ($checksum === false) {
|
if ($checksum === false) {
|
||||||
logging(error("checksum.txt not found, integrity check is not possible") . "\n");
|
logging(error("checksum.txt not found, integrity check is not possible") . "\n");
|
||||||
|
if (!question("Integrity check failed, do you want to continue the upgrade?")) {
|
||||||
|
logging("Upgrade failed\n");
|
||||||
|
die();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!empty($checksum['missing'])) {
|
if (!empty($checksum['missing'])) {
|
||||||
logging(error("The following files were not found in the installation:")."\n");
|
logging(error("The following files were not found in the installation:")."\n");
|
||||||
@@ -24,8 +28,13 @@ function run_upgrade($command, $args) {
|
|||||||
logging(" $diff\n");
|
logging(" $diff\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!(empty($checksum['missing']) || empty($checksum['diff']))) {
|
||||||
|
if (!question("Integrity check failed, do you want to continue the upgrade?")) {
|
||||||
|
logging("Upgrade failed\n");
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//TODO: Ask to continue if errors are found.
|
|
||||||
logging("Clearing cache...\n");
|
logging("Clearing cache...\n");
|
||||||
if(defined('PATH_C'))
|
if(defined('PATH_C'))
|
||||||
G::rm_dir(PATH_C);
|
G::rm_dir(PATH_C);
|
||||||
|
|||||||
@@ -160,55 +160,24 @@ class System {
|
|||||||
return $items;
|
return $items;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getFilesChecksum($dir, $root = NULL) {
|
|
||||||
if (!isset($root))
|
|
||||||
$root = $dir;
|
|
||||||
$dir = realpath($dir);
|
|
||||||
$root = realpath($root);
|
|
||||||
$items = glob($dir . "/*");
|
|
||||||
$checksums = array();
|
|
||||||
foreach ($items as $item) {
|
|
||||||
$relname = substr($item, strlen($root));
|
|
||||||
//Skip xmlform files, since they always change.
|
|
||||||
if (strpos($relname, "/xmlform/") !== false)
|
|
||||||
continue;
|
|
||||||
//Skip shared and compiled directories.
|
|
||||||
if ((strpos($relname, "/shared") === 0) || (strpos($relname, "/compiled") === 0)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (is_dir($item)) {
|
|
||||||
$checksums = array_merge($checksums, System::getFilesChecksum($item, $root));
|
|
||||||
} else {
|
|
||||||
$checksums[".$relname"] = md5_file($item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $checksums;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function verifyChecksum() {
|
public static function verifyChecksum() {
|
||||||
if (!file_exists(PATH_TRUNK . "checksum.txt"))
|
if (!file_exists(PATH_TRUNK . "checksum.txt"))
|
||||||
return false;
|
return false;
|
||||||
$filesChecksum = System::getFilesChecksum(PATH_TRUNK);
|
|
||||||
$lines = explode("\n", file_get_contents(PATH_TRUNK . "checksum.txt"));
|
$lines = explode("\n", file_get_contents(PATH_TRUNK . "checksum.txt"));
|
||||||
$originalChecksum = array();
|
$result = array("diff" => array(), "missing" => array());
|
||||||
foreach ($lines as $line) {
|
foreach ($lines as $line) {
|
||||||
if (empty($line))
|
if (empty($line))
|
||||||
continue;
|
continue;
|
||||||
list($checksum, $empty, $filename) = explode(" ", $line);
|
list($checksum, $empty, $filename) = explode(" ", $line);
|
||||||
$originalChecksum[$filename] = $checksum;
|
//Skip xmlform because these files always change.
|
||||||
}
|
|
||||||
$result = array("diff" => array(), "missing" => array());
|
|
||||||
foreach ($originalChecksum as $filename => $checksum) {
|
|
||||||
//Skip hidden files that start with a dot.
|
|
||||||
if (substr(basename($filename), 0, 1) === '.')
|
|
||||||
continue;
|
|
||||||
//Skip xmlform files, since they always change.
|
|
||||||
if (strpos($filename, "/xmlform/") !== false)
|
if (strpos($filename, "/xmlform/") !== false)
|
||||||
continue;
|
continue;
|
||||||
if (!array_key_exists($filename, $filesChecksum)) {
|
if (file_exists(realpath($filename))) {
|
||||||
|
if (strcmp($checksum, md5_file(realpath($filename))) != 0) {
|
||||||
|
$result['diff'][] = $filename;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
$result['missing'][] = $filename;
|
$result['missing'][] = $filename;
|
||||||
} else if (strcmp($checksum, $filesChecksum[$filename]) != 0) {
|
|
||||||
$result['diff'][] = $filename;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
|
|||||||
@@ -304,12 +304,14 @@ class workspaceTools {
|
|||||||
public function upgradePluginsDatabase() {
|
public function upgradePluginsDatabase() {
|
||||||
foreach (System::getPlugins() as $pluginName) {
|
foreach (System::getPlugins() as $pluginName) {
|
||||||
$pluginSchema = System::getPluginSchema($pluginName);
|
$pluginSchema = System::getPluginSchema($pluginName);
|
||||||
if ($pluginSchema !== false)
|
if ($pluginSchema !== false) {
|
||||||
|
logging("Updating plugin " . info($pluginName) . "\n");
|
||||||
$this->upgradeSchema($pluginSchema);
|
$this->upgradeSchema($pluginSchema);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function upgradeDatabase($checkOnly) {
|
public function upgradeDatabase($checkOnly = false) {
|
||||||
$systemSchema = System::getSystemSchema();
|
$systemSchema = System::getSystemSchema();
|
||||||
return $this->upgradeSchema($systemSchema);
|
return $this->upgradeSchema($systemSchema);
|
||||||
}
|
}
|
||||||
@@ -484,6 +486,36 @@ class workspaceTools {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function dumpDatabase($dbname) {
|
||||||
|
$sql="show tables;";
|
||||||
|
$result= mysql_query($sql);
|
||||||
|
if( $result)
|
||||||
|
{
|
||||||
|
while( $row= mysql_fetch_row($result))
|
||||||
|
{
|
||||||
|
$table = $row[0];
|
||||||
|
|
||||||
|
echo "/* Table structure for table `$table` */\n";
|
||||||
|
echo "DROP TABLE IF EXISTS `$table`;\n\n";
|
||||||
|
$sql="show create table `$table`; ";
|
||||||
|
$result=mysql_query($sql);
|
||||||
|
if( $result)
|
||||||
|
{
|
||||||
|
if($row= mysql_fetch_assoc($result))
|
||||||
|
{
|
||||||
|
echo $row['Create Table'].";\n\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
echo "/* no tables in $mysql_database */\n";
|
||||||
|
}
|
||||||
|
mysql_free_result($result);
|
||||||
|
}
|
||||||
|
|
||||||
public function exportDatabase($path) {
|
public function exportDatabase($path) {
|
||||||
$dbInfo = $this->getDBInfo();
|
$dbInfo = $this->getDBInfo();
|
||||||
$databases = array("wf", "rp", "rb");
|
$databases = array("wf", "rp", "rb");
|
||||||
@@ -498,5 +530,28 @@ class workspaceTools {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function addToBackup($backup, $filename, $root) {
|
||||||
|
if (is_file($filename)) {
|
||||||
|
$backup->addModify($filename, "", $root);
|
||||||
|
} else {
|
||||||
|
foreach (glob($filename . "/*") as $item) {
|
||||||
|
$this->addToBackup($backup, $item, $root);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function backup($filename, $compress = true) {
|
||||||
|
G::LoadThirdParty('pear/Archive', 'Tar');
|
||||||
|
$tar = new Archive_Tar($filename);
|
||||||
|
//Get a temporary directory for database backup
|
||||||
|
$tempDirectory = tempnam(__FILE__, '');
|
||||||
|
if (file_exists($tempDirectory)) {
|
||||||
|
unlink($tempDirectory);
|
||||||
|
}
|
||||||
|
$this->exportDatabase($tempDirectory);
|
||||||
|
$this->addToBackup($backup, $tempDirectory, $tempDirectory);
|
||||||
|
$this->addToBackup($backup, $filename, $root);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|||||||
Reference in New Issue
Block a user