adding catch block around LOCK TABLES to prevent warnings when user has no rights

This commit is contained in:
Pepijn Over 2014-08-06 16:40:55 +02:00
parent f954e1e47b
commit eeda80e17f
1 changed files with 10 additions and 2 deletions

View File

@ -64,7 +64,13 @@ class UptimeArchiver implements ArchiverInterface {
$latest_date = new \DateTime('-1 week 0:0:0');
// Lock tables to prevent simultaneous archiving (by other sessions or the cron job)
$this->db->exec('LOCK TABLES ' . PSM_DB_PREFIX . 'servers_uptime WRITE, ' . PSM_DB_PREFIX . 'servers_history WRITE');
try {
$this->db->pdo()->exec('LOCK TABLES ' . PSM_DB_PREFIX . 'servers_uptime WRITE, ' . PSM_DB_PREFIX . 'servers_history WRITE');
$locked = true;
} catch (\PDOException $e) {
// user does not have lock rights, ignore
$locked = false;
}
$latest_date_str = $latest_date->format('Y-m-d 00:00:00');
@ -107,7 +113,9 @@ class UptimeArchiver implements ArchiverInterface {
);
}
$this->db->exec('UNLOCK TABLES');
if($locked) {
$this->db->exec('UNLOCK TABLES');
}
return true;
}