User Tools

Site Tools


typo3_distribution_clear

Clear TYPO3 Distrobution

What does it do?

If you want to reinitialize a TYPO3 Distribution use this script to clear tables and delete files in fileadmin/ . Reinstall your distribution using the Extensionmanager to import the initialize.t3d and files.

Adjust paths to your distribution in fileadmin/. For TYPO3 > 7.6 make sure to access

The Code

distribution_clear.php
<?php
 
// THIS SCRIPT IS NOT RELATED TO THE TYPO3 PROJECT!
 
$tables = array('tt_content',
	'pages',
	'pages_language_overlay',
	'sys_registry',
	'tx_powermail_domain_model_fields',
	'tx_powermail_domain_model_forms',
	'tx_powermail_domain_model_pages',
	'tx_news_domain_model_news',
	'backend_layout',
	'sys_file_reference',
	'sys_template');
 
// USER INFORMATION
echo PHP_EOL;
echo '๐Ÿ”ฅ ๐Ÿ”ฅ ๐Ÿ”ฅ ๐Ÿ”ฅ ๐Ÿ”ฅ ๐Ÿ”ฅ ๐Ÿ”ฅ ๐Ÿ”ฅ ๐Ÿ”ฅ ๐Ÿ”ฅ ๐Ÿ”ฅ ๐Ÿ”ฅ ๐Ÿ”ฅ ๐Ÿ”ฅ ๐Ÿ”ฅ ๐Ÿ”ฅ ๐Ÿ”ฅ ๐Ÿ”ฅ ๐Ÿ”ฅ ๐Ÿ”ฅ ๐Ÿ”ฅ ๐Ÿ”ฅ' . PHP_EOL;
echo "\033[1;36m โ˜  THIS MAY BREAK THE CURRENT INSTALLATION \033[0m" . PHP_EOL;
echo '๐Ÿ”ฅ ๐Ÿ”ฅ ๐Ÿ”ฅ ๐Ÿ”ฅ ๐Ÿ”ฅ ๐Ÿ”ฅ ๐Ÿ”ฅ ๐Ÿ”ฅ ๐Ÿ”ฅ ๐Ÿ”ฅ ๐Ÿ”ฅ ๐Ÿ”ฅ ๐Ÿ”ฅ ๐Ÿ”ฅ ๐Ÿ”ฅ ๐Ÿ”ฅ ๐Ÿ”ฅ ๐Ÿ”ฅ ๐Ÿ”ฅ ๐Ÿ”ฅ ๐Ÿ”ฅ ๐Ÿ”ฅ' . PHP_EOL;
echo PHP_EOL;
echo 'Following steps will be performed:' . PHP_EOL;
echo 'โžค Truncate database tables:' . PHP_EOL;
 
foreach($tables as $table) {
echo "   โžค $table" . PHP_EOL;
}
echo 'โžค Delete distribution related files: fileadmin/distribution' . PHP_EOL;
echo PHP_EOL;
echo "Santa's Little Helper will wipe out this distribution from the database and fileadmin, do you agree? [yes/no] : ";
$handle = fopen ("php://stdin","r");
$line = fgets($handle);
 
// EXIT SCRIPT IF "NO" GIVEN
if(trim($line) != 'yes'){
    echo "ABORTING the magic!" . PHP_EOL;
    exit;
}
 
// GET TYPO3 DB CONNECTION AND CONNECT TO MYSQL
$config = include_once('../../LocalConfiguration.php');
$connection = new mysqli($config['DB']['Connections']['Default']['host'], $config['DB']['Connections']['Default']['user'], $config['DB']['Connections']['Default']['password'], $config['DB']['Connections']['Default']['dbname']);
if($connection->connect_error) {
    die('\033[31mOh my goodness ... can\'t connect to mysql!\033[0m Error: (' . $connection->connect_errno . ') ' . $connection->connect_error);
}
 
// CLEAR TABLES AND RESET AUTO_INCREMENT
foreach($tables as $table) {
	if(mysqli_query($connection,"TRUNCATE TABLE $table") == true) {
		mysqli_query($connection, "ALTER TABLE $table AUTO_INCREMENT = 1");
		echo "\33[1;32mโœ“\033[0m - Cleared $table" . PHP_EOL;
	} else {
		echo "\33[1;31mร—\033[0m - Cleared $table" . PHP_EOL;
	}
}
 
mysqli_close($connection);
 
$distriFolder = '../../../fileadmin/distribution';
if(is_dir($distriFolder)) {
	system("rm -fr $distriFolder");
	echo "\33[1;32mโœ“\033[0m - $distriFolder removed" . PHP_EOL;
}
 
echo 'Done!' . PHP_EOL . PHP_EOL . "Cheers," . PHP_EOL;
echo 'Santa\'s Little Helper' . PHP_EOL;
typo3_distribution_clear.txt ยท Last modified: 2018/04/09 08:44 by admin