Only check for updates every 24 hours

This commit is contained in:
Jay Trees 2022-02-22 14:40:25 +01:00
parent 777b7fe188
commit de2a551cc4
2 changed files with 34 additions and 13 deletions

View file

@ -79,10 +79,15 @@ if ($options) {
/**
* Update
*
* Check for update every 24 hours.
*/
use Github\Client;
if ($options) {
$updateLastChecked = $options->getOption('updateLastChecked');
if (!$updateLastChecked || time() - $updateLastChecked >= 86400) {
try {
$client = new Client();
$release = $client->api('repo')->releases()->latest('grandeljay', 'wishthis');
@ -93,7 +98,10 @@ if ($options) {
$options->updateAvailable = true;
}
} catch (\Github\Exception\RuntimeException $th) {
echo $th->getMessage();
echo wishthis\Page::warning($th->getMessage());
}
$options->setOption('updateLastChecked', time());
}
}

View file

@ -43,9 +43,22 @@ class Options
public function setOption(string $key, string $value): void
{
$optionExists = 0 !== $this->database
->query('SELECT *
FROM `options`
WHERE `key` = "' . $key . '";')
->rowCount();
if ($optionExists) {
$this->database->query('UPDATE `options`
SET `value` = "' . $value . '"
WHERE `key` = "' . $key . '"
;');
} else {
$this->database->query('INSERT INTO `options`
(`key`, `value`) VALUES
("' . $key . '", "' . $value . '")
;');
}
}
}