Pluf Framework

Sign in or create your account | Project List | Help

Pluf Framework Commit Details

Date:2009-10-19 20:29:29 (4 months 27 days ago)
Author:Loïc d'Anterroches
Commit:960a50f72b4001b23176252be349b70ced8471c9
Message:Added the backup/restore migration actions.

Files: src/Pluf/Migration.php (3 diffs)
src/migrate.php (5 diffs)

Change Details

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

Archive Download the corresponding diff file

Branches:
master