Compare commits

..

19 Commits

Author SHA1 Message Date
32532147e8 Minor cleanup 2023-05-29 19:07:23 +02:00
2fd033a8c5 removed debug stuff 2023-05-29 19:01:16 +02:00
a1b030e463 Fixes for language files7. 2023-05-29 16:18:23 +02:00
21fb878ffb Fixes for language files6. 2023-05-29 16:17:12 +02:00
2114bcc8b5 Fixes for language files5. 2023-05-29 16:14:05 +02:00
7d88fc5066 Fixes for language files4. 2023-05-29 16:12:03 +02:00
08a53a737f Fixes for language files3. 2023-05-29 16:07:40 +02:00
46e90bd798 Fixes for language files2. 2023-05-29 15:53:23 +02:00
c8b88021ed Fixes for language files1. 2023-05-29 15:50:59 +02:00
dabe69967d Fixes for language files. 2023-05-29 15:49:01 +02:00
154bd410a4 added more flibiliy for versions, added dry-run option 2023-05-29 15:26:11 +02:00
7e85faf2f2 added more flibiliy for versions, added dry-run option 2023-05-29 15:07:19 +02:00
21e577b2ca Added the changes regarding shebang and php version to the README.md 2022-08-30 14:20:52 +02:00
04ae283e13 Changed shebang to be more generic, a KeyHelp environment needs an explicit call with keyhelp-php81 2022-08-30 14:18:58 +02:00
9f31cf0304 Changed shebang to be more generic, a KeyHelp environment needs an explicit call with keyhelp-php81 2022-08-30 14:18:36 +02:00
e3a9fb1454 Lowered required version to php 8.0 2022-08-30 14:16:33 +02:00
b99438c925 Lowered required version to php 8.0 2022-08-30 14:16:25 +02:00
ab55fd9abb Fixed a bug when the language file is not yet available. 2022-07-02 12:56:19 +02:00
ff93b288c2 added composer part to README.md 2022-06-15 13:38:01 +02:00
3 changed files with 598 additions and 493 deletions

@ -6,6 +6,7 @@ error_reporting(error_level: E_ALL);
use DirectoryIterator;
use Exception;
use JetBrains\PhpStorm\NoReturn;
use PDO;
use PharData;
@ -18,10 +19,29 @@ const SUPPORTED_RELEASE_MINOR = 2;
*/
class UpdateController
{
private $pdo;
/**
* @var true
*/
private bool $dryRun = false;
private string $installedVersion = '';
function parseOpts(): array
{
$shortOpts = 'h::d::';
function handleUpdate()
$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));
@ -51,6 +71,7 @@ class UpdateController
exit(1);
}
if (!$this->dryRun) {
include $phpBBRootPath . 'config.php';
/** @var String $dbhost */
@ -58,16 +79,16 @@ class UpdateController
/** @var String $dbname */
/** @var String $dbuser */
/** @var String $dbpasswd */
$this->pdo = new PDO(
dsn : "mysql:host=$dbhost;port=$dbport;charset=utf8mb4;dbname=$dbname",
$pdo = new PDO(
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'";
$statement = $this->pdo->prepare(query: $sql);
$sql = "SELECT config_value FROM {$table_prefix}config WHERE config_name = 'version'";
$statement = $pdo->prepare(query: $sql);
$statement->execute();
$result = $statement->fetch();
@ -80,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 …'";
@ -105,48 +141,56 @@ 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?
// check for available language files
$useLangDeDu = false;
if (file_exists(filename: $phpBBRootPath . 'language/de')) {
$useLangDeDu = true;
// https://downloads.phpbb.de/pakete/deutsch/3.3/3.3.7/phpBB_lang_de-3.3.7.tar.bz2
$languageFile = "phpBB_lang_de-$availableUpdate.tar.bz2";
$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";
$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 . ' already exists' . PHP_EOL;
echo " Language file $languageFile does not exist." . PHP_EOL;
$useLangDeDu = false;
}
} else {
echo ' Language file ' . $languageFile . ' already exists' . PHP_EOL;
}
} else {
$useLangDeDu = false;
echo 'Language Deutsch "Du" ist not installed, skipping' . PHP_EOL;
}
$useLangDeSie = false;
if (file_exists(filename: $phpBBRootPath . 'language/de_x_sie')) {
$useLangDeSie = true;
//https://downloads.phpbb.de/pakete/deutsch/3.3/3.3.7/phpBB_lang_de_x_sie-3.3.7.tar.bz2
$languageFile = "phpBB_lang_de_x_sie-$availableUpdate.tar.bz2";
$langDeSieTarget = "dist/$languageFile";
if (!file_exists(filename: $langDeSieTarget)) {
echo "Downloading language $languageFile" . PHP_EOL;
echo " Downloading language $languageFile" . PHP_EOL;
$filePath = "https://downloads.phpbb.de/pakete/deutsch/$major.$minor/$availableUpdate/$languageFile";
$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 . ' already exists' . PHP_EOL;
echo ' Language file ' . $languageFile . ' does not exist' . PHP_EOL;
$useLangDeSie = false;
}
} else {
echo ' Language file ' . $languageFile . ' already exists' . PHP_EOL;
}
} else {
$useLangDeSie = false;
echo 'Language Deutsch "Sie" ist not installed, skipping' . PHP_EOL;
}
@ -154,14 +198,19 @@ 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'";
$statement = $this->pdo->prepare(query: $sql);
$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);
if ($result = $statement->execute()) {
if ($statement->execute()) {
echo "Disable Message set …", PHP_EOL;
} else {
echo 'There was an error talking to the DB.' . PHP_EOL;
@ -169,9 +218,9 @@ class UpdateController
exit(1);
}
$sql = "UPDATE ${table_prefix}config SET config_value = '1' WHERE config_name = 'board_disable'";
$statement = $this->pdo->prepare(query: $sql);
if ($result = $statement->execute()) {
$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;
} else {
echo 'There was an error talking to the DB.' . PHP_EOL;
@ -185,8 +234,8 @@ 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'";
$statement = $this->pdo->prepare(query: $sql);
$sql = "SELECT ext_name FROM {$table_prefix}ext WHERE ext_active = '1'";
$statement = $pdo->prepare(query: $sql);
if ($statement->execute()) {
$result = $statement->fetchAll();
@ -200,8 +249,8 @@ class UpdateController
echo 'Stored extensions state';
// disable all extensions
$sql = "UPDATE ${table_prefix}ext SET ext_active = '0' WHERE ext_active = '1'";
$statement = $this->pdo->prepare(query: $sql);
$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';
}
@ -215,8 +264,8 @@ 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'";
$statement = $this->pdo->prepare(query: $sql);
$sql = "SELECT style_name FROM {$table_prefix}styles WHERE style_active = '1'";
$statement = $pdo->prepare(query: $sql);
if ($statement->execute()) {
$result = $statement->fetchAll();
@ -230,8 +279,8 @@ 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'";
$statement = $this->pdo->prepare(query: $sql);
$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;
}
@ -296,7 +345,6 @@ class UpdateController
$command = <<<EOC
cd ..
pwd
php install/phpbbcli.php update update-config.yml
EOC;
@ -327,6 +375,7 @@ class UpdateController
}
}
// update langDeSie
if ($useLangDeSie) {
$data = new PharData(filename: $langDeSieTarget);
@ -340,9 +389,8 @@ class UpdateController
}
$sql = "UPDATE ${table_prefix}config SET config_value = '0' WHERE config_name = 'board_disable'";
$statement = $this->pdo->prepare(query: $sql);
$sql = "UPDATE {$table_prefix}config SET config_value = '0' WHERE config_name = 'board_disable'";
$statement = $pdo->prepare(query: $sql);
$statement->execute();
echo "Board reenabled …", PHP_EOL;
@ -356,8 +404,8 @@ class UpdateController
foreach ($extensions as $extension) {
$ext = $extension['ext_name'];
$sql = "UPDATE ${table_prefix}ext SET ext_active = '1' WHERE ext_name = '$ext'";
$statement = $this->pdo->prepare(query: $sql);
$sql = "UPDATE {$table_prefix}ext SET ext_active = '1' WHERE ext_name = '$ext'";
$statement = $pdo->prepare(query: $sql);
$statement->execute();
echo '.';
}
@ -374,8 +422,8 @@ class UpdateController
foreach ($styles as $style) {
$style = $style['style_name'];
$sql = "UPDATE ${table_prefix}styles SET style_active = '1' WHERE style_name = '$style'";
$statement = $this->pdo->prepare(query: $sql);
$sql = "UPDATE {$table_prefix}styles SET style_active = '1' WHERE style_name = '$style'";
$statement = $pdo->prepare(query: $sql);
$statement->execute();
echo '.';
}
@ -470,7 +518,7 @@ class UpdateController
$skip = true;
}
}
if ($skip == false) {
if (!$skip) {
rmdir(directory: $dir);
}
}
@ -513,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;
}
}

@ -1,3 +1,35 @@
# phpbb_updates
Shell Script to update phpBB to current version.
Usage:
Switch into your current phpBB root directory, then
`git clone https://git.24unix.net/tracer/phpbb_updates.git`
Or download either:
https://git.24unix.net/tracer/phpbb_updates/archive/v0.0.1.zip
or:
https://git.24unix.net/tracer/phpbb_updates/archive/v0.0.1.tar.gz
and unpack them into the same directory and change into phpbb_updates.
Then: Install composer (https://getcomposer.org/download/) and run
`composer install`
followed by:
`php update.php` or `/update.php`
If you are using KeyHelp, replace
`composer install` with `keyhelp-php81 composer install`
and
`php update.php` with `keyhelp-php81 update.php`

@ -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();