Code Duplication    Length = 5-7 lines in 10 locations

lib/private/Setup/OCI.php 10 locations

@@ 105-109 (lines=5) @@
102
		                'CREATE TRIGGER'
103
		                ) AND a2.admin_option = 'YES')";
104
		$stmt = \oci_parse($connection, $query);
105
		if (!$stmt) {
106
			$entry = $this->trans->t('DB Error: "%s"', [$this->getLastError($connection)]) . '<br />';
107
			$entry .= $this->trans->t('Offending command was: "%s"', [$query]) . '<br />';
108
			$this->logger->warning($entry, ['app' => 'setup.oci']);
109
		}
110
		$result = \oci_execute($stmt);
111
		if ($result) {
112
			$row = \oci_fetch_row($stmt);
@@ 167-171 (lines=5) @@
164
		$stmt = \oci_parse($connection, $query);
165
		$un = $this->tablePrefix.'users';
166
		\oci_bind_by_name($stmt, ':un', $un);
167
		if (!$stmt) {
168
			$entry = $this->trans->t('DB Error: "%s"', [$this->getLastError($connection)]) . '<br />';
169
			$entry .= $this->trans->t('Offending command was: "%s"', [$query]) . '<br />';
170
			$this->logger->warning($entry, ['app' => 'setup.oci']);
171
		}
172
		$result = \oci_execute($stmt);
173
174
		if ($result) {
@@ 190-194 (lines=5) @@
187
		$password = $this->dbPassword;
188
		$query = "SELECT * FROM all_users WHERE USERNAME = :un";
189
		$stmt = \oci_parse($connection, $query);
190
		if (!$stmt) {
191
			$entry = $this->trans->t('DB Error: "%s"', [$this->getLastError($connection)]) . '<br />';
192
			$entry .= $this->trans->t('Offending command was: "%s"', [$query]) . '<br />';
193
			$this->logger->warning($entry, ['app' => 'setup.oci']);
194
		}
195
		\oci_bind_by_name($stmt, ':un', $name);
196
		$result = \oci_execute($stmt);
197
		if (!$result) {
@@ 197-201 (lines=5) @@
194
		}
195
		\oci_bind_by_name($stmt, ':un', $name);
196
		$result = \oci_execute($stmt);
197
		if (!$result) {
198
			$entry = $this->trans->t('DB Error: "%s"', [$this->getLastError($connection)]) . '<br />';
199
			$entry .= $this->trans->t('Offending command was: "%s"', [$query]) . '<br />';
200
			$this->logger->warning($entry, ['app' => 'setup.oci']);
201
		}
202
203
		if (! \oci_fetch_row($stmt)) {
204
			//user does not exist, so let's create them :)
@@ 208-213 (lines=6) @@
205
			//password must start with alphabetic character in oracle
206
			$query = 'CREATE USER '.$name.' IDENTIFIED BY "'.$password.'" DEFAULT TABLESPACE '.$this->dbtablespace;
207
			$stmt = \oci_parse($connection, $query);
208
			if (!$stmt) {
209
				$entry = $this->trans->t('DB Error: "%s"', [$this->getLastError($connection)]) . '<br />';
210
				$entry .= $this->trans->t('Offending command was: "%s"', [$query]) . '<br />';
211
				$this->logger->warning($entry, ['app' => 'setup.oci']);
212
			}
213
			//oci_bind_by_name($stmt, ':un', $name);
214
			$result = \oci_execute($stmt);
215
			if (!$result) {
216
				$entry = $this->trans->t('DB Error: "%s"', [$this->getLastError($connection)]) . '<br />';
@@ 215-221 (lines=7) @@
212
			}
213
			//oci_bind_by_name($stmt, ':un', $name);
214
			$result = \oci_execute($stmt);
215
			if (!$result) {
216
				$entry = $this->trans->t('DB Error: "%s"', [$this->getLastError($connection)]) . '<br />';
217
				$entry .= $this->trans->t('Offending command was: "%s", name: %s, password: %s',
218
					[$query, $name, $password]) . '<br />';
219
				$this->logger->warning($entry, ['app' => 'setup.oci']);
220
			}
221
		} else { // change password of the existing role
222
			$query = "ALTER USER :un IDENTIFIED BY :pw";
223
			$stmt = \oci_parse($connection, $query);
224
			if (!$stmt) {
@@ 224-228 (lines=5) @@
221
		} else { // change password of the existing role
222
			$query = "ALTER USER :un IDENTIFIED BY :pw";
223
			$stmt = \oci_parse($connection, $query);
224
			if (!$stmt) {
225
				$entry = $this->trans->t('DB Error: "%s"', [$this->getLastError($connection)]) . '<br />';
226
				$entry .= $this->trans->t('Offending command was: "%s"', [$query]) . '<br />';
227
				$this->logger->warning($entry, ['app' => 'setup.oci']);
228
			}
229
			\oci_bind_by_name($stmt, ':un', $name);
230
			\oci_bind_by_name($stmt, ':pw', $password);
231
			$result = \oci_execute($stmt);
@@ 232-236 (lines=5) @@
229
			\oci_bind_by_name($stmt, ':un', $name);
230
			\oci_bind_by_name($stmt, ':pw', $password);
231
			$result = \oci_execute($stmt);
232
			if (!$result) {
233
				$entry = $this->trans->t('DB Error: "%s"', [$this->getLastError($connection)]) . '<br />';
234
				$entry .= $this->trans->t('Offending command was: "%s"', [$query]) . '<br />';
235
				$this->logger->warning($entry, ['app' => 'setup.oci']);
236
			}
237
		}
238
		// grant necessary roles
239
		$query = 'GRANT CREATE SESSION, CREATE TABLE, CREATE SEQUENCE, CREATE TRIGGER TO '.$name;
@@ 241-245 (lines=5) @@
238
		// grant necessary roles
239
		$query = 'GRANT CREATE SESSION, CREATE TABLE, CREATE SEQUENCE, CREATE TRIGGER TO '.$name;
240
		$stmt = \oci_parse($connection, $query);
241
		if (!$stmt) {
242
			$entry = $this->trans->t('DB Error: "%s"', [$this->getLastError($connection)]) . '<br />';
243
			$entry .= $this->trans->t('Offending command was: "%s"', [$query]) . '<br />';
244
			$this->logger->warning($entry, ['app' => 'setup.oci']);
245
		}
246
		$result = \oci_execute($stmt);
247
		if (!$result) {
248
			$entry = $this->trans->t('DB Error: "%s"', [$this->getLastError($connection)]) . '<br />';
@@ 247-252 (lines=6) @@
244
			$this->logger->warning($entry, ['app' => 'setup.oci']);
245
		}
246
		$result = \oci_execute($stmt);
247
		if (!$result) {
248
			$entry = $this->trans->t('DB Error: "%s"', [$this->getLastError($connection)]) . '<br />';
249
			$entry .= $this->trans->t('Offending command was: "%s", name: %s, password: %s',
250
				[$query, $name, $password]) . '<br />';
251
			$this->logger->warning($entry, ['app' => 'setup.oci']);
252
		}
253
	}
254
255
	/**