ezsystems/ezpublish-legacy — pull request #955 by bdunogier (2014-05-09 14:32:26+00:00)
Title: Fix EZP-22749: wrong working directory

> Fixes https://jira.ez.no/browse/EZP-22749
> Status: open for comments

### Actual bug
The issue affects all shutdown handlers on apache. As said on the [`register_shutdown_function()`](http://fr2.php.net/manual/en/function.register-shutdown-function.php) doc:

> Working directory of the script can change inside the shutdown function under some web servers, e.g. Apache.

In my case, with apache, the working directory is set to "/". Some shutdown functions don't care as they don't rely on the filesystem, but others do, like eZExpiryHandler, that may write the updated expiry handler cache to FS upon shutdown.

### Fix
This patch only fixes the `eZExpiryHandler` case. It does so by memorizing the directory at the time of execution, and changing back to this directory if different from the current one.

It does prevent the issue.

### Limitations
I don't really see a way to fix it for all shutdown functions without doing so manually for all of them. We could add a helper in eZExecution that switches back to the legacy folder, and back again, but it will have to be applied everywhere.