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
26
index.php
26
index.php
|
@ -79,21 +79,29 @@ if ($options) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update
|
* Update
|
||||||
|
*
|
||||||
|
* Check for update every 24 hours.
|
||||||
*/
|
*/
|
||||||
use Github\Client;
|
use Github\Client;
|
||||||
|
|
||||||
if ($options) {
|
if ($options) {
|
||||||
try {
|
$updateLastChecked = $options->getOption('updateLastChecked');
|
||||||
$client = new Client();
|
|
||||||
$release = $client->api('repo')->releases()->latest('grandeljay', 'wishthis');
|
|
||||||
$tag = $release['tag_name'];
|
|
||||||
$version = str_replace('v', '', $tag);
|
|
||||||
|
|
||||||
if (-1 === version_compare($options->version, $version)) {
|
if (!$updateLastChecked || time() - $updateLastChecked >= 86400) {
|
||||||
$options->updateAvailable = true;
|
try {
|
||||||
|
$client = new Client();
|
||||||
|
$release = $client->api('repo')->releases()->latest('grandeljay', 'wishthis');
|
||||||
|
$tag = $release['tag_name'];
|
||||||
|
$version = str_replace('v', '', $tag);
|
||||||
|
|
||||||
|
if (-1 === version_compare($options->version, $version)) {
|
||||||
|
$options->updateAvailable = true;
|
||||||
|
}
|
||||||
|
} catch (\Github\Exception\RuntimeException $th) {
|
||||||
|
echo wishthis\Page::warning($th->getMessage());
|
||||||
}
|
}
|
||||||
} catch (\Github\Exception\RuntimeException $th) {
|
|
||||||
echo $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
|
||||||
{
|
{
|
||||||
$this->database->query('UPDATE `options`
|
$optionExists = 0 !== $this->database
|
||||||
SET `value` = "' . $value . '"
|
->query('SELECT *
|
||||||
WHERE `key` = "' . $key . '"
|
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 . '")
|
||||||
|
;');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue