|
1 | 1 | <?php |
2 | 2 |
|
3 | | - namespace Hamaka; |
| 3 | +namespace Hamaka\Tasks; |
4 | 4 |
|
5 | | - use SilverStripe\Dev\BuildTask; |
6 | | - use SilverStripe\ORM\DB; |
7 | | - use SilverStripe\UserForms\Model\Submission\SubmittedForm; |
| 5 | +use SilverStripe\Dev\BuildTask; |
| 6 | +use SilverStripe\ORM\DB; |
| 7 | +use SilverStripe\UserForms\Model\Submission\SubmittedForm; |
8 | 8 |
|
9 | | - class UserFormsCleanupOldEntriesTask extends BuildTask |
10 | | - { |
| 9 | +class UserFormsCleanupOldEntriesTask extends BuildTask |
| 10 | +{ |
11 | 11 |
|
12 | | - protected $title = "UserForms Clean-up SubmittedForm task"; |
| 12 | + protected $title = "UserForms Clean-up SubmittedForm task"; |
13 | 13 |
|
14 | | - protected $description = "Removes old userdata for privacy reasons"; |
| 14 | + protected $description = "Removes old userdata for privacy reasons"; |
15 | 15 |
|
16 | | - private static $segment = 'userforms-cleanup'; |
| 16 | + private static $segment = 'userforms-cleanup'; |
17 | 17 |
|
18 | | - private static $days_retention = 31; |
| 18 | + private static $days_retention = 31; |
19 | 19 |
|
20 | | - public function run($request) |
21 | | - { |
22 | | - $iThresholdDate = strtotime('-' . $this->config()->get('days_retention') . ' days'); |
23 | | - $sThresholdDate = date('Y-m-d 00:00:00', $iThresholdDate); |
24 | | - DB::alteration_message('Removing all entries before ' . $sThresholdDate); |
| 20 | + public function run($request) |
| 21 | + { |
| 22 | + $iThresholdDate = strtotime('-' . $this->config()->get('days_retention') . ' days'); |
| 23 | + $sThresholdDate = date('Y-m-d 00:00:00', $iThresholdDate); |
| 24 | + DB::alteration_message('Removing all entries before ' . $sThresholdDate); |
25 | 25 |
|
26 | | - DB::alteration_message('Total entries in database (before cleanup): ' . SubmittedForm::get()->count()); |
| 26 | + DB::alteration_message('Total entries in database (before cleanup): ' . SubmittedForm::get()->count()); |
27 | 27 |
|
28 | | - $iClearedEntries = $this->cleanUpUserForms($sThresholdDate); |
29 | | - DB::alteration_message('Total entries to be deleted: ' . $iClearedEntries); |
| 28 | + $iClearedEntries = $this->cleanUpUserForms($sThresholdDate); |
| 29 | + DB::alteration_message('Total entries to be deleted: ' . $iClearedEntries); |
30 | 30 |
|
31 | | - DB::alteration_message("Done, total entries after cleanup: " . SubmittedForm::get()->count()); |
32 | | - } |
| 31 | + DB::alteration_message("Done, total entries after cleanup: " . SubmittedForm::get()->count()); |
| 32 | + } |
33 | 33 |
|
34 | | - /** |
35 | | - * @param $sBeforeDate String Date written as Y-m-d h:m:s |
36 | | - * |
37 | | - * @return int |
38 | | - */ |
39 | | - public static function cleanUpUserForms(string $sBeforeDate): int |
40 | | - { |
41 | | - $dlSubmissions = SubmittedForm::get()->filter('Created:LessThanOrEqual', $sBeforeDate); |
42 | | - $iTotalToBeCleared = $dlSubmissions->count(); |
43 | | - $dlSubmissions->removeAll(); |
| 34 | + /** |
| 35 | + * @param $sBeforeDate String Date written as Y-m-d h:m:s |
| 36 | + * |
| 37 | + * @return int |
| 38 | + */ |
| 39 | + public static function cleanUpUserForms(string $sBeforeDate): int |
| 40 | + { |
| 41 | + $dlSubmissions = SubmittedForm::get()->filter('Created:LessThanOrEqual', $sBeforeDate); |
| 42 | + $iTotalToBeCleared = $dlSubmissions->count(); |
| 43 | + $dlSubmissions->removeAll(); |
44 | 44 |
|
45 | | - return $iTotalToBeCleared; |
46 | | - } |
| 45 | + return $iTotalToBeCleared; |
47 | 46 | } |
| 47 | +} |
0 commit comments