Compare commits

..

No commits in common. "154bd410a4cc0b416474a1a67b461e0b5d11718d" and "21e577b2caa84cb80573818c7e9493f04e6e4a61" have entirely different histories.

3 changed files with 496 additions and 567 deletions

View File

@ -6,7 +6,6 @@ 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;
@ -19,561 +18,504 @@ const SUPPORTED_RELEASE_MINOR = 2;
*/ */
class UpdateController class UpdateController
{ {
/** function handleUpdate(): void
* @var true {
*/ define(constant_name: "PHPBB_ROOT_PATH", value: dirname(path: __DIR__, levels: 2));
private bool $dryRun = false;
private string $installedVersion = '';
function parseOpts(): array $phpBBRootPath = PHPBB_ROOT_PATH . '/';
{ $phpEx = substr(string: strrchr(haystack: __FILE__, needle: '.'), offset: 1);
$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));
$phpBBRootPath = PHPBB_ROOT_PATH . '/';
$phpEx = substr(string: strrchr(haystack: __FILE__, needle: '.'), offset: 1);
// sanity checks // sanity checks
if (strtoupper(string: substr(string: PHP_OS, offset: 0, length: 3)) === 'WIN') { if (strtoupper(string: substr(string: PHP_OS, offset: 0, length: 3)) === 'WIN') {
echo 'This program must not be used on Windows installations.' . PHP_EOL; echo 'This program must not be used on Windows installations.' . PHP_EOL;
exit(1); exit(1);
} }
if (PHP_VERSION_ID < 80100) { if (PHP_VERSION_ID < 80000) {
echo 'You need at least php version 8.1.0'; echo 'You need at least php version 8.1.0';
exit(1); exit(1);
} }
if (php_sapi_name() !== 'cli') { if (php_sapi_name() !== 'cli') {
echo 'This program must be run from the command line.' . PHP_EOL; echo 'This program must be run from the command line.' . PHP_EOL;
exit(1); exit(1);
} }
if (!extension_loaded(extension: 'bz2')) { if (!extension_loaded(extension: 'bz2')) {
echo 'You need to install/enable the bz2 PHP extension' . PHP_EOL; echo 'You need to install/enable the bz2 PHP extension' . PHP_EOL;
exit(1); exit(1);
} }
if (!$this->dryRun) { include $phpBBRootPath . 'config.php';
include $phpBBRootPath . 'config.php';
/** @var String $dbhost */ /** @var String $dbhost */
/** @var String $dbport */ /** @var String $dbport */
/** @var String $dbname */ /** @var String $dbname */
/** @var String $dbuser */ /** @var String $dbuser */
/** @var String $dbpasswd */ /** @var String $dbpasswd */
$pdo = new PDO( $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, username: $dbuser,
password: $dbpasswd password: $dbpasswd
); );
/** @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();
$installedVersion = $result['config_value']; $installedVersion = $result['config_value'];
print("Installed version: phpBB $installedVersion" . PHP_EOL); print("Installed version: phpBB $installedVersion" . PHP_EOL);
// phpBB has major, minor and maintenance version scheme // phpBB has major, minor and maintenance version scheme
[$major, $minor, $patch] = explode(separator: '.', string: $installedVersion); [$major, $minor, $patch] = explode(separator: '.', string: $installedVersion);
if ((intval(value: $major) != SUPPORTED_RELEASE_MAJOR) || (intval(value: $minor) < SUPPORTED_RELEASE_MINOR)) { if ((intval(value: $major) != SUPPORTED_RELEASE_MAJOR) || (intval(value: $minor) < SUPPORTED_RELEASE_MINOR)) {
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'};
// Get the highest stable version echo 'Current Version: ' . $availableUpdate . PHP_EOL;
$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; // check for existing update
if (!$this->dryRun) { if (!file_exists(filename: 'dist')) {
echo 'Installed Version: '. $this->installedVersion . PHP_EOL; echo "'dist' folder is missing, create a new one …'";
} mkdir(directory: 'dist');
}
[$major, $minor, $patch] = explode(separator: '.', string: $stableVersions[$highestStableVersion]['current']); $currentFile = "phpBB-$availableUpdate.tar.bz2";
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 …'";
mkdir(directory: 'dist');
}
$currentFile = "phpBB-$availableUpdate.tar.bz2"; $phpBBTarget = "dist/$currentFile";
$phpBBTarget = "dist/$currentFile"; if (!file_exists(filename: $phpBBTarget)) {
echo "Downloading $currentFile" . PHP_EOL;
$filePath = "https://download.phpbb.com/pub/release/$major.$minor/$availableUpdate/$currentFile";
$phpBBtbz = file_get_contents(filename: $filePath);
file_put_contents(filename: $phpBBTarget, data: $phpBBtbz);
} else {
echo $currentFile . ' already exists' . PHP_EOL;
}
if (!file_exists(filename: $phpBBTarget)) { // TODO check SHA256?
echo "Downloading $currentFile" . PHP_EOL;
$filePath = "https://download.phpbb.com/pub/release/$major.$minor/$availableUpdate/$currentFile";
$phpBBtbz = file_get_contents(filename: $filePath);
file_put_contents(filename: $phpBBTarget, data: $phpBBtbz);
} else {
echo $currentFile . ' already exists. Skipping download.' . PHP_EOL;
}
// TODO check SHA256? // check for available language files
// check for available language files $useLangDeDu = false;
if (file_exists(filename: $phpBBRootPath . 'language/de')) {
$useLangDeDu = true;
$languageFile = "phpBB_lang_de-$availableUpdate.tar.bz2";
$langDeDuTarget = "dist/$languageFile";
$useLangDeDu = false; if (!file_exists(filename: $langDeDuTarget)) {
if (file_exists(filename: $phpBBRootPath . 'language/de')) { echo "Downloading language $languageFile" . PHP_EOL;
$useLangDeDu = true; $filePath = "https://downloads.phpbb.de/pakete/deutsch/$major.$minor/$availableUpdate/$languageFile";
// https://downloads.phpbb.de/pakete/deutsch/3.3/3.3.10/phpBB_lang_de-3.3.10.tar.bz2 if (file_exists(filename: $filePath)) {
$languageFile = "phpBB_lang_de-$availableUpdate.tar.bz2"; $phpBBtbz = file_get_contents(filename: $filePath);
echo "language file: $languageFile"; file_put_contents(filename: $langDeDuTarget, data: $phpBBtbz);
$langDeDuTarget = "dist/$languageFile"; } else {
echo "Language file $languageFile does not exist." . PHP_EOL;
$useLangDeDu = false;
}
} else {
echo 'Language file ' . $languageFile . ' already exists' . PHP_EOL;
}
} else {
echo 'Language Deutsch "Du" ist not installed, skipping' . PHP_EOL;
}
if (!file_exists(filename: $langDeDuTarget)) { $useLangDeSie = false;
echo "Downloading language $languageFile" . PHP_EOL; if (file_exists(filename: $phpBBRootPath . 'language/de_x_sie')) {
$filePath = "https://downloads.phpbb.de/pakete/deutsch/$major.$minor/$availableUpdate/$languageFile"; $useLangDeSie = true;
if (file_exists(filename: $filePath)) { $languageFile = "phpBB_lang_de_x_sie-$availableUpdate.tar.bz2";
$phpBBtbz = file_get_contents(filename: $filePath); $langDeSieTarget = "dist/$languageFile";
file_put_contents(filename: $langDeDuTarget, data: $phpBBtbz);
} else {
echo "Language file $languageFile does not exist." . PHP_EOL;
$useLangDeDu = false;
}
} else {
echo 'Language file ' . $languageFile . ' already exists' . PHP_EOL;
}
} else {
echo 'Language Deutsch "Du" ist not installed, skipping' . PHP_EOL;
}
$useLangDeSie = false; if (!file_exists(filename: $langDeSieTarget)) {
if (file_exists(filename: $phpBBRootPath . 'language/de_x_sie')) { echo "Downloading language $languageFile" . PHP_EOL;
$useLangDeSie = true; $filePath = "https://downloads.phpbb.de/pakete/deutsch/$major.$minor/$availableUpdate/$languageFile";
$languageFile = "phpBB_lang_de_x_sie-$availableUpdate.tar.bz2"; if (file_exists(filename: $filePath)) {
$langDeSieTarget = "dist/$languageFile"; $phpBBtbz = file_get_contents(filename: $filePath);
file_put_contents(filename: $langDeSieTarget, data: $phpBBtbz);
} else {
echo 'Language file ' . $languageFile . ' does not exist' . PHP_EOL;
$useLangDeSie = false;
}
} else {
echo 'Language file ' . $languageFile . ' already exists' . PHP_EOL;
}
} else {
echo 'Language Deutsch "Sie" ist not installed, skipping' . PHP_EOL;
}
if (!file_exists(filename: $langDeSieTarget)) { if (!$this->confirm(message: 'Do you want to proceed with the update now?')) {
echo "Downloading language $languageFile" . PHP_EOL; exit(0);
$filePath = "https://downloads.phpbb.de/pakete/deutsch/$major.$minor/$availableUpdate/$languageFile"; }
if (file_exists(filename: $filePath)) {
$phpBBtbz = file_get_contents(filename: $filePath);
file_put_contents(filename: $langDeSieTarget, data: $phpBBtbz);
} else {
echo 'Language file ' . $languageFile . ' does not exist' . PHP_EOL;
$useLangDeSie = false;
}
} else {
echo 'Language file ' . $languageFile . ' already exists' . PHP_EOL;
}
} else {
echo 'Language Deutsch "Sie" ist not installed, skipping' . PHP_EOL;
}
if (!$this->confirm(message: 'Do you want to proceed with the update now?')) { // ok, start update
exit(0); $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 = $pdo->prepare(query: $sql);
$statement->bindParam(param: 'disable_message', var: $disableMsg);
if ($this->dryRun) { if ($statement->execute()) {
echo 'Dry run, exiting.' . PHP_EOL; echo "Disable Message set …", PHP_EOL;
exit(0); } else {
} echo 'There was an error talking to the DB.' . PHP_EOL;
echo 'Failed SQL-statement: ' . $sql . PHP_EOL;
exit(1);
}
// ok, start update $sql = "UPDATE ${table_prefix}config SET config_value = '1' WHERE config_name = 'board_disable'";
$now = date(format: 'd.m.Y H:i'); $statement = $pdo->prepare(query: $sql);
$disableMsg = "Software-update at $now, the forum ist down due to maintenance. We'll be back soon."; if ($statement->execute()) {
$sql = "UPDATE {$table_prefix}config SET config_value = :disable_message WHERE config_name = 'board_disable_msg'"; echo "Board disabled …", PHP_EOL;
$statement = $pdo->prepare(query: $sql); } else {
$statement->bindParam(param: 'disable_message', var: $disableMsg); echo 'There was an error talking to the DB.' . PHP_EOL;
echo 'Failed SQL-statement: ' . $sql . PHP_EOL;
exit(1);
}
if ($statement->execute()) { $extensionsFile = 'extensions.txt';
echo "Disable Message set …", PHP_EOL;
} else {
echo 'There was an error talking to the DB.' . PHP_EOL;
echo 'Failed SQL-statement: ' . $sql . PHP_EOL;
exit(1);
}
$sql = "UPDATE {$table_prefix}config SET config_value = '1' WHERE config_name = 'board_disable'"; if (file_exists(filename: $extensionsFile)) {
$statement = $pdo->prepare(query: $sql); echo 'Extensions state already stored. Remove extensions.txt if you wish to recreate it.' . PHP_EOL;
if ($statement->execute()) { } else {
echo "Board disabled …", PHP_EOL; // check for enabled extensions
} else { $sql = "SELECT ext_name FROM ${table_prefix}ext WHERE ext_active = '1'";
echo 'There was an error talking to the DB.' . PHP_EOL; $statement = $pdo->prepare(query: $sql);
echo 'Failed SQL-statement: ' . $sql . PHP_EOL; if ($statement->execute()) {
exit(1); $result = $statement->fetchAll();
}
$extensionsFile = 'extensions.txt'; if (count(value: $result) > 0) {
$extensions = json_encode(value: $result);
if (file_exists(filename: $extensionsFile)) { // safe enabled extensions
echo 'Extensions state already stored. Remove extensions.txt if you wish to recreate it.' . PHP_EOL; $oFile = fopen(filename: 'extensions.txt', mode: 'w');
} else { fputs(stream: $oFile, data: $extensions);
// check for enabled extensions fclose(stream: $oFile);
$sql = "SELECT ext_name FROM {$table_prefix}ext WHERE ext_active = '1'"; echo 'Stored extensions state';
$statement = $pdo->prepare(query: $sql);
if ($statement->execute()) {
$result = $statement->fetchAll();
if (count(value: $result) > 0) { // disable all extensions
$extensions = json_encode(value: $result); $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';
}
}
// safe enabled extensions }
$oFile = fopen(filename: 'extensions.txt', mode: 'w'); }
fputs(stream: $oFile, data: $extensions);
fclose(stream: $oFile);
echo 'Stored extensions state';
// disable all extensions $stylesFile = 'styles.txt';
$sql = "UPDATE {$table_prefix}ext SET ext_active = '0' WHERE ext_active = '1'"; if (file_exists(filename: $stylesFile)) {
$statement = $pdo->prepare(query: $sql); echo 'Styles state already stored. Remove styles.txt if you wish to recreate it' . PHP_EOL;
if ($statement->execute()) { } else {
echo 'Disabled all extensions'; // check for enabled style
} $sql = "SELECT style_name FROM ${table_prefix}styles WHERE style_active = '1'";
} $statement = $pdo->prepare(query: $sql);
if ($statement->execute()) {
$result = $statement->fetchAll();
} if (count(value: $result) > 0) {
} $styles = json_encode(value: $result);
$stylesFile = 'styles.txt'; // safe enabled styles
if (file_exists(filename: $stylesFile)) { $oFile = fopen(filename: 'styles.txt', mode: 'w');
echo 'Styles state already stored. Remove styles.txt if you wish to recreate it' . PHP_EOL; fputs(stream: $oFile, data: $styles);
} else { fclose(stream: $oFile);
// check for enabled style echo 'Stored styles state.' . PHP_EOL;
$sql = "SELECT style_name FROM {$table_prefix}styles WHERE style_active = '1'";
$statement = $pdo->prepare(query: $sql);
if ($statement->execute()) {
$result = $statement->fetchAll();
if (count(value: $result) > 0) { // disable all styles except prosilver
$styles = json_encode(value: $result); $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;
}
}
// safe enabled styles }
$oFile = fopen(filename: 'styles.txt', mode: 'w'); }
fputs(stream: $oFile, data: $styles);
fclose(stream: $oFile);
echo 'Stored styles state.' . PHP_EOL;
// disable all styles except prosilver // update phpBB
$sql = "UPDATE {$table_prefix}styles SET style_active = '0' WHERE NOT style_name = 'prosilver'"; $data = new PharData(filename: $phpBBTarget);
$statement = $pdo->prepare(query: $sql); try {
if ($statement->execute()) { unset($data['phpBB3/config.php']);
echo 'Disabled all styles except prosilver.' . PHP_EOL; unset($data['phpBB3/.htaccess']);
} } catch (Exception $e) {
} echo 'error: ', $e;
}
} // remove all old files
} $excludes = [
'config.php',
// update phpBB '.htaccess',
$data = new PharData(filename: $phpBBTarget); '.htpasswd',
try { 'images',
unset($data['phpBB3/config.php']); 'files',
unset($data['phpBB3/.htaccess']); 'ext',
} catch (Exception $e) { 'styles',
echo 'error: ', $e; 'store',
} 'updates',
'mobiquo'];
// remove all old files // this will fuck up nearly all modified boards, leave the files alone by default.
$excludes = [ // It will also destroy any API-keys and whatever you might have in your document root.
'config.php', // deleteDirectory($phpbb_root_path, $excludes);
'.htaccess',
'.htpasswd',
'images',
'files',
'ext',
'styles',
'store',
'updates',
'mobiquo'];
// this will fuck up nearly all modified boards, leave the files alone by default.
// It will also destroy any API-keys and whatever you might have in your document root.
// deleteDirectory($phpbb_root_path, $excludes);
try { try {
$data->extractTo(directory: $phpBBRootPath); $data->extractTo(directory: $phpBBRootPath);
$fromDir = $phpBBRootPath . 'phpBB3/'; $fromDir = $phpBBRootPath . 'phpBB3/';
$toDir = $phpBBRootPath; $toDir = $phpBBRootPath;
$this->copyDirectory(source: $fromDir, target: $toDir); $this->copyDirectory(source: $fromDir, target: $toDir);
$this->deleteDirectory(dir: $fromDir); $this->deleteDirectory(dir: $fromDir);
} catch (Exception $e) { } catch (Exception $e) {
print("Error while extracting $data: $e"); print("Error while extracting $data: $e");
exit(1); exit(1);
} }
echo 'Moved the update in place.', PHP_EOL; echo 'Moved the update in place.', PHP_EOL;
$fileOwner = fileowner(filename: $phpBBRootPath); $fileOwner = fileowner(filename: $phpBBRootPath);
$fileGroup = filegroup(filename: $phpBBRootPath); $fileGroup = filegroup(filename: $phpBBRootPath);
$fileOwnerName = posix_getpwuid(user_id: $fileOwner)['name']; $fileOwnerName = posix_getpwuid(user_id: $fileOwner)['name'];
$fileGroupName = posix_getgrgid(group_id: $fileGroup)['name']; $fileGroupName = posix_getgrgid(group_id: $fileGroup)['name'];
echo 'Check file owner', PHP_EOL; echo 'Check file owner', PHP_EOL;
print("You might need to perform 'chown -R $fileOwnerName:$fileGroupName $phpBBRootPath'" . PHP_EOL); print("You might need to perform 'chown -R $fileOwnerName:$fileGroupName $phpBBRootPath'" . PHP_EOL);
echo 'prepare config.yml.', PHP_EOL; echo 'prepare config.yml.', PHP_EOL;
$oFile = fopen(filename: $phpBBRootPath . '/update-config.yml', mode: 'w'); $oFile = fopen(filename: $phpBBRootPath . '/update-config.yml', mode: 'w');
fputs(stream: $oFile, data: 'updater:' . PHP_EOL . " type: db_only" . PHP_EOL); fputs(stream: $oFile, data: 'updater:' . PHP_EOL . " type: db_only" . PHP_EOL);
fclose(stream: $oFile); fclose(stream: $oFile);
$command = <<<EOC $command = <<<EOC
cd .. cd ..
php install/phpbbcli.php update update-config.yml php install/phpbbcli.php update update-config.yml
EOC; EOC;
system(command: $command, result_code: $resultCode); system(command: $command, result_code: $resultCode);
if ($resultCode != 0) { if ($resultCode != 0) {
echo 'There was an error updating the database: ' . $resultCode . PHP_EOL; echo 'There was an error updating the database: ' . $resultCode . PHP_EOL;
exit(1); exit(1);
} else { } else {
echo 'The database has been updated' . PHP_EOL; echo 'The database has been updated' . PHP_EOL;
} }
$installDir = $phpBBRootPath . '/install'; $installDir = $phpBBRootPath . '/install';
if (is_dir(filename: $installDir)) { if (is_dir(filename: $installDir)) {
$this->deleteDirectory(dir: $installDir); $this->deleteDirectory(dir: $installDir);
} }
// update langDeDu // update langDeDu
if ($useLangDeDu) { if ($useLangDeDu) {
$data = new PharData(filename: $langDeDuTarget); $data = new PharData(filename: $langDeDuTarget);
try { try {
$data->extractTo(directory: $phpBBRootPath, overwrite: true); $data->extractTo(directory: $phpBBRootPath, overwrite: true);
} catch (Exception $e) { } catch (Exception $e) {
print("Error while extracting $langDeDuTarget: $e"); print("Error while extracting $langDeDuTarget: $e");
exit(1); exit(1);
} }
} }
// update langDeSie // update langDeSie
if ($useLangDeSie) { if ($useLangDeSie) {
$data = new PharData(filename: $langDeSieTarget); $data = new PharData(filename: $langDeSieTarget);
try { try {
$data->extractTo(directory: $phpBBRootPath, overwrite: true); $data->extractTo(directory: $phpBBRootPath, overwrite: true);
} catch (Exception $e) { } catch (Exception $e) {
print("Error while extracting $langDeSieTarget: $e"); print("Error while extracting $langDeSieTarget: $e");
exit(1); exit(1);
} }
} }
$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; $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;
if (file_exists(filename: $extensionsFile)) { if (file_exists(filename: $extensionsFile)) {
$iFile = fopen(filename: $extensionsFile, mode: 'r'); $iFile = fopen(filename: $extensionsFile, mode: 'r');
$extensions = json_decode(json: fgets(stream: $iFile), associative: true); $extensions = json_decode(json: fgets(stream: $iFile), associative: true);
echo 'Enable extensions: '; echo 'Enable extensions: ';
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 '.';
} }
echo 'done.', PHP_EOL; echo 'done.', PHP_EOL;
} else { } else {
echo 'There are no saved extension information available.', PHP_EOL; echo 'There are no saved extension information available.', PHP_EOL;
} }
if (file_exists(filename: $stylesFile)) { if (file_exists(filename: $stylesFile)) {
$iFile = fopen(filename: $stylesFile, mode: 'r'); $iFile = fopen(filename: $stylesFile, mode: 'r');
$styles = json_decode(json: fgets(stream: $iFile), associative: true); $styles = json_decode(json: fgets(stream: $iFile), associative: true);
echo 'Enable styles: '; echo 'Enable styles: ';
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 '.';
} }
echo 'done.', PHP_EOL; echo 'done.', PHP_EOL;
} else { } else {
echo 'There are no saved extension information available.', PHP_EOL; echo 'There are no saved extension information available.', PHP_EOL;
} }
// clear cache // clear cache
$dataGlobalCache = $phpBBRootPath . '/cache/data_global.' . $phpEx; $dataGlobalCache = $phpBBRootPath . '/cache/data_global.' . $phpEx;
if (file_exists(filename: $dataGlobalCache)) { if (file_exists(filename: $dataGlobalCache)) {
unlink(filename: $dataGlobalCache); unlink(filename: $dataGlobalCache);
echo "Cache cleared …"; echo "Cache cleared …";
} }
echo "Your board should now be up and running." . PHP_EOL; echo "Your board should now be up and running." . PHP_EOL;
} }
/** /**
* @param String $message * @param String $message
* @param string[] $options * @param string[] $options
* @param string $default * @param string $default
* *
* @return bool * @return bool
*/ */
function confirm(string $message = 'Are you sure? ', array $options = ['y', 'n'], string $default = 'n'): bool function confirm(string $message = 'Are you sure? ', array $options = ['y', 'n'], string $default = 'n'): bool
{ {
// first $options means true, any other false // first $options means true, any other false
echo $message, ' ('; echo $message, ' (';
$first = true; $first = true;
foreach ($options as $option) { foreach ($options as $option) {
// mark default // mark default
if ($option == $default) { if ($option == $default) {
$option = strtoupper(string: $option); $option = strtoupper(string: $option);
} }
if ($first) { if ($first) {
echo $option; echo $option;
$first = false; $first = false;
} else { } else {
echo '/', $option; echo '/', $option;
} }
} }
echo '): '; echo '): ';
$handle = fopen(filename: "php://stdin", mode: 'r'); $handle = fopen(filename: "php://stdin", mode: 'r');
$line = trim(string: fgetc(stream: $handle)); $line = trim(string: fgetc(stream: $handle));
fclose(stream: $handle); fclose(stream: $handle);
if ($line == '') { if ($line == '') {
// enter // enter
$line = $default; $line = $default;
} }
if ($line == $options[0]) { if ($line == $options[0]) {
$result = true; $result = true;
} else { } else {
$result = false; $result = false;
} }
return $result; return $result;
} }
/** /**
* @param $dir * @param $dir
* @param array $excludes * @param array $excludes
* *
* @return false|void * @return false|void
*/ */
function deleteDirectory($dir, array $excludes = []) function deleteDirectory($dir, array $excludes = [])
{ {
if (!file_exists(filename: $dir)) { if (!file_exists(filename: $dir)) {
return false; return false;
} }
$dir = rtrim(string: $dir, characters: '/') . '/'; $dir = rtrim(string: $dir, characters: '/') . '/';
static $skip = false; static $skip = false;
$entries = glob(pattern: $dir . '{,.}[!.,!..]*', flags: GLOB_MARK | GLOB_BRACE); $entries = glob(pattern: $dir . '{,.}[!.,!..]*', flags: GLOB_MARK | GLOB_BRACE);
foreach ($entries as $entry) { foreach ($entries as $entry) {
if (!in_array(needle: basename(path: $entry), haystack: $excludes)) { if (!in_array(needle: basename(path: $entry), haystack: $excludes)) {
if (is_dir(filename: $entry)) { if (is_dir(filename: $entry)) {
$this->deleteDirectory(dir: $entry); $this->deleteDirectory(dir: $entry);
} else { } else {
unlink(filename: $entry); unlink(filename: $entry);
} }
} else { } else {
$skip = true; $skip = true;
} }
} }
if (!$skip) { if (!$skip) {
rmdir(directory: $dir); rmdir(directory: $dir);
} }
} }
/** /**
* @param $source * @param $source
* @param $target * @param $target
* *
* @return bool|void * @return bool|void
*/ */
function copyDirectory($source, $target) function copyDirectory($source, $target)
{ {
if (!file_exists(filename: $source)) { if (!file_exists(filename: $source)) {
die("missing source: $source"); die("missing source: $source");
} }
if (is_file(filename: $source)) { if (is_file(filename: $source)) {
if (copy(from: $source, to: $target)) { if (copy(from: $source, to: $target)) {
return true; return true;
} else { } else {
return false; return false;
} }
} }
if (is_dir(filename: $source)) { if (is_dir(filename: $source)) {
if (!file_exists(filename: $target)) { if (!file_exists(filename: $target)) {
mkdir(directory: $target); mkdir(directory: $target);
} }
$source = rtrim(string: $source, characters: '/') . '/'; $source = rtrim(string: $source, characters: '/') . '/';
$target = rtrim(string: $target, characters: '/') . '/'; $target = rtrim(string: $target, characters: '/') . '/';
$dir = new DirectoryIterator(directory: $source); $dir = new DirectoryIterator(directory: $source);
foreach ($dir as $entry) { foreach ($dir as $entry) {
if (!$entry->isDot()) { if (!$entry->isDot()) {
$this->copyDirectory(source: "$source$entry", target: "$target$entry"); $this->copyDirectory(source: "$source$entry", target: "$target$entry");
} }
} }
} }
// 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 your current phpBB root directory, then Switch into you 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,17 +6,4 @@ 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();