computerminds / cm_config_tools

DEPRECATED: Mirror of http://cgit.drupalcode.org/cm_config_tools
1 stars 0 forks source link

Flush image styles on revert #33

Open anotherjames opened 7 years ago

anotherjames commented 7 years ago

At the moment, I manually put this in an update hook:

  /** @var \Drupal\cm_config_tools\ExtensionConfigHandler $helper */
  $helper = \Drupal::service('cm_config_tools');
  $extension_dirs = $helper->getExtensionDirectories();
  $storage_comparer = $helper->getStorageComparer($extension_dirs);
  foreach ($storage_comparer->getChangelist('update') as $config) {
    if (strpos($config, 'image.style.') === 0) {
      $style_name = substr($config, 12);
      // Assumes public is the only wrapper needing flushing.
      if (file_exists($directory = 'public://styles/' . $style_name)) {
        file_unmanaged_delete_recursive($directory);
      }
    }
  }

But that shouldn't be necessary, it should be done as part of saving an ImageStyle config entity during the import? Something's not right, but I don't know what. We should resolve/handle this.

anotherjames commented 7 years ago

Oooo it may be the weird thing about the public stream wrapper not being found by the StreamWrapperManager during drush updb. That would be annoying, but might make sense. (As ImageStyle::flush() relies on that being around.) Perhaps we could just have a cm_config_tools_image_style_flush() to hook into this happening, and check if the public stream is unavailable (we could probably assume it shouldn't be)?