Contao 2 oder 3 mit PHP 7
(Kommentare: 0)
Warum auch immer, wenn man schnell ein Contao 2 oder 3 < 3.5.5 für PHP7 lauffähig machen muss, hier ein paar Erfahrungen, die ich gemacht habe... Z.B. weil der Provider auf PHP 7 umschaltet und keiner hat's mitbekommen... ;-)
Und die Diskussionen darüber und über welches Update wie und wann dauern an, dann ggf. ein schneller Hack...
Kann man in ca. 2-3 Stunden mit ein paar dreckigen Hacks im Core und einem Hilfsskript machen.
BACKUP VORHER NICHT VERGESSEN!
Prinzip: Code vom Live-System holen, Backup machen, u.g. Dinge tun, Code wieder hoch schieben...
----------------------------------------------------
Contao 2 für PHP 7
----------------------------------------------------
1. MySQLi
localconfig.php: MySQLi statt MySQL
2. String to StringUtil
Copy system/libraries/String.php to system/libraries/StringUtil.php
Edit StringUtil.php: String to StringUtil (class name und new String)
Edit system/libraries/System.php: import String umbiegen zu import StringUtil
(also bei $this->import('String'), was überall drin steht, implizit StringUtil importen)
protected function import($strClass, $strKey=false, $blnForce=false)
{ if ($strClass == 'String') { $strClass = 'StringUtil'; $strKey = 'String'; }
3. Callback calls korrigieren
$this->$callback[0]->$callback[1]... zu $this->{$callback[0]}->{$callback[1]}...
dafür Script benutzen:
contao2php7.php, siehe unten
4. /cron.php callback...
3x
$this->$callback[0]->$callback[1]();
zu $this->{$callback[0]}->{$callback[1]}();
----------------------------------------------------
Contao 3.2 für PHP 7
----------------------------------------------------
1. MySQLi
localconfig.php: MySQLi statt MySQL
2. String to StringUtil
Copy system/libraries/String.php to system/libraries/StringUtil.php
Edit StringUtil.php: String to StringUtil (class name und new String)
3. Callback calls und String:: korrigieren
$this->$callback[0]->$callback[1]... zu $this->{$callback[0]}->{$callback[1]}...
dafür Script benutzen:
contao3php7.php, siehe unten
----------------------------------------------------
Contao < 3.5.5 für PHP 7
----------------------------------------------------
1. MySQLi
localconfig.php: MySQLi statt MySQL
2. String to StringUtil
Prüfen, ob system/modules/core/library/Contao/StringUtil vorhanden ist, dann alles gut.
Sonst siehe oben (Contao 3.2 für PHP 7)
für PHP7 system/modules/core/library/Contao/Picture.php:
protected function getTemplateDataSource($imageSize)
{ if (!$imageSize->width) $imageSize->width=0; if (!$imageSize->height) $imageSize->height=0; // webdecker 2018-10-04 for php 7
sonst lauter Warnings...
Nach den o.g. Schritten liefen ein paar alte 2er und 3er-Projekte wieder - ohne allerdings alle Ecken und Ende getestet zu haben... ;-)
Hier meine schnell zusammen gehackten Hilfsskripte... Code kopieren, in eine php-Datei in document root gießen und ausführen. Keine Garantie, keine Haftung und so. Und kein Anspruch auf Vollständigkeit...!
Viel Erfolg.
contao2php7.php
<?php
date_default_timezone_set('Europe/Berlin');
header("Cache-Control: no-cache, must-revalidate");
error_reporting(E_ALL);
ini_set('max_execution_time', 240);
@date_default_timezone_set('Europe/Berlin');
ob_end_clean(); // disable output buffer
ob_implicit_flush(); // call flush() automatically after every output
?>
<html>
<head></head>
<body>
<pre>
<?php
$changed = array();
$basedir = realpath($_SERVER["DOCUMENT_ROOT"]) . '/system';
$basedir2 = realpath($_SERVER["DOCUMENT_ROOT"]) . '/contao';
function prepare($dir, $basedir) {
$rdir = realpath($basedir . '/' . $dir);
$files = scandir($rdir);
foreach ($files as $file) {
if ($file[0] == '.') continue;
$fn = $rdir . "/" . $file;
$fn = str_replace("\\", "/", $fn);
if (is_file($fn)) {
if (preg_match('~\\.php$~', $fn)) {
checkFile($fn);
}
} else {
prepare($file, $rdir);
}
}
}
function checkFile($src) {
echo "CHECKING {$src}... \n";
flush();
global $changed;
$ch = false;
$code = file_get_contents($src);
if (preg_match('~\\$this\\-\\>\\$callback\\[0\\]-\\>\\$callback\\[1\\]~', $code)) {
echo "... match callback!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
$code = preg_replace('~\\$this\\-\\>\\$callback\\[0\\]-\\>\\$callback\\[1\\]~', '$this->{$callback[0]}->{$callback[1]}', $code);
file_put_contents($src, $code);
$ch = true;
}
if (preg_match('~\\$this\\-\\>\\$v\\[\'button_callback\'\\]\\[0\\]\\-\\>\\$v\\[\'button_callback\'\\]\\[1\\]~', $code)) {
echo "... match button_callback!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
$code = preg_replace('~\\$this\\-\\>\\$v\\[\'button_callback\'\\]\\[0\\]\\-\\>\\$v\\[\'button_callback\'\\]\\[1\\]~', '$this->{$v[\'button_callback\'][0]}->{$v[\'button_callback\'][1]}', $code);
file_put_contents($src, $code);
$ch = true;
}
if (preg_match('~\\$this\\-\\>\\$arrData\\[\'options_callback\'\\]\\[0\\]\\-\\>\\$arrData\\[\'options_callback\'\\]\\[1\\]~', $code)) {
echo "... match options_callback!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
$code = preg_replace('~\\$this\\-\\>\\$arrData\\[\'options_callback\'\\]\\[0\\]\\-\\>\\$arrData\\[\'options_callback\'\\]\\[1\\]~', '$this->{$arrData[\'options_callback\'][0]}->{$arrData[\'options_callback\'][1]}', $code);
file_put_contents($src, $code);
$ch = true;
}
//
if (preg_match('~\\$this\\-\\>\\$arrData\\[\'input_field_callback\'\\]\\[0\\]\\-\\>\\$arrData\\[\'input_field_callback\'\\]\\[1\\]~', $code)) {
echo "... match input_field_callback!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
$code = preg_replace('~\\$this\\-\\>\\$arrData\\[\'input_field_callback\'\\]\\[0\\]\\-\\>\\$arrData\\[\'input_field_callback\'\\]\\[1\\]~', '$this->{$arrData[\'input_field_callback\'][0]}->{$arrData[\'input_field_callback\'][1]}', $code);
file_put_contents($src, $code);
$ch = true;
}
// PageRegular: $this->Template->{$arrModule['col']}
if (preg_match('~\\$this\\-\\>Template\\-\\>\\$arrModule\\[\'col\'\\]~', $code)) {
echo "... match PageRegular callback!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
$code = preg_replace('~\\$this\\-\\>Template\\-\\>\\$arrModule\\[\'col\'\\]~', '$this->Template->{$arrModule[\'col\']}', $code);
file_put_contents($src, $code);
$ch = true;
}
if ($ch) $changed[] = $src;
}
print "Basisverzeichnus: " . $basedir . "<br />";
prepare("", $basedir);
prepare("", $basedir2);
echo "<hr>\n";
echo implode("\n", $changed);
?>
</pre>
</body>
</html>
contao3php7.php
<?php
date_default_timezone_set('Europe/Berlin');
header("Cache-Control: no-cache, must-revalidate");
error_reporting(E_ALL);
ini_set('max_execution_time', 240);
@date_default_timezone_set('Europe/Berlin');
ob_end_clean(); // disable output buffer
ob_implicit_flush(); // call flush() automatically after every output
?>
<html>
<head></head>
<body>
<pre>
<?php
$changed = array();
$basedir = realpath($_SERVER["DOCUMENT_ROOT"]) . '/system';
$basedir2 = realpath($_SERVER["DOCUMENT_ROOT"]) . '/contao';
function prepare($dir, $basedir) {
$rdir = realpath($basedir . '/' . $dir);
if (file_exists($rdir)) {
if (is_dir($rdir)) {
$files = scandir($rdir);
foreach ($files as $file) {
if ($file[0] == '.') continue;
$fn = $rdir . "/" . $file;
$fn = str_replace("\\", "/", $fn);
if (is_file($fn)) {
if (preg_match('~\\.(php|html5)$~', $fn)) {
checkFile($fn);
}
} else {
prepare($file, $rdir);
}
}
} else {
if (preg_match('~\\.(php|html5)$~', $rdir)) {
checkFile($rdir);
}
}
}
}
function checkFile($src) {
echo "CHECKING {$src}... \n";
flush();
global $changed;
$ch = false;
$code = file_get_contents($src);
if (preg_match('~\\$this\\-\\>\\$callback\\[0\\]-\\>\\$callback\\[1\\]~', $code)) {
echo "... match callback!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
$code = preg_replace('~\\$this\\-\\>\\$callback\\[0\\]-\\>\\$callback\\[1\\]~', '$this->{$callback[0]}->{$callback[1]}', $code);
file_put_contents($src, $code);
$ch = true;
}
if (preg_match('~\\$this\\-\\>\\$v\\[\'button_callback\'\\]\\[0\\]\\-\\>\\$v\\[\'button_callback\'\\]\\[1\\]~', $code)) {
echo "... match button_callback!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
$code = preg_replace('~\\$this\\-\\>\\$v\\[\'button_callback\'\\]\\[0\\]\\-\\>\\$v\\[\'button_callback\'\\]\\[1\\]~', '$this->{$v[\'button_callback\'][0]}->{$v[\'button_callback\'][1]}', $code);
file_put_contents($src, $code);
$ch = true;
}
if (preg_match('~\\$this\\-\\>\\$arrData\\[\'options_callback\'\\]\\[0\\]\\-\\>\\$arrData\\[\'options_callback\'\\]\\[1\\]~', $code)) {
echo "... match options_callback!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
$code = preg_replace('~\\$this\\-\\>\\$arrData\\[\'options_callback\'\\]\\[0\\]\\-\\>\\$arrData\\[\'options_callback\'\\]\\[1\\]~', '$this->{$arrData[\'options_callback\'][0]}->{$arrData[\'options_callback\'][1]}', $code);
file_put_contents($src, $code);
$ch = true;
}
//
if (preg_match('~\\$this\\-\\>\\$arrData\\[\'input_field_callback\'\\]\\[0\\]\\-\\>\\$arrData\\[\'input_field_callback\'\\]\\[1\\]~', $code)) {
echo "... match input_field_callback!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
$code = preg_replace('~\\$this\\-\\>\\$arrData\\[\'input_field_callback\'\\]\\[0\\]\\-\\>\\$arrData\\[\'input_field_callback\'\\]\\[1\\]~', '$this->{$arrData[\'input_field_callback\'][0]}->{$arrData[\'input_field_callback\'][1]}', $code);
file_put_contents($src, $code);
$ch = true;
}
// PageRegular: $this->Template->{$arrModule['col']}
if (preg_match('~\\$this\\-\\>Template\\-\\>\\$arrModule\\[\'col\'\\]~', $code)) {
echo "... match PageRegular callback!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
$code = preg_replace('~\\$this\\-\\>Template\\-\\>\\$arrModule\\[\'col\'\\]~', '$this->Template->{$arrModule[\'col\']}', $code);
file_put_contents($src, $code);
$ch = true;
}
// contao 3
if (preg_match('~importStatic\\(\\$callback\\[0\\]\\)\\-\\>\\$callback\\[1\\]~', $code)) {
//importStatic($arrCallback[0])->$arrCallback[1]
echo "... match importStatic callback!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
$code = preg_replace('~importStatic\\(\\$callback\\[0\\]\\)\\-\\>\\$callback\\[1\\]~', 'importStatic($callback[0])->{$callback[1]}', $code);
file_put_contents($src, $code);
$ch = true;
}
if (preg_match('~importStatic\\(\\$arrCallback\\[0\\]\\)\\-\\>\\$arrCallback\\[1\\]~', $code)) {
//importStatic($arrCallback[0])->$arrCallback[1]
echo "... match importStatic arrCallback!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
$code = preg_replace('~importStatic\\(\\$arrCallback\\[0\\]\\)\\-\\>\\$arrCallback\\[1\\]~', 'importStatic($arrCallback[0])->{$arrCallback[1]}', $code);
file_put_contents($src, $code);
$ch = true;
}
if (preg_match('~String::~', $code)) {
echo "... match String::!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
$code = preg_replace('~String::~', 'StringUtil::', $code);
file_put_contents($src, $code);
$ch = true;
}
if (preg_match('~\'Contao\\\\String\' +=\\> +\'system/modules/core/library/Contao/String.php\'~', $code)) {
echo "... match Contao\\String!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
$code = preg_replace('~\'Contao\\\\String\' +=\\> +\'system/modules/core/library/Contao/String.php\'~', "'Contao\\StringUtil' => 'system/modules/core/library/Contao/StringUtil.php'", $code);
file_put_contents($src, $code);
$ch = true;
}
if ($ch) $changed[] = $src;
}
print "Basisverzeichnus: " . $basedir . "<br />";
prepare("", $basedir);
prepare("", $basedir2);
prepare("index.php", $_SERVER["DOCUMENT_ROOT"]);
echo "<hr>\n";
echo implode("\n", $changed);
?>
</pre>
</body>
</html>

Kommentare
Einen Kommentar schreiben