Skip to content

Commit

Permalink
Fix linting.
Browse files Browse the repository at this point in the history
  • Loading branch information
kepol committed Jun 11, 2024
1 parent 6b5d3e6 commit 5c22663
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 73 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# QuantCDN Drupal module

This module acts as a static site generator for Drupal and integrates with the [QuantCDN static edge](https://www.quantcdn.io), and is compatible with Drupal 9.x and 10.x.
This module acts as a static site generator for Drupal and integrates with the
[QuantCDN static edge](https://www.quantcdn.io), and is compatible with Drupal
9.x and 10.x.

QuantCDN is a global CDN engineered specifically for the static web and Jamstack.
QuantCDN is a global CDN engineered specifically for the static web and
Jamstack.

It allows one-time compilation and push of an entire Drupal site, as well as tracking and pushes of ongoing content change; the simplest way to export and maintain a static export of your Drupal site.
It allows one-time compilation and push of an entire Drupal site, as well as
tracking and pushes of ongoing content change; the simplest way to export and
maintain a static export of your Drupal site.

Development, issues and feature roadmap occurs in the [GitHub repository](https://github.com/quantcdn/drupal).

Expand Down
32 changes: 16 additions & 16 deletions modules/quant_api/src/Client/QuantClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,14 @@ public function search() {
*/
public function purgePath(string $path) : array {
$response = $this->client->post($this->endpoint . '/purge', [
RequestOptions::JSON => [],
'headers' => [
'Quant-Customer' => $this->username,
'Quant-Project' => $this->project,
'Quant-Token' => $this->token,
'Quant-Url' => $path,
],
'verify' => $this->tlsDisabled ? FALSE : TRUE,
RequestOptions::JSON => [],
'headers' => [
'Quant-Customer' => $this->username,
'Quant-Project' => $this->project,
'Quant-Token' => $this->token,
'Quant-Url' => $path,
],
'verify' => $this->tlsDisabled ? FALSE : TRUE,
]);

return json_decode($response->getBody(), TRUE);
Expand All @@ -255,14 +255,14 @@ public function purgePath(string $path) : array {
public function purgeTags(array $tags) : array {

$response = $this->client->post($this->endpoint . '/purge', [
RequestOptions::JSON => [],
'headers' => [
'Quant-Customer' => $this->username,
'Quant-Project' => $this->project,
'Quant-Token' => $this->token,
'Cache-Keys' => implode(' ', $tags),
],
'verify' => $this->tlsDisabled ? FALSE : TRUE,
RequestOptions::JSON => [],
'headers' => [
'Quant-Customer' => $this->username,
'Quant-Project' => $this->project,
'Quant-Token' => $this->token,
'Cache-Keys' => implode(' ', $tags),
],
'verify' => $this->tlsDisabled ? FALSE : TRUE,
]);

return json_decode($response->getBody(), TRUE);
Expand Down
2 changes: 1 addition & 1 deletion modules/quant_purger/src/Form/QuantPurgeFormBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function buildFormMetadata(array &$form, FormStateInterface $form_state,
* An associative array containing the structure of the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
* @param \Drupal\quant_purger\Entity\QuantPurgeSettingsPurgeSettings $settings
* @param \Drupal\quant_purger\Entity\QuantPurgeSettings $settings
* Configuration entity for the purger being configured.
*/
public function buildFormPerformance(array &$form, FormStateInterface $form_state, QuantPurgeSettings $settings) {
Expand Down
77 changes: 34 additions & 43 deletions modules/quant_purger/src/Plugin/Purge/Purger/QuantPurge.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,49 +29,42 @@ public function invalidate(array $invalidations) {
$filtered_validations = $this->processInvalidations($invalidations);

if ($filtered_validations['everything']) {
$this->invalidateEverything($invalidations);
return;
$this->invalidateEverything($invalidations);
return;
}

if (!empty($filtered_validations['tags'])) {
$this->invalidateTags($filtered_validations['tags']);
$this->invalidateTags($filtered_validations['tags']);
}

if (!empty($filtered_validations['paths'])) {
$this->invalidatePaths($filtered_validations['paths']);
$this->invalidatePaths($filtered_validations['paths']);
}
}


/**
* {@inheritdoc}
*/
public function invalidateTags(array $invalidations) {
$tags = [];
foreach ($invalidations as $invalidation) {
$tags[] = Hash::cacheTags([$invalidation->getExpression()])[0];
$tags[] = Hash::cacheTags([$invalidation->getExpression()])[0];
}

try {
$this->logger()->debug('[tags] Purging tags: ' . implode(' ', $tags));
$this->purgeTags($tags);
$invalidation->setState(InvalidationInterface::SUCCEEDED);
$this->logger()->debug('[tags] Purging tags: ' . implode(' ', $tags));
$this->purgeTags($tags);
$invalidation->setState(InvalidationInterface::SUCCEEDED);
}
catch (\Exception $e) {
$this->logger()->notice('Error attempting to purge cache path: ' . $e->getMessage());
error_log($e->getMessage());
$invalidation->setState(InvalidationInterface::FAILED);
$this->logger()->notice('Error attempting to purge cache path: ' . $e->getMessage());
error_log($e->getMessage());
$invalidation->setState(InvalidationInterface::FAILED);
}




}

/**
* InvalidatePaths
*
* This will invalidate path based invalidations in a loop.
* Invalidate path-based invalidations in a loop.
*
* @param array $invalidations
* This takes in an array of Invalidation, processing them all in a loop,
Expand All @@ -80,24 +73,22 @@ public function invalidateTags(array $invalidations) {
public function invalidatePaths(array $invalidations) {

foreach ($invalidations as $invalidation) {
try {
$path = '/' . $invalidation->getExpression();
$this->logger()->debug('[path] Purging path invalidation: ' . $path);
$this->purgePath($path);
$invalidation->setState(InvalidationInterface::SUCCEEDED);
}
catch (\Exception $e) {
$this->logger()->notice('Error attempting to purge cache path: ' . $e->getMessage());
error_log($e->getMessage());
$invalidation->setState(InvalidationInterface::FAILED);
}
try {
$path = '/' . $invalidation->getExpression();
$this->logger()->debug('[path] Purging path invalidation: ' . $path);
$this->purgePath($path);
$invalidation->setState(InvalidationInterface::SUCCEEDED);
}
catch (\Exception $e) {
$this->logger()->notice('Error attempting to purge cache path: ' . $e->getMessage());
error_log($e->getMessage());
$invalidation->setState(InvalidationInterface::FAILED);
}
}
}

/**
* InvalidateEverything.
*
* This will invalidate with the path '/*' to purge the entire project cache.
* Invalidate with the path '/*' to purge the entire project cache.
*
* @param array $invalidations
* This takes in an array of Invalidation, processing them all in a loop,
Expand All @@ -106,18 +97,18 @@ public function invalidatePaths(array $invalidations) {
public function invalidateEverything(array $invalidations) {

try {
$this->logger()->debug('[everything] Purging entire site cache (/*)');
$this->purgePath('/*');
foreach ($invalidations as $invalidation) {
$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 entire cache: ' . $e->getMessage());
error_log($e->getMessage());
foreach ($invalidations as $invalidation) {
$invalidation->setState(InvalidationInterface::FAILED);
}
$this->logger()->notice('Error attempting to purge entire cache: ' . $e->getMessage());
error_log($e->getMessage());
foreach ($invalidations as $invalidation) {
$invalidation->setState(InvalidationInterface::FAILED);
}
}
}

Expand Down
21 changes: 11 additions & 10 deletions modules/quant_purger/src/Plugin/Purge/Purger/QuantPurgeBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ abstract class QuantPurgeBase extends PurgerBase implements PurgerInterface {
public function __construct(array $configuration, $plugin_id, $plugin_definition, ClientInterface $http_client, Token $token) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->settings = QuantPurgeSettings::load($this->getId());
// Note: We actually use the Quant HTTP client rather than the generic Guzzle client.
// Note: We use the Quant HTTP client rather than the generic Guzzle client.
$this->client = \Drupal::service('quant_api.client');
$this->token = $token;
}
Expand Down Expand Up @@ -116,28 +116,29 @@ public function getLabel() {
* The invalidations array.
*
* @return array
* The array of filtered tags and paths.
*/
public function processInvalidations(array $invalidations) {
$filtered_tags = [];
$filtered_paths = [];

$everything = false;
$everything = FALSE;

foreach($invalidations as $invalidation) {
foreach ($invalidations as $invalidation) {

if ($invalidation->getType() == 'tag') {
$invalidation->setState(InvalidationInterface::PROCESSING);
$filtered_tags[] = $invalidation;
}
elseif ($invalidation->getType() == 'path') {
// @todo: dunno what this looks like
// @todo Not sure what this looks like.
$invalidation->setState(InvalidationInterface::PROCESSING);
$filtered_paths[] = $invalidation;
}
elseif ($invalidation->getType() == 'everything') {
// 'Everything' trumps everything and will issue a site-wide purge.
$invalidation->setState(InvalidationInterface::PROCESSING);
$everything = true;
$everything = TRUE;
$filtered_paths = [];
$filtered_tags = [];
break;
Expand All @@ -148,9 +149,9 @@ public function processInvalidations(array $invalidations) {
}

$filtered_array = [
'everything' => $everything,
'tags' => $filtered_tags,
'paths' => $filtered_paths,
'everything' => $everything,
'tags' => $filtered_tags,
'paths' => $filtered_paths,
];

return $filtered_array;
Expand Down Expand Up @@ -193,7 +194,7 @@ public function hasRuntimeMeasurement() {
* @param string $path
* The path to purge.
*/
public function purgePath($path) {
public function purgePath(string $path) {
$this->client->purgePath($path);
}

Expand All @@ -203,7 +204,7 @@ public function purgePath($path) {
* @param array $tags
* The array of tags to purge.
*/
public function purgeTags($tags) {
public function purgeTags(array $tags) {
$this->client->purgeTags($tags);
}

Expand Down

0 comments on commit 5c22663

Please sign in to comment.