wishthis/includes/pages/update.php

77 lines
2.4 KiB
PHP
Raw Normal View History

2022-01-18 09:51:40 +00:00
<?php
/**
* home.php
*
* @author Jay Trees <github.jay@grandel.anonaddy.me>
*/
use wishthis\{Page, User};
2022-01-18 12:23:37 +00:00
$page = new page(__FILE__, 'Update', 100);
2022-01-18 09:51:40 +00:00
$page->header();
$page->navigation();
2022-01-18 10:40:43 +00:00
/**
* Update
*/
if ('POST' === $_SERVER['REQUEST_METHOD']) {
2022-01-18 10:57:59 +00:00
/** Current version is below 0.2.0 */
2022-01-18 10:40:43 +00:00
if (-1 === version_compare($options->version, '0.2.0')) {
$database->query('ALTER TABLE `users`
2022-01-18 11:52:21 +00:00
ADD `last_login` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER `password`,
ADD `power` BOOLEAN NOT NULL DEFAULT 0 AFTER `last_login`
2022-01-18 10:40:43 +00:00
;');
2022-01-18 10:57:51 +00:00
$database->query('UPDATE `users`
2022-01-18 11:52:21 +00:00
SET `power` = 100
2022-01-18 10:57:51 +00:00
WHERE `id` = ' . $user->id .
';');
2022-01-18 11:09:59 +00:00
$database->query('ALTER TABLE `users` ADD INDEX(`password`);');
2022-01-18 10:40:43 +00:00
$database->query('ALTER TABLE `wishlists`
2022-01-18 11:43:28 +00:00
ADD `hash` VARCHAR(128) NOT NULL AFTER `name`
2022-01-18 10:40:43 +00:00
;');
2022-01-18 11:43:28 +00:00
$database->query('ALTER TABLE `wishlists` ADD INDEX(`hash`);');
2022-01-18 10:49:37 +00:00
$database->query('INSERT INTO `options` (`key`, `value`) VALUES ("version", "' . VERSION . '");');
// Use this for future versions since it didn't existsin 0.1.0
// $options->setOption('version', VERSION);
2022-01-18 10:40:43 +00:00
}
2022-01-18 10:49:37 +00:00
header('Location: /?page=home');
die();
2022-01-18 10:40:43 +00:00
}
2022-01-18 09:51:40 +00:00
?>
<main>
<div class="ui container">
<h1 class="ui header"><?= $page->title ?></h1>
2022-01-18 12:23:37 +00:00
<div class="ui segment">
<h2 class="ui header">New version detected</h2>
<p>Thank you for updating to <strong>v<?= VERSION ?></strong>!</p>
<p>There have been some changes in the database, please run the updater.</p>
<div class="ui icon warning message">
<i class="exclamation triangle icon"></i>
<div class="content">
<div class="header">
Use at own risk
2022-01-18 10:40:43 +00:00
</div>
2022-01-18 12:23:37 +00:00
<p>Be sure to make backups before proceeding.</p>
2022-01-18 10:40:43 +00:00
</div>
</div>
2022-01-18 12:23:37 +00:00
<form class="ui form" method="post">
<button class="ui orange button" type="submit">
<i class="upload icon"></i>
Run the updater
</button>
</form>
</div>
2022-01-18 09:51:40 +00:00
</div>
</main>
<?php
$page->footer();
?>