From 5e27ac3e0d99c272dfb1c50cf7265cd8e329558c Mon Sep 17 00:00:00 2001
From: Vincent Petry <pvince81@owncloud.com>
Date: Thu, 5 Jun 2014 16:19:24 +0200
Subject: Added CLI arguments for upgrade simulation steps

Added "dry run" argument to only run the update simulation.
Added argument to disable migration (useful for bigger setups where
table duplication would take too much space)
---
 core/command/upgrade.php | 45 ++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 42 insertions(+), 3 deletions(-)

(limited to 'core')

diff --git a/core/command/upgrade.php b/core/command/upgrade.php
index c3946d2aab5..d037082c5e8 100644
--- a/core/command/upgrade.php
+++ b/core/command/upgrade.php
@@ -12,6 +12,7 @@ use OC\Updater;
 use Symfony\Component\Console\Command\Command;
 use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Output\OutputInterface;
+use Symfony\Component\Console\Input\InputOption;
 
 class Upgrade extends Command {
 
@@ -19,12 +20,24 @@ class Upgrade extends Command {
 	const ERROR_NOT_INSTALLED = 1;
 	const ERROR_MAINTENANCE_MODE = 2;
 	const ERROR_UP_TO_DATE = 3;
+	const ERROR_INVALID_ARGUMENTS = 4;
 
 	protected function configure() {
 		$this
 			->setName('upgrade')
 			->setDescription('run upgrade routines')
-		;
+			->addOption(
+				'--skip-migration-test',
+				null,
+				InputOption::VALUE_NONE,
+				'skips the database schema migration simulation and update directly'
+			)
+			->addOption(
+				'--dry-run',
+				null,
+				InputOption::VALUE_NONE,
+				'only runs the database schema migration simulation, do not actually update'
+			);
 	}
 
 	/**
@@ -43,15 +56,41 @@ class Upgrade extends Command {
 			return self::ERROR_NOT_INSTALLED;
 		}
 
+		$simulateStepEnabled = true;
+		$updateStepEnabled = true;
+
+		if ($input->getOption('skip-migration-test')) {
+			$simulateStepEnabled = false;
+		}
+	   	if ($input->getOption('dry-run')) {
+			$updateStepEnabled = false;
+		}
+
+		if (!$simulateStepEnabled && !$updateStepEnabled) {
+			$output->writeln(
+				'<error>Only one of "--skip-migration-test" or "--dry-run" ' .
+				'can be specified at a time.</error>'
+			);
+			return self::ERROR_INVALID_ARGUMENTS;
+		}
+
 		if(\OC::checkUpgrade(false)) {
 			$updater = new Updater();
 
+			$updater->setSimulateStepEnabled($simulateStepEnabled);
+			$updater->setUpdateStepEnabled($updateStepEnabled);
+
 			$updater->listen('\OC\Updater', 'maintenanceStart', function () use($output) {
 				$output->writeln('<info>Turned on maintenance mode</info>');
 			});
-			$updater->listen('\OC\Updater', 'maintenanceEnd', function () use($output) {
+			$updater->listen('\OC\Updater', 'maintenanceEnd', function () use($output, $updateStepEnabled) {
 				$output->writeln('<info>Turned off maintenance mode</info>');
-				$output->writeln('<info>Update successful</info>');
+				if (!$updateStepEnabled) {
+					$output->writeln('<info>Update simulation successful</info>');
+				}
+				else {
+					$output->writeln('<info>Update successful</info>');
+				}
 			});
 			$updater->listen('\OC\Updater', 'dbUpgrade', function () use($output) {
 				$output->writeln('<info>Updated database</info>');
-- 
cgit v1.2.3