1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* vim: set expandtab sw=4 ts=4 sts=4: */ |
4
|
|
|
/** |
5
|
|
|
* Clean Old Notifications Shell. |
6
|
|
|
* |
7
|
|
|
* phpMyAdmin Error reporting server |
8
|
|
|
* Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/) |
9
|
|
|
* |
10
|
|
|
* Licensed under The MIT License |
11
|
|
|
* For full copyright and license information, please see the LICENSE.txt |
12
|
|
|
* Redistributions of files must retain the above copyright notice. |
13
|
|
|
* |
14
|
|
|
* @copyright Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/) |
15
|
|
|
* @license https://opensource.org/licenses/mit-license.php MIT License |
16
|
|
|
* |
17
|
|
|
* @see https://www.phpmyadmin.net/ |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace App\Shell; |
21
|
|
|
|
22
|
|
|
use Cake\Console\Shell; |
23
|
|
|
use Cake\Log\Log; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Clean old Notifications shell. |
27
|
|
|
*/ |
28
|
|
|
class CleanOldNotifsShell extends Shell |
29
|
|
|
{ |
30
|
|
|
public function initialize() |
31
|
|
|
{ |
32
|
|
|
parent::initialize(); |
33
|
|
|
$this->loadModel('Notifications'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function main() |
37
|
|
|
{ |
38
|
|
|
$XTime = time() - 60 * 24 * 3600; |
39
|
|
|
$conditions = array('Notifications.created <' => date('Y-m-d H:i:s', $XTime)); |
40
|
|
|
|
41
|
|
|
if ($this->Notifications->find('all', array('conditions' => $conditions))->count() === 0) { |
42
|
|
|
// Check if there are any notifications to delete |
43
|
|
|
Log::write( |
44
|
|
|
'warning', |
45
|
|
|
'No notifications found for deleting!', |
46
|
|
|
'cron_jobs' |
47
|
|
|
); |
48
|
|
|
} elseif (!$this->Notifications->deleteAll($conditions)) { |
49
|
|
|
// Try deleting the matched records |
50
|
|
|
Log::write( |
51
|
|
|
'info', |
52
|
|
|
'Old notifications deleted successfully!', |
53
|
|
|
'cron_jobs' |
54
|
|
|
); |
55
|
|
|
} else { |
56
|
|
|
// If NOT successful, print out an error message |
57
|
|
|
Log::write( |
58
|
|
|
'error', |
59
|
|
|
'Deleting old notifications failed!', |
60
|
|
|
'cron_jobs' |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|