|
|
@ -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,504 +19,561 @@ 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 = '';
|
|
|
|
|
|
|
|
|
|
|
|
$phpBBRootPath = PHPBB_ROOT_PATH . '/';
|
|
|
|
function parseOpts(): array
|
|
|
|
$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 < 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
include $phpBBRootPath . 'config.php';
|
|
|
|
if (!$this->dryRun) {
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$json = file_get_contents(filename: 'https://version.phpbb.com/phpbb/versions.json');
|
|
|
|
echo "Checking for the current version …" . PHP_EOL;
|
|
|
|
$versions = json_decode(json: $json);
|
|
|
|
$json = file_get_contents(filename: 'https://version.phpbb.com/phpbb/versions.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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// check for existing update
|
|
|
|
echo "Highest Stable Version: $highestStableVersion" . PHP_EOL;
|
|
|
|
if (!file_exists(filename: 'dist')) {
|
|
|
|
if (!$this->dryRun) {
|
|
|
|
echo "'dist' folder is missing, create a new one …'";
|
|
|
|
echo 'Installed Version: '. $this->installedVersion . PHP_EOL;
|
|
|
|
mkdir(directory: 'dist');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$currentFile = "phpBB-$availableUpdate.tar.bz2";
|
|
|
|
[$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 …'";
|
|
|
|
|
|
|
|
mkdir(directory: 'dist');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$phpBBTarget = "dist/$currentFile";
|
|
|
|
$currentFile = "phpBB-$availableUpdate.tar.bz2";
|
|
|
|
|
|
|
|
|
|
|
|
if (!file_exists(filename: $phpBBTarget)) {
|
|
|
|
$phpBBTarget = "dist/$currentFile";
|
|
|
|
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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO check SHA256?
|
|
|
|
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. Skipping download.' . PHP_EOL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// check for available language files
|
|
|
|
// TODO check SHA256?
|
|
|
|
|
|
|
|
|
|
|
|
$useLangDeDu = false;
|
|
|
|
// check for available language files
|
|
|
|
if (file_exists(filename: $phpBBRootPath . 'language/de')) {
|
|
|
|
|
|
|
|
$useLangDeDu = true;
|
|
|
|
|
|
|
|
$languageFile = "phpBB_lang_de-$availableUpdate.tar.bz2";
|
|
|
|
|
|
|
|
$langDeDuTarget = "dist/$languageFile";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!file_exists(filename: $langDeDuTarget)) {
|
|
|
|
$useLangDeDu = false;
|
|
|
|
echo "Downloading language $languageFile" . PHP_EOL;
|
|
|
|
if (file_exists(filename: $phpBBRootPath . 'language/de')) {
|
|
|
|
$filePath = "https://downloads.phpbb.de/pakete/deutsch/$major.$minor/$availableUpdate/$languageFile";
|
|
|
|
$useLangDeDu = true;
|
|
|
|
if (file_exists(filename: $filePath)) {
|
|
|
|
// https://downloads.phpbb.de/pakete/deutsch/3.3/3.3.10/phpBB_lang_de-3.3.10.tar.bz2
|
|
|
|
$phpBBtbz = file_get_contents(filename: $filePath);
|
|
|
|
$languageFile = "phpBB_lang_de-$availableUpdate.tar.bz2";
|
|
|
|
file_put_contents(filename: $langDeDuTarget, data: $phpBBtbz);
|
|
|
|
echo "language file: $languageFile";
|
|
|
|
} else {
|
|
|
|
$langDeDuTarget = "dist/$languageFile";
|
|
|
|
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: $langDeDuTarget)) {
|
|
|
|
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: $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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!file_exists(filename: $langDeSieTarget)) {
|
|
|
|
$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: $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?')) {
|
|
|
|
if (!file_exists(filename: $langDeSieTarget)) {
|
|
|
|
exit(0);
|
|
|
|
echo "Downloading language $languageFile" . PHP_EOL;
|
|
|
|
}
|
|
|
|
$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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ok, start update
|
|
|
|
if (!$this->confirm(message: 'Do you want to proceed with the update now?')) {
|
|
|
|
$now = date(format: 'd.m.Y H:i');
|
|
|
|
exit(0);
|
|
|
|
$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 ($statement->execute()) {
|
|
|
|
if ($this->dryRun) {
|
|
|
|
echo "Disable Message set …", PHP_EOL;
|
|
|
|
echo 'Dry run, exiting.' . PHP_EOL;
|
|
|
|
} else {
|
|
|
|
exit(0);
|
|
|
|
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'";
|
|
|
|
// ok, start update
|
|
|
|
$statement = $pdo->prepare(query: $sql);
|
|
|
|
$now = date(format: 'd.m.Y H:i');
|
|
|
|
if ($statement->execute()) {
|
|
|
|
$disableMsg = "Software-update at $now, the forum ist down due to maintenance. We'll be back soon.";
|
|
|
|
echo "Board disabled …", PHP_EOL;
|
|
|
|
$sql = "UPDATE {$table_prefix}config SET config_value = :disable_message WHERE config_name = 'board_disable_msg'";
|
|
|
|
} else {
|
|
|
|
$statement = $pdo->prepare(query: $sql);
|
|
|
|
echo 'There was an error talking to the DB.' . PHP_EOL;
|
|
|
|
$statement->bindParam(param: 'disable_message', var: $disableMsg);
|
|
|
|
echo 'Failed SQL-statement: ' . $sql . PHP_EOL;
|
|
|
|
|
|
|
|
exit(1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$extensionsFile = 'extensions.txt';
|
|
|
|
if ($statement->execute()) {
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (file_exists(filename: $extensionsFile)) {
|
|
|
|
$sql = "UPDATE {$table_prefix}config SET config_value = '1' WHERE config_name = 'board_disable'";
|
|
|
|
echo 'Extensions state already stored. Remove extensions.txt if you wish to recreate it.' . PHP_EOL;
|
|
|
|
$statement = $pdo->prepare(query: $sql);
|
|
|
|
} else {
|
|
|
|
if ($statement->execute()) {
|
|
|
|
// check for enabled extensions
|
|
|
|
echo "Board disabled …", PHP_EOL;
|
|
|
|
$sql = "SELECT ext_name FROM ${table_prefix}ext WHERE ext_active = '1'";
|
|
|
|
} else {
|
|
|
|
$statement = $pdo->prepare(query: $sql);
|
|
|
|
echo 'There was an error talking to the DB.' . PHP_EOL;
|
|
|
|
if ($statement->execute()) {
|
|
|
|
echo 'Failed SQL-statement: ' . $sql . PHP_EOL;
|
|
|
|
$result = $statement->fetchAll();
|
|
|
|
exit(1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (count(value: $result) > 0) {
|
|
|
|
$extensionsFile = 'extensions.txt';
|
|
|
|
$extensions = json_encode(value: $result);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// safe enabled extensions
|
|
|
|
if (file_exists(filename: $extensionsFile)) {
|
|
|
|
$oFile = fopen(filename: 'extensions.txt', mode: 'w');
|
|
|
|
echo 'Extensions state already stored. Remove extensions.txt if you wish to recreate it.' . PHP_EOL;
|
|
|
|
fputs(stream: $oFile, data: $extensions);
|
|
|
|
} else {
|
|
|
|
fclose(stream: $oFile);
|
|
|
|
// check for enabled extensions
|
|
|
|
echo 'Stored extensions state';
|
|
|
|
$sql = "SELECT ext_name FROM {$table_prefix}ext WHERE ext_active = '1'";
|
|
|
|
|
|
|
|
$statement = $pdo->prepare(query: $sql);
|
|
|
|
|
|
|
|
if ($statement->execute()) {
|
|
|
|
|
|
|
|
$result = $statement->fetchAll();
|
|
|
|
|
|
|
|
|
|
|
|
// disable all extensions
|
|
|
|
if (count(value: $result) > 0) {
|
|
|
|
$sql = "UPDATE ${table_prefix}ext SET ext_active = '0' WHERE ext_active = '1'";
|
|
|
|
$extensions = json_encode(value: $result);
|
|
|
|
$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';
|
|
|
|
|
|
|
|
|
|
|
|
$stylesFile = 'styles.txt';
|
|
|
|
// disable all extensions
|
|
|
|
if (file_exists(filename: $stylesFile)) {
|
|
|
|
$sql = "UPDATE {$table_prefix}ext SET ext_active = '0' WHERE ext_active = '1'";
|
|
|
|
echo 'Styles state already stored. Remove styles.txt if you wish to recreate it' . PHP_EOL;
|
|
|
|
$statement = $pdo->prepare(query: $sql);
|
|
|
|
} else {
|
|
|
|
if ($statement->execute()) {
|
|
|
|
// check for enabled style
|
|
|
|
echo 'Disabled all extensions';
|
|
|
|
$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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// safe enabled styles
|
|
|
|
$stylesFile = 'styles.txt';
|
|
|
|
$oFile = fopen(filename: 'styles.txt', mode: 'w');
|
|
|
|
if (file_exists(filename: $stylesFile)) {
|
|
|
|
fputs(stream: $oFile, data: $styles);
|
|
|
|
echo 'Styles state already stored. Remove styles.txt if you wish to recreate it' . PHP_EOL;
|
|
|
|
fclose(stream: $oFile);
|
|
|
|
} else {
|
|
|
|
echo 'Stored styles state.' . PHP_EOL;
|
|
|
|
// 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();
|
|
|
|
|
|
|
|
|
|
|
|
// disable all styles except prosilver
|
|
|
|
if (count(value: $result) > 0) {
|
|
|
|
$sql = "UPDATE ${table_prefix}styles SET style_active = '0' WHERE NOT style_name = 'prosilver'";
|
|
|
|
$styles = json_encode(value: $result);
|
|
|
|
$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;
|
|
|
|
|
|
|
|
|
|
|
|
// update phpBB
|
|
|
|
// disable all styles except prosilver
|
|
|
|
$data = new PharData(filename: $phpBBTarget);
|
|
|
|
$sql = "UPDATE {$table_prefix}styles SET style_active = '0' WHERE NOT style_name = 'prosilver'";
|
|
|
|
try {
|
|
|
|
$statement = $pdo->prepare(query: $sql);
|
|
|
|
unset($data['phpBB3/config.php']);
|
|
|
|
if ($statement->execute()) {
|
|
|
|
unset($data['phpBB3/.htaccess']);
|
|
|
|
echo 'Disabled all styles except prosilver.' . PHP_EOL;
|
|
|
|
} catch (Exception $e) {
|
|
|
|
}
|
|
|
|
echo 'error: ', $e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// remove all old files
|
|
|
|
}
|
|
|
|
$excludes = [
|
|
|
|
}
|
|
|
|
'config.php',
|
|
|
|
|
|
|
|
'.htaccess',
|
|
|
|
// update phpBB
|
|
|
|
'.htpasswd',
|
|
|
|
$data = new PharData(filename: $phpBBTarget);
|
|
|
|
'images',
|
|
|
|
try {
|
|
|
|
'files',
|
|
|
|
unset($data['phpBB3/config.php']);
|
|
|
|
'ext',
|
|
|
|
unset($data['phpBB3/.htaccess']);
|
|
|
|
'styles',
|
|
|
|
} catch (Exception $e) {
|
|
|
|
'store',
|
|
|
|
echo 'error: ', $e;
|
|
|
|
'updates',
|
|
|
|
}
|
|
|
|
'mobiquo'];
|
|
|
|
|
|
|
|
// this will fuck up nearly all modified boards, leave the files alone by default.
|
|
|
|
// remove all old files
|
|
|
|
// It will also destroy any API-keys and whatever you might have in your document root.
|
|
|
|
$excludes = [
|
|
|
|
// deleteDirectory($phpbb_root_path, $excludes);
|
|
|
|
'config.php',
|
|
|
|
|
|
|
|
'.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();
|
|
|
|
|
|
|
|
|
|
|
|
$sql = "UPDATE ${table_prefix}config SET config_value = '0' WHERE config_name = 'board_disable'";
|
|
|
|
echo "Board reenabled …", PHP_EOL;
|
|
|
|
$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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|