Unverified Commit fef92a29 authored by Alex Pott's avatar Alex Pott
Browse files

fix: #3592577 Ensure that hook attributes are never parsed from a stale opcache

By: catch
By: nicxvan
By: larowlan
(cherry picked from commit 16d92a48)
parent b9e3893a
Loading
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@
use Drupal\Component\Annotation\Doctrine\StaticReflectionParser;
use Drupal\Component\Annotation\Reflection\MockFileFinder;
use Drupal\Component\FileCache\FileCacheFactory;
use Drupal\Component\Utility\OpCodeCache;
use Drupal\Core\Extension\ProceduralCall;
use Drupal\Core\Hook\Attribute\Hook;
use Drupal\Core\Hook\Attribute\HookAttributeInterface;
@@ -472,6 +473,12 @@ protected function collectModuleHookImplementations($dir, $module, $current_modu
          $attributes = $cached['attributes'];
        }
        else {
          // Immediately after a deployment, opcache may not yet have refreshed
          // depending on the value of opcache.revalidation_freq which defaults
          // to 2 seconds. Ensure that reflection operates on the new code by
          // forcibly invalidating the opcode cache.
          // @see https://www.php.net/manual/en/opcache.configuration.php#ini.opcache.revalidate-freq
          OpCodeCache::invalidate($filename);
          $namespace = preg_replace('#^src/#', "Drupal/$module/", $iterator->getSubPath());
          $class = $namespace . '/' . $fileinfo->getBasename('.php');
          $class = str_replace('/', '\\', $class);
+7 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@
use Drupal\Component\Annotation\Doctrine\StaticReflectionParser;
use Drupal\Component\Annotation\Reflection\MockFileFinder;
use Drupal\Component\FileCache\FileCacheFactory;
use Drupal\Component\Utility\OpCodeCache;
use Drupal\Core\Hook\Attribute\Hook;
use Drupal\Core\Hook\Attribute\HookAttributeInterface;
use Drupal\Core\Hook\Attribute\LegacyHook;
@@ -230,6 +231,12 @@ protected function collectThemeHookImplementations($dir, $theme, $currentThemePr
          $attributes = $cached['attributes'];
        }
        else {
          // Immediately after a deployment, opcache may not yet have refreshed
          // depending on the value of opcache.revalidation_freq which defaults
          // to 2 seconds. Ensure that reflection operates on the new code by
          // forcibly invalidating the opcode cache.
          // @see https://www.php.net/manual/en/opcache.configuration.php#ini.opcache.revalidate-freq
          OpCodeCache::invalidate($filename);
          $namespace = preg_replace('#^src/#', "Drupal/$theme/", $iterator->getSubPath());
          $class = $namespace . '/' . $fileinfo->getBasename('.php');
          $class = str_replace('/', '\\', $class);