diff --git a/patternkit.services.yml b/patternkit.services.yml index 44e9e04..3b56a04 100644 --- a/patternkit.services.yml +++ b/patternkit.services.yml @@ -11,7 +11,7 @@ services: arguments: ['@patternkit.library.discovery.collector'] patternkit.library.discovery.collector: class: Drupal\patternkit\PatternLibraryCollector - arguments: ['@cache.discovery', '@config.factory', '@file_system', '@plugin.manager.library.pattern', '@lock', '@module_handler', '@app.root', '@theme.manager'] + arguments: ['@cache.discovery', '@config.factory', '@file_system', '@plugin.manager.library.pattern', '@lock', '@logger.channel.default', '@module_handler', '@app.root', '@theme.manager'] tags: - { name: needs_destruction } patternkit.library.discovery.parser.file: diff --git a/src/PatternLibraryCollector.php b/src/PatternLibraryCollector.php index 2d7177f..c053a13 100644 --- a/src/PatternLibraryCollector.php +++ b/src/PatternLibraryCollector.php @@ -13,6 +13,7 @@ use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\File\FileSystemInterface; +use Drupal\Core\Logger\LoggerChannelInterface; use Drupal\Core\Serialization\Yaml; use Drupal\Core\Theme\ThemeManagerInterface; use Drupal\patternkit\Form\PatternkitSettingsForm; @@ -50,6 +51,9 @@ class PatternLibraryCollector extends CacheCollector implements ContainerInjecti /** @var \Drupal\patternkit\PatternLibraryPluginManager */ protected $libraryPluginManager; + /** @var \Drupal\Core\Logger\LoggerChannelInterface */ + protected $logger; + /** @var \Drupal\Core\Extension\ModuleHandlerInterface */ protected $moduleHandler; @@ -74,6 +78,8 @@ class PatternLibraryCollector extends CacheCollector implements ContainerInjecti * Provide the file system service. * @param \Drupal\Core\Lock\LockBackendInterface $lock * Provide the lock backend. + * @param \Drupal\Core\Logger\LoggerChannelInterface $logger + * Provide the logging channel. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * Provide a module handler. * @param \Drupal\patternkit\PatternLibraryPluginManager $library_plugin_manager @@ -89,6 +95,7 @@ public function __construct( FileSystemInterface $file_system, PatternLibraryPluginManager $library_plugin_manager, LockBackendInterface $lock, + LoggerChannelInterface $logger, ModuleHandlerInterface $module_handler, $root, ThemeManagerInterface $theme_manager) { @@ -97,6 +104,7 @@ public function __construct( $this->config = $this->configFactory->get(PatternkitSettingsForm::SETTINGS); $this->fileSystem = $file_system; $this->libraryPluginManager = $library_plugin_manager; + $this->logger = $logger; $this->moduleHandler = $module_handler; $this->root = $root; $this->themeManager = $theme_manager; @@ -120,6 +128,8 @@ public static function create(ContainerInterface $container): self { $file_system = $container->get('file_system'); /** @var \Drupal\Core\Lock\LockBackendInterface $lock */ $lock = $container->get('lock'); + /** @var \Drupal\Core\Logger\LoggerChannelInterface $logger */ + $logger = $container->get('@logger.channel.default'); /** @var \Drupal\Core\Extension\ModuleHandlerInterface $module_handler */ $module_handler = $container->get('module_handler'); /** @var string $root */ @@ -132,6 +142,7 @@ public static function create(ContainerInterface $container): self { $file_system, $library_plugin_manager, $lock, + $logger, $module_handler, $root, $theme_manager); @@ -159,8 +170,13 @@ public function getLibraryDefinitions(): array { // (if cache enabled, otherwise just a slow, redundant memcache set). if ($cache_enabled) { // Explicit copy of the data into cache_set to avoid implicit copy. + // @todo Evaluate encoding via JSON instead to shrink data size. $this->cache->set(static::PERSISTENT_CACHE_ID, $cached_metadata); + $cache = $this->cache->get(static::PERSISTENT_CACHE_ID); + if ($cache->data !== $cached_metadata) { + $this->logger->warning('Error storing Patternkit Library Metadata in cache. Check that memcache or your caching module has be configured correctly.'); + } } } return $cached_metadata;