Source of file DatabaseMigrationLegacyYML.php
Size: 2,587 Bytes - Last Modified: 2020-07-03T12:08:09+00:00
/var/www/docs.ssmods.com/process/src/src/Tasks/IndividualTasks/DatabaseMigrationLegacyYML.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 | <?php namespace Sunnysideup\UpgradeToSilverstripe4\Tasks\IndividualTasks; use Sunnysideup\UpgradeToSilverstripe4\Api\FileSystemFixes; use Sunnysideup\UpgradeToSilverstripe4\Tasks\Task; /** * This task adds a legacy branch to the git repo of the original to act as a backup/legacy version for * holding a version of the module before it was changed */ class DatabaseMigrationLegacyYML extends Task { protected $taskStep = 's50'; public function getTitle() { return 'Copy legacy data to database migration file'; } public function getDescription() { return ' Take the data from .upgrade.yml and move it to _config/legay.yml with a header.'; } /** * [runActualTask description] * @param array $params not currently used for this task */ public function runActualTask($params = []) { foreach ($this->mu()->getExistingModuleDirLocations() as $moduleDir) { $oldFile = $moduleDir . '/.upgrade.yml'; $newFile = $moduleDir . '/_config/database.legacy.yml'; $tmpFile = $moduleDir . '/_config/database.legacy.yml.tmp'; $mvStatement = $newFile . ' > ' . $tmpFile . ' && mv ' . $tmpFile . ' ' . $newFile; if (! file_exists($oldFile)) { return $oldFile . ' NOT FOUND!!!'; } $dir = dirname($newFile); FileSystemFixes::inst($this->mu()) ->mkDir($dir) ->copyFolderOrFile($oldFile, $newFile); $this->mu()->execMe( $moduleDir, 'sed \'1d\' ' . $mvStatement, 'removing the first line and placing into temp file', false ); $this->mu()->execMe( $moduleDir, "sed -i -e 's/^/ /' " . $newFile, 'adding two additional spaces to the start of each line', false ); $this->mu()->execMe( $moduleDir, 'echo \' classname_value_remapping:\' | cat - ' . $mvStatement, 'adding ` classname_value_remapping:` to the start of ' . $newFile, false ); $this->mu()->execMe( $moduleDir, 'echo \'SilverStripe\ORM\DatabaseAdmin:\' | cat - ' . $mvStatement, 'adding `SilverStripe\ORM\DatabaseAdmin:` to the start of ' . $newFile, false ); } } protected function hasCommitAndPush() { return true; } } |