From 3c55219c7e51cf150405d791f2d4a20bbe64bcf6 Mon Sep 17 00:00:00 2001 From: Jay Trees Date: Fri, 14 Jan 2022 14:13:07 +0100 Subject: [PATCH] Add update button placeholder --- includes/classes/database.php | 6 +----- includes/classes/options.php | 4 +++- includes/classes/page.php | 6 ++++++ index.php | 35 +++++++++++++++++++++++++++++------ 4 files changed, 39 insertions(+), 12 deletions(-) diff --git a/includes/classes/database.php b/includes/classes/database.php index 4ee194ce..4089c463 100644 --- a/includes/classes/database.php +++ b/includes/classes/database.php @@ -23,11 +23,7 @@ class Database $dsn = 'mysql:host=' . $this->host . ';dbname=' . $this->database . ';port=3306;charset=utf8'; $options = array(); - try { - $this->pdo = new \PDO($dsn, $this->user, $this->password, $options); - } catch (\PDOException $PDOE) { - throw new \PDOException($PDOE->getMessage(), (int)$PDOE->getCode()); - } + $this->pdo = new \PDO($dsn, $this->user, $this->password, $options); } public function query(string $query) diff --git a/includes/classes/options.php b/includes/classes/options.php index 0a551af6..f5579ade 100644 --- a/includes/classes/options.php +++ b/includes/classes/options.php @@ -12,6 +12,8 @@ namespace wishthis; class Options { + public bool $updateAvailable = false; + public function __construct(private Database $database) { } @@ -23,6 +25,6 @@ class Options WHERE `key` = "' . $key . '";' )->fetch(); - return $option['value']; + return $option['value'] ?? ''; } } diff --git a/includes/classes/page.php b/includes/classes/page.php index c3576b9e..182805c5 100644 --- a/includes/classes/page.php +++ b/includes/classes/page.php @@ -146,6 +146,12 @@ class Page ?> + + updateAvailable) { ?> + + Update + +
diff --git a/index.php b/index.php index ee778ac2..1a2ff928 100644 --- a/index.php +++ b/index.php @@ -6,6 +6,8 @@ * @author Jay Trees */ +$version_new = '0.1.0'; + /** * Include */ @@ -27,6 +29,7 @@ if (file_exists($configPath)) { * Database */ $database = false; +$options = false; if ( defined('DATABASE_HOST') @@ -40,12 +43,12 @@ if ( DATABASE_USER, DATABASE_PASSWORD ); -} -/** - * Options - */ -$options = new wishthis\Options($database); + /** + * Options + */ + $options = new wishthis\Options($database); +} /** * Session @@ -66,6 +69,17 @@ if (!$options) { $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 */ @@ -74,4 +88,13 @@ if (!isset($page)) { } $pagePath = 'includes/pages/' . $page . '.php'; -require $pagePath; +if (file_exists($pagePath)) { + require $pagePath; +} else { + http_response_code(404); + ?> +

Not found

+

The requested URL was not found on this server.

+