The use of the magic constant "__FILE__" create a bug when you include this module in a installation profile which is linked to the project via a symlink.
This is typically what is done with "Platform.sh".

To avoid a such bug, the callback script should use instead the "$_SERVER['SCRIPT_FILENAME']" which resolves symlink and contains the full path in Drupal context.

Comments

sebastien m.’s picture

Status: Active » Needs review
StatusFileSize
new556 bytes

Status: Needs review » Needs work

The last submitted patch, 1: authcache-callback_error_with_symlink-2394217-1.patch, failed testing.

znerol’s picture

Version: 7.x-2.0-beta4 » 7.x-2.x-dev
Status: Needs work » Needs review

Thanks for the patch. There are three additional occurrences of the __FILE__ constant. I guess they also need the update?

$ git grep __FILE__
modules/authcache_builtin/tests/frontcontroller/index.php:$__file__ = __FILE__;
modules/authcache_enum/lib/Drupal/authcache_enum/Tests/AuthcacheEnumCartesianTestCase.php:    $module_dir = dirname(dirname(dirname(dirname(dirname(__FILE__)))));
modules/authcache_enum/lib/Drupal/authcache_enum/Tests/AuthcacheEnumCombTestCase.php:    $module_dir = dirname(dirname(dirname(dirname(dirname(__FILE__)))));
modules/authcache_p13n/frontcontroller/authcache.php:$__file__ = __FILE__;

Btw, I strongly recommend to use the safe front controller script in production (see README.txt in the Authcache Personalization API). Is there anything I could do to make installing the safe frontcontroller easier for platform.sh users?

Setting version to 7.x-2.x-dev otherwise test-bot will fail due to missing module dependencies.

sebastien m.’s picture

Thanks for the tip about the test-bot.
Concerning others files I supposed they should changed too, but I don't know how to check it.
On my dev environment I've issues when running simpletest scripts, but I'll do my best.

znerol’s picture

So, I think that modifying AuthcacheEnumCartesianTestCase.php and AuthcacheEnumCombTestCase.php is not necessary, because there is no reason to symlink any of the path components there. The destination points to the Authcache Enum directory which is a subdirectory inside the authcache project.

The remaining case is modules/authcache_builtin/tests/frontcontroller/index.php where the same fix can be applied.

I still think that modules/authcache_p13n/frontcontroller/authcache.php should not be used at all if possible and therefore I'm reluctant to modify it with the goal to make it more usable on special deployments. Also note that __FILE__ is a predefined constant in PHP, while $_SERVER['SCRIPT_FILENAME'] depends on the SAPI. For example when using nginx, this variable needs to be supplied in configuration files.

Is there something special about platform.sh which prevents the usage of the safe front controller?

sebastien m.’s picture

Nothing prevent platform.sh to use the safe front controller.
You just need to setup the ".platform.app.yaml" to specify a hook to do it.

I'm currently in contact with the platform support to define the best command line for the hook.

znerol’s picture

Would it help if there was a drush command which installs the safe frontcontroller?

sebastien m.’s picture

The only thing you have to do is to edit the file ".platform.app.yaml" by adding the "build" hook:

# The hooks executed at various points in the lifecycle of the application.
hooks:
    build: "cp public/profiles/custom_profile/authcache.php public/"
    # We run deploy hook after your application has been deployed and started.
    deploy: "cd /app/public ; drush -y updatedb"

With that, the file is copied at each deployment in the drupal root folder.
Don't prefix folders by "app", because a this step, the root folder is not this one, so the command must use relative folders.

I encountered issue when setting the variable "authcache_p13n_frontcontroller_path".
I have been oblige to install again the profile to apply correctly the new value in spite of "platform build".

znerol’s picture

The remaining case is modules/authcache_builtin/tests/frontcontroller/index.php where the same fix can be applied.

Patch attached.

znerol’s picture

Status: Needs review » Fixed

Thank you for reporting the issue. A modified version of the patch has been committed and is now part of the 7.x-2.x-dev version.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.