wishthis/includes/pages/update.php

131 lines
3.7 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-21 14:35:33 +00:00
/**
* Files
*/
$zip_filename = __DIR__ . '/' . $tag . '.zip';
/** Download */
file_put_contents(
$zip_filename,
file_get_contents('https://github.com/grandeljay/wishthis/archive/refs/tags/' . $tag . '.zip')
);
/** Decompress */
$zip = new ZipArchive();
if ($zip->open($zip_filename)) {
$zip->extractTo(__DIR__);
$zip->close();
$directory_wishthis_github = __DIR__ . '/wishthis-' . $version;
foreach (scandir($directory_wishthis_github) as $filename) {
if (in_array($filename, array('.', '..', 'config'))) {
continue;
}
$filepath = __DIR__ . '/' . $filename;
$filepath_github = $directory_wishthis_github . '/' . $filename;
if (is_dir($filepath) && is_dir($filepath_github)) {
delete_directory($filepath);
}
rename($filepath_github, $filepath);
}
}
/** Delete */
unlink($zip_filename);
/**
* Database
*/
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 13:37:35 +00:00
ADD `last_login` DATETIME NOT NULL DEFAULT NOW() 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-20 12:45:09 +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
2022-01-21 14:35:33 +00:00
$database->query('INSERT INTO `options` (`key`, `value`) VALUES ("version", "' . $version . '");');
2022-01-18 10:40:43 +00:00
}
2022-01-18 10:49:37 +00:00
2022-01-20 12:45:09 +00:00
/** Current version is below 0.3.0 */
if (-1 === version_compare($options->version, '0.3.0')) {
$database->query('ALTER TABLE `products`
ADD `status` VARCHAR(32) NOT NULL AFTER `url`
;');
}
/** Update version */
2022-01-21 14:35:33 +00:00
$options->setOption('version', $version);
2022-01-18 13:59: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>
2022-01-21 14:35:33 +00:00
<p>An update is available. If you are brave, please click the button to start the self updater.</p>
2022-01-18 12:23:37 +00:00
<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>
2022-01-21 14:35:33 +00:00
Update to v<?= $version ?>
2022-01-18 12:23:37 +00:00
</button>
</form>
</div>
2022-01-21 14:35:33 +00:00
<div class="ui segment">
<h2 class="ui header">Changes</h2>
<?= str_replace(PHP_EOL, '<br>', $release['body']) ?>
</div>
2022-01-18 09:51:40 +00:00
</div>
</main>
<?php
$page->footer();
?>