Code Duplication    Length = 20-20 lines in 2 locations

lib/backend.php 1 location

@@ 206-225 (lines=20) @@
203
		if ($results)
204
			foreach ($results as $result) {
205
				foreach ($results2 as $result2) {
206
					if ($result['id'] != $result2['id'] && $result['name'] == $result2['name'] && $result['grouping'] == $result2['grouping']) {
207
						// We have a duplicate that should not exist. Need to remove the offending record first
208
						$delid = -1;
209
						if ($result['mtime'] == $result2['mtime']) {
210
							// If the mtime's match, delete the oldest ID.
211
							$delid = $result['id'];
212
							if ($result['id'] > $result2['id'])
213
								$delid = $result2['id'];
214
						} elseif ($result['mtime'] > $result2['mtime']) {
215
							// Again, delete the oldest
216
							$delid = $result2['id'];
217
						} elseif ($result['mtime'] < $result2['mtime']) {
218
							// The only thing left is if result is older
219
							$delid = $result['id'];
220
						}
221
						if ($delid != -1) {
222
							$this->db->executeQuery("DELETE FROM *PREFIX*ownnote WHERE id=?", Array($delid));
223
							$requery = true;
224
						}
225
					}
226
				}
227
			}
228
		if ($requery) {

lib/Service/OwnNoteService.php 1 location

@@ 258-277 (lines=20) @@
255
					if($result2 instanceof OwnNote) {
256
						$result2 = $result2->jsonSerialize();
257
					}
258
					if ($result['id'] != $result2['id'] && $result['name'] == $result2['name'] && $result['grouping'] == $result2['grouping']) {
259
						// We have a duplicate that should not exist. Need to remove the offending record first
260
						$delid = -1;
261
						if ($result['mtime'] == $result2['mtime']) {
262
							// If the mtime's match, delete the oldest ID.
263
							$delid = $result['id'];
264
							if ($result['id'] > $result2['id'])
265
								$delid = $result2['id'];
266
						} elseif ($result['mtime'] > $result2['mtime']) {
267
							// Again, delete the oldest
268
							$delid = $result2['id'];
269
						} elseif ($result['mtime'] < $result2['mtime']) {
270
							// The only thing left is if result is older
271
							$delid = $result['id'];
272
						}
273
						if ($delid != -1) {
274
							$this->delete('', $delid);
275
							$requery = true;
276
						}
277
					}
278
				}
279
			}
280
		if ($requery) {