Add update button placeholder

This commit is contained in:
Jay Trees 2022-01-14 14:13:07 +01:00
parent 0b7b775c4b
commit 3c55219c7e
4 changed files with 39 additions and 12 deletions

View file

@ -23,11 +23,7 @@ class Database
$dsn = 'mysql:host=' . $this->host . ';dbname=' . $this->database . ';port=3306;charset=utf8'; $dsn = 'mysql:host=' . $this->host . ';dbname=' . $this->database . ';port=3306;charset=utf8';
$options = array(); $options = array();
try { $this->pdo = new \PDO($dsn, $this->user, $this->password, $options);
$this->pdo = new \PDO($dsn, $this->user, $this->password, $options);
} catch (\PDOException $PDOE) {
throw new \PDOException($PDOE->getMessage(), (int)$PDOE->getCode());
}
} }
public function query(string $query) public function query(string $query)

View file

@ -12,6 +12,8 @@ namespace wishthis;
class Options class Options
{ {
public bool $updateAvailable = false;
public function __construct(private Database $database) public function __construct(private Database $database)
{ {
} }
@ -23,6 +25,6 @@ class Options
WHERE `key` = "' . $key . '";' WHERE `key` = "' . $key . '";'
)->fetch(); )->fetch();
return $option['value']; return $option['value'] ?? '';
} }
} }

View file

@ -146,6 +146,12 @@ class Page
?> ?>
</div> </div>
</div> </div>
<?php global $options; ?>
<?php if ($options->updateAvailable) { ?>
<a class="item" href="/?page=update">
<i class="upload icon"></i> Update
</a>
<?php } ?>
<div class="right item"> <div class="right item">
<div class="ui input"><input type="text" placeholder="Search..."></div> <div class="ui input"><input type="text" placeholder="Search..."></div>
</div> </div>

View file

@ -6,6 +6,8 @@
* @author Jay Trees <github.jay@grandel.anonaddy.me> * @author Jay Trees <github.jay@grandel.anonaddy.me>
*/ */
$version_new = '0.1.0';
/** /**
* Include * Include
*/ */
@ -27,6 +29,7 @@ if (file_exists($configPath)) {
* Database * Database
*/ */
$database = false; $database = false;
$options = false;
if ( if (
defined('DATABASE_HOST') defined('DATABASE_HOST')
@ -40,12 +43,12 @@ if (
DATABASE_USER, DATABASE_USER,
DATABASE_PASSWORD DATABASE_PASSWORD
); );
}
/** /**
* Options * Options
*/ */
$options = new wishthis\Options($database); $options = new wishthis\Options($database);
}
/** /**
* Session * Session
@ -66,6 +69,17 @@ if (!$options) {
$page = 'install'; $page = 'install';
} }
/**
* Update
*/
if ($options) {
$version_current = $options->getOption('version') ?? '0.0.0';
if (-1 === version_compare($version_current, $version_new)) {
$options->updateAvailable = true;
}
}
/** /**
* Page * Page
*/ */
@ -74,4 +88,13 @@ if (!isset($page)) {
} }
$pagePath = 'includes/pages/' . $page . '.php'; $pagePath = 'includes/pages/' . $page . '.php';
require $pagePath; if (file_exists($pagePath)) {
require $pagePath;
} else {
http_response_code(404);
?>
<h1>Not found</h1>
<p>The requested URL was not found on this server.</p>
<?php
die();
}