Skip to content

Instantly share code, notes, and snippets.

@jmetzger
Created November 18, 2014 16:45
Show Gist options
  • Save jmetzger/47b37c6636952a06923a to your computer and use it in GitHub Desktop.
Save jmetzger/47b37c6636952a06923a to your computer and use it in GitHub Desktop.
Rewrite Your Localconf before updating to 6.2 (Get Rid of incompatibel extensions)
#!/usr/bin/php
<?php
class ConfigManager {
var $lines;
var $pathFilename;
var $uninstallExtensions;
public function __construct(){
$this->setHeader();
}
public function uninstallExtensions($arr){
if (!is_array($arr)){
return FALSE;
}
if (isset($GLOBALS['TYPO3_CONF_VARS']['EXT']['extList'])){
$extListValues = explode(",",$GLOBALS['TYPO3_CONF_VARS']['EXT']['extList']);
if (is_array($extListValues)){
$extListKeys=array_flip($extListValues);
}
}
if (isset($GLOBALS['TYPO3_CONF_VARS']['EXT']['extList_FE'])){
$extListFEValues = explode(",",$GLOBALS['TYPO3_CONF_VARS']['EXT']['extList_FE']);
if (is_array($extListFEValues)){
$extListFEKeys=array_flip($extListFEValues);
}
}
foreach ($arr as $ext){
if (isset($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$ext])){
unset($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$ext]);
}
if (isset($extListKeys[$ext])){
unset($extListKeys[$ext]);
}
if (isset($extListFEKeys[$ext])){
unset($extListFEKeys[$ext]);
}
}
if (isset($GLOBALS['TYPO3_CONF_VARS']['EXT']['extList'])){
$GLOBALS['TYPO3_CONF_VARS']['EXT']['extList'] = implode(",",array_keys($extListKeys));
}
if (isset($GLOBALS['TYPO3_CONF_VARS']['EXT']['extList_FE'])){
$GLOBALS['TYPO3_CONF_VARS']['EXT']['extList_FE'] = implode(",",array_keys($extListFEKeys));
}
}
public function setPathFilename($pathFile){
$this->pathFilename = $pathFile;
}
private function getPathFilename(){
return $this->pathFilename;
}
private function setHeader(){
$this->setLine('<?php');
$this->setLine("if (!defined ('TYPO3_MODE')) {");
$this->setLine(" die ('Access denied.');");
$this->setLine('}');
}
private function setFooter(){
$this->setLine('?>');
}
public function setLine($line){
$this->lines[] = $line;
}
public function analyzeT3ConfVar($key){
$this->flatten($key);
}
/**
* a bit ugly, but works
**/
public function flatten($key){
if (is_array($GLOBALS[$key])){
foreach (array_keys($GLOBALS[$key]) as $key_sub){
if (is_array($GLOBALS[$key][$key_sub])){
foreach (array_keys($GLOBALS[$key][$key_sub]) as $key_sub_sub){
if (is_array($GLOBALS[$key][$key_sub][$key_sub_sub])){
foreach (array_keys($GLOBALS[$key][$key_sub][$key_sub_sub]) as $key_sub_sub_sub){
$this->setLine('$'.$key."['".$key_sub."']['".$key_sub_sub."']['".$key_sub_sub_sub."'] = '".$GLOBALS[$key][$key_sub][$key_sub_sub][$key_sub_sub_sub]."';");
}
}
else {
$this->setLine('$'.$key."['".$key_sub."']['".$key_sub_sub."'] = '".$GLOBALS[$key][$key_sub][$key_sub_sub]."';");
}
}
}
else {
$this->setLine('$'.$key."['".$key_sub."'] = '".$GLOBALS[$key][$key_sub]."';");
}
}
}
else {
$this->setLine('$'.$key." = '".$GLOBALS[$key]."';");
}
}
public function output(){
$this->setFooter();
$fp=fopen($this->getPathFilename().".rewritten","w");
fwrite($fp,implode("\n",$this->lines));
fclose ($fp);
}
}
$options = getopt("",array('path:','uninstall::'));
$uninstallExtensions = array();
if (sizeof($options) == 0){
print "Required: --path=/path/to/typo3/installation/\n";
print "Example: ./rewriteLocalconf45.php --path=/path/to/typo3/installation --uninstall=cssspamprotect,cag_relatedcontent,t3quixplorer";
print "Sorry. Giving up \n";
exit;
}
$path = $options["path"];
if (isset($options['uninstall'])){
$uninstallExtensions=explode(",",$options["uninstall"]);
}
if (!is_dir($path)){
print "Sorry. ".$path." - directory does not exist !!\n";
exit;
}
$pathLocalconf = $path."/typo3conf/localconf.php";
if (!file_exists($pathLocalconf)){
print "Sorry. ".$pathLocalconf." - file does not exist !!\n";
exit;
}
define('TYPO3_MODE','BE');
include_once($pathLocalconf);
$cf = new ConfigManager();
$cf->setPathFilename($pathLocalconf);
$cf->uninstallExtensions($uninstallExtensions);
foreach (array_keys($GLOBALS) as $key){
if (substr($key,0,strlen('typo')) == 'typo'){
$cf->setLine('$'.$key." = '".$GLOBALS[$key]."';");
}
elseif (substr($key,0,strlen('TYPO3_CONF_VARS')) == 'TYPO3_CONF_VARS'){
$cf->analyzeT3ConfVar($key);
}
}
echo "Creating ".$cf->getPathFilename().".rewritten\n";
$cf->output();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment