|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class CleanupOrphanedRecordsTask extends BuildTask { |
|
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
public function run($request) { |
|
6
|
|
View Code Duplication |
$log = function($message) { |
|
|
|
|
|
|
7
|
|
|
$message = sprintf('[%s] ', date('Y-m-d H:i:s')) . $message; |
|
8
|
|
|
echo $message . PHP_EOL; |
|
9
|
|
|
}; |
|
10
|
|
|
|
|
11
|
|
|
$count = 0; |
|
12
|
|
|
|
|
13
|
|
|
foreach (DNDeployment::get() as $deployment) { |
|
14
|
|
|
$environment = $deployment->Environment(); |
|
15
|
|
|
if (!$environment || !$environment->exists()) { |
|
16
|
|
|
$log(sprintf( |
|
17
|
|
|
'Deployment (ID %s, Created: %s, State: %s) is linked to a non-existent environment. Deleting', |
|
18
|
|
|
$deployment->ID, |
|
19
|
|
|
$deployment->Created, |
|
20
|
|
|
$deployment->State |
|
21
|
|
|
)); |
|
22
|
|
|
$deployment->delete(); |
|
23
|
|
|
$deployment->destroy(); |
|
24
|
|
|
$count++; |
|
25
|
|
|
} |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
View Code Duplication |
foreach (DNDataTransfer::get() as $transfer) { |
|
|
|
|
|
|
29
|
|
|
$environment = $transfer->Environment(); |
|
30
|
|
|
if (!$environment || !$environment->exists()) { |
|
31
|
|
|
$log(sprintf( |
|
32
|
|
|
'Data transfer (ID %s, Created: %s) is linked to a non-existent environment. Deleting', |
|
33
|
|
|
$transfer->ID, |
|
34
|
|
|
$transfer->Created |
|
35
|
|
|
)); |
|
36
|
|
|
$transfer->delete(); |
|
37
|
|
|
$transfer->destroy(); |
|
38
|
|
|
$count++; |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
View Code Duplication |
foreach (DNDataArchive::get() as $archive) { |
|
|
|
|
|
|
43
|
|
|
$environment = $archive->Environment(); |
|
44
|
|
|
if (!$environment || !$environment->exists()) { |
|
45
|
|
|
$log(sprintf( |
|
46
|
|
|
'Archive (ID %s, Created: %s) is linked to a non-existent environment. Deleting', |
|
47
|
|
|
$archive->ID, |
|
48
|
|
|
$archive->Created |
|
49
|
|
|
)); |
|
50
|
|
|
$archive->delete(); |
|
51
|
|
|
$archive->destroy(); |
|
52
|
|
|
$count++; |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
View Code Duplication |
foreach (DNGitFetch::get() as $fetch) { |
|
|
|
|
|
|
57
|
|
|
$project = $fetch->Project(); |
|
58
|
|
|
if (!$project || !$project->exists()) { |
|
59
|
|
|
$log(sprintf( |
|
60
|
|
|
'Git fetch (ID %s, Created: %s) is linked to a non-existent project. Deleting', |
|
61
|
|
|
$fetch->ID, |
|
62
|
|
|
$fetch->Created |
|
63
|
|
|
)); |
|
64
|
|
|
$fetch->delete(); |
|
65
|
|
|
$fetch->destroy(); |
|
66
|
|
|
$count++; |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
View Code Duplication |
foreach (DNPing::get() as $ping) { |
|
|
|
|
|
|
71
|
|
|
$environment = $ping->Environment(); |
|
72
|
|
|
if (!$environment || !$environment->exists()) { |
|
73
|
|
|
$log(sprintf( |
|
74
|
|
|
'Ping (ID %s, Created: %s) is linked to a non-existent environment. Deleting', |
|
75
|
|
|
$ping->ID, |
|
76
|
|
|
$ping->Created |
|
77
|
|
|
)); |
|
78
|
|
|
$ping->delete(); |
|
79
|
|
|
$ping->destroy(); |
|
80
|
|
|
$count++; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
$log(sprintf('Finished. Processed %s records', $count)); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
} |
|
88
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.