Compare commits

...

17 Commits

3 changed files with 569 additions and 499 deletions

View File

@ -6,6 +6,7 @@ error_reporting(error_level: E_ALL);
use DirectoryIterator;
use Exception;
use JetBrains\PhpStorm\NoReturn;
use PDO;
use PharData;
@ -18,6 +19,28 @@ const SUPPORTED_RELEASE_MINOR = 2;
*/
class UpdateController
{
/**
* @var true
*/
private bool $dryRun = false;
private string $installedVersion = '';
function parseOpts(): array
{
$shortOpts = 'h::d::';
$longOpts = [
'help',
'dry-run',
];
return getopt(
short_options: $shortOpts,
long_options: $longOpts
);
}
#[NoReturn]
function handleUpdate(): void
{
define(constant_name: "PHPBB_ROOT_PATH", value: dirname(path: __DIR__, levels: 2));
@ -48,6 +71,7 @@ class UpdateController
exit(1);
}
if (!$this->dryRun) {
include $phpBBRootPath . 'config.php';
/** @var String $dbhost */
@ -63,7 +87,7 @@ class UpdateController
/** @var String $table_prefix */
$sql = "SELECT config_value FROM ${table_prefix}config WHERE config_name = 'version'";
$sql = "SELECT config_value FROM {$table_prefix}config WHERE config_name = 'version'";
$statement = $pdo->prepare(query: $sql);
$statement->execute();
$result = $statement->fetch();
@ -77,15 +101,30 @@ class UpdateController
echo 'This script only supports phpBB ' . SUPPORTED_RELEASE_MAJOR . '.' . SUPPORTED_RELEASE_MINOR . ' and above branch.', PHP_EOL;
exit(1);
}
}
echo "Checking for the current version …" . PHP_EOL;
$json = file_get_contents(filename: 'https://version.phpbb.com/phpbb/versions.json');
$versions = json_decode(json: $json);
$versions = json_decode(json: $json, associative: true);
$stableVersions = $versions->stable;
$availableUpdate = $stableVersions->{$major . '.' . $minor}->{'current'};
$stableVersions = $versions['stable'];
echo 'Current Version: ' . $availableUpdate . PHP_EOL;
// Get the highest stable version
$highestStableVersion = null;
foreach ($stableVersions as $version => $details) {
if ($highestStableVersion === null || version_compare(version1: $version, version2: $highestStableVersion, operator: '>')) {
$highestStableVersion = $version;
}
}
echo "Highest Stable Version: $highestStableVersion" . PHP_EOL;
if (!$this->dryRun) {
echo 'Installed Version: '. $this->installedVersion . PHP_EOL;
}
[$major, $minor, $patch] = explode(separator: '.', string: $stableVersions[$highestStableVersion]['current']);
echo "Latest stable release: $major.$minor.$patch" . PHP_EOL;
$availableUpdate = $stableVersions[$highestStableVersion]['current'];
// check for existing update
if (!file_exists(filename: 'dist')) {
echo "'dist' folder is missing, create a new one …'";
@ -102,7 +141,7 @@ class UpdateController
$phpBBtbz = file_get_contents(filename: $filePath);
file_put_contents(filename: $phpBBTarget, data: $phpBBtbz);
} else {
echo $currentFile . ' already exists' . PHP_EOL;
echo $currentFile . ' already exists. Skipping download.' . PHP_EOL;
}
// TODO check SHA256?
@ -116,10 +155,10 @@ class UpdateController
$langDeDuTarget = "dist/$languageFile";
if (!file_exists(filename: $langDeDuTarget)) {
echo "Downloading language $languageFile" . PHP_EOL;
echo " Downloading $languageFile" . PHP_EOL;
$filePath = "https://downloads.phpbb.de/pakete/deutsch/$major.$minor/$availableUpdate/$languageFile";
if (file_exists(filename: $filePath)) {
$phpBBtbz = file_get_contents(filename: $filePath);
if ($phpBBtbz = file_get_contents(filename: $filePath)) {
file_put_contents(filename: $langDeDuTarget, data: $phpBBtbz);
} else {
echo " Language file $languageFile does not exist." . PHP_EOL;
@ -141,8 +180,8 @@ class UpdateController
if (!file_exists(filename: $langDeSieTarget)) {
echo " Downloading language $languageFile" . PHP_EOL;
$filePath = "https://downloads.phpbb.de/pakete/deutsch/$major.$minor/$availableUpdate/$languageFile";
if (file_exists(filename: $filePath)) {
$phpBBtbz = file_get_contents(filename: $filePath);
if ($phpBBtbz = file_get_contents(filename: $filePath)) {
file_put_contents(filename: $langDeSieTarget, data: $phpBBtbz);
} else {
echo ' Language file ' . $languageFile . ' does not exist' . PHP_EOL;
@ -159,10 +198,15 @@ class UpdateController
exit(0);
}
if ($this->dryRun) {
echo 'Dry run, exiting.' . PHP_EOL;
exit(0);
}
// ok, start update
$now = date(format: 'd.m.Y H:i');
$disableMsg = "Software-update at $now, the forum ist down due to maintenance. We'll be back soon.";
$sql = "UPDATE ${table_prefix}config SET config_value = :disable_message WHERE config_name = 'board_disable_msg'";
$sql = "UPDATE {$table_prefix}config SET config_value = :disable_message WHERE config_name = 'board_disable_msg'";
$statement = $pdo->prepare(query: $sql);
$statement->bindParam(param: 'disable_message', var: $disableMsg);
@ -174,7 +218,7 @@ class UpdateController
exit(1);
}
$sql = "UPDATE ${table_prefix}config SET config_value = '1' WHERE config_name = 'board_disable'";
$sql = "UPDATE {$table_prefix}config SET config_value = '1' WHERE config_name = 'board_disable'";
$statement = $pdo->prepare(query: $sql);
if ($statement->execute()) {
echo "Board disabled …", PHP_EOL;
@ -190,7 +234,7 @@ class UpdateController
echo 'Extensions state already stored. Remove extensions.txt if you wish to recreate it.' . PHP_EOL;
} else {
// check for enabled extensions
$sql = "SELECT ext_name FROM ${table_prefix}ext WHERE ext_active = '1'";
$sql = "SELECT ext_name FROM {$table_prefix}ext WHERE ext_active = '1'";
$statement = $pdo->prepare(query: $sql);
if ($statement->execute()) {
$result = $statement->fetchAll();
@ -205,7 +249,7 @@ class UpdateController
echo 'Stored extensions state';
// disable all extensions
$sql = "UPDATE ${table_prefix}ext SET ext_active = '0' WHERE ext_active = '1'";
$sql = "UPDATE {$table_prefix}ext SET ext_active = '0' WHERE ext_active = '1'";
$statement = $pdo->prepare(query: $sql);
if ($statement->execute()) {
echo 'Disabled all extensions';
@ -220,7 +264,7 @@ class UpdateController
echo 'Styles state already stored. Remove styles.txt if you wish to recreate it' . PHP_EOL;
} else {
// check for enabled style
$sql = "SELECT style_name FROM ${table_prefix}styles WHERE style_active = '1'";
$sql = "SELECT style_name FROM {$table_prefix}styles WHERE style_active = '1'";
$statement = $pdo->prepare(query: $sql);
if ($statement->execute()) {
$result = $statement->fetchAll();
@ -235,7 +279,7 @@ class UpdateController
echo 'Stored styles state.' . PHP_EOL;
// disable all styles except prosilver
$sql = "UPDATE ${table_prefix}styles SET style_active = '0' WHERE NOT style_name = 'prosilver'";
$sql = "UPDATE {$table_prefix}styles SET style_active = '0' WHERE NOT style_name = 'prosilver'";
$statement = $pdo->prepare(query: $sql);
if ($statement->execute()) {
echo 'Disabled all styles except prosilver.' . PHP_EOL;
@ -345,8 +389,7 @@ class UpdateController
}
$sql = "UPDATE ${table_prefix}config SET config_value = '0' WHERE config_name = 'board_disable'";
$sql = "UPDATE {$table_prefix}config SET config_value = '0' WHERE config_name = 'board_disable'";
$statement = $pdo->prepare(query: $sql);
$statement->execute();
@ -361,7 +404,7 @@ class UpdateController
foreach ($extensions as $extension) {
$ext = $extension['ext_name'];
$sql = "UPDATE ${table_prefix}ext SET ext_active = '1' WHERE ext_name = '$ext'";
$sql = "UPDATE {$table_prefix}ext SET ext_active = '1' WHERE ext_name = '$ext'";
$statement = $pdo->prepare(query: $sql);
$statement->execute();
echo '.';
@ -379,7 +422,7 @@ class UpdateController
foreach ($styles as $style) {
$style = $style['style_name'];
$sql = "UPDATE ${table_prefix}styles SET style_active = '1' WHERE style_name = '$style'";
$sql = "UPDATE {$table_prefix}styles SET style_active = '1' WHERE style_name = '$style'";
$statement = $pdo->prepare(query: $sql);
$statement->execute();
echo '.';
@ -518,4 +561,17 @@ class UpdateController
// ignore links, not part of phpBB arch
}
public function printHelp(): void
{
echo "Usage: php update.php [options]", PHP_EOL;
echo "Options:", PHP_EOL;
echo "-h --help Print this help", PHP_EOL;
echo "-d --dry-run Just check for downloadable files, don't connect to database.", PHP_EOL;
}
public function setDryRun(): void
{
$this->dryRun = true;
}
}

View File

@ -5,7 +5,7 @@ Shell Script to update phpBB to current version.
Usage:
Switch into you current phpBB root directory, then
Switch into your current phpBB root directory, then
`git clone https://git.24unix.net/tracer/phpbb_updates.git`
@ -21,7 +21,7 @@ Then: Install composer (https://getcomposer.org/download/) and run
`composer install`
followed by:
`php update.php`
`php update.php` or `/update.php`
If you are using KeyHelp, replace
@ -31,3 +31,5 @@ and

View File

@ -1,9 +1,21 @@
#!/usr/bin/keyhelp-php81 -d apc.enable_cli=1
#!/usr/bin/env php
<?php
use App\UpdateController;
require __DIR__ . '/vendor/autoload.php';
$update = new UpdateController();
$options = $update->parseOpts();
// Help option
if (array_key_exists(key: 'h', array: $options) || array_key_exists(key: 'help', array: $options)) {
$update->printHelp();
exit(0);
}
if (array_key_exists(key: 'd', array: $options) || array_key_exists(key: 'dry-run', array: $options)) {
$update->setDryRun();
}
$update->handleUpdate();