Completed
Pull Request — master (#10075)
by
unknown
27:10
created
apps/federation/lib/DAV/FedAuth.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -29,40 +29,40 @@
 block discarded – undo
29 29
 
30 30
 class FedAuth extends AbstractBasic {
31 31
 
32
-	/** @var DbHandler */
33
-	private $db;
32
+    /** @var DbHandler */
33
+    private $db;
34 34
 
35
-	/**
36
-	 * FedAuth constructor.
37
-	 *
38
-	 * @param DbHandler $db
39
-	 */
40
-	public function __construct(DbHandler $db) {
41
-		$this->db = $db;
42
-		$this->principalPrefix = 'principals/system/';
35
+    /**
36
+     * FedAuth constructor.
37
+     *
38
+     * @param DbHandler $db
39
+     */
40
+    public function __construct(DbHandler $db) {
41
+        $this->db = $db;
42
+        $this->principalPrefix = 'principals/system/';
43 43
 
44
-		// setup realm
45
-		$defaults = new \OCP\Defaults();
46
-		$this->realm = $defaults->getName();
47
-	}
44
+        // setup realm
45
+        $defaults = new \OCP\Defaults();
46
+        $this->realm = $defaults->getName();
47
+    }
48 48
 
49
-	/**
50
-	 * Validates a username and password
51
-	 *
52
-	 * This method should return true or false depending on if login
53
-	 * succeeded.
54
-	 *
55
-	 * @param string $username
56
-	 * @param string $password
57
-	 * @return bool
58
-	 */
59
-	protected function validateUserPass($username, $password) {
60
-		return $this->db->auth($username, $password);
61
-	}
49
+    /**
50
+     * Validates a username and password
51
+     *
52
+     * This method should return true or false depending on if login
53
+     * succeeded.
54
+     *
55
+     * @param string $username
56
+     * @param string $password
57
+     * @return bool
58
+     */
59
+    protected function validateUserPass($username, $password) {
60
+        return $this->db->auth($username, $password);
61
+    }
62 62
 
63
-	/**
64
-	 * @inheritdoc
65
-	 */
66
-	public function challenge(RequestInterface $request, ResponseInterface $response) {
67
-	}
63
+    /**
64
+     * @inheritdoc
65
+     */
66
+    public function challenge(RequestInterface $request, ResponseInterface $response) {
67
+    }
68 68
 }
Please login to merge, or discard this patch.
lib/private/L10N/L10NString.php 3 patches
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -61,8 +61,7 @@
 block discarded – undo
61 61
 				$fn = $this->l10n->getPluralFormFunction();
62 62
 				$id = $fn($this->count);
63 63
 				$text = $translations[$this->text][$id];
64
-			}
65
-			else{
64
+			} else{
66 65
 				$text = $translations[$this->text];
67 66
 			}
68 67
 		}
Please login to merge, or discard this patch.
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -29,59 +29,59 @@
 block discarded – undo
29 29
 namespace OC\L10N;
30 30
 
31 31
 class L10NString implements \JsonSerializable {
32
-	/** @var \OC\L10N\L10N */
33
-	protected $l10n;
32
+    /** @var \OC\L10N\L10N */
33
+    protected $l10n;
34 34
 
35
-	/** @var string */
36
-	protected $text;
35
+    /** @var string */
36
+    protected $text;
37 37
 
38
-	/** @var array */
39
-	protected $parameters;
38
+    /** @var array */
39
+    protected $parameters;
40 40
 
41
-	/** @var integer */
42
-	protected $count;
41
+    /** @var integer */
42
+    protected $count;
43 43
 
44
-	/**
45
-	 * @param \OC\L10N\L10N $l10n
46
-	 * @param string|string[] $text
47
-	 * @param array $parameters
48
-	 * @param int $count
49
-	 */
50
-	public function __construct(\OC\L10N\L10N $l10n, $text, $parameters, $count = 1) {
51
-		$this->l10n = $l10n;
52
-		$this->text = $text;
53
-		$this->parameters = $parameters;
54
-		$this->count = $count;
55
-	}
44
+    /**
45
+     * @param \OC\L10N\L10N $l10n
46
+     * @param string|string[] $text
47
+     * @param array $parameters
48
+     * @param int $count
49
+     */
50
+    public function __construct(\OC\L10N\L10N $l10n, $text, $parameters, $count = 1) {
51
+        $this->l10n = $l10n;
52
+        $this->text = $text;
53
+        $this->parameters = $parameters;
54
+        $this->count = $count;
55
+    }
56 56
 
57
-	/**
58
-	 * @return string
59
-	 */
60
-	public function __toString() {
61
-		$translations = $this->l10n->getTranslations();
57
+    /**
58
+     * @return string
59
+     */
60
+    public function __toString() {
61
+        $translations = $this->l10n->getTranslations();
62 62
 
63
-		$text = $this->text;
64
-		if(array_key_exists($this->text, $translations)) {
65
-			if(is_array($translations[$this->text])) {
66
-				$fn = $this->l10n->getPluralFormFunction();
67
-				$id = $fn($this->count);
68
-				$text = $translations[$this->text][$id];
69
-			}
70
-			else{
71
-				$text = $translations[$this->text];
72
-			}
73
-		}
63
+        $text = $this->text;
64
+        if(array_key_exists($this->text, $translations)) {
65
+            if(is_array($translations[$this->text])) {
66
+                $fn = $this->l10n->getPluralFormFunction();
67
+                $id = $fn($this->count);
68
+                $text = $translations[$this->text][$id];
69
+            }
70
+            else{
71
+                $text = $translations[$this->text];
72
+            }
73
+        }
74 74
 
75
-		// Replace %n first (won't interfere with vsprintf)
76
-		$text = str_replace('%n', (string)$this->count, $text);
77
-		return vsprintf($text, $this->parameters);
78
-	}
75
+        // Replace %n first (won't interfere with vsprintf)
76
+        $text = str_replace('%n', (string)$this->count, $text);
77
+        return vsprintf($text, $this->parameters);
78
+    }
79 79
 
80 80
 
81
-	/**
82
-	 * @return string
83
-	 */
84
-	public function jsonSerialize() {
85
-		return $this->__toString();
86
-	}
81
+    /**
82
+     * @return string
83
+     */
84
+    public function jsonSerialize() {
85
+        return $this->__toString();
86
+    }
87 87
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -56,19 +56,19 @@
 block discarded – undo
56 56
 		$translations = $this->l10n->getTranslations();
57 57
 
58 58
 		$text = $this->text;
59
-		if(array_key_exists($this->text, $translations)) {
60
-			if(is_array($translations[$this->text])) {
59
+		if (array_key_exists($this->text, $translations)) {
60
+			if (is_array($translations[$this->text])) {
61 61
 				$fn = $this->l10n->getPluralFormFunction();
62 62
 				$id = $fn($this->count);
63 63
 				$text = $translations[$this->text][$id];
64 64
 			}
65
-			else{
65
+			else {
66 66
 				$text = $translations[$this->text];
67 67
 			}
68 68
 		}
69 69
 
70 70
 		// Replace %n first (won't interfere with vsprintf)
71
-		$text = str_replace('%n', (string)$this->count, $text);
71
+		$text = str_replace('%n', (string) $this->count, $text);
72 72
 		return vsprintf($text, $this->parameters);
73 73
 	}
74 74
 
Please login to merge, or discard this patch.
lib/private/DB/QueryBuilder/ExpressionBuilder/OCIExpressionBuilder.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
 	public function castColumn($column, $type) {
148 148
 		if ($type === IQueryBuilder::PARAM_STR) {
149 149
 			$column = $this->helper->quoteColumnName($column);
150
-			return new QueryFunction('to_char(' . $column . ')');
150
+			return new QueryFunction('to_char('.$column.')');
151 151
 		}
152 152
 
153 153
 		return parent::castColumn($column, $type);
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
 	 * @inheritdoc
158 158
 	 */
159 159
 	public function like($x, $y, $type = null) {
160
-		return parent::like($x, $y, $type) . " ESCAPE '\\'";
160
+		return parent::like($x, $y, $type)." ESCAPE '\\'";
161 161
 	}
162 162
 
163 163
 	/**
@@ -166,6 +166,6 @@  discard block
 block discarded – undo
166 166
 	public function iLike($x, $y, $type = null) {
167 167
 		$x = $this->helper->quoteColumnName($x);
168 168
 		$y = $this->helper->quoteColumnName($y);
169
-		return new QueryFunction('REGEXP_LIKE(' . $x . ', \'^\' || REPLACE(REPLACE(' . $y . ', \'%\', \'.*\'), \'_\', \'.\') || \'$\', \'i\')');
169
+		return new QueryFunction('REGEXP_LIKE('.$x.', \'^\' || REPLACE(REPLACE('.$y.', \'%\', \'.*\'), \'_\', \'.\') || \'$\', \'i\')');
170 170
 	}
171 171
 }
Please login to merge, or discard this patch.
Indentation   +157 added lines, -157 removed lines patch added patch discarded remove patch
@@ -33,161 +33,161 @@
 block discarded – undo
33 33
 
34 34
 class OCIExpressionBuilder extends ExpressionBuilder {
35 35
 
36
-	/**
37
-	 * @param mixed $column
38
-	 * @param mixed|null $type
39
-	 * @return array|IQueryFunction|string
40
-	 */
41
-	protected function prepareColumn($column, $type) {
42
-		if ($type === IQueryBuilder::PARAM_STR && !is_array($column) && !($column instanceof IParameter) && !($column instanceof ILiteral)) {
43
-			$column = $this->castColumn($column, $type);
44
-		} else {
45
-			$column = $this->helper->quoteColumnNames($column);
46
-		}
47
-		return $column;
48
-	}
49
-
50
-	/**
51
-	 * @inheritdoc
52
-	 */
53
-	public function comparison($x, $operator, $y, $type = null) {
54
-		$x = $this->prepareColumn($x, $type);
55
-		$y = $this->prepareColumn($y, $type);
56
-
57
-		return $this->expressionBuilder->comparison($x, $operator, $y);
58
-	}
59
-
60
-	/**
61
-	 * @inheritdoc
62
-	 */
63
-	public function eq($x, $y, $type = null) {
64
-		$x = $this->prepareColumn($x, $type);
65
-		$y = $this->prepareColumn($y, $type);
66
-
67
-		return $this->expressionBuilder->eq($x, $y);
68
-	}
69
-
70
-	/**
71
-	 * @inheritdoc
72
-	 */
73
-	public function neq($x, $y, $type = null) {
74
-		$x = $this->prepareColumn($x, $type);
75
-		$y = $this->prepareColumn($y, $type);
76
-
77
-		return $this->expressionBuilder->neq($x, $y);
78
-	}
79
-
80
-	/**
81
-	 * @inheritdoc
82
-	 */
83
-	public function lt($x, $y, $type = null) {
84
-		$x = $this->prepareColumn($x, $type);
85
-		$y = $this->prepareColumn($y, $type);
86
-
87
-		return $this->expressionBuilder->lt($x, $y);
88
-	}
89
-
90
-	/**
91
-	 * @inheritdoc
92
-	 */
93
-	public function lte($x, $y, $type = null) {
94
-		$x = $this->prepareColumn($x, $type);
95
-		$y = $this->prepareColumn($y, $type);
96
-
97
-		return $this->expressionBuilder->lte($x, $y);
98
-	}
99
-
100
-	/**
101
-	 * @inheritdoc
102
-	 */
103
-	public function gt($x, $y, $type = null) {
104
-		$x = $this->prepareColumn($x, $type);
105
-		$y = $this->prepareColumn($y, $type);
106
-
107
-		return $this->expressionBuilder->gt($x, $y);
108
-	}
109
-
110
-	/**
111
-	 * @inheritdoc
112
-	 */
113
-	public function gte($x, $y, $type = null) {
114
-		$x = $this->prepareColumn($x, $type);
115
-		$y = $this->prepareColumn($y, $type);
116
-
117
-		return $this->expressionBuilder->gte($x, $y);
118
-	}
119
-
120
-	/**
121
-	 * @inheritdoc
122
-	 */
123
-	public function in($x, $y, $type = null) {
124
-		$x = $this->prepareColumn($x, $type);
125
-		$y = $this->prepareColumn($y, $type);
126
-
127
-		return $this->expressionBuilder->in($x, $y);
128
-	}
129
-
130
-	/**
131
-	 * @inheritdoc
132
-	 */
133
-	public function notIn($x, $y, $type = null) {
134
-		$x = $this->prepareColumn($x, $type);
135
-		$y = $this->prepareColumn($y, $type);
136
-
137
-		return $this->expressionBuilder->notIn($x, $y);
138
-	}
139
-
140
-	/**
141
-	 * Creates a $x = '' statement, because Oracle needs a different check
142
-	 *
143
-	 * @param string $x The field in string format to be inspected by the comparison.
144
-	 * @return string
145
-	 * @since 13.0.0
146
-	 */
147
-	public function emptyString($x) {
148
-		return $this->isNull($x);
149
-	}
150
-
151
-	/**
152
-	 * Creates a `$x <> ''` statement, because Oracle needs a different check
153
-	 *
154
-	 * @param string $x The field in string format to be inspected by the comparison.
155
-	 * @return string
156
-	 * @since 13.0.0
157
-	 */
158
-	public function nonEmptyString($x) {
159
-		return $this->isNotNull($x);
160
-	}
161
-
162
-	/**
163
-	 * Returns a IQueryFunction that casts the column to the given type
164
-	 *
165
-	 * @param string $column
166
-	 * @param mixed $type One of IQueryBuilder::PARAM_*
167
-	 * @return IQueryFunction
168
-	 */
169
-	public function castColumn($column, $type) {
170
-		if ($type === IQueryBuilder::PARAM_STR) {
171
-			$column = $this->helper->quoteColumnName($column);
172
-			return new QueryFunction('to_char(' . $column . ')');
173
-		}
174
-
175
-		return parent::castColumn($column, $type);
176
-	}
177
-
178
-	/**
179
-	 * @inheritdoc
180
-	 */
181
-	public function like($x, $y, $type = null) {
182
-		return parent::like($x, $y, $type) . " ESCAPE '\\'";
183
-	}
184
-
185
-	/**
186
-	 * @inheritdoc
187
-	 */
188
-	public function iLike($x, $y, $type = null) {
189
-		$x = $this->helper->quoteColumnName($x);
190
-		$y = $this->helper->quoteColumnName($y);
191
-		return new QueryFunction('REGEXP_LIKE(' . $x . ', \'^\' || REPLACE(REPLACE(' . $y . ', \'%\', \'.*\'), \'_\', \'.\') || \'$\', \'i\')');
192
-	}
36
+    /**
37
+     * @param mixed $column
38
+     * @param mixed|null $type
39
+     * @return array|IQueryFunction|string
40
+     */
41
+    protected function prepareColumn($column, $type) {
42
+        if ($type === IQueryBuilder::PARAM_STR && !is_array($column) && !($column instanceof IParameter) && !($column instanceof ILiteral)) {
43
+            $column = $this->castColumn($column, $type);
44
+        } else {
45
+            $column = $this->helper->quoteColumnNames($column);
46
+        }
47
+        return $column;
48
+    }
49
+
50
+    /**
51
+     * @inheritdoc
52
+     */
53
+    public function comparison($x, $operator, $y, $type = null) {
54
+        $x = $this->prepareColumn($x, $type);
55
+        $y = $this->prepareColumn($y, $type);
56
+
57
+        return $this->expressionBuilder->comparison($x, $operator, $y);
58
+    }
59
+
60
+    /**
61
+     * @inheritdoc
62
+     */
63
+    public function eq($x, $y, $type = null) {
64
+        $x = $this->prepareColumn($x, $type);
65
+        $y = $this->prepareColumn($y, $type);
66
+
67
+        return $this->expressionBuilder->eq($x, $y);
68
+    }
69
+
70
+    /**
71
+     * @inheritdoc
72
+     */
73
+    public function neq($x, $y, $type = null) {
74
+        $x = $this->prepareColumn($x, $type);
75
+        $y = $this->prepareColumn($y, $type);
76
+
77
+        return $this->expressionBuilder->neq($x, $y);
78
+    }
79
+
80
+    /**
81
+     * @inheritdoc
82
+     */
83
+    public function lt($x, $y, $type = null) {
84
+        $x = $this->prepareColumn($x, $type);
85
+        $y = $this->prepareColumn($y, $type);
86
+
87
+        return $this->expressionBuilder->lt($x, $y);
88
+    }
89
+
90
+    /**
91
+     * @inheritdoc
92
+     */
93
+    public function lte($x, $y, $type = null) {
94
+        $x = $this->prepareColumn($x, $type);
95
+        $y = $this->prepareColumn($y, $type);
96
+
97
+        return $this->expressionBuilder->lte($x, $y);
98
+    }
99
+
100
+    /**
101
+     * @inheritdoc
102
+     */
103
+    public function gt($x, $y, $type = null) {
104
+        $x = $this->prepareColumn($x, $type);
105
+        $y = $this->prepareColumn($y, $type);
106
+
107
+        return $this->expressionBuilder->gt($x, $y);
108
+    }
109
+
110
+    /**
111
+     * @inheritdoc
112
+     */
113
+    public function gte($x, $y, $type = null) {
114
+        $x = $this->prepareColumn($x, $type);
115
+        $y = $this->prepareColumn($y, $type);
116
+
117
+        return $this->expressionBuilder->gte($x, $y);
118
+    }
119
+
120
+    /**
121
+     * @inheritdoc
122
+     */
123
+    public function in($x, $y, $type = null) {
124
+        $x = $this->prepareColumn($x, $type);
125
+        $y = $this->prepareColumn($y, $type);
126
+
127
+        return $this->expressionBuilder->in($x, $y);
128
+    }
129
+
130
+    /**
131
+     * @inheritdoc
132
+     */
133
+    public function notIn($x, $y, $type = null) {
134
+        $x = $this->prepareColumn($x, $type);
135
+        $y = $this->prepareColumn($y, $type);
136
+
137
+        return $this->expressionBuilder->notIn($x, $y);
138
+    }
139
+
140
+    /**
141
+     * Creates a $x = '' statement, because Oracle needs a different check
142
+     *
143
+     * @param string $x The field in string format to be inspected by the comparison.
144
+     * @return string
145
+     * @since 13.0.0
146
+     */
147
+    public function emptyString($x) {
148
+        return $this->isNull($x);
149
+    }
150
+
151
+    /**
152
+     * Creates a `$x <> ''` statement, because Oracle needs a different check
153
+     *
154
+     * @param string $x The field in string format to be inspected by the comparison.
155
+     * @return string
156
+     * @since 13.0.0
157
+     */
158
+    public function nonEmptyString($x) {
159
+        return $this->isNotNull($x);
160
+    }
161
+
162
+    /**
163
+     * Returns a IQueryFunction that casts the column to the given type
164
+     *
165
+     * @param string $column
166
+     * @param mixed $type One of IQueryBuilder::PARAM_*
167
+     * @return IQueryFunction
168
+     */
169
+    public function castColumn($column, $type) {
170
+        if ($type === IQueryBuilder::PARAM_STR) {
171
+            $column = $this->helper->quoteColumnName($column);
172
+            return new QueryFunction('to_char(' . $column . ')');
173
+        }
174
+
175
+        return parent::castColumn($column, $type);
176
+    }
177
+
178
+    /**
179
+     * @inheritdoc
180
+     */
181
+    public function like($x, $y, $type = null) {
182
+        return parent::like($x, $y, $type) . " ESCAPE '\\'";
183
+    }
184
+
185
+    /**
186
+     * @inheritdoc
187
+     */
188
+    public function iLike($x, $y, $type = null) {
189
+        $x = $this->helper->quoteColumnName($x);
190
+        $y = $this->helper->quoteColumnName($y);
191
+        return new QueryFunction('REGEXP_LIKE(' . $x . ', \'^\' || REPLACE(REPLACE(' . $y . ', \'%\', \'.*\'), \'_\', \'.\') || \'$\', \'i\')');
192
+    }
193 193
 }
Please login to merge, or discard this patch.
core/Command/Db/ConvertType.php 2 patches
Indentation   +405 added lines, -405 removed lines patch added patch discarded remove patch
@@ -49,409 +49,409 @@
 block discarded – undo
49 49
 use Symfony\Component\Console\Question\Question;
50 50
 
51 51
 class ConvertType extends Command implements CompletionAwareInterface {
52
-	/**
53
-	 * @var \OCP\IConfig
54
-	 */
55
-	protected $config;
56
-
57
-	/**
58
-	 * @var \OC\DB\ConnectionFactory
59
-	 */
60
-	protected $connectionFactory;
61
-
62
-	/** @var array */
63
-	protected $columnTypes;
64
-
65
-	/**
66
-	 * @param \OCP\IConfig $config
67
-	 * @param \OC\DB\ConnectionFactory $connectionFactory
68
-	 */
69
-	public function __construct(IConfig $config, ConnectionFactory $connectionFactory) {
70
-		$this->config = $config;
71
-		$this->connectionFactory = $connectionFactory;
72
-		parent::__construct();
73
-	}
74
-
75
-	protected function configure() {
76
-		$this
77
-			->setName('db:convert-type')
78
-			->setDescription('Convert the Nextcloud database to the newly configured one')
79
-			->addArgument(
80
-				'type',
81
-				InputArgument::REQUIRED,
82
-				'the type of the database to convert to'
83
-			)
84
-			->addArgument(
85
-				'username',
86
-				InputArgument::REQUIRED,
87
-				'the username of the database to convert to'
88
-			)
89
-			->addArgument(
90
-				'hostname',
91
-				InputArgument::REQUIRED,
92
-				'the hostname of the database to convert to'
93
-			)
94
-			->addArgument(
95
-				'database',
96
-				InputArgument::REQUIRED,
97
-				'the name of the database to convert to'
98
-			)
99
-			->addOption(
100
-				'port',
101
-				null,
102
-				InputOption::VALUE_REQUIRED,
103
-				'the port of the database to convert to'
104
-			)
105
-			->addOption(
106
-				'password',
107
-				null,
108
-				InputOption::VALUE_REQUIRED,
109
-				'the password of the database to convert to. Will be asked when not specified. Can also be passed via stdin.'
110
-			)
111
-			->addOption(
112
-				'clear-schema',
113
-				null,
114
-				InputOption::VALUE_NONE,
115
-				'remove all tables from the destination database'
116
-			)
117
-			->addOption(
118
-				'all-apps',
119
-				null,
120
-				InputOption::VALUE_NONE,
121
-				'whether to create schema for all apps instead of only installed apps'
122
-			)
123
-			->addOption(
124
-				'chunk-size',
125
-				null,
126
-				InputOption::VALUE_REQUIRED,
127
-				'the maximum number of database rows to handle in a single query, bigger tables will be handled in chunks of this size. Lower this if the process runs out of memory during conversion.',
128
-				1000
129
-			)
130
-		;
131
-	}
132
-
133
-	protected function validateInput(InputInterface $input, OutputInterface $output) {
134
-		$type = $this->connectionFactory->normalizeType($input->getArgument('type'));
135
-		if ($type === 'sqlite3') {
136
-			throw new \InvalidArgumentException(
137
-				'Converting to SQLite (sqlite3) is currently not supported.'
138
-			);
139
-		}
140
-		if ($type === $this->config->getSystemValue('dbtype', '')) {
141
-			throw new \InvalidArgumentException(sprintf(
142
-				'Can not convert from %1$s to %1$s.',
143
-				$type
144
-			));
145
-		}
146
-		if ($type === 'oci' && $input->getOption('clear-schema')) {
147
-			// Doctrine unconditionally tries (at least in version 2.3)
148
-			// to drop sequence triggers when dropping a table, even though
149
-			// such triggers may not exist. This results in errors like
150
-			// "ORA-04080: trigger 'OC_STORAGES_AI_PK' does not exist".
151
-			throw new \InvalidArgumentException(
152
-				'The --clear-schema option is not supported when converting to Oracle (oci).'
153
-			);
154
-		}
155
-	}
156
-
157
-	protected function readPassword(InputInterface $input, OutputInterface $output) {
158
-		// Explicitly specified password
159
-		if ($input->getOption('password')) {
160
-			return;
161
-		}
162
-
163
-		// Read from stdin. stream_set_blocking is used to prevent blocking
164
-		// when nothing is passed via stdin.
165
-		stream_set_blocking(STDIN, 0);
166
-		$password = file_get_contents('php://stdin');
167
-		stream_set_blocking(STDIN, 1);
168
-		if (trim($password) !== '') {
169
-			$input->setOption('password', $password);
170
-			return;
171
-		}
172
-
173
-		// Read password by interacting
174
-		if ($input->isInteractive()) {
175
-			/** @var QuestionHelper $helper */
176
-			$helper = $this->getHelper('question');
177
-			$question = new Question('What is the database password?');
178
-			$question->setHidden(true);
179
-			$question->setHiddenFallback(false);
180
-			$password = $helper->ask($input, $output, $question);
181
-			$input->setOption('password', $password);
182
-			return;
183
-		}
184
-	}
185
-
186
-	protected function execute(InputInterface $input, OutputInterface $output) {
187
-		$this->validateInput($input, $output);
188
-		$this->readPassword($input, $output);
189
-
190
-		$fromDB = \OC::$server->getDatabaseConnection();
191
-		$toDB = $this->getToDBConnection($input, $output);
192
-
193
-		if ($input->getOption('clear-schema')) {
194
-			$this->clearSchema($toDB, $input, $output);
195
-		}
196
-
197
-		$this->createSchema($fromDB, $toDB, $input, $output);
198
-
199
-		$toTables = $this->getTables($toDB);
200
-		$fromTables = $this->getTables($fromDB);
201
-
202
-		// warn/fail if there are more tables in 'from' database
203
-		$extraFromTables = array_diff($fromTables, $toTables);
204
-		if (!empty($extraFromTables)) {
205
-			$output->writeln('<comment>The following tables will not be converted:</comment>');
206
-			$output->writeln($extraFromTables);
207
-			if (!$input->getOption('all-apps')) {
208
-				$output->writeln('<comment>Please note that tables belonging to available but currently not installed apps</comment>');
209
-				$output->writeln('<comment>can be included by specifying the --all-apps option.</comment>');
210
-			}
211
-
212
-			/** @var QuestionHelper $helper */
213
-			$helper = $this->getHelper('question');
214
-			$question = new ConfirmationQuestion('Continue with the conversion (y/n)? [n] ', false);
215
-
216
-			if (!$helper->ask($input, $output, $question)) {
217
-				return;
218
-			}
219
-		}
220
-		$intersectingTables = array_intersect($toTables, $fromTables);
221
-		$this->convertDB($fromDB, $toDB, $intersectingTables, $input, $output);
222
-	}
223
-
224
-	protected function createSchema(Connection $fromDB, Connection $toDB, InputInterface $input, OutputInterface $output) {
225
-		$output->writeln('<info>Creating schema in new database</info>');
226
-
227
-		$fromMS = new MigrationService('core', $fromDB);
228
-		$currentMigration = $fromMS->getMigration('current');
229
-		if ($currentMigration !== '0') {
230
-			$toMS = new MigrationService('core', $toDB);
231
-			$toMS->migrate($currentMigration);
232
-		}
233
-
234
-		$schemaManager = new \OC\DB\MDB2SchemaManager($toDB);
235
-		$apps = $input->getOption('all-apps') ? \OC_App::getAllApps() : \OC_App::getEnabledApps();
236
-		foreach($apps as $app) {
237
-			if (file_exists(\OC_App::getAppPath($app).'/appinfo/database.xml')) {
238
-				$schemaManager->createDbFromStructure(\OC_App::getAppPath($app).'/appinfo/database.xml');
239
-			} else {
240
-				// Make sure autoloading works...
241
-				\OC_App::loadApp($app);
242
-				$fromMS = new MigrationService($app, $fromDB);
243
-				$currentMigration = $fromMS->getMigration('current');
244
-				if ($currentMigration !== '0') {
245
-					$toMS = new MigrationService($app, $toDB);
246
-					$toMS->migrate($currentMigration);
247
-				}
248
-			}
249
-		}
250
-	}
251
-
252
-	protected function getToDBConnection(InputInterface $input, OutputInterface $output) {
253
-		$type = $input->getArgument('type');
254
-		$connectionParams = $this->connectionFactory->createConnectionParams();
255
-		$connectionParams = array_merge($connectionParams, [
256
-			'host' => $input->getArgument('hostname'),
257
-			'user' => $input->getArgument('username'),
258
-			'password' => $input->getOption('password'),
259
-			'dbname' => $input->getArgument('database'),
260
-		]);
261
-		if ($input->getOption('port')) {
262
-			$connectionParams['port'] = $input->getOption('port');
263
-		}
264
-		return $this->connectionFactory->getConnection($type, $connectionParams);
265
-	}
266
-
267
-	protected function clearSchema(Connection $db, InputInterface $input, OutputInterface $output) {
268
-		$toTables = $this->getTables($db);
269
-		if (!empty($toTables)) {
270
-			$output->writeln('<info>Clearing schema in new database</info>');
271
-		}
272
-		foreach($toTables as $table) {
273
-			$db->getSchemaManager()->dropTable($table);
274
-		}
275
-	}
276
-
277
-	protected function getTables(Connection $db) {
278
-		$filterExpression = '/^' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/';
279
-		$db->getConfiguration()->
280
-			setFilterSchemaAssetsExpression($filterExpression);
281
-		return $db->getSchemaManager()->listTableNames();
282
-	}
283
-
284
-	/**
285
-	 * @param Connection $fromDB
286
-	 * @param Connection $toDB
287
-	 * @param Table $table
288
-	 * @param InputInterface $input
289
-	 * @param OutputInterface $output
290
-	 * @suppress SqlInjectionChecker
291
-	 */
292
-	protected function copyTable(Connection $fromDB, Connection $toDB, Table $table, InputInterface $input, OutputInterface $output) {
293
-		if ($table->getName() === $toDB->getPrefix() . 'migrations') {
294
-			$output->writeln('<comment>Skipping migrations table because it was already filled by running the migrations</comment>');
295
-			return;
296
-		}
297
-
298
-		$chunkSize = $input->getOption('chunk-size');
299
-
300
-		$query = $fromDB->getQueryBuilder();
301
-		$query->automaticTablePrefix(false);
302
-		$query->selectAlias($query->createFunction('COUNT(*)'), 'num_entries')
303
-			->from($table->getName());
304
-		$result = $query->execute();
305
-		$count = $result->fetchColumn();
306
-		$result->closeCursor();
307
-
308
-		$numChunks = ceil($count/$chunkSize);
309
-		if ($numChunks > 1) {
310
-			$output->writeln('chunked query, ' . $numChunks . ' chunks');
311
-		}
312
-
313
-		$progress = new ProgressBar($output, $count);
314
-		$progress->start();
315
-		$redraw = $count > $chunkSize ? 100 : ($count > 100 ? 5 : 1);
316
-		$progress->setRedrawFrequency($redraw);
317
-
318
-		$query = $fromDB->getQueryBuilder();
319
-		$query->automaticTablePrefix(false);
320
-		$query->select('*')
321
-			->from($table->getName())
322
-			->setMaxResults($chunkSize);
323
-
324
-		try {
325
-			$orderColumns = $table->getPrimaryKeyColumns();
326
-		} catch (DBALException $e) {
327
-			$orderColumns = [];
328
-			foreach ($table->getColumns() as $column) {
329
-				$orderColumns[] = $column->getName();
330
-			}
331
-		}
332
-
333
-		foreach ($orderColumns as $column) {
334
-			$query->addOrderBy($column);
335
-		}
336
-
337
-		$insertQuery = $toDB->getQueryBuilder();
338
-		$insertQuery->automaticTablePrefix(false);
339
-		$insertQuery->insert($table->getName());
340
-		$parametersCreated = false;
341
-
342
-		for ($chunk = 0; $chunk < $numChunks; $chunk++) {
343
-			$query->setFirstResult($chunk * $chunkSize);
344
-
345
-			$result = $query->execute();
346
-
347
-			while ($row = $result->fetch()) {
348
-				$progress->advance();
349
-				if (!$parametersCreated) {
350
-					foreach ($row as $key => $value) {
351
-						$insertQuery->setValue($key, $insertQuery->createParameter($key));
352
-					}
353
-					$parametersCreated = true;
354
-				}
355
-
356
-				foreach ($row as $key => $value) {
357
-					$type = $this->getColumnType($table, $key);
358
-					if ($type !== false) {
359
-						$insertQuery->setParameter($key, $value, $type);
360
-					} else {
361
-						$insertQuery->setParameter($key, $value);
362
-					}
363
-				}
364
-				$insertQuery->execute();
365
-			}
366
-			$result->closeCursor();
367
-		}
368
-		$progress->finish();
369
-	}
370
-
371
-	protected function getColumnType(Table $table, $columnName) {
372
-		$tableName = $table->getName();
373
-		if (isset($this->columnTypes[$tableName][$columnName])) {
374
-			return $this->columnTypes[$tableName][$columnName];
375
-		}
376
-
377
-		$type = $table->getColumn($columnName)->getType()->getName();
378
-
379
-		switch ($type) {
380
-			case Type::BLOB:
381
-			case Type::TEXT:
382
-				$this->columnTypes[$tableName][$columnName] = IQueryBuilder::PARAM_LOB;
383
-				break;
384
-			default:
385
-				$this->columnTypes[$tableName][$columnName] = false;
386
-		}
387
-
388
-		return $this->columnTypes[$tableName][$columnName];
389
-	}
390
-
391
-	protected function convertDB(Connection $fromDB, Connection $toDB, array $tables, InputInterface $input, OutputInterface $output) {
392
-		$this->config->setSystemValue('maintenance', true);
393
-		$schema = $fromDB->createSchema();
394
-
395
-		try {
396
-			// copy table rows
397
-			foreach($tables as $table) {
398
-				$output->writeln($table);
399
-				$this->copyTable($fromDB, $toDB, $schema->getTable($table), $input, $output);
400
-			}
401
-			if ($input->getArgument('type') === 'pgsql') {
402
-				$tools = new \OC\DB\PgSqlTools($this->config);
403
-				$tools->resynchronizeDatabaseSequences($toDB);
404
-			}
405
-			// save new database config
406
-			$this->saveDBInfo($input);
407
-		} catch(\Exception $e) {
408
-			$this->config->setSystemValue('maintenance', false);
409
-			throw $e;
410
-		}
411
-		$this->config->setSystemValue('maintenance', false);
412
-	}
413
-
414
-	protected function saveDBInfo(InputInterface $input) {
415
-		$type = $input->getArgument('type');
416
-		$username = $input->getArgument('username');
417
-		$dbHost = $input->getArgument('hostname');
418
-		$dbName = $input->getArgument('database');
419
-		$password = $input->getOption('password');
420
-		if ($input->getOption('port')) {
421
-			$dbHost .= ':'.$input->getOption('port');
422
-		}
423
-
424
-		$this->config->setSystemValues([
425
-			'dbtype'		=> $type,
426
-			'dbname'		=> $dbName,
427
-			'dbhost'		=> $dbHost,
428
-			'dbuser'		=> $username,
429
-			'dbpassword'	=> $password,
430
-		]);
431
-	}
432
-
433
-	/**
434
-	 * Return possible values for the named option
435
-	 *
436
-	 * @param string $optionName
437
-	 * @param CompletionContext $context
438
-	 * @return string[]
439
-	 */
440
-	public function completeOptionValues($optionName, CompletionContext $context) {
441
-		return [];
442
-	}
443
-
444
-	/**
445
-	 * Return possible values for the named argument
446
-	 *
447
-	 * @param string $argumentName
448
-	 * @param CompletionContext $context
449
-	 * @return string[]
450
-	 */
451
-	public function completeArgumentValues($argumentName, CompletionContext $context) {
452
-		if ($argumentName === 'type') {
453
-			return ['mysql', 'oci', 'pgsql'];
454
-		}
455
-		return [];
456
-	}
52
+    /**
53
+     * @var \OCP\IConfig
54
+     */
55
+    protected $config;
56
+
57
+    /**
58
+     * @var \OC\DB\ConnectionFactory
59
+     */
60
+    protected $connectionFactory;
61
+
62
+    /** @var array */
63
+    protected $columnTypes;
64
+
65
+    /**
66
+     * @param \OCP\IConfig $config
67
+     * @param \OC\DB\ConnectionFactory $connectionFactory
68
+     */
69
+    public function __construct(IConfig $config, ConnectionFactory $connectionFactory) {
70
+        $this->config = $config;
71
+        $this->connectionFactory = $connectionFactory;
72
+        parent::__construct();
73
+    }
74
+
75
+    protected function configure() {
76
+        $this
77
+            ->setName('db:convert-type')
78
+            ->setDescription('Convert the Nextcloud database to the newly configured one')
79
+            ->addArgument(
80
+                'type',
81
+                InputArgument::REQUIRED,
82
+                'the type of the database to convert to'
83
+            )
84
+            ->addArgument(
85
+                'username',
86
+                InputArgument::REQUIRED,
87
+                'the username of the database to convert to'
88
+            )
89
+            ->addArgument(
90
+                'hostname',
91
+                InputArgument::REQUIRED,
92
+                'the hostname of the database to convert to'
93
+            )
94
+            ->addArgument(
95
+                'database',
96
+                InputArgument::REQUIRED,
97
+                'the name of the database to convert to'
98
+            )
99
+            ->addOption(
100
+                'port',
101
+                null,
102
+                InputOption::VALUE_REQUIRED,
103
+                'the port of the database to convert to'
104
+            )
105
+            ->addOption(
106
+                'password',
107
+                null,
108
+                InputOption::VALUE_REQUIRED,
109
+                'the password of the database to convert to. Will be asked when not specified. Can also be passed via stdin.'
110
+            )
111
+            ->addOption(
112
+                'clear-schema',
113
+                null,
114
+                InputOption::VALUE_NONE,
115
+                'remove all tables from the destination database'
116
+            )
117
+            ->addOption(
118
+                'all-apps',
119
+                null,
120
+                InputOption::VALUE_NONE,
121
+                'whether to create schema for all apps instead of only installed apps'
122
+            )
123
+            ->addOption(
124
+                'chunk-size',
125
+                null,
126
+                InputOption::VALUE_REQUIRED,
127
+                'the maximum number of database rows to handle in a single query, bigger tables will be handled in chunks of this size. Lower this if the process runs out of memory during conversion.',
128
+                1000
129
+            )
130
+        ;
131
+    }
132
+
133
+    protected function validateInput(InputInterface $input, OutputInterface $output) {
134
+        $type = $this->connectionFactory->normalizeType($input->getArgument('type'));
135
+        if ($type === 'sqlite3') {
136
+            throw new \InvalidArgumentException(
137
+                'Converting to SQLite (sqlite3) is currently not supported.'
138
+            );
139
+        }
140
+        if ($type === $this->config->getSystemValue('dbtype', '')) {
141
+            throw new \InvalidArgumentException(sprintf(
142
+                'Can not convert from %1$s to %1$s.',
143
+                $type
144
+            ));
145
+        }
146
+        if ($type === 'oci' && $input->getOption('clear-schema')) {
147
+            // Doctrine unconditionally tries (at least in version 2.3)
148
+            // to drop sequence triggers when dropping a table, even though
149
+            // such triggers may not exist. This results in errors like
150
+            // "ORA-04080: trigger 'OC_STORAGES_AI_PK' does not exist".
151
+            throw new \InvalidArgumentException(
152
+                'The --clear-schema option is not supported when converting to Oracle (oci).'
153
+            );
154
+        }
155
+    }
156
+
157
+    protected function readPassword(InputInterface $input, OutputInterface $output) {
158
+        // Explicitly specified password
159
+        if ($input->getOption('password')) {
160
+            return;
161
+        }
162
+
163
+        // Read from stdin. stream_set_blocking is used to prevent blocking
164
+        // when nothing is passed via stdin.
165
+        stream_set_blocking(STDIN, 0);
166
+        $password = file_get_contents('php://stdin');
167
+        stream_set_blocking(STDIN, 1);
168
+        if (trim($password) !== '') {
169
+            $input->setOption('password', $password);
170
+            return;
171
+        }
172
+
173
+        // Read password by interacting
174
+        if ($input->isInteractive()) {
175
+            /** @var QuestionHelper $helper */
176
+            $helper = $this->getHelper('question');
177
+            $question = new Question('What is the database password?');
178
+            $question->setHidden(true);
179
+            $question->setHiddenFallback(false);
180
+            $password = $helper->ask($input, $output, $question);
181
+            $input->setOption('password', $password);
182
+            return;
183
+        }
184
+    }
185
+
186
+    protected function execute(InputInterface $input, OutputInterface $output) {
187
+        $this->validateInput($input, $output);
188
+        $this->readPassword($input, $output);
189
+
190
+        $fromDB = \OC::$server->getDatabaseConnection();
191
+        $toDB = $this->getToDBConnection($input, $output);
192
+
193
+        if ($input->getOption('clear-schema')) {
194
+            $this->clearSchema($toDB, $input, $output);
195
+        }
196
+
197
+        $this->createSchema($fromDB, $toDB, $input, $output);
198
+
199
+        $toTables = $this->getTables($toDB);
200
+        $fromTables = $this->getTables($fromDB);
201
+
202
+        // warn/fail if there are more tables in 'from' database
203
+        $extraFromTables = array_diff($fromTables, $toTables);
204
+        if (!empty($extraFromTables)) {
205
+            $output->writeln('<comment>The following tables will not be converted:</comment>');
206
+            $output->writeln($extraFromTables);
207
+            if (!$input->getOption('all-apps')) {
208
+                $output->writeln('<comment>Please note that tables belonging to available but currently not installed apps</comment>');
209
+                $output->writeln('<comment>can be included by specifying the --all-apps option.</comment>');
210
+            }
211
+
212
+            /** @var QuestionHelper $helper */
213
+            $helper = $this->getHelper('question');
214
+            $question = new ConfirmationQuestion('Continue with the conversion (y/n)? [n] ', false);
215
+
216
+            if (!$helper->ask($input, $output, $question)) {
217
+                return;
218
+            }
219
+        }
220
+        $intersectingTables = array_intersect($toTables, $fromTables);
221
+        $this->convertDB($fromDB, $toDB, $intersectingTables, $input, $output);
222
+    }
223
+
224
+    protected function createSchema(Connection $fromDB, Connection $toDB, InputInterface $input, OutputInterface $output) {
225
+        $output->writeln('<info>Creating schema in new database</info>');
226
+
227
+        $fromMS = new MigrationService('core', $fromDB);
228
+        $currentMigration = $fromMS->getMigration('current');
229
+        if ($currentMigration !== '0') {
230
+            $toMS = new MigrationService('core', $toDB);
231
+            $toMS->migrate($currentMigration);
232
+        }
233
+
234
+        $schemaManager = new \OC\DB\MDB2SchemaManager($toDB);
235
+        $apps = $input->getOption('all-apps') ? \OC_App::getAllApps() : \OC_App::getEnabledApps();
236
+        foreach($apps as $app) {
237
+            if (file_exists(\OC_App::getAppPath($app).'/appinfo/database.xml')) {
238
+                $schemaManager->createDbFromStructure(\OC_App::getAppPath($app).'/appinfo/database.xml');
239
+            } else {
240
+                // Make sure autoloading works...
241
+                \OC_App::loadApp($app);
242
+                $fromMS = new MigrationService($app, $fromDB);
243
+                $currentMigration = $fromMS->getMigration('current');
244
+                if ($currentMigration !== '0') {
245
+                    $toMS = new MigrationService($app, $toDB);
246
+                    $toMS->migrate($currentMigration);
247
+                }
248
+            }
249
+        }
250
+    }
251
+
252
+    protected function getToDBConnection(InputInterface $input, OutputInterface $output) {
253
+        $type = $input->getArgument('type');
254
+        $connectionParams = $this->connectionFactory->createConnectionParams();
255
+        $connectionParams = array_merge($connectionParams, [
256
+            'host' => $input->getArgument('hostname'),
257
+            'user' => $input->getArgument('username'),
258
+            'password' => $input->getOption('password'),
259
+            'dbname' => $input->getArgument('database'),
260
+        ]);
261
+        if ($input->getOption('port')) {
262
+            $connectionParams['port'] = $input->getOption('port');
263
+        }
264
+        return $this->connectionFactory->getConnection($type, $connectionParams);
265
+    }
266
+
267
+    protected function clearSchema(Connection $db, InputInterface $input, OutputInterface $output) {
268
+        $toTables = $this->getTables($db);
269
+        if (!empty($toTables)) {
270
+            $output->writeln('<info>Clearing schema in new database</info>');
271
+        }
272
+        foreach($toTables as $table) {
273
+            $db->getSchemaManager()->dropTable($table);
274
+        }
275
+    }
276
+
277
+    protected function getTables(Connection $db) {
278
+        $filterExpression = '/^' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/';
279
+        $db->getConfiguration()->
280
+            setFilterSchemaAssetsExpression($filterExpression);
281
+        return $db->getSchemaManager()->listTableNames();
282
+    }
283
+
284
+    /**
285
+     * @param Connection $fromDB
286
+     * @param Connection $toDB
287
+     * @param Table $table
288
+     * @param InputInterface $input
289
+     * @param OutputInterface $output
290
+     * @suppress SqlInjectionChecker
291
+     */
292
+    protected function copyTable(Connection $fromDB, Connection $toDB, Table $table, InputInterface $input, OutputInterface $output) {
293
+        if ($table->getName() === $toDB->getPrefix() . 'migrations') {
294
+            $output->writeln('<comment>Skipping migrations table because it was already filled by running the migrations</comment>');
295
+            return;
296
+        }
297
+
298
+        $chunkSize = $input->getOption('chunk-size');
299
+
300
+        $query = $fromDB->getQueryBuilder();
301
+        $query->automaticTablePrefix(false);
302
+        $query->selectAlias($query->createFunction('COUNT(*)'), 'num_entries')
303
+            ->from($table->getName());
304
+        $result = $query->execute();
305
+        $count = $result->fetchColumn();
306
+        $result->closeCursor();
307
+
308
+        $numChunks = ceil($count/$chunkSize);
309
+        if ($numChunks > 1) {
310
+            $output->writeln('chunked query, ' . $numChunks . ' chunks');
311
+        }
312
+
313
+        $progress = new ProgressBar($output, $count);
314
+        $progress->start();
315
+        $redraw = $count > $chunkSize ? 100 : ($count > 100 ? 5 : 1);
316
+        $progress->setRedrawFrequency($redraw);
317
+
318
+        $query = $fromDB->getQueryBuilder();
319
+        $query->automaticTablePrefix(false);
320
+        $query->select('*')
321
+            ->from($table->getName())
322
+            ->setMaxResults($chunkSize);
323
+
324
+        try {
325
+            $orderColumns = $table->getPrimaryKeyColumns();
326
+        } catch (DBALException $e) {
327
+            $orderColumns = [];
328
+            foreach ($table->getColumns() as $column) {
329
+                $orderColumns[] = $column->getName();
330
+            }
331
+        }
332
+
333
+        foreach ($orderColumns as $column) {
334
+            $query->addOrderBy($column);
335
+        }
336
+
337
+        $insertQuery = $toDB->getQueryBuilder();
338
+        $insertQuery->automaticTablePrefix(false);
339
+        $insertQuery->insert($table->getName());
340
+        $parametersCreated = false;
341
+
342
+        for ($chunk = 0; $chunk < $numChunks; $chunk++) {
343
+            $query->setFirstResult($chunk * $chunkSize);
344
+
345
+            $result = $query->execute();
346
+
347
+            while ($row = $result->fetch()) {
348
+                $progress->advance();
349
+                if (!$parametersCreated) {
350
+                    foreach ($row as $key => $value) {
351
+                        $insertQuery->setValue($key, $insertQuery->createParameter($key));
352
+                    }
353
+                    $parametersCreated = true;
354
+                }
355
+
356
+                foreach ($row as $key => $value) {
357
+                    $type = $this->getColumnType($table, $key);
358
+                    if ($type !== false) {
359
+                        $insertQuery->setParameter($key, $value, $type);
360
+                    } else {
361
+                        $insertQuery->setParameter($key, $value);
362
+                    }
363
+                }
364
+                $insertQuery->execute();
365
+            }
366
+            $result->closeCursor();
367
+        }
368
+        $progress->finish();
369
+    }
370
+
371
+    protected function getColumnType(Table $table, $columnName) {
372
+        $tableName = $table->getName();
373
+        if (isset($this->columnTypes[$tableName][$columnName])) {
374
+            return $this->columnTypes[$tableName][$columnName];
375
+        }
376
+
377
+        $type = $table->getColumn($columnName)->getType()->getName();
378
+
379
+        switch ($type) {
380
+            case Type::BLOB:
381
+            case Type::TEXT:
382
+                $this->columnTypes[$tableName][$columnName] = IQueryBuilder::PARAM_LOB;
383
+                break;
384
+            default:
385
+                $this->columnTypes[$tableName][$columnName] = false;
386
+        }
387
+
388
+        return $this->columnTypes[$tableName][$columnName];
389
+    }
390
+
391
+    protected function convertDB(Connection $fromDB, Connection $toDB, array $tables, InputInterface $input, OutputInterface $output) {
392
+        $this->config->setSystemValue('maintenance', true);
393
+        $schema = $fromDB->createSchema();
394
+
395
+        try {
396
+            // copy table rows
397
+            foreach($tables as $table) {
398
+                $output->writeln($table);
399
+                $this->copyTable($fromDB, $toDB, $schema->getTable($table), $input, $output);
400
+            }
401
+            if ($input->getArgument('type') === 'pgsql') {
402
+                $tools = new \OC\DB\PgSqlTools($this->config);
403
+                $tools->resynchronizeDatabaseSequences($toDB);
404
+            }
405
+            // save new database config
406
+            $this->saveDBInfo($input);
407
+        } catch(\Exception $e) {
408
+            $this->config->setSystemValue('maintenance', false);
409
+            throw $e;
410
+        }
411
+        $this->config->setSystemValue('maintenance', false);
412
+    }
413
+
414
+    protected function saveDBInfo(InputInterface $input) {
415
+        $type = $input->getArgument('type');
416
+        $username = $input->getArgument('username');
417
+        $dbHost = $input->getArgument('hostname');
418
+        $dbName = $input->getArgument('database');
419
+        $password = $input->getOption('password');
420
+        if ($input->getOption('port')) {
421
+            $dbHost .= ':'.$input->getOption('port');
422
+        }
423
+
424
+        $this->config->setSystemValues([
425
+            'dbtype'		=> $type,
426
+            'dbname'		=> $dbName,
427
+            'dbhost'		=> $dbHost,
428
+            'dbuser'		=> $username,
429
+            'dbpassword'	=> $password,
430
+        ]);
431
+    }
432
+
433
+    /**
434
+     * Return possible values for the named option
435
+     *
436
+     * @param string $optionName
437
+     * @param CompletionContext $context
438
+     * @return string[]
439
+     */
440
+    public function completeOptionValues($optionName, CompletionContext $context) {
441
+        return [];
442
+    }
443
+
444
+    /**
445
+     * Return possible values for the named argument
446
+     *
447
+     * @param string $argumentName
448
+     * @param CompletionContext $context
449
+     * @return string[]
450
+     */
451
+    public function completeArgumentValues($argumentName, CompletionContext $context) {
452
+        if ($argumentName === 'type') {
453
+            return ['mysql', 'oci', 'pgsql'];
454
+        }
455
+        return [];
456
+    }
457 457
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
 
234 234
 		$schemaManager = new \OC\DB\MDB2SchemaManager($toDB);
235 235
 		$apps = $input->getOption('all-apps') ? \OC_App::getAllApps() : \OC_App::getEnabledApps();
236
-		foreach($apps as $app) {
236
+		foreach ($apps as $app) {
237 237
 			if (file_exists(\OC_App::getAppPath($app).'/appinfo/database.xml')) {
238 238
 				$schemaManager->createDbFromStructure(\OC_App::getAppPath($app).'/appinfo/database.xml');
239 239
 			} else {
@@ -269,13 +269,13 @@  discard block
 block discarded – undo
269 269
 		if (!empty($toTables)) {
270 270
 			$output->writeln('<info>Clearing schema in new database</info>');
271 271
 		}
272
-		foreach($toTables as $table) {
272
+		foreach ($toTables as $table) {
273 273
 			$db->getSchemaManager()->dropTable($table);
274 274
 		}
275 275
 	}
276 276
 
277 277
 	protected function getTables(Connection $db) {
278
-		$filterExpression = '/^' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/';
278
+		$filterExpression = '/^'.preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')).'/';
279 279
 		$db->getConfiguration()->
280 280
 			setFilterSchemaAssetsExpression($filterExpression);
281 281
 		return $db->getSchemaManager()->listTableNames();
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
 	 * @suppress SqlInjectionChecker
291 291
 	 */
292 292
 	protected function copyTable(Connection $fromDB, Connection $toDB, Table $table, InputInterface $input, OutputInterface $output) {
293
-		if ($table->getName() === $toDB->getPrefix() . 'migrations') {
293
+		if ($table->getName() === $toDB->getPrefix().'migrations') {
294 294
 			$output->writeln('<comment>Skipping migrations table because it was already filled by running the migrations</comment>');
295 295
 			return;
296 296
 		}
@@ -305,9 +305,9 @@  discard block
 block discarded – undo
305 305
 		$count = $result->fetchColumn();
306 306
 		$result->closeCursor();
307 307
 
308
-		$numChunks = ceil($count/$chunkSize);
308
+		$numChunks = ceil($count / $chunkSize);
309 309
 		if ($numChunks > 1) {
310
-			$output->writeln('chunked query, ' . $numChunks . ' chunks');
310
+			$output->writeln('chunked query, '.$numChunks.' chunks');
311 311
 		}
312 312
 
313 313
 		$progress = new ProgressBar($output, $count);
@@ -394,7 +394,7 @@  discard block
 block discarded – undo
394 394
 
395 395
 		try {
396 396
 			// copy table rows
397
-			foreach($tables as $table) {
397
+			foreach ($tables as $table) {
398 398
 				$output->writeln($table);
399 399
 				$this->copyTable($fromDB, $toDB, $schema->getTable($table), $input, $output);
400 400
 			}
@@ -404,7 +404,7 @@  discard block
 block discarded – undo
404 404
 			}
405 405
 			// save new database config
406 406
 			$this->saveDBInfo($input);
407
-		} catch(\Exception $e) {
407
+		} catch (\Exception $e) {
408 408
 			$this->config->setSystemValue('maintenance', false);
409 409
 			throw $e;
410 410
 		}
Please login to merge, or discard this patch.
lib/private/App/AppStore/Bundles/EducationBundle.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@
 block discarded – undo
27 27
 	 * {@inheritDoc}
28 28
 	 */
29 29
 	public function getName() {
30
-		return (string)$this->l10n->t('Education Edition');
30
+		return (string) $this->l10n->t('Education Edition');
31 31
 	}
32 32
 
33 33
 	/**
Please login to merge, or discard this patch.
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -23,28 +23,28 @@
 block discarded – undo
23 23
 
24 24
 class EducationBundle extends Bundle {
25 25
 
26
-	/**
27
-	 * {@inheritDoc}
28
-	 */
29
-	public function getName() {
30
-		return (string)$this->l10n->t('Education Edition');
31
-	}
26
+    /**
27
+     * {@inheritDoc}
28
+     */
29
+    public function getName() {
30
+        return (string)$this->l10n->t('Education Edition');
31
+    }
32 32
 
33
-	/**
34
-	 * {@inheritDoc}
35
-	 */
36
-	public function getAppIdentifiers() {
37
-		return [
38
-			'zenodo',
39
-			'dashboard',
40
-			'circles',
41
-			'groupfolders',
42
-			'announcementcenter',
43
-			'admin_notifications',
44
-			'quota_warning',
45
-			'orcid',
46
-			'user_saml',
47
-		];
48
-	}
33
+    /**
34
+     * {@inheritDoc}
35
+     */
36
+    public function getAppIdentifiers() {
37
+        return [
38
+            'zenodo',
39
+            'dashboard',
40
+            'circles',
41
+            'groupfolders',
42
+            'announcementcenter',
43
+            'admin_notifications',
44
+            'quota_warning',
45
+            'orcid',
46
+            'user_saml',
47
+        ];
48
+    }
49 49
 
50 50
 }
Please login to merge, or discard this patch.
apps/files_sharing/lib/AppInfo/Application.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 		/**
52 52
 		 * Controllers
53 53
 		 */
54
-		$container->registerService('ShareController', function (SimpleContainer $c) use ($server) {
54
+		$container->registerService('ShareController', function(SimpleContainer $c) use ($server) {
55 55
 			$federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application();
56 56
 			return new ShareController(
57 57
 				$c->query('AppName'),
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 				$server->query(Defaults::class)
72 72
 			);
73 73
 		});
74
-		$container->registerService('ExternalSharesController', function (SimpleContainer $c) {
74
+		$container->registerService('ExternalSharesController', function(SimpleContainer $c) {
75 75
 			return new ExternalSharesController(
76 76
 				$c->query('AppName'),
77 77
 				$c->query('Request'),
@@ -83,13 +83,13 @@  discard block
 block discarded – undo
83 83
 		/**
84 84
 		 * Core class wrappers
85 85
 		 */
86
-		$container->registerService('HttpClientService', function (SimpleContainer $c) use ($server) {
86
+		$container->registerService('HttpClientService', function(SimpleContainer $c) use ($server) {
87 87
 			return $server->getHTTPClientService();
88 88
 		});
89
-		$container->registerService(ICloudIdManager::class, function (SimpleContainer $c) use ($server) {
89
+		$container->registerService(ICloudIdManager::class, function(SimpleContainer $c) use ($server) {
90 90
 			return $server->getCloudIdManager();
91 91
 		});
92
-		$container->registerService('ExternalManager', function (SimpleContainer $c) use ($server) {
92
+		$container->registerService('ExternalManager', function(SimpleContainer $c) use ($server) {
93 93
 			$user = $server->getUserSession()->getUser();
94 94
 			$uid = $user ? $user->getUID() : null;
95 95
 			return new \OCA\Files_Sharing\External\Manager(
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
 		/**
108 108
 		 * Middleware
109 109
 		 */
110
-		$container->registerService('SharingCheckMiddleware', function (SimpleContainer $c) use ($server) {
110
+		$container->registerService('SharingCheckMiddleware', function(SimpleContainer $c) use ($server) {
111 111
 			return new SharingCheckMiddleware(
112 112
 				$c->query('AppName'),
113 113
 				$server->getConfig(),
@@ -118,14 +118,14 @@  discard block
 block discarded – undo
118 118
 			);
119 119
 		});
120 120
 
121
-		$container->registerService('OCSShareAPIMiddleware', function (SimpleContainer $c) use ($server) {
121
+		$container->registerService('OCSShareAPIMiddleware', function(SimpleContainer $c) use ($server) {
122 122
 			return new OCSShareAPIMiddleware(
123 123
 				$server->getShareManager(),
124 124
 				$server->getL10N($c->query('AppName'))
125 125
 			);
126 126
 		});
127 127
 
128
-		$container->registerService(ShareInfoMiddleware::class, function () use ($server) {
128
+		$container->registerService(ShareInfoMiddleware::class, function() use ($server) {
129 129
 			return new ShareInfoMiddleware(
130 130
 				$server->getShareManager()
131 131
 			);
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 		$container->registerMiddleWare('OCSShareAPIMiddleware');
137 137
 		$container->registerMiddleWare(ShareInfoMiddleware::class);
138 138
 
139
-		$container->registerService('MountProvider', function (IContainer $c) {
139
+		$container->registerService('MountProvider', function(IContainer $c) {
140 140
 			/** @var \OCP\IServerContainer $server */
141 141
 			$server = $c->query('ServerContainer');
142 142
 			return new MountProvider(
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 			);
147 147
 		});
148 148
 
149
-		$container->registerService('ExternalMountProvider', function (IContainer $c) {
149
+		$container->registerService('ExternalMountProvider', function(IContainer $c) {
150 150
 			/** @var \OCP\IServerContainer $server */
151 151
 			$server = $c->query('ServerContainer');
152 152
 			return new \OCA\Files_Sharing\External\MountProvider(
Please login to merge, or discard this patch.
Indentation   +117 added lines, -117 removed lines patch added patch discarded remove patch
@@ -45,134 +45,134 @@
 block discarded – undo
45 45
 use OCA\Files_Sharing\External\Manager;
46 46
 
47 47
 class Application extends App {
48
-	public function __construct(array $urlParams = array()) {
49
-		parent::__construct('files_sharing', $urlParams);
48
+    public function __construct(array $urlParams = array()) {
49
+        parent::__construct('files_sharing', $urlParams);
50 50
 
51
-		$container = $this->getContainer();
52
-		/** @var IServerContainer $server */
53
-		$server = $container->getServer();
51
+        $container = $this->getContainer();
52
+        /** @var IServerContainer $server */
53
+        $server = $container->getServer();
54 54
 
55
-		/**
56
-		 * Controllers
57
-		 */
58
-		$container->registerService('ShareController', function (SimpleContainer $c) use ($server) {
59
-			$federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application();
60
-			return new ShareController(
61
-				$c->query('AppName'),
62
-				$c->query('Request'),
63
-				$server->getConfig(),
64
-				$server->getURLGenerator(),
65
-				$server->getUserManager(),
66
-				$server->getLogger(),
67
-				$server->getActivityManager(),
68
-				$server->getShareManager(),
69
-				$server->getSession(),
70
-				$server->getPreviewManager(),
71
-				$server->getRootFolder(),
72
-				$federatedSharingApp->getFederatedShareProvider(),
73
-				$server->getEventDispatcher(),
74
-				$server->getL10N($c->query('AppName')),
75
-				$server->query(Defaults::class)
76
-			);
77
-		});
78
-		$container->registerService('ExternalSharesController', function (SimpleContainer $c) {
79
-			return new ExternalSharesController(
80
-				$c->query('AppName'),
81
-				$c->query('Request'),
82
-				$c->query('ExternalManager'),
83
-				$c->query('HttpClientService')
84
-			);
85
-		});
55
+        /**
56
+         * Controllers
57
+         */
58
+        $container->registerService('ShareController', function (SimpleContainer $c) use ($server) {
59
+            $federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application();
60
+            return new ShareController(
61
+                $c->query('AppName'),
62
+                $c->query('Request'),
63
+                $server->getConfig(),
64
+                $server->getURLGenerator(),
65
+                $server->getUserManager(),
66
+                $server->getLogger(),
67
+                $server->getActivityManager(),
68
+                $server->getShareManager(),
69
+                $server->getSession(),
70
+                $server->getPreviewManager(),
71
+                $server->getRootFolder(),
72
+                $federatedSharingApp->getFederatedShareProvider(),
73
+                $server->getEventDispatcher(),
74
+                $server->getL10N($c->query('AppName')),
75
+                $server->query(Defaults::class)
76
+            );
77
+        });
78
+        $container->registerService('ExternalSharesController', function (SimpleContainer $c) {
79
+            return new ExternalSharesController(
80
+                $c->query('AppName'),
81
+                $c->query('Request'),
82
+                $c->query('ExternalManager'),
83
+                $c->query('HttpClientService')
84
+            );
85
+        });
86 86
 
87
-		/**
88
-		 * Core class wrappers
89
-		 */
90
-		$container->registerService('HttpClientService', function (SimpleContainer $c) use ($server) {
91
-			return $server->getHTTPClientService();
92
-		});
93
-		$container->registerService(ICloudIdManager::class, function (SimpleContainer $c) use ($server) {
94
-			return $server->getCloudIdManager();
95
-		});
96
-		$container->registerService('ExternalManager', function (SimpleContainer $c) use ($server) {
97
-			$user = $server->getUserSession()->getUser();
98
-			$uid = $user ? $user->getUID() : null;
99
-			return new \OCA\Files_Sharing\External\Manager(
100
-				$server->getDatabaseConnection(),
101
-				\OC\Files\Filesystem::getMountManager(),
102
-				\OC\Files\Filesystem::getLoader(),
103
-				$server->getHTTPClientService(),
104
-				$server->getNotificationManager(),
105
-				$server->query(\OCP\OCS\IDiscoveryService::class),
106
-				$uid
107
-			);
108
-		});
109
-		$container->registerAlias(Manager::class, 'ExternalManager');
87
+        /**
88
+         * Core class wrappers
89
+         */
90
+        $container->registerService('HttpClientService', function (SimpleContainer $c) use ($server) {
91
+            return $server->getHTTPClientService();
92
+        });
93
+        $container->registerService(ICloudIdManager::class, function (SimpleContainer $c) use ($server) {
94
+            return $server->getCloudIdManager();
95
+        });
96
+        $container->registerService('ExternalManager', function (SimpleContainer $c) use ($server) {
97
+            $user = $server->getUserSession()->getUser();
98
+            $uid = $user ? $user->getUID() : null;
99
+            return new \OCA\Files_Sharing\External\Manager(
100
+                $server->getDatabaseConnection(),
101
+                \OC\Files\Filesystem::getMountManager(),
102
+                \OC\Files\Filesystem::getLoader(),
103
+                $server->getHTTPClientService(),
104
+                $server->getNotificationManager(),
105
+                $server->query(\OCP\OCS\IDiscoveryService::class),
106
+                $uid
107
+            );
108
+        });
109
+        $container->registerAlias(Manager::class, 'ExternalManager');
110 110
 
111
-		/**
112
-		 * Middleware
113
-		 */
114
-		$container->registerService('SharingCheckMiddleware', function (SimpleContainer $c) use ($server) {
115
-			return new SharingCheckMiddleware(
116
-				$c->query('AppName'),
117
-				$server->getConfig(),
118
-				$server->getAppManager(),
119
-				$c['ControllerMethodReflector'],
120
-				$server->getShareManager(),
121
-				$server->getRequest()
122
-			);
123
-		});
111
+        /**
112
+         * Middleware
113
+         */
114
+        $container->registerService('SharingCheckMiddleware', function (SimpleContainer $c) use ($server) {
115
+            return new SharingCheckMiddleware(
116
+                $c->query('AppName'),
117
+                $server->getConfig(),
118
+                $server->getAppManager(),
119
+                $c['ControllerMethodReflector'],
120
+                $server->getShareManager(),
121
+                $server->getRequest()
122
+            );
123
+        });
124 124
 
125
-		$container->registerService('OCSShareAPIMiddleware', function (SimpleContainer $c) use ($server) {
126
-			return new OCSShareAPIMiddleware(
127
-				$server->getShareManager(),
128
-				$server->getL10N($c->query('AppName'))
129
-			);
130
-		});
125
+        $container->registerService('OCSShareAPIMiddleware', function (SimpleContainer $c) use ($server) {
126
+            return new OCSShareAPIMiddleware(
127
+                $server->getShareManager(),
128
+                $server->getL10N($c->query('AppName'))
129
+            );
130
+        });
131 131
 
132
-		$container->registerService(ShareInfoMiddleware::class, function () use ($server) {
133
-			return new ShareInfoMiddleware(
134
-				$server->getShareManager()
135
-			);
136
-		});
132
+        $container->registerService(ShareInfoMiddleware::class, function () use ($server) {
133
+            return new ShareInfoMiddleware(
134
+                $server->getShareManager()
135
+            );
136
+        });
137 137
 
138
-		// Execute middlewares
139
-		$container->registerMiddleWare('SharingCheckMiddleware');
140
-		$container->registerMiddleWare('OCSShareAPIMiddleware');
141
-		$container->registerMiddleWare(ShareInfoMiddleware::class);
138
+        // Execute middlewares
139
+        $container->registerMiddleWare('SharingCheckMiddleware');
140
+        $container->registerMiddleWare('OCSShareAPIMiddleware');
141
+        $container->registerMiddleWare(ShareInfoMiddleware::class);
142 142
 
143
-		$container->registerService('MountProvider', function (IContainer $c) {
144
-			/** @var \OCP\IServerContainer $server */
145
-			$server = $c->query('ServerContainer');
146
-			return new MountProvider(
147
-				$server->getConfig(),
148
-				$server->getShareManager(),
149
-				$server->getLogger()
150
-			);
151
-		});
143
+        $container->registerService('MountProvider', function (IContainer $c) {
144
+            /** @var \OCP\IServerContainer $server */
145
+            $server = $c->query('ServerContainer');
146
+            return new MountProvider(
147
+                $server->getConfig(),
148
+                $server->getShareManager(),
149
+                $server->getLogger()
150
+            );
151
+        });
152 152
 
153
-		$container->registerService('ExternalMountProvider', function (IContainer $c) {
154
-			/** @var \OCP\IServerContainer $server */
155
-			$server = $c->query('ServerContainer');
156
-			return new \OCA\Files_Sharing\External\MountProvider(
157
-				$server->getDatabaseConnection(),
158
-				function() use ($c) {
159
-					return $c->query('ExternalManager');
160
-				},
161
-				$server->getCloudIdManager()
162
-			);
163
-		});
153
+        $container->registerService('ExternalMountProvider', function (IContainer $c) {
154
+            /** @var \OCP\IServerContainer $server */
155
+            $server = $c->query('ServerContainer');
156
+            return new \OCA\Files_Sharing\External\MountProvider(
157
+                $server->getDatabaseConnection(),
158
+                function() use ($c) {
159
+                    return $c->query('ExternalManager');
160
+                },
161
+                $server->getCloudIdManager()
162
+            );
163
+        });
164 164
 
165
-		/*
165
+        /*
166 166
 		 * Register capabilities
167 167
 		 */
168
-		$container->registerCapability(Capabilities::class);
169
-	}
168
+        $container->registerCapability(Capabilities::class);
169
+    }
170 170
 
171
-	public function registerMountProviders() {
172
-		/** @var \OCP\IServerContainer $server */
173
-		$server = $this->getContainer()->query('ServerContainer');
174
-		$mountProviderCollection = $server->getMountProviderCollection();
175
-		$mountProviderCollection->registerProvider($this->getContainer()->query('MountProvider'));
176
-		$mountProviderCollection->registerProvider($this->getContainer()->query('ExternalMountProvider'));
177
-	}
171
+    public function registerMountProviders() {
172
+        /** @var \OCP\IServerContainer $server */
173
+        $server = $this->getContainer()->query('ServerContainer');
174
+        $mountProviderCollection = $server->getMountProviderCollection();
175
+        $mountProviderCollection->registerProvider($this->getContainer()->query('MountProvider'));
176
+        $mountProviderCollection->registerProvider($this->getContainer()->query('ExternalMountProvider'));
177
+    }
178 178
 }
Please login to merge, or discard this patch.
core/Middleware/TwoFactorMiddleware.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -104,6 +104,9 @@
 block discarded – undo
104 104
 		// TODO: dont check/enforce 2FA if a auth token is used
105 105
 	}
106 106
 
107
+	/**
108
+	 * @param string $methodName
109
+	 */
107 110
 	private function checkTwoFactor(Controller $controller, $methodName, IUser $user) {
108 111
 		// If two-factor auth is in progress disallow access to any controllers
109 112
 		// defined within "LoginController".
Please login to merge, or discard this patch.
Indentation   +95 added lines, -95 removed lines patch added patch discarded remove patch
@@ -41,100 +41,100 @@
 block discarded – undo
41 41
 
42 42
 class TwoFactorMiddleware extends Middleware {
43 43
 
44
-	/** @var Manager */
45
-	private $twoFactorManager;
46
-
47
-	/** @var Session */
48
-	private $userSession;
49
-
50
-	/** @var ISession */
51
-	private $session;
52
-
53
-	/** @var IURLGenerator */
54
-	private $urlGenerator;
55
-
56
-	/** @var IControllerMethodReflector */
57
-	private $reflector;
58
-
59
-	/** @var IRequest */
60
-	private $request;
61
-
62
-	/**
63
-	 * @param Manager $twoFactorManager
64
-	 * @param Session $userSession
65
-	 * @param ISession $session
66
-	 * @param IURLGenerator $urlGenerator
67
-	 */
68
-	public function __construct(Manager $twoFactorManager, Session $userSession, ISession $session,
69
-		IURLGenerator $urlGenerator, IControllerMethodReflector $reflector, IRequest $request) {
70
-		$this->twoFactorManager = $twoFactorManager;
71
-		$this->userSession = $userSession;
72
-		$this->session = $session;
73
-		$this->urlGenerator = $urlGenerator;
74
-		$this->reflector = $reflector;
75
-		$this->request = $request;
76
-	}
77
-
78
-	/**
79
-	 * @param Controller $controller
80
-	 * @param string $methodName
81
-	 */
82
-	public function beforeController($controller, $methodName) {
83
-		if ($this->reflector->hasAnnotation('PublicPage')) {
84
-			// Don't block public pages
85
-			return;
86
-		}
87
-
88
-		if ($controller instanceof LoginController && $methodName === 'logout') {
89
-			// Don't block the logout page, to allow canceling the 2FA
90
-			return;
91
-		}
92
-
93
-		if ($this->userSession->isLoggedIn()) {
94
-			$user = $this->userSession->getUser();
95
-
96
-			if ($this->twoFactorManager->isTwoFactorAuthenticated($user)) {
97
-				$this->checkTwoFactor($controller, $methodName, $user);
98
-			} else if ($controller instanceof TwoFactorChallengeController) {
99
-				// Allow access to the two-factor controllers only if two-factor authentication
100
-				// is in progress.
101
-				throw new UserAlreadyLoggedInException();
102
-			}
103
-		}
104
-		// TODO: dont check/enforce 2FA if a auth token is used
105
-	}
106
-
107
-	private function checkTwoFactor(Controller $controller, $methodName, IUser $user) {
108
-		// If two-factor auth is in progress disallow access to any controllers
109
-		// defined within "LoginController".
110
-		$needsSecondFactor = $this->twoFactorManager->needsSecondFactor($user);
111
-		$twoFactor = $controller instanceof TwoFactorChallengeController;
112
-
113
-		// Disallow access to any controller if 2FA needs to be checked
114
-		if ($needsSecondFactor && !$twoFactor) {
115
-			throw new TwoFactorAuthRequiredException();
116
-		}
117
-
118
-		// Allow access to the two-factor controllers only if two-factor authentication
119
-		// is in progress.
120
-		if (!$needsSecondFactor && $twoFactor) {
121
-			throw new UserAlreadyLoggedInException();
122
-		}
123
-	}
124
-
125
-	public function afterException($controller, $methodName, Exception $exception) {
126
-		if ($exception instanceof TwoFactorAuthRequiredException) {
127
-			$params = [];
128
-			if (isset($this->request->server['REQUEST_URI'])) {
129
-				$params['redirect_url'] = $this->request->server['REQUEST_URI'];
130
-			}
131
-			return new RedirectResponse($this->urlGenerator->linkToRoute('core.TwoFactorChallenge.selectChallenge', $params));
132
-		}
133
-		if ($exception instanceof UserAlreadyLoggedInException) {
134
-			return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index'));
135
-		}
136
-
137
-		throw $exception;
138
-	}
44
+    /** @var Manager */
45
+    private $twoFactorManager;
46
+
47
+    /** @var Session */
48
+    private $userSession;
49
+
50
+    /** @var ISession */
51
+    private $session;
52
+
53
+    /** @var IURLGenerator */
54
+    private $urlGenerator;
55
+
56
+    /** @var IControllerMethodReflector */
57
+    private $reflector;
58
+
59
+    /** @var IRequest */
60
+    private $request;
61
+
62
+    /**
63
+     * @param Manager $twoFactorManager
64
+     * @param Session $userSession
65
+     * @param ISession $session
66
+     * @param IURLGenerator $urlGenerator
67
+     */
68
+    public function __construct(Manager $twoFactorManager, Session $userSession, ISession $session,
69
+        IURLGenerator $urlGenerator, IControllerMethodReflector $reflector, IRequest $request) {
70
+        $this->twoFactorManager = $twoFactorManager;
71
+        $this->userSession = $userSession;
72
+        $this->session = $session;
73
+        $this->urlGenerator = $urlGenerator;
74
+        $this->reflector = $reflector;
75
+        $this->request = $request;
76
+    }
77
+
78
+    /**
79
+     * @param Controller $controller
80
+     * @param string $methodName
81
+     */
82
+    public function beforeController($controller, $methodName) {
83
+        if ($this->reflector->hasAnnotation('PublicPage')) {
84
+            // Don't block public pages
85
+            return;
86
+        }
87
+
88
+        if ($controller instanceof LoginController && $methodName === 'logout') {
89
+            // Don't block the logout page, to allow canceling the 2FA
90
+            return;
91
+        }
92
+
93
+        if ($this->userSession->isLoggedIn()) {
94
+            $user = $this->userSession->getUser();
95
+
96
+            if ($this->twoFactorManager->isTwoFactorAuthenticated($user)) {
97
+                $this->checkTwoFactor($controller, $methodName, $user);
98
+            } else if ($controller instanceof TwoFactorChallengeController) {
99
+                // Allow access to the two-factor controllers only if two-factor authentication
100
+                // is in progress.
101
+                throw new UserAlreadyLoggedInException();
102
+            }
103
+        }
104
+        // TODO: dont check/enforce 2FA if a auth token is used
105
+    }
106
+
107
+    private function checkTwoFactor(Controller $controller, $methodName, IUser $user) {
108
+        // If two-factor auth is in progress disallow access to any controllers
109
+        // defined within "LoginController".
110
+        $needsSecondFactor = $this->twoFactorManager->needsSecondFactor($user);
111
+        $twoFactor = $controller instanceof TwoFactorChallengeController;
112
+
113
+        // Disallow access to any controller if 2FA needs to be checked
114
+        if ($needsSecondFactor && !$twoFactor) {
115
+            throw new TwoFactorAuthRequiredException();
116
+        }
117
+
118
+        // Allow access to the two-factor controllers only if two-factor authentication
119
+        // is in progress.
120
+        if (!$needsSecondFactor && $twoFactor) {
121
+            throw new UserAlreadyLoggedInException();
122
+        }
123
+    }
124
+
125
+    public function afterException($controller, $methodName, Exception $exception) {
126
+        if ($exception instanceof TwoFactorAuthRequiredException) {
127
+            $params = [];
128
+            if (isset($this->request->server['REQUEST_URI'])) {
129
+                $params['redirect_url'] = $this->request->server['REQUEST_URI'];
130
+            }
131
+            return new RedirectResponse($this->urlGenerator->linkToRoute('core.TwoFactorChallenge.selectChallenge', $params));
132
+        }
133
+        if ($exception instanceof UserAlreadyLoggedInException) {
134
+            return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index'));
135
+        }
136
+
137
+        throw $exception;
138
+    }
139 139
 
140 140
 }
Please login to merge, or discard this patch.
core/templates/403.php 2 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,11 +1,11 @@
 block discarded – undo
1 1
 <?php
2 2
 // @codeCoverageIgnoreStart
3 3
 if(!isset($_)) {//standalone  page is not supported anymore - redirect to /
4
-	require_once '../../lib/base.php';
4
+    require_once '../../lib/base.php';
5 5
 
6
-	$urlGenerator = \OC::$server->getURLGenerator();
7
-	header('Location: ' . $urlGenerator->getAbsoluteURL('/'));
8
-	exit;
6
+    $urlGenerator = \OC::$server->getURLGenerator();
7
+    header('Location: ' . $urlGenerator->getAbsoluteURL('/'));
8
+    exit;
9 9
 }
10 10
 // @codeCoverageIgnoreEnd
11 11
 ?>
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,17 +1,17 @@
 block discarded – undo
1 1
 <?php
2 2
 // @codeCoverageIgnoreStart
3
-if(!isset($_)) {//standalone  page is not supported anymore - redirect to /
3
+if (!isset($_)) {//standalone  page is not supported anymore - redirect to /
4 4
 	require_once '../../lib/base.php';
5 5
 
6 6
 	$urlGenerator = \OC::$server->getURLGenerator();
7
-	header('Location: ' . $urlGenerator->getAbsoluteURL('/'));
7
+	header('Location: '.$urlGenerator->getAbsoluteURL('/'));
8 8
 	exit;
9 9
 }
10 10
 // @codeCoverageIgnoreEnd
11 11
 ?>
12 12
 <ul>
13 13
 	<li class='error'>
14
-		<?php p($l->t( 'Access forbidden' )); ?><br>
15
-		<p class='hint'><?php if(isset($_['file'])) p($_['file'])?></p>
14
+		<?php p($l->t('Access forbidden')); ?><br>
15
+		<p class='hint'><?php if (isset($_['file'])) p($_['file'])?></p>
16 16
 	</li>
17 17
 </ul>
Please login to merge, or discard this patch.
lib/private/Preview/Office.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -41,20 +41,20 @@
 block discarded – undo
41 41
 
42 42
 		$tmpDir = \OC::$server->getTempManager()->getTempBaseDir();
43 43
 
44
-		$defaultParameters = ' -env:UserInstallation=file://' . escapeshellarg($tmpDir . '/owncloud-' . \OC_Util::getInstanceId() . '/') . ' --headless --nologo --nofirststartwizard --invisible --norestore --convert-to pdf --outdir ';
44
+		$defaultParameters = ' -env:UserInstallation=file://'.escapeshellarg($tmpDir.'/owncloud-'.\OC_Util::getInstanceId().'/').' --headless --nologo --nofirststartwizard --invisible --norestore --convert-to pdf --outdir ';
45 45
 		$clParameters = \OC::$server->getConfig()->getSystemValue('preview_office_cl_parameters', $defaultParameters);
46 46
 
47
-		$exec = $this->cmd . $clParameters . escapeshellarg($tmpDir) . ' ' . escapeshellarg($absPath);
47
+		$exec = $this->cmd.$clParameters.escapeshellarg($tmpDir).' '.escapeshellarg($absPath);
48 48
 
49 49
 		shell_exec($exec);
50 50
 
51 51
 		//create imagick object from pdf
52 52
 		$pdfPreview = null;
53 53
 		try {
54
-			list($dirname, , , $filename) = array_values(pathinfo($absPath));
55
-			$pdfPreview = $dirname . '/' . $filename . '.pdf';
54
+			list($dirname,,, $filename) = array_values(pathinfo($absPath));
55
+			$pdfPreview = $dirname.'/'.$filename.'.pdf';
56 56
 
57
-			$pdf = new \imagick($pdfPreview . '[0]');
57
+			$pdf = new \imagick($pdfPreview.'[0]');
58 58
 			$pdf->setImageFormat('jpg');
59 59
 		} catch (\Exception $e) {
60 60
 			unlink($absPath);
Please login to merge, or discard this patch.
Indentation   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -28,83 +28,83 @@
 block discarded – undo
28 28
 use OCP\ILogger;
29 29
 
30 30
 abstract class Office extends Provider {
31
-	private $cmd;
31
+    private $cmd;
32 32
 
33
-	/**
34
-	 * {@inheritDoc}
35
-	 */
36
-	public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
37
-		$this->initCmd();
38
-		if (is_null($this->cmd)) {
39
-			return false;
40
-		}
33
+    /**
34
+     * {@inheritDoc}
35
+     */
36
+    public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
37
+        $this->initCmd();
38
+        if (is_null($this->cmd)) {
39
+            return false;
40
+        }
41 41
 
42
-		$absPath = $fileview->toTmpFile($path);
42
+        $absPath = $fileview->toTmpFile($path);
43 43
 
44
-		$tmpDir = \OC::$server->getTempManager()->getTempBaseDir();
44
+        $tmpDir = \OC::$server->getTempManager()->getTempBaseDir();
45 45
 
46
-		$defaultParameters = ' -env:UserInstallation=file://' . escapeshellarg($tmpDir . '/owncloud-' . \OC_Util::getInstanceId() . '/') . ' --headless --nologo --nofirststartwizard --invisible --norestore --convert-to pdf --outdir ';
47
-		$clParameters = \OC::$server->getConfig()->getSystemValue('preview_office_cl_parameters', $defaultParameters);
46
+        $defaultParameters = ' -env:UserInstallation=file://' . escapeshellarg($tmpDir . '/owncloud-' . \OC_Util::getInstanceId() . '/') . ' --headless --nologo --nofirststartwizard --invisible --norestore --convert-to pdf --outdir ';
47
+        $clParameters = \OC::$server->getConfig()->getSystemValue('preview_office_cl_parameters', $defaultParameters);
48 48
 
49
-		$exec = $this->cmd . $clParameters . escapeshellarg($tmpDir) . ' ' . escapeshellarg($absPath);
49
+        $exec = $this->cmd . $clParameters . escapeshellarg($tmpDir) . ' ' . escapeshellarg($absPath);
50 50
 
51
-		shell_exec($exec);
51
+        shell_exec($exec);
52 52
 
53
-		//create imagick object from pdf
54
-		$pdfPreview = null;
55
-		try {
56
-			list($dirname, , , $filename) = array_values(pathinfo($absPath));
57
-			$pdfPreview = $dirname . '/' . $filename . '.pdf';
53
+        //create imagick object from pdf
54
+        $pdfPreview = null;
55
+        try {
56
+            list($dirname, , , $filename) = array_values(pathinfo($absPath));
57
+            $pdfPreview = $dirname . '/' . $filename . '.pdf';
58 58
 
59
-			$pdf = new \imagick($pdfPreview . '[0]');
60
-			$pdf->setImageFormat('jpg');
61
-		} catch (\Exception $e) {
62
-			unlink($absPath);
63
-			unlink($pdfPreview);
64
-			\OC::$server->getLogger()->logException($e, [
65
-				'level' => ILogger::ERROR,
66
-				'app' => 'core',
67
-			]);
68
-			return false;
69
-		}
59
+            $pdf = new \imagick($pdfPreview . '[0]');
60
+            $pdf->setImageFormat('jpg');
61
+        } catch (\Exception $e) {
62
+            unlink($absPath);
63
+            unlink($pdfPreview);
64
+            \OC::$server->getLogger()->logException($e, [
65
+                'level' => ILogger::ERROR,
66
+                'app' => 'core',
67
+            ]);
68
+            return false;
69
+        }
70 70
 
71
-		$image = new \OC_Image();
72
-		$image->loadFromData($pdf);
71
+        $image = new \OC_Image();
72
+        $image->loadFromData($pdf);
73 73
 
74
-		unlink($absPath);
75
-		unlink($pdfPreview);
74
+        unlink($absPath);
75
+        unlink($pdfPreview);
76 76
 
77
-		if ($image->valid()) {
78
-			$image->scaleDownToFit($maxX, $maxY);
77
+        if ($image->valid()) {
78
+            $image->scaleDownToFit($maxX, $maxY);
79 79
 
80
-			return $image;
81
-		}
82
-		return false;
80
+            return $image;
81
+        }
82
+        return false;
83 83
 
84
-	}
84
+    }
85 85
 
86
-	private function initCmd() {
87
-		$cmd = '';
86
+    private function initCmd() {
87
+        $cmd = '';
88 88
 
89
-		$libreOfficePath = \OC::$server->getConfig()->getSystemValue('preview_libreoffice_path', null);
90
-		if (is_string($libreOfficePath)) {
91
-			$cmd = $libreOfficePath;
92
-		}
89
+        $libreOfficePath = \OC::$server->getConfig()->getSystemValue('preview_libreoffice_path', null);
90
+        if (is_string($libreOfficePath)) {
91
+            $cmd = $libreOfficePath;
92
+        }
93 93
 
94
-		$whichLibreOffice = shell_exec('command -v libreoffice');
95
-		if ($cmd === '' && !empty($whichLibreOffice)) {
96
-			$cmd = 'libreoffice';
97
-		}
94
+        $whichLibreOffice = shell_exec('command -v libreoffice');
95
+        if ($cmd === '' && !empty($whichLibreOffice)) {
96
+            $cmd = 'libreoffice';
97
+        }
98 98
 
99
-		$whichOpenOffice = shell_exec('command -v openoffice');
100
-		if ($cmd === '' && !empty($whichOpenOffice)) {
101
-			$cmd = 'openoffice';
102
-		}
99
+        $whichOpenOffice = shell_exec('command -v openoffice');
100
+        if ($cmd === '' && !empty($whichOpenOffice)) {
101
+            $cmd = 'openoffice';
102
+        }
103 103
 
104
-		if ($cmd === '') {
105
-			$cmd = null;
106
-		}
104
+        if ($cmd === '') {
105
+            $cmd = null;
106
+        }
107 107
 
108
-		$this->cmd = $cmd;
109
-	}
108
+        $this->cmd = $cmd;
109
+    }
110 110
 }
Please login to merge, or discard this patch.