Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions downgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function run()
if (('cli' === PHP_SAPI || !isset($_SERVER['REQUEST_URI']))
&& (!isset($_SERVER['argv'][1]) || 'downgrade' !== $_SERVER['argv'][1])
) {
echo 'You are using PHP '.phpversion()." but you need least PHP 8.1.0 to run the Contao Manager.\n";
echo 'You are using PHP '.phpversion()." but you need at least PHP 8.1.0 to run the Contao Manager.\n";
echo 'Run "'.$_SERVER['argv'][0]." downgrade\" to downgrade to a PHP 7.2 compatible version.\n";
exit;
}
Expand All @@ -31,11 +31,27 @@ public static function run()

$stream = @fopen($url, 'rb', false, StreamContextFactory::getContext($url));

$failMsg = 'You are using PHP '.phpversion()." which is not supported by this Contao Manager. Automatic downgrade to version 1.8 was not successful.\n";

if (false === $stream
|| false === file_put_contents($tempFile, $stream)
|| false === rename($tempFile, $phar)
) {
die('You are using PHP '.phpversion()." which is not supported by this Contao Manager. Automatic downgrade to version 1.8 was not successful.\n");
die($failMsg);
}

if (false === rename($tempFile, $phar)) {
// If rename fails, try to rename original script first
if (false === rename($phar, $phar.'.old')) {
die($failMsg);
}

if (false === rename($tempFile, $phar)) {
@rename($phar.'.old', $phar);

die($failMsg);
}

@unlink($phar.'.old');
}

if (function_exists('opcache_reset')) {
Expand Down
16 changes: 15 additions & 1 deletion installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,25 @@ public static function run()

if (false === $stream
|| false === file_put_contents($tempFile, $stream)
|| false === rename($tempFile, $fileName)
) {
self::error();
}

if (false === rename($tempFile, $fileName)) {
// If rename fails, try to rename original script first
if (false === rename($fileName, $fileName.'.old')) {
self::error();
}

if (false === rename($tempFile, $fileName)) {
@rename($fileName.'.old', $fileName);

self::error();
}

@unlink($fileName.'.old');
}

if (function_exists('opcache_reset')) {
opcache_reset();
}
Expand Down