diff --git a/modules/quant_purger/src/Entity/QuantPurgerSettings.php b/modules/quant_purger/src/Entity/QuantPurgerSettings.php index 6c04fd7d..627e159d 100644 --- a/modules/quant_purger/src/Entity/QuantPurgerSettings.php +++ b/modules/quant_purger/src/Entity/QuantPurgerSettings.php @@ -40,7 +40,7 @@ class QuantPurgerSettings extends PurgerSettingsBase implements PurgerSettingsIn * * @var string */ - public $name = ''; + public $name = 'Quant Purger'; /** * The invalidation plugin ID that this purger invalidates. diff --git a/modules/quant_purger/src/Form/QuantPurgeForm.php b/modules/quant_purger/src/Form/QuantPurgerConfigForm.php similarity index 69% rename from modules/quant_purger/src/Form/QuantPurgeForm.php rename to modules/quant_purger/src/Form/QuantPurgerConfigForm.php index ae19cd6c..3b83036e 100644 --- a/modules/quant_purger/src/Form/QuantPurgeForm.php +++ b/modules/quant_purger/src/Form/QuantPurgerConfigForm.php @@ -3,9 +3,9 @@ namespace Drupal\quant_purger\Form; /** - * Configuration form for the HTTP Bundled Purger. + * Configuration form for the Quant Purger. */ -class QuantPurgeForm extends QuantPurgeFormBase { +class QuantPurgerConfigForm extends QuantPurgerConfigFormBase { /** * The token group names this purger supports replacing tokens for. diff --git a/modules/quant_purger/src/Form/QuantPurgeFormBase.php b/modules/quant_purger/src/Form/QuantPurgerConfigFormBase.php similarity index 96% rename from modules/quant_purger/src/Form/QuantPurgeFormBase.php rename to modules/quant_purger/src/Form/QuantPurgerConfigFormBase.php index 644ddafa..ffd21a0a 100644 --- a/modules/quant_purger/src/Form/QuantPurgeFormBase.php +++ b/modules/quant_purger/src/Form/QuantPurgerConfigFormBase.php @@ -2,18 +2,18 @@ namespace Drupal\quant_purger\Form; -use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\Config\ConfigFactoryInterface; +use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\purge\Plugin\Purge\Invalidation\InvalidationsServiceInterface; use Drupal\purge_ui\Form\PurgerConfigFormBase; use Drupal\quant_purger\Entity\QuantPurgerSettings; -use Drupal\Core\Entity\EntityTypeManagerInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** - * Abstract form base for HTTP based configurable purgers. + * Abstract form base for Quant Purger configuration. */ -abstract class QuantPurgeFormBase extends PurgerConfigFormBase { +abstract class QuantPurgerConfigFormBase extends PurgerConfigFormBase { /** * The service that generates invalidation objects on-demand. @@ -23,7 +23,7 @@ abstract class QuantPurgeFormBase extends PurgerConfigFormBase { protected $purgeInvalidationFactory; /** - * Constructs a \Drupal\quant_purger\Form\ConfigurationForm object. + * Constructs a base Quant Purger configuration form. * * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The factory for configuration objects. @@ -122,7 +122,7 @@ public function buildFormPerformance(array &$form, FormStateInterface $form_stat '#title' => $this->t('Cooldown time'), '#default_value' => $settings->cooldown_time, '#required' => TRUE, - '#description' => $this->t('Number of seconds to wait after a group of HTTP requests (so that other purgers get fresh content)'), + '#description' => $this->t('Number of seconds to wait after a group of HTTP requests so that other purgers get fresh content.'), ]; $form['performance']['max_requests'] = [ '#type' => 'number', diff --git a/modules/quant_purger/src/Form/ConfigurationForm.php b/modules/quant_purger/src/Form/QuantPurgerQueuerConfigForm.php similarity index 93% rename from modules/quant_purger/src/Form/ConfigurationForm.php rename to modules/quant_purger/src/Form/QuantPurgerQueuerConfigForm.php index cde184a4..1cd3ff12 100644 --- a/modules/quant_purger/src/Form/ConfigurationForm.php +++ b/modules/quant_purger/src/Form/QuantPurgerQueuerConfigForm.php @@ -8,9 +8,9 @@ use Drupal\purge_ui\Form\QueuerConfigFormBase; /** - * Configuration form for the Quant queuer. + * Configuration form for the Quant Purger Queuer. */ -class ConfigurationForm extends QueuerConfigFormBase { +class QuantPurgerQueuerConfigForm extends QueuerConfigFormBase { /** * {@inheritdoc} @@ -23,6 +23,8 @@ protected function getEditableConfigNames() { * {@inheritdoc} */ public function getFormId() { + // @todo This should be 'quant_purger.queuer_config_form' which will + // require an update hook. return 'quant_purger.configuration_form'; } @@ -39,7 +41,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { ]; $form['info'] = [ - '#markup' => $this->t('

After making changes to the Quant Purger configuration, all content must be re-seeded so the database reflects the changes.

'), + '#markup' => $this->t('

After making changes to the Quant Purger Queuer configuration, all content must be re-seeded so the database reflects the changes.

'), '#weight' => -10, ]; @@ -153,7 +155,7 @@ public function submitFormSuccess(array &$form, FormStateInterface $form_state) ->set('path_allowlist', $form_state->getValue('path_allowlist')) ->save(); - \Drupal::messenger()->addMessage($this->t('Successfully saved the Quant Purger configuration. All content must be re-seeded so the database reflects the changes.')); + \Drupal::messenger()->addMessage($this->t('Successfully saved the Quant Purger Queuer configuration. All content must be re-seeded so the database reflects the changes.')); } /** diff --git a/modules/quant_purger/src/Plugin/Purge/Purger/QuantPurge.php b/modules/quant_purger/src/Plugin/Purge/Purger/QuantPurger.php similarity index 68% rename from modules/quant_purger/src/Plugin/Purge/Purger/QuantPurge.php rename to modules/quant_purger/src/Plugin/Purge/Purger/QuantPurger.php index 19d541e5..aabc227a 100644 --- a/modules/quant_purger/src/Plugin/Purge/Purger/QuantPurge.php +++ b/modules/quant_purger/src/Plugin/Purge/Purger/QuantPurger.php @@ -11,71 +11,75 @@ * * @PurgePurger( * id = "quant_purger", - * label = @Translation("QuantCDN Purger"), - * configform = "\Drupal\quant_purger\Form\QuantPurgeForm", + * label = @Translation("Quant Purger"), + * configform = "\Drupal\quant_purger\Form\QuantPurgerConfigForm", * cooldown_time = 0.2, * description = @Translation("Purger that sends invalidation expressions from your Drupal instance to the QuantCDN platform."), * multi_instance = FALSE, - * types = {"tag", "everything", "path"}, + * types = {"everything", "path", "tag"}, * ) */ -class QuantPurge extends QuantPurgeBase implements PurgerInterface { +class QuantPurger extends QuantPurgerBase implements PurgerInterface { /** * {@inheritdoc} */ public function invalidate(array $invalidations) { - $filtered_validations = $this->processInvalidations($invalidations); + $processed = $this->processInvalidations($invalidations); - if ($filtered_validations['everything']) { + if ($processed['everything']) { $this->invalidateEverything($invalidations); return; } - if (!empty($filtered_validations['tags'])) { - $this->invalidateTags($filtered_validations['tags']); + if (!empty($processed['paths'])) { + $this->invalidatePaths($processed['paths']); } - if (!empty($filtered_validations['paths'])) { - $this->invalidatePaths($filtered_validations['paths']); + if (!empty($processed['tags'])) { + $this->invalidateTags($processed['tags']); } + } /** - * {@inheritdoc} + * Invalidate with the path '/*' to purge the entire project cache. + * + * @param array $invalidations + * This takes in an array of Invalidation objects, processing them all in a + * loop, generally from the purge queue. */ - public function invalidateTags(array $invalidations) { - $tags = []; - foreach ($invalidations as $invalidation) { - $tags[] = Hash::cacheTags([$invalidation->getExpression()])[0]; - } + public function invalidateEverything(array $invalidations) { try { - $this->logger()->debug('[tags] Purging tags: ' . implode(' ', $tags)); - $this->purgeTags($tags); - $invalidation->setState(InvalidationInterface::SUCCEEDED); + $this->logger()->debug('[everything] Purging entire site cache (/*)'); + $this->purgePath('/*'); + foreach ($invalidations as $invalidation) { + $invalidation->setState(InvalidationInterface::SUCCEEDED); + } } catch (\Exception $e) { - $this->logger()->notice('Error attempting to purge cache path: ' . $e->getMessage()); + $this->logger()->notice('Error attempting to purge entire cache: ' . $e->getMessage()); error_log($e->getMessage()); - $invalidation->setState(InvalidationInterface::FAILED); + foreach ($invalidations as $invalidation) { + $invalidation->setState(InvalidationInterface::FAILED); + } } } /** - * Invalidate path-based invalidations in a loop. + * Invalidate path-based invalidations. * * @param array $invalidations - * This takes in an array of Invalidation, processing them all in a loop, - * generally from the purge queue. + * Array of Invalidation objects to process. */ public function invalidatePaths(array $invalidations) { foreach ($invalidations as $invalidation) { try { $path = '/' . $invalidation->getExpression(); - $this->logger()->debug('[path] Purging path invalidation: ' . $path); + $this->logger()->debug('[path] Purging path: ' . $path); $this->purgePath($path); $invalidation->setState(InvalidationInterface::SUCCEEDED); } @@ -88,27 +92,27 @@ public function invalidatePaths(array $invalidations) { } /** - * Invalidate with the path '/*' to purge the entire project cache. + * Invalidate tag-based invalidations. * * @param array $invalidations - * This takes in an array of Invalidation, processing them all in a loop, - * generally from the purge queue. + * Array of Invalidation objects to process. */ - public function invalidateEverything(array $invalidations) { - + public function invalidateTags(array $invalidations) { try { - $this->logger()->debug('[everything] Purging entire site cache (/*)'); - $this->purgePath('/*'); + $this->logger()->debug('[tags] Purging tags: ' . implode(' ', $invalidations)); + + $tags = []; foreach ($invalidations as $invalidation) { - $invalidation->setState(InvalidationInterface::SUCCEEDED); + $tags[] = Hash::cacheTags([$invalidation->getExpression()])[0]; } + + $this->purgeTags($tags); + $invalidation->setState(InvalidationInterface::SUCCEEDED); } catch (\Exception $e) { - $this->logger()->notice('Error attempting to purge entire cache: ' . $e->getMessage()); + $this->logger()->notice('Error attempting to purge cache path: ' . $e->getMessage()); error_log($e->getMessage()); - foreach ($invalidations as $invalidation) { - $invalidation->setState(InvalidationInterface::FAILED); - } + $invalidation->setState(InvalidationInterface::FAILED); } } diff --git a/modules/quant_purger/src/Plugin/Purge/Purger/QuantPurgeBase.php b/modules/quant_purger/src/Plugin/Purge/Purger/QuantPurgerBase.php similarity index 85% rename from modules/quant_purger/src/Plugin/Purge/Purger/QuantPurgeBase.php rename to modules/quant_purger/src/Plugin/Purge/Purger/QuantPurgerBase.php index 4f624df7..bba5f4fa 100644 --- a/modules/quant_purger/src/Plugin/Purge/Purger/QuantPurgeBase.php +++ b/modules/quant_purger/src/Plugin/Purge/Purger/QuantPurgerBase.php @@ -3,17 +3,17 @@ namespace Drupal\quant_purger\Plugin\Purge\Purger; use Drupal\Core\Utility\Token; -use GuzzleHttp\ClientInterface; +use Drupal\purge\Plugin\Purge\Invalidation\InvalidationInterface; use Drupal\purge\Plugin\Purge\Purger\PurgerBase; use Drupal\purge\Plugin\Purge\Purger\PurgerInterface; use Drupal\quant_purger\Entity\QuantPurgerSettings; +use GuzzleHttp\ClientInterface; use Symfony\Component\DependencyInjection\ContainerInterface; -use Drupal\purge\Plugin\Purge\Invalidation\InvalidationInterface; /** - * Abstract base class for HTTP based configurable purgers. + * Abstract base class for Quant Purger. */ -abstract class QuantPurgeBase extends PurgerBase implements PurgerInterface { +abstract class QuantPurgerBase extends PurgerBase implements PurgerInterface { /** * The Guzzle HTTP client. @@ -105,51 +105,49 @@ public function getLabel() { } /** - * Returns array of tags and paths to purge in the provided array. + * Process invalidations based on type. * * @param array $invalidations * The invalidations array. * * @return array - * The array of filtered tags and paths. + * The processed array with 'everything', 'paths' and 'tags' keys. */ public function processInvalidations(array $invalidations) { - $filtered_tags = []; - $filtered_paths = []; - $everything = FALSE; + $paths = []; + $tags = []; foreach ($invalidations as $invalidation) { - if ($invalidation->getType() == 'tag') { + if ($invalidation->getType() == 'everything') { + // 'Everything' trumps everything and will issue a site-wide purge. $invalidation->setState(InvalidationInterface::PROCESSING); - $filtered_tags[] = $invalidation; + $everything = TRUE; + $paths = []; + $tags = []; + break; } elseif ($invalidation->getType() == 'path') { - // @todo Not sure what this looks like. $invalidation->setState(InvalidationInterface::PROCESSING); - $filtered_paths[] = $invalidation; + $paths[] = $invalidation; } - elseif ($invalidation->getType() == 'everything') { - // 'Everything' trumps everything and will issue a site-wide purge. + elseif ($invalidation->getType() == 'tag') { $invalidation->setState(InvalidationInterface::PROCESSING); - $everything = TRUE; - $filtered_paths = []; - $filtered_tags = []; - break; + $tags[] = $invalidation; } else { $invalidation->setState(InvalidationInterface::NOT_SUPPORTED); } } - $filtered_array = [ + $processed = [ 'everything' => $everything, - 'tags' => $filtered_tags, - 'paths' => $filtered_paths, + 'paths' => $paths, + 'tags' => $tags, ]; - return $filtered_array; + return $processed; } /** @@ -170,9 +168,9 @@ public function getTimeHint() { */ public function getTypes() { return [ - "tag", - "everything", - "path", + 'everything', + 'path', + 'tag', ]; } diff --git a/modules/quant_purger/src/Plugin/Purge/Queuer/QuantPurger.php b/modules/quant_purger/src/Plugin/Purge/Queuer/QuantPurger.php index a0182014..41f95648 100644 --- a/modules/quant_purger/src/Plugin/Purge/Queuer/QuantPurger.php +++ b/modules/quant_purger/src/Plugin/Purge/Queuer/QuantPurger.php @@ -44,7 +44,7 @@ class QuantPurger implements CacheTagsInvalidatorInterface, ContainerAwareInterf /** * The queuer plugin or FALSE when the plugin is disabled. * - * @var null|false|\Drupal\quant_purger\Plugin\Purge\Queuer\QuantPurgerPlugin + * @var null|false|\Drupal\quant_purger\Plugin\Purge\Queuer\QuantPurgerQueuer */ protected $queuer; diff --git a/modules/quant_purger/src/Plugin/Purge/Queuer/QuantPurgerPlugin.php b/modules/quant_purger/src/Plugin/Purge/Queuer/QuantPurgerQueuer.php similarity index 54% rename from modules/quant_purger/src/Plugin/Purge/Queuer/QuantPurgerPlugin.php rename to modules/quant_purger/src/Plugin/Purge/Queuer/QuantPurgerQueuer.php index 7ab7e9c2..6aef9c3e 100644 --- a/modules/quant_purger/src/Plugin/Purge/Queuer/QuantPurgerPlugin.php +++ b/modules/quant_purger/src/Plugin/Purge/Queuer/QuantPurgerQueuer.php @@ -6,15 +6,16 @@ use Drupal\purge\Plugin\Purge\Queuer\QueuerInterface; /** - * Quant purger. + * Quant Purger Queuer. * * @PurgeQueuer( * id = "quant", - * label = @Translation("Purge Quant"), + * label = @Translation("Quant Purger Queuer"), * description = @Translation("Queue impacted content updates."), * enable_by_default = true, * types = {"tag"}, - * configform = "\Drupal\quant_purger\Form\ConfigurationForm", + * configform = "\Drupal\quant_purger\Form\QuantPurgerQueuerConfigForm", * ) */ -class QuantPurgerPlugin extends QueuerBase implements QueuerInterface {} +// @todo Change id to 'quant_purger_queuer' which requires an update hook. +class QuantPurgerQueuer extends QueuerBase implements QueuerInterface {} diff --git a/modules/quant_purger/src/Plugin/Purge/TagsHeader/QuantCacheTagsHeader.php b/modules/quant_purger/src/Plugin/Purge/TagsHeader/QuantPurgerTagsHeader.php similarity index 80% rename from modules/quant_purger/src/Plugin/Purge/TagsHeader/QuantCacheTagsHeader.php rename to modules/quant_purger/src/Plugin/Purge/TagsHeader/QuantPurgerTagsHeader.php index b8083bad..e8e2027a 100644 --- a/modules/quant_purger/src/Plugin/Purge/TagsHeader/QuantCacheTagsHeader.php +++ b/modules/quant_purger/src/Plugin/Purge/TagsHeader/QuantPurgerTagsHeader.php @@ -2,19 +2,19 @@ namespace Drupal\quant_purger\Plugin\Purge\TagsHeader; -use Drupal\quant_purger\Entity\Hash; -use Drupal\purge\Plugin\Purge\TagsHeader\TagsHeaderInterface; use Drupal\purge\Plugin\Purge\TagsHeader\TagsHeaderBase; +use Drupal\purge\Plugin\Purge\TagsHeader\TagsHeaderInterface; +use Drupal\quant_purger\Entity\Hash; /** * Sets and formats the default response header with cache tags. * * @PurgeTagsHeader( - * id = "quant_tagsheader", + * id = "quant_purger_tags_header", * header_name = "Cache-Keys", * ) */ -class QuantCacheTagsHeader extends TagsHeaderBase implements TagsHeaderInterface { +class QuantPurgerTagsHeader extends TagsHeaderBase implements TagsHeaderInterface { /** * {@inheritdoc}