Code Duplication    Length = 15-16 lines in 6 locations

code/tasks/CleanupOrphanedRecordsTask.php 6 locations

@@ 25-40 (lines=16) @@
22
23
		$count = 0;
24
25
		foreach (DNEnvironment::get() as $environment) {
26
			$project = $environment->Project();
27
			if (!$project || !$project->exists()) {
28
				$log(sprintf(
29
					'Environment (ID %s, Name: %s, Created: %s) is linked to a non-existent project. Deleting',
30
					$environment->ID,
31
					$environment->Name,
32
					$environment->Created
33
				));
34
				if (!$dryRun) {
35
					$environment->delete();
36
					$environment->destroy();
37
				}
38
				$count++;
39
			}
40
		}
41
42
		foreach (DNDeployment::get() as $deployment) {
43
			$environment = $deployment->Environment();
@@ 42-56 (lines=15) @@
39
			}
40
		}
41
42
		foreach (DNDeployment::get() as $deployment) {
43
			$environment = $deployment->Environment();
44
			if (!$environment || !$environment->exists()) {
45
				$log(sprintf(
46
					'Deployment (ID %s, Created: %s) is linked to a non-existent environment. Deleting',
47
					$deployment->ID,
48
					$deployment->Created
49
				));
50
				if (!$dryRun) {
51
					$deployment->delete();
52
					$deployment->destroy();
53
				}
54
				$count++;
55
			}
56
		}
57
58
		foreach (DNDataTransfer::get() as $transfer) {
59
			$environment = $transfer->Environment();
@@ 58-72 (lines=15) @@
55
			}
56
		}
57
58
		foreach (DNDataTransfer::get() as $transfer) {
59
			$environment = $transfer->Environment();
60
			if (!$environment || !$environment->exists()) {
61
				$log(sprintf(
62
					'Data transfer (ID %s, Created: %s) is linked to a non-existent environment. Deleting',
63
					$transfer->ID,
64
					$transfer->Created
65
				));
66
				if (!$dryRun) {
67
					$transfer->delete();
68
					$transfer->destroy();
69
				}
70
				$count++;
71
			}
72
		}
73
74
		foreach (DNDataArchive::get() as $archive) {
75
			$environment = $archive->Environment();
@@ 74-88 (lines=15) @@
71
			}
72
		}
73
74
		foreach (DNDataArchive::get() as $archive) {
75
			$environment = $archive->Environment();
76
			if (!$environment || !$environment->exists()) {
77
				$log(sprintf(
78
					'Archive (ID %s, Created: %s) is linked to a non-existent environment. Deleting',
79
					$archive->ID,
80
					$archive->Created
81
				));
82
				if (!$dryRun) {
83
					$archive->delete();
84
					$archive->destroy();
85
				}
86
				$count++;
87
			}
88
		}
89
90
		foreach (DNGitFetch::get() as $fetch) {
91
			$project = $fetch->Project();
@@ 90-104 (lines=15) @@
87
			}
88
		}
89
90
		foreach (DNGitFetch::get() as $fetch) {
91
			$project = $fetch->Project();
92
			if (!$project || !$project->exists()) {
93
				$log(sprintf(
94
					'Git fetch (ID %s, Created: %s) is linked to a non-existent project. Deleting',
95
					$fetch->ID,
96
					$fetch->Created
97
				));
98
				if (!$dryRun) {
99
					$fetch->delete();
100
					$fetch->destroy();
101
				}
102
				$count++;
103
			}
104
		}
105
106
		foreach (DNPing::get() as $ping) {
107
			$environment = $ping->Environment();
@@ 106-120 (lines=15) @@
103
			}
104
		}
105
106
		foreach (DNPing::get() as $ping) {
107
			$environment = $ping->Environment();
108
			if (!$environment || !$environment->exists()) {
109
				$log(sprintf(
110
					'Ping (ID %s, Created: %s) is linked to a non-existent environment. Deleting',
111
					$ping->ID,
112
					$ping->Created
113
				));
114
				if (!$dryRun) {
115
					$ping->delete();
116
					$ping->destroy();
117
				}
118
				$count++;
119
			}
120
		}
121
122
		$log(sprintf('Finished. Processed %s records', $count));
123
	}