Fix database upgrade.
This commit is contained in:
@@ -71,6 +71,52 @@ function logging($message, $filename = NULL) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function progress($done, $total, $size=30) {
|
||||||
|
|
||||||
|
static $start_time;
|
||||||
|
|
||||||
|
// if we go over our bound, just ignore it
|
||||||
|
if($done > $total) return;
|
||||||
|
|
||||||
|
if(empty($start_time)) $start_time=time();
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$perc=(double)($done/$total);
|
||||||
|
|
||||||
|
$bar=floor($perc*$size);
|
||||||
|
|
||||||
|
$status_bar="\r[";
|
||||||
|
$status_bar.=str_repeat("=", $bar);
|
||||||
|
if($bar<$size){
|
||||||
|
$status_bar.=">";
|
||||||
|
$status_bar.=str_repeat(" ", $size-$bar);
|
||||||
|
} else {
|
||||||
|
$status_bar.="=";
|
||||||
|
}
|
||||||
|
|
||||||
|
$disp=number_format($perc*100, 0);
|
||||||
|
|
||||||
|
$status_bar.="] $disp% $done/$total";
|
||||||
|
|
||||||
|
$rate = ($now-$start_time)/$done;
|
||||||
|
$left = $total - $done;
|
||||||
|
$eta = round($rate * $left, 2);
|
||||||
|
|
||||||
|
$elapsed = $now - $start_time;
|
||||||
|
|
||||||
|
$status_bar.= " remaining: ".number_format($eta)." sec. elapsed: ".number_format($elapsed)." sec.";
|
||||||
|
|
||||||
|
echo "$status_bar ";
|
||||||
|
|
||||||
|
flush();
|
||||||
|
|
||||||
|
// when done, send a newline
|
||||||
|
if($done == $total) {
|
||||||
|
echo "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
function get_workspaces_from_args($args, $includeAll = true) {
|
function get_workspaces_from_args($args, $includeAll = true) {
|
||||||
$opts = parse_args($args);
|
$opts = parse_args($args);
|
||||||
$workspaces = array();
|
$workspaces = array();
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ pake_task('info');
|
|||||||
|
|
||||||
pake_task('workspace-upgrade');
|
pake_task('workspace-upgrade');
|
||||||
|
|
||||||
|
pake_task('workspace-backup');
|
||||||
|
|
||||||
pake_task('translation-upgrade');
|
pake_task('translation-upgrade');
|
||||||
pake_task('cacheview-upgrade');
|
pake_task('cacheview-upgrade');
|
||||||
|
|
||||||
@@ -77,7 +79,6 @@ function run_plugins_database_upgrade($command, $args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function run_database_export($command, $args) {
|
function run_database_export($command, $args) {
|
||||||
G::LoadSystem('dbMaintenance');
|
|
||||||
if (count($args) < 2)
|
if (count($args) < 2)
|
||||||
throw new Exception ("Please provide a workspace name and a directory for export");
|
throw new Exception ("Please provide a workspace name and a directory for export");
|
||||||
$workspace = new workspaceTools($args[0]);
|
$workspace = new workspaceTools($args[0]);
|
||||||
@@ -105,7 +106,7 @@ function database_upgrade($command, $args) {
|
|||||||
else
|
else
|
||||||
print_r("Upgrading database in ".pakeColor::colorize($workspace->name, "INFO")." ");
|
print_r("Upgrading database in ".pakeColor::colorize($workspace->name, "INFO")." ");
|
||||||
try {
|
try {
|
||||||
$changes = $workspace->repairSchema($checkOnly);
|
$changes = $workspace->upgradeDatabase($checkOnly);
|
||||||
if ($changes != false) {
|
if ($changes != false) {
|
||||||
if ($checkOnly) {
|
if ($checkOnly) {
|
||||||
echo "> ".pakeColor::colorize("Run upgrade", "INFO")."\n";
|
echo "> ".pakeColor::colorize("Run upgrade", "INFO")."\n";
|
||||||
@@ -210,4 +211,13 @@ function run_drafts_clean($task, $args) {
|
|||||||
echo "\n";
|
echo "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function run_workspace_backup($task, $args) {
|
||||||
|
$workspace = new workspaceTools($args[0]);
|
||||||
|
if (isset($args[1]))
|
||||||
|
$filename = $args[1];
|
||||||
|
else
|
||||||
|
$filename = PATH_DATA . "backups/" . $workspace->name . ".tar";
|
||||||
|
$workspace->backup($filename);
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
@@ -6,6 +6,8 @@
|
|||||||
* @author Alexandre Rosenfeld
|
* @author Alexandre Rosenfeld
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
G::LoadSystem('dbMaintenance');
|
||||||
|
|
||||||
class workspaceTools {
|
class workspaceTools {
|
||||||
var $name = NULL;
|
var $name = NULL;
|
||||||
var $path = NULL;
|
var $path = NULL;
|
||||||
@@ -486,36 +488,6 @@ 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");
|
||||||
@@ -524,7 +496,7 @@ class workspaceTools {
|
|||||||
$oDbMaintainer = new DataBaseMaintenance($dbInfo["host"], $dbInfo["user"],
|
$oDbMaintainer = new DataBaseMaintenance($dbInfo["host"], $dbInfo["user"],
|
||||||
$dbInfo["pass"]);
|
$dbInfo["pass"]);
|
||||||
$oDbMaintainer->connect($dbInfo["name"]);
|
$oDbMaintainer->connect($dbInfo["name"]);
|
||||||
$oDbMaintainer->setTempDir($path . $dbInfo["name"] . "/");
|
$oDbMaintainer->setTempDir($path . "/" . $dbInfo["name"] . "/");
|
||||||
$oDbMaintainer->backupDataBaseSchema($oDbMaintainer->getTempDir() . $dbInfo["name"] . ".sql");
|
$oDbMaintainer->backupDataBaseSchema($oDbMaintainer->getTempDir() . $dbInfo["name"] . ".sql");
|
||||||
$oDbMaintainer->backupSqlData();
|
$oDbMaintainer->backupSqlData();
|
||||||
}
|
}
|
||||||
@@ -536,21 +508,38 @@ class workspaceTools {
|
|||||||
} else {
|
} else {
|
||||||
foreach (glob($filename . "/*") as $item) {
|
foreach (glob($filename . "/*") as $item) {
|
||||||
$this->addToBackup($backup, $item, $root);
|
$this->addToBackup($backup, $item, $root);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function backup($filename, $compress = true) {
|
static public function createBackup($filename, $compress = true) {
|
||||||
G::LoadThirdParty('pear/Archive', 'Tar');
|
G::LoadThirdParty('pear/Archive', 'Tar');
|
||||||
$tar = new Archive_Tar($filename);
|
$backup = new Archive_Tar($filename);
|
||||||
|
return $backup;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function backup($filename, $compress = true) {
|
||||||
|
if (is_string($filename))
|
||||||
|
$backup = $this->createBackup($filename);
|
||||||
|
else
|
||||||
|
$backup = $filename;
|
||||||
//Get a temporary directory for database backup
|
//Get a temporary directory for database backup
|
||||||
$tempDirectory = tempnam(__FILE__, '');
|
$tempDirectory = tempnam(__FILE__, '');
|
||||||
if (file_exists($tempDirectory)) {
|
if (file_exists($tempDirectory)) {
|
||||||
unlink($tempDirectory);
|
unlink($tempDirectory);
|
||||||
}
|
}
|
||||||
$this->exportDatabase($tempDirectory);
|
mkdir($tempDirectory);
|
||||||
|
//$this->exportDatabase($tempDirectory);
|
||||||
|
//print_r(info("Database: $tempDirectory\n"));
|
||||||
|
$metaFilename = "$tempDirectory/{$this->name}.meta";
|
||||||
|
file_put_contents($metaFilename,
|
||||||
|
str_replace(array(",", "{", "}"), array(",\n ", "{\n ", "\n}\n"),
|
||||||
|
G::json_encode($this->getMetadata())));
|
||||||
$this->addToBackup($backup, $tempDirectory, $tempDirectory);
|
$this->addToBackup($backup, $tempDirectory, $tempDirectory);
|
||||||
$this->addToBackup($backup, $filename, $root);
|
$this->addToBackup($backup, $this->path, $this->path);
|
||||||
|
//print_r(file_get_contents($metaFilename));
|
||||||
|
//print_r(G::json_decode(file_get_contents($metaFilename)));
|
||||||
|
//$this->addToBackup($backup, $filename, $root);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user