blob: 3f82dba9e6469312d079f4a47a70557a17e03b16 (
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
45
46
47
48
49
50
51
52
53
54
|
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugins\CoreAdminHome;
use Piwik\DataAccess\ArchivePurger;
use Piwik\DataAccess\ArchiveTableCreator;
use Piwik\Date;
use Piwik\Db;
class Tasks extends \Piwik\Plugin\Tasks
{
public function schedule()
{
// general data purge on older archive tables, executed daily
$this->daily('purgeOutdatedArchives', null, self::HIGH_PRIORITY);
// general data purge on invalidated archive records, executed daily
$this->daily('purgeInvalidatedArchives', null, self::HIGH_PRIORITY);
// lowest priority since tables should be optimized after they are modified
$this->daily('optimizeArchiveTable', null, self::LOWEST_PRIORITY);
}
public function purgeOutdatedArchives()
{
$archiveTables = ArchiveTableCreator::getTablesArchivesInstalled();
foreach ($archiveTables as $table) {
$date = ArchiveTableCreator::getDateFromTableName($table);
list($year, $month) = explode('_', $date);
// Somehow we may have archive tables created with older dates, prevent exception from being thrown
if($year > 1990) {
ArchivePurger::purgeOutdatedArchives(Date::factory("$year-$month-15"));
}
}
}
public function purgeInvalidatedArchives()
{
ArchivePurger::purgeInvalidatedArchives();
}
public function optimizeArchiveTable()
{
$archiveTables = ArchiveTableCreator::getTablesArchivesInstalled();
Db::optimizeTables($archiveTables);
}
}
|