芝麻web文件管理V1.00
编辑当前文件:/home/mgatv524/public_html/midiatech/vendor/robmorgan/phinx/src/Phinx/Console/Command/Rollback.php
addOption('--environment', '-e', InputOption::VALUE_REQUIRED, 'The target environment'); $this->setName('rollback') ->setDescription('Rollback the last or to a specific migration') ->addOption('--target', '-t', InputOption::VALUE_REQUIRED, 'The version number to rollback to') ->addOption('--date', '-d', InputOption::VALUE_REQUIRED, 'The date to rollback to') ->addOption('--force', '-f', InputOption::VALUE_NONE, 'Force rollback to ignore breakpoints') ->addOption('--dry-run', '-x', InputOption::VALUE_NONE, 'Dump query to standard output instead of executing it') ->setHelp( <<
rollback command reverts the last migration, or optionally up to a specific version
phinx rollback -e development
phinx rollback -e development -t 20111018185412
phinx rollback -e development -d 20111018
phinx rollback -e development -v
phinx rollback -e development -t 20111018185412 -f
If you have a breakpoint set, then you can rollback to target 0 and the rollbacks will stop at the breakpoint.
phinx rollback -e development -t 0
The
version_order
configuration option is used to determine the order of the migrations when rolling back. This can be used to allow the rolling back of the last executed migration instead of the last created one, or combined with the
-d|--date
option to rollback to a certain date using the migration start times to order them. EOT ); } /** * Rollback the migration. * * @param \Symfony\Component\Console\Input\InputInterface $input * @param \Symfony\Component\Console\Output\OutputInterface $output * @return void */ protected function execute(InputInterface $input, OutputInterface $output) { $this->bootstrap($input, $output); $environment = $input->getOption('environment'); $version = $input->getOption('target'); $date = $input->getOption('date'); $force = (bool)$input->getOption('force'); $config = $this->getConfig(); if ($environment === null) { $environment = $config->getDefaultEnvironment(); $output->writeln('
warning
no environment specified, defaulting to: ' . $environment); } else { $output->writeln('
using environment
' . $environment); } $envOptions = $config->getEnvironment($environment); if (isset($envOptions['adapter'])) { $output->writeln('
using adapter
' . $envOptions['adapter']); } if (isset($envOptions['wrapper'])) { $output->writeln('
using wrapper
' . $envOptions['wrapper']); } if (isset($envOptions['name'])) { $output->writeln('
using database
' . $envOptions['name']); } $versionOrder = $this->getConfig()->getVersionOrder(); $output->writeln('
ordering by
' . $versionOrder . " time"); // rollback the specified environment if ($date === null) { $targetMustMatchVersion = true; $target = $version; } else { $targetMustMatchVersion = false; $target = $this->getTargetFromDate($date); } $start = microtime(true); $this->getManager()->rollback($environment, $target, $force, $targetMustMatchVersion); $end = microtime(true); $output->writeln(''); $output->writeln('
All Done. Took ' . sprintf('%.4fs', $end - $start) . '
'); } /** * Get Target from Date * * @param string $date The date to convert to a target. * @return string The target */ public function getTargetFromDate($date) { if (!preg_match('/^\d{4,14}$/', $date)) { throw new \InvalidArgumentException('Invalid date. Format is YYYY[MM[DD[HH[II[SS]]]]].'); } // what we need to append to the date according to the possible date string lengths $dateStrlenToAppend = [ 14 => '', 12 => '00', 10 => '0000', 8 => '000000', 6 => '01000000', 4 => '0101000000', ]; if (!isset($dateStrlenToAppend[strlen($date)])) { throw new \InvalidArgumentException('Invalid date. Format is YYYY[MM[DD[HH[II[SS]]]]].'); } $target = $date . $dateStrlenToAppend[strlen($date)]; $dateTime = \DateTime::createFromFormat('YmdHis', $target); if ($dateTime === false) { throw new \InvalidArgumentException('Invalid date. Format is YYYY[MM[DD[HH[II[SS]]]]].'); } return $dateTime->format('YmdHis'); } }