/Task/Pdx/Reset.php
PHP | 84 lines | 62 code | 11 blank | 11 comment | 15 complexity | 544123057997132c0276af461d4e1217 MD5 | raw file
Possible License(s): BSD-3-Clause
- <?php namespace mjolnir\database;
- /**
- * @package mjolnir
- * @category Database
- * @author Ibidem Team
- * @copyright (c) 2013, Ibidem Team
- * @license https://github.com/ibidem/ibidem/blob/master/LICENSE.md
- */
- class Task_Pdx_Reset extends \app\Task_Base
- {
- /**
- * ...
- */
- function run()
- {
- \app\Task::consolewriter($this->writer);
- if (\app\CFS::config('mjolnir/base')['db:migrations'] !== 'paradox')
- {
- $this->writer
- ->printf('error', 'System is currently setup to use ['.\app\CFS::config('mjolnir/base')['db:migrations'].'] migrations.')
- ->eol()->eol();
- return;
- }
- $pivot = $this->get('pivot', false);
- $version = $this->get('version', false);
- $dryrun = $this->get('dry-run', false);
- $verbose = $this->get('verbose', false);
- $pivot !== false || $pivot = null;
- $version !== false || $version = null;
- $dryrun !== false || $dryrun = null;
- $verbose !== false || $verbose = null;
- if ($version !== null && $pivot === null)
- {
- $this->writer->writef(' You must provide a pivot channel.')->eol();
- return;
- }
- if ($version === null && $pivot !== null)
- {
- $this->writer->writef(' You must provide a version with the pivot channel. Use no parameters for complete install.')->eol();
- return;
- }
- $pdx = \app\Pdx::instance($this->writer, $verbose);
- if (($history = $pdx->reset($pivot, $version, $dryrun)) === false)
- {
- $this->writer->writef(' The database is locked and operation could not be performed in non-destructive manner.')->eol();
- }
- else # reset done
- {
- // dry run?
- if ($dryrun)
- {
- if ($verbose)
- {
- $this->writer->eol();
- }
- foreach ($history as $entry)
- {
- $this->writer->writef(' %9s %s %s', $entry['version'], $entry['channel'], empty($entry['hotfix']) ? '' : '/ '.$entry['hotfix'])->eol();
- }
- }
- else # not dry-run
- {
- if ($verbose)
- {
- $this->writer->eol();
- }
- $this->writer
- ->eol()->eol()
- ->writef(' Reset complete.')->eol();
- }
- }
- }
- } # class