silverstripe /
silverstripe-framework
| 1 | <?php |
||
| 2 | |||
| 3 | namespace SilverStripe\Dev; |
||
| 4 | |||
| 5 | /** |
||
| 6 | * A migration task is a build task that is reversible. |
||
| 7 | * |
||
| 8 | * <b>Creating Migration Tasks</b> |
||
| 9 | * |
||
| 10 | * To create your own migration task, you need to define your own subclass of MigrationTask |
||
| 11 | * and implement the following methods |
||
| 12 | * |
||
| 13 | * <i>app/src/MyMigrationTask.php</i> |
||
| 14 | * |
||
| 15 | * <code> |
||
| 16 | * class MyMigrationTask extends MigrationTask { |
||
| 17 | * |
||
| 18 | * private static $segment = 'MyMigrationTask'; // segment in the dev/tasks/ namespace for URL access |
||
| 19 | * protected $title = "My Database Migrations"; // title of the script |
||
| 20 | * protected $description = "My Description"; // description of what it does |
||
| 21 | * |
||
| 22 | * public function run($request) { |
||
| 23 | * if ($request->getVar('Direction') == 'down') { |
||
| 24 | * $this->down(); |
||
| 25 | * } else { |
||
| 26 | * $this->up(); |
||
| 27 | * } |
||
| 28 | * } |
||
| 29 | * |
||
| 30 | * public function up() { |
||
| 31 | * // do something when going from old -> new |
||
| 32 | * } |
||
| 33 | * |
||
| 34 | * public function down() { |
||
| 35 | * // do something when going from new -> old |
||
| 36 | * } |
||
| 37 | * } |
||
| 38 | * </code> |
||
| 39 | * |
||
| 40 | * <b>Running Migration Tasks</b> |
||
| 41 | * You can find all tasks under the dev/tasks/ namespace. |
||
| 42 | * To run the above script you would need to run the following and note - Either the site has to be |
||
| 43 | * in [devmode](debugging) or you need to add ?isDev=1 to the URL. |
||
| 44 | * |
||
| 45 | * <code> |
||
| 46 | * // url to visit if in dev mode. |
||
| 47 | * https://www.yoursite.com/dev/tasks/MyMigrationTask |
||
| 48 | * |
||
| 49 | * // url to visit if you are in live mode but need to run this |
||
| 50 | * https://www.yoursite.com/dev/tasks/MyMigrationTask?isDev=1 |
||
| 51 | * </code> |
||
| 52 | */ |
||
| 53 | abstract class MigrationTask extends BuildTask |
||
| 54 | { |
||
| 55 | |||
| 56 | private static $segment = 'MigrationTask'; |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 57 | |||
| 58 | protected $title = "Database Migrations"; |
||
| 59 | |||
| 60 | protected $description = "Provide atomic database changes (subclass this and implement yourself)"; |
||
| 61 | |||
| 62 | public function run($request) |
||
| 63 | { |
||
| 64 | if ($request->param('Direction') == 'down') { |
||
| 65 | $this->down(); |
||
| 66 | } else { |
||
| 67 | $this->up(); |
||
| 68 | } |
||
| 69 | } |
||
| 70 | |||
| 71 | public function up() |
||
| 72 | { |
||
| 73 | } |
||
| 74 | |||
| 75 | public function down() |
||
| 76 | { |
||
| 77 | } |
||
| 78 | } |
||
| 79 |