Code Duplication    Length = 5-7 lines in 10 locations

lib/private/Setup/OCI.php 10 locations

@@ 101-105 (lines=5) @@
98
		$query='SELECT count(*) FROM user_role_privs, role_sys_privs'
99
			." WHERE user_role_privs.granted_role = role_sys_privs.role AND privilege = 'CREATE ROLE'";
100
		$stmt = oci_parse($connection, $query);
101
		if (!$stmt) {
102
			$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
103
			$entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />';
104
			$this->logger->warning($entry, ['app' => 'setup.oci']);
105
		}
106
		$result = oci_execute($stmt);
107
		if($result) {
108
			$row = oci_fetch_row($stmt);
@@ 163-167 (lines=5) @@
160
		$stmt = oci_parse($connection, $query);
161
		$un = $this->tablePrefix.'users';
162
		oci_bind_by_name($stmt, ':un', $un);
163
		if (!$stmt) {
164
			$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
165
			$entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />';
166
			$this->logger->warning( $entry, ['app' => 'setup.oci']);
167
		}
168
		oci_execute($stmt);
169
	}
170
@@ 179-183 (lines=5) @@
176
		$password = $this->dbPassword;
177
		$query = "SELECT * FROM all_users WHERE USERNAME = :un";
178
		$stmt = oci_parse($connection, $query);
179
		if (!$stmt) {
180
			$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
181
			$entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />';
182
			$this->logger->warning($entry, ['app' => 'setup.oci']);
183
		}
184
		oci_bind_by_name($stmt, ':un', $name);
185
		$result = oci_execute($stmt);
186
		if(!$result) {
@@ 186-190 (lines=5) @@
183
		}
184
		oci_bind_by_name($stmt, ':un', $name);
185
		$result = oci_execute($stmt);
186
		if(!$result) {
187
			$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
188
			$entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />';
189
			$this->logger->warning($entry, ['app' => 'setup.oci']);
190
		}
191
192
		if(! oci_fetch_row($stmt)) {
193
			//user does not exists let's create it :)
@@ 197-202 (lines=6) @@
194
			//password must start with alphabetic character in oracle
195
			$query = 'CREATE USER '.$name.' IDENTIFIED BY "'.$password.'" DEFAULT TABLESPACE '.$this->dbtablespace;
196
			$stmt = oci_parse($connection, $query);
197
			if (!$stmt) {
198
				$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
199
				$entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />';
200
				$this->logger->warning($entry, ['app' => 'setup.oci']);
201
202
			}
203
			//oci_bind_by_name($stmt, ':un', $name);
204
			$result = oci_execute($stmt);
205
			if(!$result) {
@@ 205-211 (lines=7) @@
202
			}
203
			//oci_bind_by_name($stmt, ':un', $name);
204
			$result = oci_execute($stmt);
205
			if(!$result) {
206
				$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
207
				$entry .= $this->trans->t('Offending command was: "%s", name: %s, password: %s',
208
					array($query, $name, $password)) . '<br />';
209
				$this->logger->warning($entry, ['app' => 'setup.oci']);
210
211
			}
212
		} else { // change password of the existing role
213
			$query = "ALTER USER :un IDENTIFIED BY :pw";
214
			$stmt = oci_parse($connection, $query);
@@ 215-219 (lines=5) @@
212
		} else { // change password of the existing role
213
			$query = "ALTER USER :un IDENTIFIED BY :pw";
214
			$stmt = oci_parse($connection, $query);
215
			if (!$stmt) {
216
				$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
217
				$entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />';
218
				$this->logger->warning($entry, ['app' => 'setup.oci']);
219
			}
220
			oci_bind_by_name($stmt, ':un', $name);
221
			oci_bind_by_name($stmt, ':pw', $password);
222
			$result = oci_execute($stmt);
@@ 223-227 (lines=5) @@
220
			oci_bind_by_name($stmt, ':un', $name);
221
			oci_bind_by_name($stmt, ':pw', $password);
222
			$result = oci_execute($stmt);
223
			if(!$result) {
224
				$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
225
				$entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />';
226
				$this->logger->warning($entry, ['app' => 'setup.oci']);
227
			}
228
		}
229
		// grant necessary roles
230
		$query = 'GRANT CREATE SESSION, CREATE TABLE, CREATE SEQUENCE, CREATE TRIGGER, UNLIMITED TABLESPACE TO '.$name;
@@ 232-236 (lines=5) @@
229
		// grant necessary roles
230
		$query = 'GRANT CREATE SESSION, CREATE TABLE, CREATE SEQUENCE, CREATE TRIGGER, UNLIMITED TABLESPACE TO '.$name;
231
		$stmt = oci_parse($connection, $query);
232
		if (!$stmt) {
233
			$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
234
			$entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />';
235
			$this->logger->warning($entry, ['app' => 'setup.oci']);
236
		}
237
		$result = oci_execute($stmt);
238
		if(!$result) {
239
			$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
@@ 238-243 (lines=6) @@
235
			$this->logger->warning($entry, ['app' => 'setup.oci']);
236
		}
237
		$result = oci_execute($stmt);
238
		if(!$result) {
239
			$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
240
			$entry .= $this->trans->t('Offending command was: "%s", name: %s, password: %s',
241
				array($query, $name, $password)) . '<br />';
242
			$this->logger->warning($entry, ['app' => 'setup.oci']);
243
		}
244
	}
245
246
	/**