Compare commits
No commits in common. "154bd410a4cc0b416474a1a67b461e0b5d11718d" and "21e577b2caa84cb80573818c7e9493f04e6e4a61" have entirely different histories.
154bd410a4
...
21e577b2ca
|
@ -6,7 +6,6 @@ error_reporting(error_level: E_ALL);
|
|||
|
||||
use DirectoryIterator;
|
||||
use Exception;
|
||||
use JetBrains\PhpStorm\NoReturn;
|
||||
use PDO;
|
||||
use PharData;
|
||||
|
||||
|
@ -19,28 +18,6 @@ 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));
|
||||
|
@ -56,7 +33,7 @@ class UpdateController
|
|||
exit(1);
|
||||
}
|
||||
|
||||
if (PHP_VERSION_ID < 80100) {
|
||||
if (PHP_VERSION_ID < 80000) {
|
||||
echo 'You need at least php version 8.1.0';
|
||||
exit(1);
|
||||
}
|
||||
|
@ -71,7 +48,6 @@ class UpdateController
|
|||
exit(1);
|
||||
}
|
||||
|
||||
if (!$this->dryRun) {
|
||||
include $phpBBRootPath . 'config.php';
|
||||
|
||||
/** @var String $dbhost */
|
||||
|
@ -87,7 +63,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();
|
||||
|
@ -101,30 +77,15 @@ 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, associative: true);
|
||||
$versions = json_decode(json: $json);
|
||||
|
||||
$stableVersions = $versions['stable'];
|
||||
$stableVersions = $versions->stable;
|
||||
$availableUpdate = $stableVersions->{$major . '.' . $minor}->{'current'};
|
||||
|
||||
// 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 'Current Version: ' . $availableUpdate . PHP_EOL;
|
||||
|
||||
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 …'";
|
||||
|
@ -141,7 +102,7 @@ class UpdateController
|
|||
$phpBBtbz = file_get_contents(filename: $filePath);
|
||||
file_put_contents(filename: $phpBBTarget, data: $phpBBtbz);
|
||||
} else {
|
||||
echo $currentFile . ' already exists. Skipping download.' . PHP_EOL;
|
||||
echo $currentFile . ' already exists' . PHP_EOL;
|
||||
}
|
||||
|
||||
// TODO check SHA256?
|
||||
|
@ -151,9 +112,7 @@ 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)) {
|
||||
|
@ -200,15 +159,10 @@ 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);
|
||||
|
||||
|
@ -220,7 +174,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;
|
||||
|
@ -236,7 +190,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();
|
||||
|
@ -251,7 +205,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';
|
||||
|
@ -266,7 +220,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();
|
||||
|
@ -281,7 +235,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;
|
||||
|
@ -391,7 +345,8 @@ 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();
|
||||
|
||||
|
@ -406,7 +361,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 '.';
|
||||
|
@ -424,7 +379,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 '.';
|
||||
|
@ -563,17 +518,4 @@ 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 your current phpBB root directory, then
|
||||
Switch into you current phpBB root directory, then
|
||||
|
||||
`git clone https://git.24unix.net/tracer/phpbb_updates.git`
|
||||
|
||||
|
|
13
update.php
13
update.php
|
@ -6,17 +6,4 @@ 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