Code Duplication    Length = 15-15 lines in 6 locations

code/tasks/CleanupOrphanedRecordsTask.php 6 locations

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