-
Notifications
You must be signed in to change notification settings - Fork 0
/
utilityprocess_database_purge_olddata.php
58 lines (43 loc) · 1.82 KB
/
utilityprocess_database_purge_olddata.php
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
55
56
57
58
<?php
/*
* Utility Process Purge Old Data
*/
namespace Fizzik;
require_once 'includes/include.php';
use Fizzik\Database\MySqlDatabase;
use Fizzik\Utility\SleepHandler;
set_time_limit(0);
date_default_timezone_set(HotstatusPipeline::REPLAY_TIMEZONE);
$db = new MysqlDatabase();
$creds = Credentials::getCredentialsForUser(Credentials::USER_REPLAYPROCESS);
HotstatusPipeline::hotstatus_mysql_connect($db, $creds);
$db->setEncoding(HotstatusPipeline::DATABASE_CHARSET);
//Constants and qol
const E = PHP_EOL;
const SLEEP_DURATION = 1;
$sleep = new SleepHandler();
//Helper Functions
function log($str) {
$datetime = new \DateTime("now");
$datestr = $datetime->format(HotstatusPipeline::FORMAT_DATETIME);
echo "[$datestr] $str".E;
}
//Mininum Date Inclusive for replays to process
//$replaymindate = HotstatusPipeline::$SEASONS[HotstatusPipeline::SEASON_UNKNOWN]["end"];
$replaymindate = "2018-03-01 00:00:00";
//Purge old data
//$db->transaction_begin();
$db->prepare("delete_heroes_bans", "DELETE FROM `heroes_bans_recent_granular` WHERE `date_end` < \"$replaymindate\" ORDER BY `date_end` ASC LIMIT 1000");
$db->prepare("delete_heroes_matches", "DELETE FROM `heroes_matches_recent_granular` WHERE `date_end` < \"$replaymindate\" ORDER BY `date_end` ASC LIMIT 1000");
while (TRUE) {
$db->execute("delete_heroes_bans");
$db->execute("delete_heroes_matches");
log("Purged Heroes data older than [$replaymindate].");
//$db->query("DELETE FROM `matches` WHERE `date` < \"$replaymindate\"");
//$db->query("DELETE FROM `players_matches` WHERE `date` < \"$replaymindate\"");
//$db->query("DELETE FROM `players_matches_recent_granular` WHERE `date_end` < \"$replaymindate\"");
//$db->query("DELETE FROM `players_mmr` WHERE `season` = \"2017 Season 2\"");
$sleep->add(SLEEP_DURATION);
$sleep->execute();
}
?>