Passed
Push — master ( 052ddc...675ec9 )
by Joas
13:56 queued 13s
created
core/Command/Maintenance/Install.php 2 patches
Indentation   +161 added lines, -161 removed lines patch added patch discarded remove patch
@@ -46,165 +46,165 @@
 block discarded – undo
46 46
 
47 47
 class Install extends Command {
48 48
 
49
-	/**
50
-	 * @var SystemConfig
51
-	 */
52
-	private $config;
53
-
54
-	public function __construct(SystemConfig $config) {
55
-		parent::__construct();
56
-		$this->config = $config;
57
-	}
58
-
59
-	protected function configure() {
60
-		$this
61
-			->setName('maintenance:install')
62
-			->setDescription('install Nextcloud')
63
-			->addOption('database', null, InputOption::VALUE_REQUIRED, 'Supported database type', 'sqlite')
64
-			->addOption('database-name', null, InputOption::VALUE_REQUIRED, 'Name of the database')
65
-			->addOption('database-host', null, InputOption::VALUE_REQUIRED, 'Hostname of the database', 'localhost')
66
-			->addOption('database-port', null, InputOption::VALUE_REQUIRED, 'Port the database is listening on')
67
-			->addOption('database-user', null, InputOption::VALUE_REQUIRED, 'User name to connect to the database')
68
-			->addOption('database-pass', null, InputOption::VALUE_OPTIONAL, 'Password of the database user', null)
69
-			->addOption('database-table-space', null, InputOption::VALUE_OPTIONAL, 'Table space of the database (oci only)', null)
70
-			->addOption('admin-user', null, InputOption::VALUE_REQUIRED, 'User name of the admin account', 'admin')
71
-			->addOption('admin-pass', null, InputOption::VALUE_REQUIRED, 'Password of the admin account')
72
-			->addOption('admin-email', null, InputOption::VALUE_OPTIONAL, 'E-Mail of the admin account')
73
-			->addOption('data-dir', null, InputOption::VALUE_REQUIRED, 'Path to data directory', \OC::$SERVERROOT."/data");
74
-	}
75
-
76
-	protected function execute(InputInterface $input, OutputInterface $output) {
77
-
78
-		// validate the environment
79
-		$server = \OC::$server;
80
-		$setupHelper = new Setup(
81
-			$this->config,
82
-			$server->getIniWrapper(),
83
-			$server->getL10N('lib'),
84
-			$server->query(Defaults::class),
85
-			$server->getLogger(),
86
-			$server->getSecureRandom(),
87
-			\OC::$server->query(Installer::class)
88
-		);
89
-		$sysInfo = $setupHelper->getSystemInfo(true);
90
-		$errors = $sysInfo['errors'];
91
-		if (count($errors) > 0) {
92
-			$this->printErrors($output, $errors);
93
-
94
-			// ignore the OS X setup warning
95
-			if (count($errors) !== 1 ||
96
-				(string)$errors[0]['error'] !== 'Mac OS X is not supported and Nextcloud will not work properly on this platform. Use it at your own risk! ') {
97
-				return 1;
98
-			}
99
-		}
100
-
101
-		// validate user input
102
-		$options = $this->validateInput($input, $output, array_keys($sysInfo['databases']));
103
-
104
-		// perform installation
105
-		$errors = $setupHelper->install($options);
106
-		if (count($errors) > 0) {
107
-			$this->printErrors($output, $errors);
108
-			return 1;
109
-		}
110
-		$output->writeln("Nextcloud was successfully installed");
111
-		return 0;
112
-	}
113
-
114
-	/**
115
-	 * @param InputInterface $input
116
-	 * @param OutputInterface $output
117
-	 * @param string[] $supportedDatabases
118
-	 * @return array
119
-	 */
120
-	protected function validateInput(InputInterface $input, OutputInterface $output, $supportedDatabases) {
121
-		$db = strtolower($input->getOption('database'));
122
-
123
-		if (!in_array($db, $supportedDatabases)) {
124
-			throw new InvalidArgumentException("Database <$db> is not supported.");
125
-		}
126
-
127
-		$dbUser = $input->getOption('database-user');
128
-		$dbPass = $input->getOption('database-pass');
129
-		$dbName = $input->getOption('database-name');
130
-		$dbPort = $input->getOption('database-port');
131
-		if ($db === 'oci') {
132
-			// an empty hostname needs to be read from the raw parameters
133
-			$dbHost = $input->getParameterOption('--database-host', '');
134
-		} else {
135
-			$dbHost = $input->getOption('database-host');
136
-		}
137
-		if ($dbPort) {
138
-			// Append the port to the host so it is the same as in the config (there is no dbport config)
139
-			$dbHost .= ':' . $dbPort;
140
-		}
141
-		if ($input->hasParameterOption('--database-pass')) {
142
-			$dbPass = (string) $input->getOption('database-pass');
143
-		}
144
-		$adminLogin = $input->getOption('admin-user');
145
-		$adminPassword = $input->getOption('admin-pass');
146
-		$adminEmail = $input->getOption('admin-email');
147
-		$dataDir = $input->getOption('data-dir');
148
-
149
-		if ($db !== 'sqlite') {
150
-			if (is_null($dbUser)) {
151
-				throw new InvalidArgumentException("Database user not provided.");
152
-			}
153
-			if (is_null($dbName)) {
154
-				throw new InvalidArgumentException("Database name not provided.");
155
-			}
156
-			if (is_null($dbPass)) {
157
-				/** @var QuestionHelper $helper */
158
-				$helper = $this->getHelper('question');
159
-				$question = new Question('What is the password to access the database with user <'.$dbUser.'>?');
160
-				$question->setHidden(true);
161
-				$question->setHiddenFallback(false);
162
-				$dbPass = $helper->ask($input, $output, $question);
163
-			}
164
-		}
165
-
166
-		if (is_null($adminPassword)) {
167
-			/** @var QuestionHelper $helper */
168
-			$helper = $this->getHelper('question');
169
-			$question = new Question('What is the password you like to use for the admin account <'.$adminLogin.'>?');
170
-			$question->setHidden(true);
171
-			$question->setHiddenFallback(false);
172
-			$adminPassword = $helper->ask($input, $output, $question);
173
-		}
174
-
175
-		if ($adminEmail !== null && !filter_var($adminEmail, FILTER_VALIDATE_EMAIL)) {
176
-			throw new InvalidArgumentException('Invalid e-mail-address <' . $adminEmail . '> for <' . $adminLogin . '>.');
177
-		}
178
-
179
-		$options = [
180
-			'dbtype' => $db,
181
-			'dbuser' => $dbUser,
182
-			'dbpass' => $dbPass,
183
-			'dbname' => $dbName,
184
-			'dbhost' => $dbHost,
185
-			'adminlogin' => $adminLogin,
186
-			'adminpass' => $adminPassword,
187
-			'adminemail' => $adminEmail,
188
-			'directory' => $dataDir
189
-		];
190
-		if ($db === 'oci') {
191
-			$options['dbtablespace'] = $input->getParameterOption('--database-table-space', '');
192
-		}
193
-		return $options;
194
-	}
195
-
196
-	/**
197
-	 * @param OutputInterface $output
198
-	 * @param $errors
199
-	 */
200
-	protected function printErrors(OutputInterface $output, $errors) {
201
-		foreach ($errors as $error) {
202
-			if (is_array($error)) {
203
-				$output->writeln('<error>' . (string)$error['error'] . '</error>');
204
-				$output->writeln('<info> -> ' . (string)$error['hint'] . '</info>');
205
-			} else {
206
-				$output->writeln('<error>' . (string)$error . '</error>');
207
-			}
208
-		}
209
-	}
49
+    /**
50
+     * @var SystemConfig
51
+     */
52
+    private $config;
53
+
54
+    public function __construct(SystemConfig $config) {
55
+        parent::__construct();
56
+        $this->config = $config;
57
+    }
58
+
59
+    protected function configure() {
60
+        $this
61
+            ->setName('maintenance:install')
62
+            ->setDescription('install Nextcloud')
63
+            ->addOption('database', null, InputOption::VALUE_REQUIRED, 'Supported database type', 'sqlite')
64
+            ->addOption('database-name', null, InputOption::VALUE_REQUIRED, 'Name of the database')
65
+            ->addOption('database-host', null, InputOption::VALUE_REQUIRED, 'Hostname of the database', 'localhost')
66
+            ->addOption('database-port', null, InputOption::VALUE_REQUIRED, 'Port the database is listening on')
67
+            ->addOption('database-user', null, InputOption::VALUE_REQUIRED, 'User name to connect to the database')
68
+            ->addOption('database-pass', null, InputOption::VALUE_OPTIONAL, 'Password of the database user', null)
69
+            ->addOption('database-table-space', null, InputOption::VALUE_OPTIONAL, 'Table space of the database (oci only)', null)
70
+            ->addOption('admin-user', null, InputOption::VALUE_REQUIRED, 'User name of the admin account', 'admin')
71
+            ->addOption('admin-pass', null, InputOption::VALUE_REQUIRED, 'Password of the admin account')
72
+            ->addOption('admin-email', null, InputOption::VALUE_OPTIONAL, 'E-Mail of the admin account')
73
+            ->addOption('data-dir', null, InputOption::VALUE_REQUIRED, 'Path to data directory', \OC::$SERVERROOT."/data");
74
+    }
75
+
76
+    protected function execute(InputInterface $input, OutputInterface $output) {
77
+
78
+        // validate the environment
79
+        $server = \OC::$server;
80
+        $setupHelper = new Setup(
81
+            $this->config,
82
+            $server->getIniWrapper(),
83
+            $server->getL10N('lib'),
84
+            $server->query(Defaults::class),
85
+            $server->getLogger(),
86
+            $server->getSecureRandom(),
87
+            \OC::$server->query(Installer::class)
88
+        );
89
+        $sysInfo = $setupHelper->getSystemInfo(true);
90
+        $errors = $sysInfo['errors'];
91
+        if (count($errors) > 0) {
92
+            $this->printErrors($output, $errors);
93
+
94
+            // ignore the OS X setup warning
95
+            if (count($errors) !== 1 ||
96
+                (string)$errors[0]['error'] !== 'Mac OS X is not supported and Nextcloud will not work properly on this platform. Use it at your own risk! ') {
97
+                return 1;
98
+            }
99
+        }
100
+
101
+        // validate user input
102
+        $options = $this->validateInput($input, $output, array_keys($sysInfo['databases']));
103
+
104
+        // perform installation
105
+        $errors = $setupHelper->install($options);
106
+        if (count($errors) > 0) {
107
+            $this->printErrors($output, $errors);
108
+            return 1;
109
+        }
110
+        $output->writeln("Nextcloud was successfully installed");
111
+        return 0;
112
+    }
113
+
114
+    /**
115
+     * @param InputInterface $input
116
+     * @param OutputInterface $output
117
+     * @param string[] $supportedDatabases
118
+     * @return array
119
+     */
120
+    protected function validateInput(InputInterface $input, OutputInterface $output, $supportedDatabases) {
121
+        $db = strtolower($input->getOption('database'));
122
+
123
+        if (!in_array($db, $supportedDatabases)) {
124
+            throw new InvalidArgumentException("Database <$db> is not supported.");
125
+        }
126
+
127
+        $dbUser = $input->getOption('database-user');
128
+        $dbPass = $input->getOption('database-pass');
129
+        $dbName = $input->getOption('database-name');
130
+        $dbPort = $input->getOption('database-port');
131
+        if ($db === 'oci') {
132
+            // an empty hostname needs to be read from the raw parameters
133
+            $dbHost = $input->getParameterOption('--database-host', '');
134
+        } else {
135
+            $dbHost = $input->getOption('database-host');
136
+        }
137
+        if ($dbPort) {
138
+            // Append the port to the host so it is the same as in the config (there is no dbport config)
139
+            $dbHost .= ':' . $dbPort;
140
+        }
141
+        if ($input->hasParameterOption('--database-pass')) {
142
+            $dbPass = (string) $input->getOption('database-pass');
143
+        }
144
+        $adminLogin = $input->getOption('admin-user');
145
+        $adminPassword = $input->getOption('admin-pass');
146
+        $adminEmail = $input->getOption('admin-email');
147
+        $dataDir = $input->getOption('data-dir');
148
+
149
+        if ($db !== 'sqlite') {
150
+            if (is_null($dbUser)) {
151
+                throw new InvalidArgumentException("Database user not provided.");
152
+            }
153
+            if (is_null($dbName)) {
154
+                throw new InvalidArgumentException("Database name not provided.");
155
+            }
156
+            if (is_null($dbPass)) {
157
+                /** @var QuestionHelper $helper */
158
+                $helper = $this->getHelper('question');
159
+                $question = new Question('What is the password to access the database with user <'.$dbUser.'>?');
160
+                $question->setHidden(true);
161
+                $question->setHiddenFallback(false);
162
+                $dbPass = $helper->ask($input, $output, $question);
163
+            }
164
+        }
165
+
166
+        if (is_null($adminPassword)) {
167
+            /** @var QuestionHelper $helper */
168
+            $helper = $this->getHelper('question');
169
+            $question = new Question('What is the password you like to use for the admin account <'.$adminLogin.'>?');
170
+            $question->setHidden(true);
171
+            $question->setHiddenFallback(false);
172
+            $adminPassword = $helper->ask($input, $output, $question);
173
+        }
174
+
175
+        if ($adminEmail !== null && !filter_var($adminEmail, FILTER_VALIDATE_EMAIL)) {
176
+            throw new InvalidArgumentException('Invalid e-mail-address <' . $adminEmail . '> for <' . $adminLogin . '>.');
177
+        }
178
+
179
+        $options = [
180
+            'dbtype' => $db,
181
+            'dbuser' => $dbUser,
182
+            'dbpass' => $dbPass,
183
+            'dbname' => $dbName,
184
+            'dbhost' => $dbHost,
185
+            'adminlogin' => $adminLogin,
186
+            'adminpass' => $adminPassword,
187
+            'adminemail' => $adminEmail,
188
+            'directory' => $dataDir
189
+        ];
190
+        if ($db === 'oci') {
191
+            $options['dbtablespace'] = $input->getParameterOption('--database-table-space', '');
192
+        }
193
+        return $options;
194
+    }
195
+
196
+    /**
197
+     * @param OutputInterface $output
198
+     * @param $errors
199
+     */
200
+    protected function printErrors(OutputInterface $output, $errors) {
201
+        foreach ($errors as $error) {
202
+            if (is_array($error)) {
203
+                $output->writeln('<error>' . (string)$error['error'] . '</error>');
204
+                $output->writeln('<info> -> ' . (string)$error['hint'] . '</info>');
205
+            } else {
206
+                $output->writeln('<error>' . (string)$error . '</error>');
207
+            }
208
+        }
209
+    }
210 210
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 
94 94
 			// ignore the OS X setup warning
95 95
 			if (count($errors) !== 1 ||
96
-				(string)$errors[0]['error'] !== 'Mac OS X is not supported and Nextcloud will not work properly on this platform. Use it at your own risk! ') {
96
+				(string) $errors[0]['error'] !== 'Mac OS X is not supported and Nextcloud will not work properly on this platform. Use it at your own risk! ') {
97 97
 				return 1;
98 98
 			}
99 99
 		}
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 		}
137 137
 		if ($dbPort) {
138 138
 			// Append the port to the host so it is the same as in the config (there is no dbport config)
139
-			$dbHost .= ':' . $dbPort;
139
+			$dbHost .= ':'.$dbPort;
140 140
 		}
141 141
 		if ($input->hasParameterOption('--database-pass')) {
142 142
 			$dbPass = (string) $input->getOption('database-pass');
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
 		}
174 174
 
175 175
 		if ($adminEmail !== null && !filter_var($adminEmail, FILTER_VALIDATE_EMAIL)) {
176
-			throw new InvalidArgumentException('Invalid e-mail-address <' . $adminEmail . '> for <' . $adminLogin . '>.');
176
+			throw new InvalidArgumentException('Invalid e-mail-address <'.$adminEmail.'> for <'.$adminLogin.'>.');
177 177
 		}
178 178
 
179 179
 		$options = [
@@ -200,10 +200,10 @@  discard block
 block discarded – undo
200 200
 	protected function printErrors(OutputInterface $output, $errors) {
201 201
 		foreach ($errors as $error) {
202 202
 			if (is_array($error)) {
203
-				$output->writeln('<error>' . (string)$error['error'] . '</error>');
204
-				$output->writeln('<info> -> ' . (string)$error['hint'] . '</info>');
203
+				$output->writeln('<error>'.(string) $error['error'].'</error>');
204
+				$output->writeln('<info> -> '.(string) $error['hint'].'</info>');
205 205
 			} else {
206
-				$output->writeln('<error>' . (string)$error . '</error>');
206
+				$output->writeln('<error>'.(string) $error.'</error>');
207 207
 			}
208 208
 		}
209 209
 	}
Please login to merge, or discard this patch.