stmllr.net

Clearing TYPO3 Cache in PhpStorm

by on stmllr.net

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.

Overview

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.

TYPO3

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

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:

#!/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.

  • 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:"

$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

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 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.

Tags

Comments

  1. Philipp Gampe

    This extension does not work at all with 6.0.

    It uses ``$TYPO3_CONF_VARS`` instead of ``$GLOBALS['TYPO3_CONF_VARS']`` and also removes the extension key by calling ``global $_EXTKEY``.

    The whole cli code fails for 6.0 because it looks like it does not use the CLI like it should.

  2. Steffen

    Thanks for your Feedback, Philipp.
    I didn't test on 6.0, since it's in a alpha state ATM. Unfortunately there's no issue tracker for the extension. I will ask the author to add one at http://forge.typo3.org/projects/extension-cleartypo3cache

  3. Steffen

    6.0 compatibility issue can be found: http://forge.typo3.org/issues/39386

  4. Armin

    Have a look on this Google Chrome extension to clear the cache of TYPO3 right out of the browser, without switching to backend: http://goo.gl/UE0ga