Only check for updates every 24 hours
This commit is contained in:
parent
777b7fe188
commit
de2a551cc4
2 changed files with 34 additions and 13 deletions
10
index.php
10
index.php
|
@ -79,10 +79,15 @@ if ($options) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update
|
* Update
|
||||||
|
*
|
||||||
|
* Check for update every 24 hours.
|
||||||
*/
|
*/
|
||||||
use Github\Client;
|
use Github\Client;
|
||||||
|
|
||||||
if ($options) {
|
if ($options) {
|
||||||
|
$updateLastChecked = $options->getOption('updateLastChecked');
|
||||||
|
|
||||||
|
if (!$updateLastChecked || time() - $updateLastChecked >= 86400) {
|
||||||
try {
|
try {
|
||||||
$client = new Client();
|
$client = new Client();
|
||||||
$release = $client->api('repo')->releases()->latest('grandeljay', 'wishthis');
|
$release = $client->api('repo')->releases()->latest('grandeljay', 'wishthis');
|
||||||
|
@ -93,7 +98,10 @@ if ($options) {
|
||||||
$options->updateAvailable = true;
|
$options->updateAvailable = true;
|
||||||
}
|
}
|
||||||
} catch (\Github\Exception\RuntimeException $th) {
|
} catch (\Github\Exception\RuntimeException $th) {
|
||||||
echo $th->getMessage();
|
echo wishthis\Page::warning($th->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
$options->setOption('updateLastChecked', time());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,9 +43,22 @@ class Options
|
||||||
|
|
||||||
public function setOption(string $key, string $value): void
|
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`
|
$this->database->query('UPDATE `options`
|
||||||
SET `value` = "' . $value . '"
|
SET `value` = "' . $value . '"
|
||||||
WHERE `key` = "' . $key . '"
|
WHERE `key` = "' . $key . '"
|
||||||
;');
|
;');
|
||||||
|
} else {
|
||||||
|
$this->database->query('INSERT INTO `options`
|
||||||
|
(`key`, `value`) VALUES
|
||||||
|
("' . $key . '", "' . $value . '")
|
||||||
|
;');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue