Compare commits

...

2 Commits

3 changed files with 567 additions and 496 deletions

View File

@ -6,6 +6,7 @@ error_reporting(error_level: E_ALL);
use DirectoryIterator; use DirectoryIterator;
use Exception; use Exception;
use JetBrains\PhpStorm\NoReturn;
use PDO; use PDO;
use PharData; use PharData;
@ -18,6 +19,28 @@ const SUPPORTED_RELEASE_MINOR = 2;
*/ */
class UpdateController 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 function handleUpdate(): void
{ {
define(constant_name: "PHPBB_ROOT_PATH", value: dirname(path: __DIR__, levels: 2)); define(constant_name: "PHPBB_ROOT_PATH", value: dirname(path: __DIR__, levels: 2));
@ -33,7 +56,7 @@ class UpdateController
exit(1); exit(1);
} }
if (PHP_VERSION_ID < 80000) { if (PHP_VERSION_ID < 80100) {
echo 'You need at least php version 8.1.0'; echo 'You need at least php version 8.1.0';
exit(1); exit(1);
} }
@ -48,6 +71,7 @@ class UpdateController
exit(1); exit(1);
} }
if (!$this->dryRun) {
include $phpBBRootPath . 'config.php'; include $phpBBRootPath . 'config.php';
/** @var String $dbhost */ /** @var String $dbhost */
@ -63,7 +87,7 @@ class UpdateController
/** @var String $table_prefix */ /** @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 = $pdo->prepare(query: $sql);
$statement->execute(); $statement->execute();
$result = $statement->fetch(); $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; echo 'This script only supports phpBB ' . SUPPORTED_RELEASE_MAJOR . '.' . SUPPORTED_RELEASE_MINOR . ' and above branch.', PHP_EOL;
exit(1); exit(1);
} }
}
echo "Checking for the current version …" . PHP_EOL;
$json = file_get_contents(filename: 'https://version.phpbb.com/phpbb/versions.json'); $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; $stableVersions = $versions['stable'];
$availableUpdate = $stableVersions->{$major . '.' . $minor}->{'current'};
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 // check for existing update
if (!file_exists(filename: 'dist')) { if (!file_exists(filename: 'dist')) {
echo "'dist' folder is missing, create a new one …'"; echo "'dist' folder is missing, create a new one …'";
@ -102,7 +141,7 @@ class UpdateController
$phpBBtbz = file_get_contents(filename: $filePath); $phpBBtbz = file_get_contents(filename: $filePath);
file_put_contents(filename: $phpBBTarget, data: $phpBBtbz); file_put_contents(filename: $phpBBTarget, data: $phpBBtbz);
} else { } else {
echo $currentFile . ' already exists' . PHP_EOL; echo $currentFile . ' already exists. Skipping download.' . PHP_EOL;
} }
// TODO check SHA256? // TODO check SHA256?
@ -112,7 +151,9 @@ class UpdateController
$useLangDeDu = false; $useLangDeDu = false;
if (file_exists(filename: $phpBBRootPath . 'language/de')) { if (file_exists(filename: $phpBBRootPath . 'language/de')) {
$useLangDeDu = true; $useLangDeDu = true;
// https://downloads.phpbb.de/pakete/deutsch/3.3/3.3.10/phpBB_lang_de-3.3.10.tar.bz2
$languageFile = "phpBB_lang_de-$availableUpdate.tar.bz2"; $languageFile = "phpBB_lang_de-$availableUpdate.tar.bz2";
echo "language file: $languageFile";
$langDeDuTarget = "dist/$languageFile"; $langDeDuTarget = "dist/$languageFile";
if (!file_exists(filename: $langDeDuTarget)) { if (!file_exists(filename: $langDeDuTarget)) {
@ -159,10 +200,15 @@ class UpdateController
exit(0); exit(0);
} }
if ($this->dryRun) {
echo 'Dry run, exiting.' . PHP_EOL;
exit(0);
}
// ok, start update // ok, start update
$now = date(format: 'd.m.Y H:i'); $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."; $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 = $pdo->prepare(query: $sql);
$statement->bindParam(param: 'disable_message', var: $disableMsg); $statement->bindParam(param: 'disable_message', var: $disableMsg);
@ -174,7 +220,7 @@ class UpdateController
exit(1); 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); $statement = $pdo->prepare(query: $sql);
if ($statement->execute()) { if ($statement->execute()) {
echo "Board disabled …", PHP_EOL; echo "Board disabled …", PHP_EOL;
@ -190,7 +236,7 @@ class UpdateController
echo 'Extensions state already stored. Remove extensions.txt if you wish to recreate it.' . PHP_EOL; echo 'Extensions state already stored. Remove extensions.txt if you wish to recreate it.' . PHP_EOL;
} else { } else {
// check for enabled extensions // 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); $statement = $pdo->prepare(query: $sql);
if ($statement->execute()) { if ($statement->execute()) {
$result = $statement->fetchAll(); $result = $statement->fetchAll();
@ -205,7 +251,7 @@ class UpdateController
echo 'Stored extensions state'; echo 'Stored extensions state';
// disable all extensions // 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); $statement = $pdo->prepare(query: $sql);
if ($statement->execute()) { if ($statement->execute()) {
echo 'Disabled all extensions'; echo 'Disabled all extensions';
@ -220,7 +266,7 @@ class UpdateController
echo 'Styles state already stored. Remove styles.txt if you wish to recreate it' . PHP_EOL; echo 'Styles state already stored. Remove styles.txt if you wish to recreate it' . PHP_EOL;
} else { } else {
// check for enabled style // 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); $statement = $pdo->prepare(query: $sql);
if ($statement->execute()) { if ($statement->execute()) {
$result = $statement->fetchAll(); $result = $statement->fetchAll();
@ -235,7 +281,7 @@ class UpdateController
echo 'Stored styles state.' . PHP_EOL; echo 'Stored styles state.' . PHP_EOL;
// disable all styles except prosilver // 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); $statement = $pdo->prepare(query: $sql);
if ($statement->execute()) { if ($statement->execute()) {
echo 'Disabled all styles except prosilver.' . PHP_EOL; echo 'Disabled all styles except prosilver.' . PHP_EOL;
@ -345,8 +391,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 = $pdo->prepare(query: $sql);
$statement->execute(); $statement->execute();
@ -361,7 +406,7 @@ class UpdateController
foreach ($extensions as $extension) { foreach ($extensions as $extension) {
$ext = $extension['ext_name']; $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 = $pdo->prepare(query: $sql);
$statement->execute(); $statement->execute();
echo '.'; echo '.';
@ -379,7 +424,7 @@ class UpdateController
foreach ($styles as $style) { foreach ($styles as $style) {
$style = $style['style_name']; $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 = $pdo->prepare(query: $sql);
$statement->execute(); $statement->execute();
echo '.'; echo '.';
@ -518,4 +563,17 @@ class UpdateController
// ignore links, not part of phpBB arch // 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: 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` `git clone https://git.24unix.net/tracer/phpbb_updates.git`

View File

@ -6,4 +6,17 @@ use App\UpdateController;
require __DIR__ . '/vendor/autoload.php'; require __DIR__ . '/vendor/autoload.php';
$update = new UpdateController(); $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(); $update->handleUpdate();