silverstripe-framework/src/Dev/MigrationTask.php

77 lines
1.9 KiB
PHP
Raw Permalink Normal View History

<?php
namespace SilverStripe\Dev;
/**
* A migration task is a build task that is reversible.
2014-08-15 08:53:05 +02:00
*
* <b>Creating Migration Tasks</b>
2014-08-15 08:53:05 +02:00
*
* To create your own migration task all you need to do is define your own subclass of MigrationTask and define the
* following functions
2014-08-15 08:53:05 +02:00
*
* <i>mysite/code/MyMigrationTask.php</i>
2014-08-15 08:53:05 +02:00
*
* <code>
* class MyMigrationTask extends BuildTask {
2014-08-15 08:53:05 +02:00
*
2016-11-29 00:31:16 +01:00
* protected $title = "My Database Migrations"; // title of the script
* protected $description = "Description"; // description of what it does
2014-08-15 08:53:05 +02:00
*
2016-11-29 00:31:16 +01:00
* public function run($request) {
* if ($request->getVar('Direction') == 'down') {
* $this->down();
* } else {
* $this->up();
* }
* }
2014-08-15 08:53:05 +02:00
*
2016-11-29 00:31:16 +01:00
* public function up() {
* // do something when going from old -> new
* }
2014-08-15 08:53:05 +02:00
*
2016-11-29 00:31:16 +01:00
* public function down() {
* // do something when going from new -> old
* }
* }
* </code>
2014-08-15 08:53:05 +02:00
*
* <b>Running Migration Tasks</b>
2014-08-15 08:53:05 +02:00
* To run any tasks you can find them under the dev/ namespace. To run the above script you would need to run
* the following and note - Either the site has to be in [devmode](debugging) or you need to add ?isDev=1 to the URL
2014-08-15 08:53:05 +02:00
*
* <code>
* // url to visit if in dev mode.
* http://www.yoursite.com/dev/tasks/MyMigrationTask
2014-08-15 08:53:05 +02:00
*
* // url if you are in live mode but need to run this
* http://www.yoursite.com/dev/tasks/MyMigrationTask?isDev=1
* </code>
*/
2016-11-29 00:31:16 +01:00
class MigrationTask extends BuildTask
{
2014-08-15 08:53:05 +02:00
2016-11-29 00:31:16 +01:00
private static $segment = 'MigrationTask';
2016-11-29 00:31:16 +01:00
protected $title = "Database Migrations";
2014-08-15 08:53:05 +02:00
2020-03-05 21:57:31 +01:00
protected $description = "Provide atomic database changes (subclass this and implement yourself)";
2014-08-15 08:53:05 +02:00
2016-11-29 00:31:16 +01:00
public function run($request)
{
if ($request->param('Direction') == 'down') {
$this->down();
} else {
$this->up();
}
}
2014-08-15 08:53:05 +02:00
2016-11-29 00:31:16 +01:00
public function up()
{
}
2014-08-15 08:53:05 +02:00
2016-11-29 00:31:16 +01:00
public function down()
{
}
}