Developing and Testing TYPO3 websites might force you to clear TYPO3 caches whenever you made a change. Especially if you write Extbase/Fluid extensions on TYPO3 4.5, you need to clear reflection/object cache when altering a class file. This task can be solved automatically by your IDE! This articles describes how to do that with PhpStorm 4.
Clicking on TYPO3 clear cache buttons is tiring while development and sucks if you need to switch between TYPO3 backend, frontend and your IDE over and over again.
To stop that madness, you basically need...
- to install the TYPO3 Extension cleartypo3cache
- to create a tool and a keyboard shortcut in PhpStorm 4 to trigger cleartypo3cache
- SSH access with passwordless pubkey authentication when pushing to a remote host.
Install Extension "cleartypo3cache" and create the BE user "_cli_cleartypo3cache" and add the following TSconfig:
Now test if cache is cleared:
$ cd /path/tp/typo3-site/
$ php typo3/cli_dispatch.phpsh cleartypo3cache all
Shell script wrapper for remote hosts
If your webserver is on localhost, you are lucky because you don't need this shell script. You can skip to the next chapter.
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:
/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.
- Go to PhpStorm-->Settings-->External Tools-->Add...
- Give your tool a name and a group, e.g. "Deployment" -> "Clear TYPO3 Cache"
- Deactivate checkbox "Open Console" and "Menu->Search Results"
Remote host scenario
Add the following line to "Programm:"
Add this line to "Program:"
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
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 navigate to the External Tool you have created (e.g. External Tools-->Deployment->Clear TYPO3 Cache)
- Right click "Add Keyboard Shortcut"
- Create the particular shortcut in "First Stroke"
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.