added more flibiliy for versions, added dry-run option
This commit is contained in:
parent
ab55fd9abb
commit
7e85faf2f2
|
@ -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 */
|
||||
|
@ -56,14 +80,14 @@ class UpdateController
|
|||
/** @var String $dbuser */
|
||||
/** @var String $dbpasswd */
|
||||
$pdo = new PDO(
|
||||
dsn : "mysql:host=$dbhost;port=$dbport;charset=utf8mb4;dbname=$dbname",
|
||||
dsn: "mysql:host=$dbhost;port=$dbport;charset=utf8mb4;dbname=$dbname",
|
||||
username: $dbuser,
|
||||
password: $dbpasswd
|
||||
);
|
||||
|
||||
|
||||
/** @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: $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?
|
||||
|
@ -112,7 +151,9 @@ class UpdateController
|
|||
$useLangDeDu = false;
|
||||
if (file_exists(filename: $phpBBRootPath . 'language/de')) {
|
||||
$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";
|
||||
echo "language file: $languageFile";
|
||||
$langDeDuTarget = "dist/$languageFile";
|
||||
|
||||
if (!file_exists(filename: $langDeDuTarget)) {
|
||||
|
@ -159,10 +200,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 +220,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 +236,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 +251,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 +266,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 +281,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 +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->execute();
|
||||
|
||||
|
@ -361,7 +406,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 +424,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 +563,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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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`
|
||||
|
||||
|
|
13
update.php
13
update.php
|
@ -6,4 +6,17 @@ 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();
|
||||
|
|
Loading…
Reference in New Issue