blob: 51c580487bf40b165f0690ba4c5ecec13cdc3e69 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
<?php
class ConvertCronjobLogs extends Migration
{
public function description()
{
return 'Converts serialized exceptions in cronjobs logs to their '
. 'textual representation';
}
public function up()
{
// Limits the operations to chunks this size
$LIMIT = 10000;
// Remove logs of successful executions older than 2 weeks
// and logs of erroneous executions older than 6 months
$query = "DELETE FROM `cronjobs_logs`
WHERE (`exception` IS NULL
AND `executed` < UNIX_TIMESTAMP(NOW() - INTERVAL 2 WEEK))
OR (`exception` IS NOT NULL
AND `executed` < UNIX_TIMESTAMP(NOW() - INTERVAL 6 MONTH))";
DBManager::get()->exec($query);
// Quickly convert serialized NULL entries for exception column
$query = "UPDATE `cronjobs_logs`
SET `exception` = NULL
WHERE `exception` = 'N;'";
DBManager::get()->exec($query);
// Convert all remaining logs
do {
$converted = CronjobLog::findEachBySQL(function ($entry) {
$entry->exception = unserialize($entry->exception) ?: null;
$entry->store();
unset($entry);
}, "exception RLIKE '^(N;|O:)' LIMIT {$LIMIT}");
} while ($converted > 0);
}
public function down()
{
// Not neccessary
}
}
|