Source of file MigrateDataTask.php
Size: 2,481 Bytes - Last Modified: 2021-12-23T10:42:12+00:00
/var/www/docs.ssmods.com/process/src/src/Tasks/MigrateDataTask.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 | <?php namespace Sunnysideup\MigrateData\Tasks; use SilverStripe\Core\Config\Config; class MigrateDataTask extends MigrateDataTaskBase { protected $title = 'Migrate Data'; protected $description = 'Migrates specific data defined in yml'; protected $enabled = true; /** * an array that is formatted like this: * Name => [ * pre_sql_queries: [ * - 'SELECT * FROM FOO' * ], * data => [ * [ * 'include_inserts' => true|false, #assumed true if not provided * 'old_table' => 'foo', * 'new_table' => 'bar' (can be the same!). * * 'simple_move_fields' => ['A', 'B', 'C'] * --- OR ---- * 'complex_move_fields' => ['A' => 'Anew', 'B' => 'BBew', 'C2' => 'Cnew'] * ] * ] * publish_classes => [ * - MyClassName1 * - MyClassName2 * ] * post_sql_queries => [ * - 'SELECT * FROM FOO' * ] * * ] * * @var array */ private static $items_to_migrate = []; /** * Queries the config for Migrate definitions, and runs migrations * if you extend this task then overwrite it this method. */ protected function performMigration() { $fullList = Config::inst()->get(self::class, 'items_to_migrate'); foreach ($fullList as $item => $details) { $this->flushNow('<h2>Starting Migration for ' . $item . '</h2>'); if (isset($details['pre_sql_queries'])) { $preSqlQueries = $details['pre_sql_queries']; $this->runSQLQueries($preSqlQueries, 'PRE'); } if (isset($details['data'])) { $data = $details['data']; $this->runMoveData($data); } if (isset($details['publish_classes'])) { $publishClasses = $details['publish_classes']; $this->runPublishClasses($publishClasses); } if (isset($details['post_sql_queries'])) { $postSqlQueries = $details['post_sql_queries']; $this->runSQLQueries($postSqlQueries, 'POST'); } $this->flushNow('<h2>Finish Migration for ' . $item . '</h2>'); } } } |