pluf2

pluf2 Commit Details


Date:2009-10-19 13:29:29 (15 years 2 months ago)
Author:Loic d'Anterroches
Branch:master
Commit:960a50f72b4001b23176252be349b70ced8471c9
Parents: 7e289cd7237c3c034aa392654d610057d1c424f7
Message:Added the backup/restore migration actions.

Changes:

File differences

src/Pluf/Migration.php
2929
3030
3131
32
3233
3334
3435
......
4344
4445
4546
47
4648
4749
4850
......
9799
98100
99101
100
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
101144
102145
103146
*
* Simple example usage:
*
* <pre>
* $m = new Pluf_Migration('MyApp');
* $m->migrate();
*
*
* $m = new Pluf_Migration();
* $m->migrate(3); // migrate (upgrade or downgrade) to version 3
* </pre>
*
*/
class Pluf_Migration
}
}
/**
* Backup the application.
*
* @param string Path to the backup folder
* @param string Backup name (null)
*/
public function backup($path, $name=null)
{
foreach ($this->apps as $app) {
$func = $app.'_Migrations_Backup_run';
Pluf::loadFunction($func);
if ($this->display) {
echo($func."\n");
}
if (!$this->dry_run) {
$ret = $func($path, $name);
}
}
return true;
}
/**
* Restore the application.
*
* @param string Path to the backup folder
* @param string Backup name
*/
public function restore($path, $name)
{
foreach ($this->apps as $app) {
$func = $app.'_Migrations_Backup_restore';
Pluf::loadFunction($func);
if ($this->display) {
echo($func."\n");
}
if (!$this->dry_run) {
$ret = $func($path, $name);
}
}
return true;
}
/**
* Run the migration.
*
src/migrate.php
3737
3838
3939
40
41
40
41
42
4243
4344
4445
......
5657
5758
5859
60
61
5962
6063
6164
......
6871
6972
7073
74
75
7176
7277
7378
......
100105
101106
102107
108
109
103110
104111
105112
113
106114
107115
108116
109117
110118
111119
120
121
122
123
124
125
112126
113127
114128
......
211225
212226
213227
228
229
230
231
232
233
234
214235
215236
216237
$search_path = null;
$cg = new Console_Getopt();
$shortoptions = 'aixuc:v:d';
$longoptions = array('app=', 'version=', 'conf=', 'search-path=', 'include-path=');
$shortoptions = 'aixubrc:v:d';
$longoptions = array('app=', 'version=', 'conf=', 'search-path=',
'include-path=');
$args = $cg->readPHPArgv();
.' Upgrade all: migrate.php --conf=path/to/config.php -a'."\n"
.' All to version 3: migrate.php --conf=path/to/config.php -a -v3'."\n"
.' Upgrade MyApp: migrate.php --conf=path/to/config.php --app=MyApp'."\n"
.' Backup MyApp: migrate.php --conf=path/to/config.php --app=MyApp -b /path/to/backup/folder [backupname]'."\n"
.' Restore MyApp: migrate.php --conf=path/to/config.php --app=MyApp -r /path/to/backup/folder backupname'."\n"
.''."\n"
.'Options:'."\n"
.' c, --conf: Path to the configuration file.'."\n"
.' d: Display debug information.'."\n"
.' i: Install the application(s).'."\n"
.' x: Uninstall the application(s).'."\n"
.' b: Backup the application(s).'."\n"
.' r: Restore the application(s).'."\n"
.''."\n"
.'Note: The command line parser of PEAR is not very robust'."\n"
.' if you have an unexpected error about an offset not'."\n"
'dry_run' => false,
'un-install' => false,
'install' => false,
'backup' => false,
'restore' => false,
);
$opts = $ret[0];
$args = $ret[1];
if (sizeof($opts) > 0) {
foreach ($opts as $o) {
switch ($o[0]) {
case 'a':
$what['all'] = true;
break;
case 'b':
$what['backup'] = true;
break;
case 'r':
$what['restore'] = true;
break;
case 'v':
case '--version':
$what['version'] = $o[1];
} elseif ($what['un-install']) {
debug('Uninstall '.$app_disp);
$m->unInstall();
} elseif ($what['backup']) {
debug('Backup '.$app_disp);
if (!isset($args[1])) $args[1] = null;
$m->backup($args[0], $args[1]);
} elseif ($what['restore']) {
debug('Restore '.$app_disp);
$m->restore($args[0], $args[1]);
} else {
debug('Migrate '.$app.' to version '.$what['version']);
$m->migrate($what['version']);

Archive Download the corresponding diff file

Branches

Number of commits:
Page rendered in 0.05749s using 13 queries.