| src/Pluf/Migration.php |
| 29 | 29 | * |
| 30 | 30 | * Simple example usage: |
| 31 | 31 | * |
| 32 | * <pre> |
| 32 | 33 | * $m = new Pluf_Migration('MyApp'); |
| 33 | 34 | * $m->migrate(); |
| 34 | 35 | * |
| ... | ... | |
| 43 | 44 | * |
| 44 | 45 | * $m = new Pluf_Migration(); |
| 45 | 46 | * $m->migrate(3); // migrate (upgrade or downgrade) to version 3 |
| 47 | * </pre> |
| 46 | 48 | * |
| 47 | 49 | */ |
| 48 | 50 | class Pluf_Migration |
| ... | ... | |
| 97 | 99 | } |
| 98 | 100 | } |
| 99 | 101 | |
| 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 | |
| 101 | 144 | /** |
| 102 | 145 | * Run the migration. |
| 103 | 146 | * |
| src/migrate.php |
| 37 | 37 | $search_path = null; |
| 38 | 38 | |
| 39 | 39 | $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='); |
| 42 | 43 | |
| 43 | 44 | $args = $cg->readPHPArgv(); |
| 44 | 45 | |
| ... | ... | |
| 56 | 57 | .' Upgrade all: migrate.php --conf=path/to/config.php -a'."\n" |
| 57 | 58 | .' All to version 3: migrate.php --conf=path/to/config.php -a -v3'."\n" |
| 58 | 59 | .' 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" |
| 59 | 62 | .''."\n" |
| 60 | 63 | .'Options:'."\n" |
| 61 | 64 | .' c, --conf: Path to the configuration file.'."\n" |
| ... | ... | |
| 68 | 71 | .' d: Display debug information.'."\n" |
| 69 | 72 | .' i: Install the application(s).'."\n" |
| 70 | 73 | .' x: Uninstall the application(s).'."\n" |
| 74 | .' b: Backup the application(s).'."\n" |
| 75 | .' r: Restore the application(s).'."\n" |
| 71 | 76 | .''."\n" |
| 72 | 77 | .'Note: The command line parser of PEAR is not very robust'."\n" |
| 73 | 78 | .' if you have an unexpected error about an offset not'."\n" |
| ... | ... | |
| 100 | 105 | 'dry_run' => false, |
| 101 | 106 | 'un-install' => false, |
| 102 | 107 | 'install' => false, |
| 108 | 'backup' => false, |
| 109 | 'restore' => false, |
| 103 | 110 | ); |
| 104 | 111 | |
| 105 | 112 | $opts = $ret[0]; |
| 113 | $args = $ret[1]; |
| 106 | 114 | if (sizeof($opts) > 0) { |
| 107 | 115 | foreach ($opts as $o) { |
| 108 | 116 | switch ($o[0]) { |
| 109 | 117 | case 'a': |
| 110 | 118 | $what['all'] = true; |
| 111 | 119 | break; |
| 120 | case 'b': |
| 121 | $what['backup'] = true; |
| 122 | break; |
| 123 | case 'r': |
| 124 | $what['restore'] = true; |
| 125 | break; |
| 112 | 126 | case 'v': |
| 113 | 127 | case '--version': |
| 114 | 128 | $what['version'] = $o[1]; |
| ... | ... | |
| 211 | 225 | } elseif ($what['un-install']) { |
| 212 | 226 | debug('Uninstall '.$app_disp); |
| 213 | 227 | $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]); |
| 214 | 235 | } else { |
| 215 | 236 | debug('Migrate '.$app.' to version '.$what['version']); |
| 216 | 237 | $m->migrate($what['version']); |