|
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
|
1 |
|
public function initialize() |
|
31
|
|
|
{ |
|
32
|
1 |
|
parent::initialize(); |
|
33
|
1 |
|
$this->loadModel('Notifications'); |
|
34
|
1 |
|
} |
|
35
|
|
|
|
|
36
|
1 |
|
public function main() |
|
37
|
|
|
{ |
|
38
|
1 |
|
$XTime = time() - 60 * 24 * 3600; |
|
39
|
1 |
|
$conditions = array('Notifications.created <' => date('Y-m-d H:i:s', $XTime)); |
|
40
|
|
|
|
|
41
|
1 |
|
if ($this->Notifications->find('all', array('conditions' => $conditions))->count() === 0) { |
|
42
|
|
|
// Check if there are any notifications to delete |
|
43
|
1 |
|
Log::write( |
|
44
|
1 |
|
'info', |
|
45
|
1 |
|
'No notifications found for deleting!', |
|
46
|
1 |
|
'cron_jobs' |
|
47
|
|
|
); |
|
48
|
1 |
|
} 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
|
1 |
|
Log::write( |
|
58
|
1 |
|
'error', |
|
59
|
1 |
|
'Deleting old notifications failed!', |
|
60
|
1 |
|
'cron_jobs' |
|
61
|
|
|
); |
|
62
|
|
|
} |
|
63
|
1 |
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|