I do have a PHP script, which is not an extension for Typo3. Now I would like to delete the whole Cache of Typo3 out of this script. How is that possible?
Install Extension "cleartypo3cache" and create the BE user "_cli_cleartypo3cache" and add the following TSconfig:
options.clearCache.all=1
options.clearCache.pages=1
Now test if cache is cleared:
$ cd /path/tp/typo3-site/
$ php typo3/cli_dispatch.phpsh cleartypo3cache all
If your webserver is on localhost, you are lucky because you don't need this shell script. If your webserver is on a remote host, you need an additional wrapper script. This is because PhpStorm does not provide an environment variable for the remote host directory. You have to set this directory statically for each project in the wrapper script:
#!/bin/sh
TYPO3_SITE_PATH="/path/to/typo3-site"
USER="alice"
HOST="example.com"
/usr/bin/ssh $USER@$HOST '/usr/bin/php $TYPO3_SITE_PATH/typo3/cli_dispatch.phpsh cleartypo3cache all'
Save this file in your project file directory into .idea/clear-typo3-cache.sh and make it executable:
$ chmod 755 .idea/clear-typo3-cache.sh
PhpStorm External Tools You need to create an "external tool" in PhpStorm to be able to clear cache.
Remote host scenario
Add the following line to "Programm:"
$ProjectFileDir$/.idea/clear-typo3-cache.sh
Localhost scenario
Add this line to "Program:"
$PhpExecutable$
Add this line to "Parameters:"
$ProjectFileDir$/typo3/cli_dispatch.phpsh cleartypo3cache all
You need to have a PHP interpreter configured in PhpStorm-->Settings-->PHP to use $PhpExecutable$. Alternatively you can use /usr/bin/php

(source: t3node.com)
PhpStorm Keymap I suggest to use the same key binding as you use for saving or remote host uploading:
Go to PhpStorm-->Settings-->Keymap
For remote host scenario, navigate to: Main menu-->Tools-->Deployment-->Upload to Default Server. Notice the existing shortcut. If you don't have one for that, create a new one (I use ALT+SHIFT+U) For the localhost scenario, just use Ctrl+S (Main menu-->File-->Save All).
Now PhpStorm will warn you that the shortcut is already in use for a different command. That's fine, it's exactly what we want to have.
That's it. Your TYPO3 caches are always cleared when you hit save or upload on your keyboard.
adapted from t3node
I found the solution myself and its actually pretty easy. I took a look into the class.t3lib_tcemain.php in the t3lib folder. There you've got the necessary commands to clear the cache. It also checks, if you have the cachingframework enabled. If so, you need to truncate a few other tables as well (Starts with cachingframework_cache_)
It is basically:
<?php
require_once('./typo3conf/localconf.php');
$conn = mysql_connect($typo_db_host, $typo_db_username, $typo_db_password);
mysql_select_db($typo_db);
// Clear Cache here
mysql_query("TRUNCATE cache_treelist;");
mysql_query("TRUNCATE cache_pagesection;");
mysql_query("TRUNCATE cache_hash;");
mysql_query("TRUNCATE cache_pages;");
if($handle = opendir('./typo3conf')) {
while (false !== ($file = readdir($handle))) {
if(strpos($file, 'temp_CACHED_')!==false) {
unlink('./typo3conf/'.$file);
}
}
closedir($handle);
}
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With