Problem/Motivation

When I set up a custom class for PHPStorage by setting, for example, by setting a custom directory for compiled twig like:

  $settings['php_storage']['twig'] = array(
    'directory' => '/var/tmp/mysite/php_storage/twig',
  );

I get an undefined index (and really should be an exception):

Notice: Undefined index: secret in Drupal\Component\PhpStorage\MTimeProtectedFastFileStorage->__construct() (line 62 of core/lib/Drupal/Component/PhpStorage/MTimeProtectedFastFileStorage.php).

Proposed resolution

Merge in default settings instead of making site owners set the secret and class

Remaining tasks

review patch
decide if we need to throw an exception if the secret is empty

User interface changes

n/a

API changes

n/a

Data model changes

n/a

original report:

I have a fresh install of Drupal 8.0.3 that is reporting the following:
Notice: Undefined index: secret in Drupal\Component\PhpStorage\MTimeProtectedFastFileStorage->__construct() (line 62 of {path}/docroot/core/lib/Drupal/Component/PhpStorage/MTimeProtectedFastFileStorage.php).

Is this an error on my end? Or just a silent error in drupal?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

christianmgrupp created an issue. See original summary.

yobottehg’s picture

We also have this message on all Acquia Cloud hostings. We reported that, but they could not find the error.

dawehner’s picture

That is a clear sign of the sadness of Acquia Cloud to not write the hash salt into settings.php on install, see core/lib/Drupal/Core/PhpStorage/PhpStorageFactory.php:47

Afaik they don't allow settings.php to be writeable at all, so you better do it on your own :)

michaellander’s picture

I might be misunderstanding, but we setup our site outside of Acquia, and have a hash_salt defined, and are getting the same error only on our Acquia environment. I've also tried defining the hash_salt again after including the Acquia stuff, but still the same issue. I do think it's an Acquia thing, but am not entirely clear what I'm missing.

kurund’s picture

Assigned: Unassigned » kurund
Issue tags: +drupalconasia2016
kurund’s picture

I have tested this issue but I am not able to replicate this on the vanilla install of Drupal running on 8.0.x branch. This might be Acquia environment related issue hence, can be closed.

kurund’s picture

Status: Active » Closed (cannot reproduce)
chrisyawman’s picture

I came across this issue only after I modified my $settings['php_storage'] array in the settings.php. I resolved it by adding the following at the end of the settings.php file:

$settings['php_storage']['twig']['secret'] = $settings['hash_salt'];

bneva’s picture

I feel like manually setting the Twig secret in settings.php is only treating the symptom.

I think there are three solutions, but I don't know the Core well enough to know about any side effects.

1. Modify \Drupal\Component\PhpStorage\MTimeProtectedFastFileStorage such that the constructor either ignores or prepends the hash_salt when it pulls the secret from the $configuration variable. (e.g., $this->secret = $configuration['secret']; should be $this->secret = isset($configuration['secret']) ? : Settings::getHashSalt() -or- '';)

2. Modify \Drupal\Core\PhpStorage\PhpStorageFactory to automatically add the hash_salt to the $configuration array if one is not set. Perhaps log this as an error if it's not set.

3. Modify \Drupal\Core\Template\TwigPhpStorageCache (or wherever else Twig's Storage Cache sets its configuration) to include the provided hash_salt.

pwolanin’s picture

Version: 8.0.3 » 8.0.x-dev
Issue summary: View changes
Status: Closed (cannot reproduce) » Needs review
FileSize
1.35 KB

Comments #8 and #9 seem basically correct to me.

We already have a check for:
isset($configuration['class'])

This patch just merges in the 2 required keys instead of having an else clause.

pwolanin’s picture

Assigned: kurund » Unassigned

Status: Needs review » Needs work

The last submitted patch, 10: 2669418-10.patch, failed testing.

pwolanin’s picture

Status: Needs work » Needs review
FileSize
3.85 KB
3.64 KB

mm, how about this. Doesn't break the test, and adds a little more coverage (and converts 2 deprecated method calls).

amateescu’s picture

Status: Needs review » Reviewed & tested by the community

I also encountered this problem recently on a site hosted on Acquia Cloud, and the patch makes sense :)

amateescu’s picture

Just one nit though:

+++ b/core/modules/system/tests/src/Kernel/PhpStorage/PhpStorageFactoryTest.php
@@ -65,18 +65,28 @@ public function testGetOverride() {
+    $this->assertNotEquals('mock hash salt', $php->getConfigurationValue('secret'), 'The default secret is used if one is not set in the overridden settings.');

This message is copied from below, so it's not really accurate for this assertion.

pwolanin’s picture

Thanks - here's the patch with a fix for the test text.

  • alexpott committed f5f6479 on 8.2.x
    Issue #2669418 by pwolanin: Php Storage not defining secret index
    
alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed ed78a4c and pushed to 8.0.x, 8.1.x and 8.2.x. Thanks!

  • alexpott committed 33c4717 on 8.1.x
    Issue #2669418 by pwolanin: Php Storage not defining secret index
    
    (...

  • alexpott committed ed78a4c on 8.0.x
    Issue #2669418 by pwolanin: Php Storage not defining secret index
    
    (...
alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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