From 74460fc6d13a19c636d7527b0dc9be2bfe6b937b Mon Sep 17 00:00:00 2001 From: steveworley Date: Sun, 27 Sep 2020 13:29:48 +1000 Subject: [PATCH 01/11] Support binary file routes. --- src/Event/CollectRoutesEvent.php | 38 ++++++++++++++++++-- src/Event/QuantCollectionEvents.php | 11 ++++++ src/EventSubscriber/CollectionSubscriber.php | 2 +- src/Form/SeedForm.php | 5 +++ src/Seed.php | 36 ++++++++++++++++++- 5 files changed, 88 insertions(+), 4 deletions(-) diff --git a/src/Event/CollectRoutesEvent.php b/src/Event/CollectRoutesEvent.php index 586f77e3..6f224d1e 100644 --- a/src/Event/CollectRoutesEvent.php +++ b/src/Event/CollectRoutesEvent.php @@ -19,12 +19,20 @@ class CollectRoutesEvent extends ConfigFormEventBase { */ protected $routes; + /** + * A list of binary routes. + * + * @var array + */ + protected $binaryRoutes; + /** * {@inheritdoc} */ public function __construct(array $routes = [], FormStateInterface $state = NULL) { parent::__construct($state); $this->routes = $routes; + $this->binaryRoutes = []; } /** @@ -43,7 +51,8 @@ public function getSetting($key) { * @var string $route * The entity object. * - * @return self + * @return Drupal\quant\Event\CollectRoutesEvent + * The route collection event. */ public function addRoute($route) { $this->routes[] = $route; @@ -51,12 +60,37 @@ public function addRoute($route) { } /** - * Get an entity from the evetn. + * Add a route as a binary file. + * + * @var string $route + * The route to retrieve. + * + * @return Drupal\quant\Event\CollectRoutesEvent + * The route collection event. + */ + public function addBinaryRoute($route) { + $this->binaryRoutes[] = $route; + return $this; + } + + /** + * Get an route from the event. * * @return string + * A route. */ public function getRoute() { return array_shift($this->routes); } + /** + * Get a binary route from the event. + * + * @return string + * A route. + */ + public function getBinaryRoute() { + return array_shift($this->binaryRoutes); + } + } diff --git a/src/Event/QuantCollectionEvents.php b/src/Event/QuantCollectionEvents.php index c3d6e409..3e5ffac1 100644 --- a/src/Event/QuantCollectionEvents.php +++ b/src/Event/QuantCollectionEvents.php @@ -51,4 +51,15 @@ final class QuantCollectionEvents { */ const ROUTES = 'quant.seed.routes'; + /** + * Name of the event when collecting the routes to push as files. + * + * @Event + * + * @see Drupal\quant\Event\CollectRoutesEvent + * + * @var string + */ + const BINARY_ROUTES = 'quant.seed.binary_routes'; + } diff --git a/src/EventSubscriber/CollectionSubscriber.php b/src/EventSubscriber/CollectionSubscriber.php index 6c30df76..b9a6c358 100644 --- a/src/EventSubscriber/CollectionSubscriber.php +++ b/src/EventSubscriber/CollectionSubscriber.php @@ -215,7 +215,7 @@ public function collectRoutes(CollectRoutesEvent $event) { } if ($event->getFormState()->getValue('robots')) { - $event->addRoute('/robots.txt'); + $event->addBinaryRoute('/robots.txt'); } if ($event->getFormState()->getValue('views_pages')) { diff --git a/src/Form/SeedForm.php b/src/Form/SeedForm.php index 4d2cbab4..ca5db87b 100644 --- a/src/Form/SeedForm.php +++ b/src/Form/SeedForm.php @@ -295,9 +295,14 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $event = new CollectRoutesEvent($routes, $form_state); $this->dispatcher->dispatch(QuantCollectionEvents::ROUTES, $event); + $this->dispatcher->dispatch(QuantCollectionEvents::BINARY_ROUTES, $event); + while ($route = $event->getRoute()) { $batch['operations'][] = ['\Drupal\quant\Seed::exportRoute', [$route]]; } + while ($bin_route = $event->getBinaryRoute()) { + $batch['operations'][] = ['\Drupal\quant\Seed::exportBinaryRoute', [$bin_route]]; + } $event = new CollectFilesEvent($assets, $form_state); $this->dispatcher->dispatch(QuantCollectionEvents::FILES, $event); diff --git a/src/Seed.php b/src/Seed.php index c2ceb007..36ed8b01 100644 --- a/src/Seed.php +++ b/src/Seed.php @@ -8,7 +8,8 @@ use Drupal\quant\Event\QuantRedirectEvent; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Url; - +use Drupal\Core\File\Exception\FileException; +use Drupal\Core\File\FileSystemInterface; /** * Seed Manager. @@ -86,6 +87,39 @@ public static function exportRoute($route, &$context) { $context['results'][] = $route; } + /** + * Trigger an export for an arbitrary route. + * + * @param string $route + * The route. + * @param array &$context + * The batch context. + */ + public function exportBinaryFile($route, array &$context) { + $config = \Drupal::config('quant.settings'); + $host = $config->get('local_server') ?: 'http://localhost'; + $route = '/' . ltrim($route, '/'); + + $file_data = @file_get_contents("$host$route"); + if (empty($file_data)) { + return; + } + + try { + // Can't use file_save_data until core patch. + // @see https://www.drupal.org/project/drupal/issues/1659116 + $uri = \Drupal::service('file_system')->saveData($file_data, "temporary://", FileSystemInterface::EXISTS_RENAME); + } catch (FileException $error) { + return; + } + + $event = new QuantFileEvent($uri, $route); + \Drupal::service('event_dispatcher')->dispatch(QuantFileEvent::OUTPUT, $event); + + $context['message'] = "Processing binary route: $route"; + $context['results'][] = [$route]; + } + /** * Trigger export file via event dispatcher. */ From b564c9c404b492148230cb764877efbd95708ef7 Mon Sep 17 00:00:00 2001 From: steveworley Date: Sun, 27 Sep 2020 13:35:32 +1000 Subject: [PATCH 02/11] Add file route export to seed form. --- src/Event/CollectRoutesEvent.php | 4 ++-- src/Form/SeedForm.php | 25 +++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/Event/CollectRoutesEvent.php b/src/Event/CollectRoutesEvent.php index 6f224d1e..9797e498 100644 --- a/src/Event/CollectRoutesEvent.php +++ b/src/Event/CollectRoutesEvent.php @@ -29,10 +29,10 @@ class CollectRoutesEvent extends ConfigFormEventBase { /** * {@inheritdoc} */ - public function __construct(array $routes = [], FormStateInterface $state = NULL) { + public function __construct(array $routes = [], array $binary_routes = [], FormStateInterface $state = NULL) { parent::__construct($state); $this->routes = $routes; - $this->binaryRoutes = []; + $this->binaryRoutes = $binary_routes; } /** diff --git a/src/Form/SeedForm.php b/src/Form/SeedForm.php index ca5db87b..96c6e387 100644 --- a/src/Form/SeedForm.php +++ b/src/Form/SeedForm.php @@ -199,6 +199,18 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#default_value' => $config->get('routes_export', ''), ]; + $form['binary_routes_textarea'] = [ + '#type' => 'textarea', + '#title' => $this->t('File Routes'), + '#description' => $this->t('Add file routes to export, each on a new line.'), + '#states' => [ + 'visible' => [ + ':input[name="routes"]' => ['checked' => TRUE], + ], + ], + '#default_value' => $config->get('binary_routes_export', ''), + ]; + $form['robots'] = [ '#type' => 'checkbox', '#title' => $this->t('Robots.txt'), @@ -246,6 +258,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $assets = []; $routes = []; + $binary_routes = []; $redirects = []; // Lunr. @@ -261,11 +274,19 @@ public function submitForm(array &$form, FormStateInterface $form_state) { if (strpos((trim($route)), '/') !== 0) { continue; } - $routes[] = trim($route); } } + if ($form_state->getValue('binary_routes_textarea')) { + foreach (explode(PHP_EOL, $form_state->getValue('binary_routes_textarea')) as $route) { + if (strpos((trim($route)), '/') !== 0) { + continue; + } + $binary_routes[] = trim($route); + } + } + $batch = [ 'title' => t('Exporting to Quant...'), 'operations' => [], @@ -293,7 +314,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { } } - $event = new CollectRoutesEvent($routes, $form_state); + $event = new CollectRoutesEvent($routes, $binary_routes, $form_state); $this->dispatcher->dispatch(QuantCollectionEvents::ROUTES, $event); $this->dispatcher->dispatch(QuantCollectionEvents::BINARY_ROUTES, $event); From 412dc4df74f55cd27fb1f633801c755f49992bee Mon Sep 17 00:00:00 2001 From: steveworley Date: Mon, 5 Oct 2020 21:20:53 +1000 Subject: [PATCH 03/11] Update to export content_type from requested asset. --- .../src/EventSubscriber/QuantApi.php | 4 ++ quant.services.yml | 3 + src/Event/CollectRoutesEvent.php | 3 +- src/Event/QuantCollectionEvents.php | 11 ---- src/EventSubscriber/CollectionSubscriber.php | 2 +- src/Form/SeedForm.php | 28 +--------- src/Seed.php | 34 +----------- src/Service/MimeType.php | 55 +++++++++++++++++++ 8 files changed, 66 insertions(+), 74 deletions(-) create mode 100644 src/Service/MimeType.php diff --git a/modules/quant_api/src/EventSubscriber/QuantApi.php b/modules/quant_api/src/EventSubscriber/QuantApi.php index c819732d..d6ea55a0 100644 --- a/modules/quant_api/src/EventSubscriber/QuantApi.php +++ b/modules/quant_api/src/EventSubscriber/QuantApi.php @@ -114,6 +114,10 @@ public function onOutput(QuantEvent $event) { 'proxy_override' => $meta['proxy_override'], ]; + if (isset($meta['content_type'])) { + $data['headers']['content_type'] = $meta['content_type']; + } + if (!empty($rid = $event->getRevisionId())) { $data['revision'] = $rid; } diff --git a/quant.services.yml b/quant.services.yml index 854fa323..eabe47c1 100644 --- a/quant.services.yml +++ b/quant.services.yml @@ -28,3 +28,6 @@ services: arguments: - '@database' - '@request_stack' + + quant.mime_type: + class: Drupal\quant\Service\MimeType diff --git a/src/Event/CollectRoutesEvent.php b/src/Event/CollectRoutesEvent.php index 9797e498..66389742 100644 --- a/src/Event/CollectRoutesEvent.php +++ b/src/Event/CollectRoutesEvent.php @@ -29,10 +29,9 @@ class CollectRoutesEvent extends ConfigFormEventBase { /** * {@inheritdoc} */ - public function __construct(array $routes = [], array $binary_routes = [], FormStateInterface $state = NULL) { + public function __construct(array $routes = [], FormStateInterface $state = NULL) { parent::__construct($state); $this->routes = $routes; - $this->binaryRoutes = $binary_routes; } /** diff --git a/src/Event/QuantCollectionEvents.php b/src/Event/QuantCollectionEvents.php index 3e5ffac1..c3d6e409 100644 --- a/src/Event/QuantCollectionEvents.php +++ b/src/Event/QuantCollectionEvents.php @@ -51,15 +51,4 @@ final class QuantCollectionEvents { */ const ROUTES = 'quant.seed.routes'; - /** - * Name of the event when collecting the routes to push as files. - * - * @Event - * - * @see Drupal\quant\Event\CollectRoutesEvent - * - * @var string - */ - const BINARY_ROUTES = 'quant.seed.binary_routes'; - } diff --git a/src/EventSubscriber/CollectionSubscriber.php b/src/EventSubscriber/CollectionSubscriber.php index b9a6c358..6c30df76 100644 --- a/src/EventSubscriber/CollectionSubscriber.php +++ b/src/EventSubscriber/CollectionSubscriber.php @@ -215,7 +215,7 @@ public function collectRoutes(CollectRoutesEvent $event) { } if ($event->getFormState()->getValue('robots')) { - $event->addBinaryRoute('/robots.txt'); + $event->addRoute('/robots.txt'); } if ($event->getFormState()->getValue('views_pages')) { diff --git a/src/Form/SeedForm.php b/src/Form/SeedForm.php index 96c6e387..fb1c93c2 100644 --- a/src/Form/SeedForm.php +++ b/src/Form/SeedForm.php @@ -199,18 +199,6 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#default_value' => $config->get('routes_export', ''), ]; - $form['binary_routes_textarea'] = [ - '#type' => 'textarea', - '#title' => $this->t('File Routes'), - '#description' => $this->t('Add file routes to export, each on a new line.'), - '#states' => [ - 'visible' => [ - ':input[name="routes"]' => ['checked' => TRUE], - ], - ], - '#default_value' => $config->get('binary_routes_export', ''), - ]; - $form['robots'] = [ '#type' => 'checkbox', '#title' => $this->t('Robots.txt'), @@ -258,7 +246,6 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $assets = []; $routes = []; - $binary_routes = []; $redirects = []; // Lunr. @@ -278,15 +265,6 @@ public function submitForm(array &$form, FormStateInterface $form_state) { } } - if ($form_state->getValue('binary_routes_textarea')) { - foreach (explode(PHP_EOL, $form_state->getValue('binary_routes_textarea')) as $route) { - if (strpos((trim($route)), '/') !== 0) { - continue; - } - $binary_routes[] = trim($route); - } - } - $batch = [ 'title' => t('Exporting to Quant...'), 'operations' => [], @@ -314,16 +292,12 @@ public function submitForm(array &$form, FormStateInterface $form_state) { } } - $event = new CollectRoutesEvent($routes, $binary_routes, $form_state); + $event = new CollectRoutesEvent($routes, $form_state); $this->dispatcher->dispatch(QuantCollectionEvents::ROUTES, $event); - $this->dispatcher->dispatch(QuantCollectionEvents::BINARY_ROUTES, $event); while ($route = $event->getRoute()) { $batch['operations'][] = ['\Drupal\quant\Seed::exportRoute', [$route]]; } - while ($bin_route = $event->getBinaryRoute()) { - $batch['operations'][] = ['\Drupal\quant\Seed::exportBinaryRoute', [$bin_route]]; - } $event = new CollectFilesEvent($assets, $form_state); $this->dispatcher->dispatch(QuantCollectionEvents::FILES, $event); diff --git a/src/Seed.php b/src/Seed.php index 36ed8b01..c7154e55 100644 --- a/src/Seed.php +++ b/src/Seed.php @@ -79,6 +79,7 @@ public static function exportRoute($route, &$context) { 'transitions' => [], 'proxy_override' => $proxy_override, 'content_timestamp' => time(), + 'content_type' => \Drupal::service('quant.mime_type')->get($route), ]; \Drupal::service('event_dispatcher')->dispatch(QuantEvent::OUTPUT, new QuantEvent($markup, $route, $meta)); @@ -87,39 +88,6 @@ public static function exportRoute($route, &$context) { $context['results'][] = $route; } - /** - * Trigger an export for an arbitrary route. - * - * @param string $route - * The route. - * @param array &$context - * The batch context. - */ - public function exportBinaryFile($route, array &$context) { - $config = \Drupal::config('quant.settings'); - $host = $config->get('local_server') ?: 'http://localhost'; - $route = '/' . ltrim($route, '/'); - - $file_data = @file_get_contents("$host$route"); - if (empty($file_data)) { - return; - } - - try { - // Can't use file_save_data until core patch. - // @see https://www.drupal.org/project/drupal/issues/1659116 - $uri = \Drupal::service('file_system')->saveData($file_data, "temporary://", FileSystemInterface::EXISTS_RENAME); - } catch (FileException $error) { - return; - } - - $event = new QuantFileEvent($uri, $route); - \Drupal::service('event_dispatcher')->dispatch(QuantFileEvent::OUTPUT, $event); - - $context['message'] = "Processing binary route: $route"; - $context['results'][] = [$route]; - } - /** * Trigger export file via event dispatcher. */ diff --git a/src/Service/MimeType.php b/src/Service/MimeType.php new file mode 100644 index 00000000..0cb5aeb7 --- /dev/null +++ b/src/Service/MimeType.php @@ -0,0 +1,55 @@ + Date: Tue, 6 Oct 2020 19:38:56 +1000 Subject: [PATCH 04/11] Header support and content type. --- quant.services.yml | 3 -- src/Event/CollectRoutesEvent.php | 31 ------------------ src/Seed.php | 38 ++++++++++++++-------- src/Service/MimeType.php | 55 -------------------------------- 4 files changed, 24 insertions(+), 103 deletions(-) delete mode 100644 src/Service/MimeType.php diff --git a/quant.services.yml b/quant.services.yml index eabe47c1..854fa323 100644 --- a/quant.services.yml +++ b/quant.services.yml @@ -28,6 +28,3 @@ services: arguments: - '@database' - '@request_stack' - - quant.mime_type: - class: Drupal\quant\Service\MimeType diff --git a/src/Event/CollectRoutesEvent.php b/src/Event/CollectRoutesEvent.php index 66389742..c71eda33 100644 --- a/src/Event/CollectRoutesEvent.php +++ b/src/Event/CollectRoutesEvent.php @@ -19,13 +19,6 @@ class CollectRoutesEvent extends ConfigFormEventBase { */ protected $routes; - /** - * A list of binary routes. - * - * @var array - */ - protected $binaryRoutes; - /** * {@inheritdoc} */ @@ -58,20 +51,6 @@ public function addRoute($route) { return $this; } - /** - * Add a route as a binary file. - * - * @var string $route - * The route to retrieve. - * - * @return Drupal\quant\Event\CollectRoutesEvent - * The route collection event. - */ - public function addBinaryRoute($route) { - $this->binaryRoutes[] = $route; - return $this; - } - /** * Get an route from the event. * @@ -82,14 +61,4 @@ public function getRoute() { return array_shift($this->routes); } - /** - * Get a binary route from the event. - * - * @return string - * A route. - */ - public function getBinaryRoute() { - return array_shift($this->binaryRoutes); - } - } diff --git a/src/Seed.php b/src/Seed.php index c7154e55..c1f74fea 100644 --- a/src/Seed.php +++ b/src/Seed.php @@ -60,13 +60,14 @@ public static function exportRedirect($redirect, &$context) { */ public static function exportRoute($route, &$context) { $message = "Processing route: {$route}"; + $response = self::markupFromRoute($route); - $markup = self::markupFromRoute($route); - - if (empty($markup)) { + if (empty($response)) { return; } + list($markup, $content_type) = $response; + $config = \Drupal::config('quant.settings'); $proxy_override = boolval($config->get('proxy_override', false)); @@ -79,7 +80,7 @@ public static function exportRoute($route, &$context) { 'transitions' => [], 'proxy_override' => $proxy_override, 'content_timestamp' => time(), - 'content_type' => \Drupal::service('quant.mime_type')->get($route), + 'content_type' => $content_type, ]; \Drupal::service('event_dispatcher')->dispatch(QuantEvent::OUTPUT, new QuantEvent($markup, $route, $meta)); @@ -197,12 +198,16 @@ public static function seedTaxonomyTerm($entity, $langcode=NULL) { } $url = Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $tid], $options)->toString(); - $markup = self::markupFromRoute($url); + $response = self::markupFromRoute($url); + if (empty($response)) { + return; + } $meta = []; + list($markup, $content_type) = $response; - if (empty($markup)) { - return; + if (!empty($content_type)) { + $meta['content_type'] = $content_type; } $metaManager = \Drupal::service('plugin.manager.quant.metadata'); @@ -248,16 +253,20 @@ public static function seedNode($entity, $langcode=NULL) { // Generate a request token. $token = \Drupal::service('quant.token_manager')->create($nid); - $markup = self::markupFromRoute($url, [ + $response = self::markupFromRoute($url, [ 'quant-revision' => $rid, 'quant-token' => $token, ]); $meta = []; - - if (empty($markup)) { + if (empty($response)) { return; } + list($markup, $content_type) = $response; + + if (!empty($content_type)) { + $meta['content_type'] = $content_type; + } $metaManager = \Drupal::service('plugin.manager.quant.metadata'); foreach ($metaManager->getDefinitions() as $pid => $def) { @@ -345,27 +354,28 @@ protected static function markupFromRoute($route, array $headers = []) { 'allow_redirects' => FALSE, ]); - $markup = ''; + $markup = $content_type = ''; + + $response->getHeader('content-type'); if ($response->getStatusCode() == 301 || $response->getStatusCode() == 302) { $destination = reset($response->getHeader('Location')); - // Ensure relative for internal redirect. $destination = self::rewriteRelative($destination); - \Drupal::service('event_dispatcher')->dispatch(QuantRedirectEvent::UPDATE, new QuantRedirectEvent($route, $destination, $response->getStatusCode())); return FALSE; } if ($response->getStatusCode() == 200) { $markup = $response->getBody(); + $content_type = $response->getHeader('content-type'); } else { $messenger = \Drupal::messenger(); $messenger->addMessage("Non-200 response for {$route}: " . $response->getStatusCode(), $messenger::TYPE_WARNING); } - return $markup; + return [$markup, $content_type]; } diff --git a/src/Service/MimeType.php b/src/Service/MimeType.php deleted file mode 100644 index 0cb5aeb7..00000000 --- a/src/Service/MimeType.php +++ /dev/null @@ -1,55 +0,0 @@ - Date: Thu, 8 Oct 2020 16:31:08 +1000 Subject: [PATCH 05/11] Update redirect support. --- src/Seed.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Seed.php b/src/Seed.php index c1f74fea..0d5d4fe2 100644 --- a/src/Seed.php +++ b/src/Seed.php @@ -173,6 +173,12 @@ public static function seedRedirect($redirect) { $source = $redirect->getSourcePathWithQuery(); $destination = $redirect->getRedirectUrl()->toString(); $statusCode = $redirect->getStatusCode(); + + if (!(bool) $statusCode && !$redirect->isNew()) { + \Drupal::service('event_dispatcher')->dispatch(QuantEvent::UNPUBLISH, new QuantEvent('', $source, [], NULL)); + return; + } + \Drupal::service('event_dispatcher')->dispatch(QuantRedirectEvent::UPDATE, new QuantRedirectEvent($source, $destination, $statusCode)); } @@ -181,7 +187,6 @@ public static function seedRedirect($redirect) { */ public static function deleteRedirect($redirect) { $source = $redirect->getSourcePathWithQuery(); - $destination = $redirect->getRedirectUrl()->toString(); \Drupal::service('event_dispatcher')->dispatch(QuantEvent::UNPUBLISH, new QuantEvent('', $source, [], NULL)); } From d936db5ff0d195b2b9e52b40b20ab30a804cde94 Mon Sep 17 00:00:00 2001 From: steveworley Date: Sun, 11 Oct 2020 18:31:04 +1000 Subject: [PATCH 06/11] Info.log. --- info.log | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 info.log diff --git a/info.log b/info.log new file mode 100644 index 00000000..e69de29b From d597fb1b125698b863b196c691b85148c458e9e0 Mon Sep 17 00:00:00 2001 From: steveworley Date: Sun, 11 Oct 2020 19:03:48 +1000 Subject: [PATCH 07/11] Code standards. --- modules/quant_api/src/Client/QuantClient.php | 9 +++--- .../src/EventSubscriber/QuantApi.php | 18 ++++++----- modules/quant_api/src/Form/SettingsForm.php | 3 +- .../tests/src/Unit/QuantClientTest.php | 21 ++++++++---- modules/quant_cron/quant_cron.module | 8 +++++ .../quant_cron/src/Form/CronSettingsForm.php | 8 ++--- modules/quant_sitemap/quant_sitemap.module | 1 + .../EventSubscriber/CollectionSubscriber.php | 4 ++- quant.install | 2 -- quant.module | 32 +++++++++---------- src/Controller/QuantNodeViewController.php | 6 ++++ src/Event/CollectEntitiesEvent.php | 8 ++--- src/Event/CollectFilesEvent.php | 4 ++- src/Event/CollectRedirectsEvent.php | 2 ++ src/Event/NodeInsertEvent.php | 8 +++-- src/EventSubscriber/CollectionSubscriber.php | 2 ++ src/EventSubscriber/NodeInsertSubscriber.php | 2 +- src/Form/MetadataConfigForm.php | 7 ++++ src/Form/SeedForm.php | 11 ++++--- src/Plugin/Quant/Metadata/ProxyOverride.php | 10 +++--- src/Plugin/Quant/Metadata/Published.php | 10 +++--- .../Quant/Metadata/PublishedRevision.php | 4 ++- src/Plugin/QuantMetadataManager.php | 2 +- src/Seed.php | 24 ++++++++------ src/TokenManager.php | 4 ++- 25 files changed, 134 insertions(+), 76 deletions(-) diff --git a/modules/quant_api/src/Client/QuantClient.php b/modules/quant_api/src/Client/QuantClient.php index 8d408809..1f069c02 100644 --- a/modules/quant_api/src/Client/QuantClient.php +++ b/modules/quant_api/src/Client/QuantClient.php @@ -2,6 +2,7 @@ namespace Drupal\quant_api\Client; +use Psr7\MultipartStream; use Drupal\Core\Config\ConfigFactoryInterface; use GuzzleHttp\Client; use GuzzleHttp\RequestOptions; @@ -12,7 +13,7 @@ use GuzzleHttp\Psr7\Request; /** - * + * Quant API client. */ class QuantClient implements QuantClientInterface { @@ -82,7 +83,7 @@ public function ping() { ]); } catch (RequestException $e) { - \Drupal::messenger()->addError(t($e->getMessage())); + \Drupal::messenger()->addError($e->getMessage()); return FALSE; } @@ -150,7 +151,7 @@ public function sendFile(string $file, string $url, int $rid = NULL) : array { 'POST', $this->endpoint, $headers, - new Psr7\MultipartStream([ + new MultipartStream([ [ 'name' => basename($file), 'filename' => basename($file), @@ -180,7 +181,7 @@ public function unpublish(string $url) : array { 'Quant-Customer' => $this->username, 'Quant-Project' => $this->project, 'Quant-Token' => $this->token, - ] + ], ]); return json_decode($response->getBody(), TRUE); diff --git a/modules/quant_api/src/EventSubscriber/QuantApi.php b/modules/quant_api/src/EventSubscriber/QuantApi.php index aac6de18..9de976f1 100644 --- a/modules/quant_api/src/EventSubscriber/QuantApi.php +++ b/modules/quant_api/src/EventSubscriber/QuantApi.php @@ -46,6 +46,10 @@ class QuantApi implements EventSubscriberInterface { * * @param \Drupal\quant_api\Client\QuantClientInterface $client * The Drupal HTTP Client to make requests. + * @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $logger_factory + * The logger channel factory. + * @param \Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher $event_dispatcher + * The event dispatcher. */ public function __construct(QuantClientInterface $client, LoggerChannelFactoryInterface $logger_factory, ContainerAwareEventDispatcher $event_dispatcher) { $this->client = $client; @@ -78,7 +82,7 @@ public function onRedirect(QuantRedirectEvent $event) { $data = [ 'url' => $source, 'redirect_url' => $dest, - 'redirect_http_code' => (int)$statusCode, + 'redirect_http_code' => (int) $statusCode, 'published' => TRUE, ]; @@ -92,7 +96,6 @@ public function onRedirect(QuantRedirectEvent $event) { return $res; } - /** * Trigger an API request with the event data. * @@ -155,9 +158,9 @@ public function onOutput(QuantEvent $event) { if (file_exists(DRUPAL_ROOT . $file)) { $this->eventDispatcher->dispatch(QuantFileEvent::OUTPUT, new QuantFileEvent(DRUPAL_ROOT . $file, $file)); } - else if (strpos($url, '/styles/')) { - // Image style derivative does not exist. - // Quant API returns an expected full_path item which allows for image generation. + elseif (strpos($url, '/styles/')) { + // Image style derivative does not exist. Quant API returns an expected + // full_path item which allows for image generation. if (isset($item['full_path'])) { // Build internal request. $config = \Drupal::config('quant.settings'); @@ -191,8 +194,8 @@ public function onOutput(QuantEvent $event) { /** @var \DOMElement $node */ $pager_operations = []; - // @todo: Make this xpath configurable. - // This supports the use case for core views output (mini and standard pager). + // This supports the use case for core views (mini and standard pager). + // @TODO: selector should be configurable. foreach ($xpath->query('//a[contains(@href,"page=") and (./span[contains(text(), "Next")])]') as $node) { $original_href = $node->getAttribute('href'); if ($original_href[0] === '?') { @@ -218,7 +221,6 @@ public function onOutput(QuantEvent $event) { batch_set($batch); } - // @todo: Report on forms that need proxying (attachments.forms). } diff --git a/modules/quant_api/src/Form/SettingsForm.php b/modules/quant_api/src/Form/SettingsForm.php index be1bc8fc..699025e7 100644 --- a/modules/quant_api/src/Form/SettingsForm.php +++ b/modules/quant_api/src/Form/SettingsForm.php @@ -56,7 +56,8 @@ public function buildForm(array $form, FormStateInterface $form_state) { if ($config->get('api_token')) { if ($project = $this->client->ping()) { - \Drupal::messenger()->addMessage(t('Successfully connected to ' . $config->get('api_project'))); + $message = t('Successfully connected to @api', ['@api' => $config->get('api_project')]); + \Drupal::messenger()->addMessage($message); } else { \Drupal::messenger()->addError(t('Unable to connect to Quant API, check settings.')); diff --git a/modules/quant_api/tests/src/Unit/QuantClientTest.php b/modules/quant_api/tests/src/Unit/QuantClientTest.php index becea901..c31e2547 100644 --- a/modules/quant_api/tests/src/Unit/QuantClientTest.php +++ b/modules/quant_api/tests/src/Unit/QuantClientTest.php @@ -11,7 +11,6 @@ use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\Response; use GuzzleHttp\RequestOptions; -use Drupal\quant_api\Exception\InvalidPayload; /** * Ensure that the client responds correctly. @@ -21,7 +20,8 @@ class QuantClientTest extends UnitTestCase { /** * Get a stubbed config factory. * - * @return ConfigFactoryInterface + * @return \Drupal\Core\Config\ConfigFactoryInterface + * The config interface. */ protected function getConfigStub($default = []) { $value = [ @@ -45,12 +45,13 @@ protected function getConfigStub($default = []) { * Get a successful project response. * * @return GuzzleHttp\Psr7\Response + * A response object. */ protected function getProjectResponse() { // @TODO - should these be fixtures. $body = [ 'project' => 'test', - 'error' => false, + 'error' => FALSE, 'errorMsg' => '', ]; @@ -65,6 +66,7 @@ protected function getProjectResponse() { * A valid redirect response. * * @return GuzzleHttp\Psr7\Response + * A response object. */ protected function getRedirectResponse() { $body = [ @@ -73,7 +75,7 @@ protected function getRedirectResponse() { 'url' => '/a', 'redirect_http_code' => 302, 'errorMsg' => '', - 'error' => false, + 'error' => FALSE, ]; $res = $this->prophesize(Response::class); @@ -87,10 +89,11 @@ protected function getRedirectResponse() { * Get an invalid response. * * @return GuzzleHttp\Psr7\Response + * A response object. */ protected function getInvalidResponse() { $body = [ - 'error' => true, + 'error' => TRUE, 'errorMsg' => 'Error', ]; @@ -239,7 +242,7 @@ public function testSendRedirectValid() { 'url' => '/a', 'redirect_http_code' => 302, 'errorMsg' => '', - 'error' => false, + 'error' => FALSE, ], $redirect); } @@ -272,7 +275,9 @@ public function testSendRedirectError() { * @expectedException Drupal\quant_api\Exception\InvalidPayload */ public function testSendFileFileNoExist() { + // phpcs:ignore global $exists_return; + // phpcs:ignore global $readable_return; $exists_return = FALSE; @@ -290,7 +295,9 @@ public function testSendFileFileNoExist() { * Ensure files are validated before sending. */ public function testSendFileValid() { + // phpcs:ignore global $exists_return; + // phpcs:ignore global $readable_return; $exists_return = TRUE; @@ -332,6 +339,7 @@ public function testSendFileValid() { * Stub file_exists. */ function file_exists($path) { + // phpcs:ignore global $exists_return; if (isset($exists_return)) { return $exists_return; @@ -343,6 +351,7 @@ function file_exists($path) { * Stub is_readable. */ function is_readable($path) { + // phpcs:ignore global $readable_return; if (isset($readable_return)) { return $readable_return; diff --git a/modules/quant_cron/quant_cron.module b/modules/quant_cron/quant_cron.module index 31c5d33e..e9740adb 100644 --- a/modules/quant_cron/quant_cron.module +++ b/modules/quant_cron/quant_cron.module @@ -1,5 +1,10 @@ loadMultiple(); $content_types = []; - foreach($types as $type) { + foreach ($types as $type) { $content_types[$type->id()] = $type->label(); } diff --git a/modules/quant_sitemap/quant_sitemap.module b/modules/quant_sitemap/quant_sitemap.module index 27cd74c7..f8769eb3 100644 --- a/modules/quant_sitemap/quant_sitemap.module +++ b/modules/quant_sitemap/quant_sitemap.module @@ -1,6 +1,7 @@ entityTypeManager; @@ -111,7 +113,7 @@ public function collectRoutes(CollectRoutesEvent $event) { if ($this->moduleHandler->moduleExists('simple_sitemap')) { $items = $this->getSimpleSitemapItems(); } - else if ($this->moduleHandler->moduleExists('xmlsitemap')) { + elseif ($this->moduleHandler->moduleExists('xmlsitemap')) { $items = $this->getXmlsitemapItems(); } diff --git a/quant.install b/quant.install index f0515a8f..8c37be0a 100644 --- a/quant.install +++ b/quant.install @@ -1,7 +1,5 @@ getEntityTypeId()) { + switch ($entity->getEntityTypeId()) { case 'node': Seed::seedNode($entity); - break; + break; + case 'taxonomy_term': Seed::seedTaxonomyTerm($entity); - break; + break; } } @@ -239,14 +239,14 @@ function _quant_entity_update_op($entity) { /** * Entity delete operation hook. * - * Used to trigger an unpublish from the Quant API. - * - * @TODO: Entity support. - * * @param Drupal\Core\Entity\EntityInterface $entity * The entity. + * + * Used to trigger an unpublish from the Quant API. + * + * @TODO: Entity support. */ -function _quant_entity_delete_op($entity) { +function _quant_entity_delete_op(EntityInterface $entity) { if ($entity->getEntityTypeId() != 'node') { return; } diff --git a/src/Controller/QuantNodeViewController.php b/src/Controller/QuantNodeViewController.php index 2bf62939..49a06d7c 100644 --- a/src/Controller/QuantNodeViewController.php +++ b/src/Controller/QuantNodeViewController.php @@ -47,6 +47,12 @@ class QuantNodeViewController extends NodeViewController { * this will be removed before Drupal 9.0.0. * @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository * The entity repository. + * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack + * The request stack. + * @param \Drupal\Core\Routing\CurrentRouteMatch $route_match + * The route matcher. + * @param \Drupal\Core\Session\AccountSwitcherInterface $account_switcher + * The account switcher interface. */ public function __construct(EntityTypeManagerInterface $entity_type_manager, RendererInterface $renderer, AccountInterface $current_user = NULL, EntityRepositoryInterface $entity_repository = NULL, RequestStack $request_stack, CurrentRouteMatch $route_match, AccountSwitcherInterface $account_switcher) { parent::__construct($entity_type_manager, $renderer, $current_user, $entity_repository); diff --git a/src/Event/CollectEntitiesEvent.php b/src/Event/CollectEntitiesEvent.php index c747422c..3ce7ab25 100644 --- a/src/Event/CollectEntitiesEvent.php +++ b/src/Event/CollectEntitiesEvent.php @@ -15,10 +15,6 @@ class CollectEntitiesEvent extends ConfigFormEventBase { /** * A list of entity ids that are to be exported. * - * @TODO: See memory usage by storing a class list - * of all entities. We might need to simplify this - * hash to be [id, type]. - * * @var array */ protected $entities; @@ -59,8 +55,9 @@ public function includeRevisions() { * The language code of the entity. * * @return self + * The class instance. */ - public function addEntity($entity, $langcode=NULL) { + public function addEntity($entity, $langcode = NULL) { $this->entities[] = [ 'entity' => $entity, 'langcode' => $langcode, @@ -73,6 +70,7 @@ public function addEntity($entity, $langcode=NULL) { * Get an entity from the evetn. * * @return mixed + * A single entity. */ public function getEntity() { return array_shift($this->entities); diff --git a/src/Event/CollectFilesEvent.php b/src/Event/CollectFilesEvent.php index 6bb7eae7..496be256 100644 --- a/src/Event/CollectFilesEvent.php +++ b/src/Event/CollectFilesEvent.php @@ -34,6 +34,7 @@ public function __construct(array $filePaths = [], FormStateInterface $state = N * The entity object. * * @return self + * The class instance. */ public function addFilePath($path) { $this->filePaths[] = $path; @@ -41,9 +42,10 @@ public function addFilePath($path) { } /** - * Get an entity from the evetn. + * Get an entity from the event. * * @return mixed + * The next file path. */ public function getFilePath() { return array_shift($this->filePaths); diff --git a/src/Event/CollectRedirectsEvent.php b/src/Event/CollectRedirectsEvent.php index 92c1fb24..f5931ca6 100644 --- a/src/Event/CollectRedirectsEvent.php +++ b/src/Event/CollectRedirectsEvent.php @@ -34,6 +34,7 @@ public function __construct(array $entities = [], FormStateInterface $state = NU * The entity object. * * @return self + * The class instance. */ public function addEntity($entity) { $this->entities[] = $entity; @@ -44,6 +45,7 @@ public function addEntity($entity) { * Get an entity from the evetn. * * @return mixed + * A single entity. */ public function getEntity() { return array_shift($this->entities); diff --git a/src/Event/NodeInsertEvent.php b/src/Event/NodeInsertEvent.php index 39100563..ef6b289f 100644 --- a/src/Event/NodeInsertEvent.php +++ b/src/Event/NodeInsertEvent.php @@ -22,16 +22,19 @@ class NodeInsertEvent extends Event { /** * Language code for export. * - * @var string $langcode + * @var string */ + protected $langcode; /** * Constructs a node insertion demo event object. * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity object. + * @param string $langcode + * A two character langcode. */ - public function __construct(EntityInterface $entity, $langcode=NULL) { + public function __construct(EntityInterface $entity, $langcode = NULL) { $this->entity = $entity; $this->langcode = $langcode; } @@ -50,6 +53,7 @@ public function getEntity() { * Get the language code associated with the event. * * @return string + * The language code for the event. */ public function getLangcode() { return $this->langcode; diff --git a/src/EventSubscriber/CollectionSubscriber.php b/src/EventSubscriber/CollectionSubscriber.php index 1e1c9300..97217cb6 100644 --- a/src/EventSubscriber/CollectionSubscriber.php +++ b/src/EventSubscriber/CollectionSubscriber.php @@ -22,6 +22,8 @@ class CollectionSubscriber implements EventSubscriberInterface { /** * The entity type manager. + * + * @var \Drupal\Core\Entity\EntityTypeManager */ protected $entityTypeManager; diff --git a/src/EventSubscriber/NodeInsertSubscriber.php b/src/EventSubscriber/NodeInsertSubscriber.php index 6e439a39..640fbd82 100644 --- a/src/EventSubscriber/NodeInsertSubscriber.php +++ b/src/EventSubscriber/NodeInsertSubscriber.php @@ -4,7 +4,6 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Drupal\quant\Event\NodeInsertEvent; -use Drupal\quant\EntityRendererInterface; use Drupal\quant\Plugin\QuantMetadataManager; use Drupal\quant\Seed; @@ -27,6 +26,7 @@ public function __construct(QuantMetadataManager $metadata_manager) { * Log the creation of a new node. * * @param \Drupal\quant\Event\NodeInsertEvent $event + * The event interface. */ public function onNodeInsert(NodeInsertEvent $event) { $entity = $event->getEntity(); diff --git a/src/Form/MetadataConfigForm.php b/src/Form/MetadataConfigForm.php index 775c0f07..d918ac7f 100644 --- a/src/Form/MetadataConfigForm.php +++ b/src/Form/MetadataConfigForm.php @@ -5,6 +5,9 @@ use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\FormStateInterface; +/** + * The metadata configuration form. + */ class MetadataConfigForm extends ConfigFormBase { const SETTINGS = 'quant.metadata.settings'; @@ -25,6 +28,9 @@ protected function getEditableConfigNames() { ]; } + /** + * {@inheritdoc} + */ public function buildForm(array $form, FormStateInterface $form_state) { $config = $this->config(static::SETTINGS); @@ -77,4 +83,5 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $config->save(); parent::submitForm($form, $form_state); } + } diff --git a/src/Form/SeedForm.php b/src/Form/SeedForm.php index 89693ebf..1faab2e8 100644 --- a/src/Form/SeedForm.php +++ b/src/Form/SeedForm.php @@ -13,6 +13,7 @@ use Drupal\quant\QuantStaticTrait; use Drupal\quant_api\Client\QuantClientInterface; use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** * Contains a form for initializing a static build. @@ -31,14 +32,16 @@ class SeedForm extends FormBase { protected $client; /** + * The event dispatcher. * + * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface */ protected $dispatcher; /** * Build the form. */ - public function __construct(QuantClientInterface $client, $event_dispatcher) { + public function __construct(QuantClientInterface $client, EventDispatcherInterface $event_dispatcher) { $this->client = $client; $this->dispatcher = $event_dispatcher; } @@ -54,14 +57,14 @@ public static function create(ContainerInterface $container) { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getFormId() { return 'quant_seed_form'; } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { @@ -125,7 +128,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { ->loadMultiple(); $content_types = []; - foreach($types as $type) { + foreach ($types as $type) { $content_types[$type->id()] = $type->label(); } diff --git a/src/Plugin/Quant/Metadata/ProxyOverride.php b/src/Plugin/Quant/Metadata/ProxyOverride.php index 3af23125..48c1fad3 100644 --- a/src/Plugin/Quant/Metadata/ProxyOverride.php +++ b/src/Plugin/Quant/Metadata/ProxyOverride.php @@ -20,7 +20,9 @@ class ProxyOverride extends MetadataBase implements ContainerFactoryPluginInterface { /** - * @var EntityStorage + * The entity type manager. + * + * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ protected $entityManager; @@ -48,10 +50,10 @@ public static function create(ContainerInterface $container, array $configuratio * {@inheritdoc} */ public function build(EntityInterface $entity) : array { - // Proxies are created manually and usually not something you want to replace. - // This is a globally configurable to allow override, just in case. + // Proxies are created manually and usually not something you want to + // replace. This is a globally configurable to allow override just in case. $config = \Drupal::config('quant.settings'); - $proxy_override = boolval($config->get('proxy_override', true)); + $proxy_override = boolval($config->get('proxy_override', TRUE)); return ['proxy_override' => $proxy_override]; } diff --git a/src/Plugin/Quant/Metadata/Published.php b/src/Plugin/Quant/Metadata/Published.php index 73a48a1e..03f977e0 100644 --- a/src/Plugin/Quant/Metadata/Published.php +++ b/src/Plugin/Quant/Metadata/Published.php @@ -20,7 +20,9 @@ class Published extends MetadataBase implements ContainerFactoryPluginInterface { /** - * @var EntityStorage + * The entity type manager. + * + * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ protected $entityManager; @@ -48,9 +50,9 @@ public static function create(ContainerInterface $container, array $configuratio * {@inheritdoc} */ public function build(EntityInterface $entity) : array { - // Note: This approach returns the default published state of the parent node. - // This should be used to make content non-viewable if it is unpublished. - // $default = $this->entityManager->getStorage($entity->getEntityTypeId())->load($entity->id()); + // Note: This approach returns the default published state of the parent + // node. This should be used to make content non-viewable if it is + // unpublished. // Return the published status of the revision. return ['published' => $entity->isPublished()]; } diff --git a/src/Plugin/Quant/Metadata/PublishedRevision.php b/src/Plugin/Quant/Metadata/PublishedRevision.php index 004447b0..440e8c85 100644 --- a/src/Plugin/Quant/Metadata/PublishedRevision.php +++ b/src/Plugin/Quant/Metadata/PublishedRevision.php @@ -20,7 +20,9 @@ class PublishedRevision extends MetadataBase implements ContainerFactoryPluginInterface { /** - * @var EntityStorage + * The entity type manager. + * + * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ protected $entityManager; diff --git a/src/Plugin/QuantMetadataManager.php b/src/Plugin/QuantMetadataManager.php index c92011c7..a00038d4 100644 --- a/src/Plugin/QuantMetadataManager.php +++ b/src/Plugin/QuantMetadataManager.php @@ -30,7 +30,7 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac /** * {@inheritdoc} */ - public function createInstance($plugin_id, array $configuration = array()) { + public function createInstance($plugin_id, array $configuration = []) { $plugin = parent::createInstance($plugin_id, $configuration); $config = \Drupal::config(MetadataConfigForm::SETTINGS)->get($plugin_id) ?: []; diff --git a/src/Seed.php b/src/Seed.php index 0d5d4fe2..73b7d989 100644 --- a/src/Seed.php +++ b/src/Seed.php @@ -8,8 +8,6 @@ use Drupal\quant\Event\QuantRedirectEvent; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Url; -use Drupal\Core\File\Exception\FileException; -use Drupal\Core\File\FileSystemInterface; /** * Seed Manager. @@ -69,7 +67,7 @@ public static function exportRoute($route, &$context) { list($markup, $content_type) = $response; $config = \Drupal::config('quant.settings'); - $proxy_override = boolval($config->get('proxy_override', false)); + $proxy_override = boolval($config->get('proxy_override', FALSE)); $meta = [ 'info' => [ @@ -106,7 +104,7 @@ public static function exportFile($file, &$context) { } /** - * + * Batch finish callback for the seed. */ public static function finishedSeedCallback($success, $results, $operations) { // The 'success' parameter means no fatal PHP errors were detected. All @@ -125,6 +123,7 @@ public static function finishedSeedCallback($success, $results, $operations) { /** * Find lunr assets. + * * This includes static output from the lunr module. */ public static function findLunrAssets() { @@ -153,6 +152,7 @@ public static function findLunrAssets() { /** * Find lunr routes. + * * Determine URLs lunr indexes are exposed on. */ public static function findLunrRoutes() { @@ -193,7 +193,7 @@ public static function deleteRedirect($redirect) { /** * Seeds taxonomy term. */ - public static function seedTaxonomyTerm($entity, $langcode=NULL) { + public static function seedTaxonomyTerm($entity, $langcode = NULL) { $tid = $entity->get('tid')->value; $options = ['absolute' => FALSE]; @@ -228,9 +228,15 @@ public static function seedTaxonomyTerm($entity, $langcode=NULL) { /** * Trigger an internal http request to retrieve node markup. + * * Seeds an individual node update to Quant. + * + * @param \Drupal\Core\Entity\EntityInterface $entity + * A node interface. + * @param string $langcode + * The node language. */ - public static function seedNode($entity, $langcode=NULL) { + public static function seedNode(EntityInterface $entity, $langcode = NULL) { $nid = $entity->get('nid')->value; $rid = $entity->get('vid')->value; @@ -250,7 +256,7 @@ public static function seedNode($entity, $langcode=NULL) { if ((strpos($front, '/node/') === 0) && $nid == substr($front, 6)) { if ($entity->isPublished() && $entity->isDefaultRevision()) { // Trigger redirect event from alias to home. - \Drupal::service('event_dispatcher')->dispatch(QuantRedirectEvent::UPDATE, new QuantRedirectEvent($url, "/", 301)); + \Drupal::service('event_dispatcher')->dispatch(QuantRedirectEvent::UPDATE, new QuantRedirectEvent($url, "/", 301)); } $url = "/"; } @@ -327,8 +333,8 @@ public static function unpublishRoute(EntityInterface $entity) { * * @param string $route * The route to collect markup from. - * @param array $query - * Query parameters to add to the route. + * @param array $headers + * Headers to add to the request. * * @return string|bool * The markup from the $route. diff --git a/src/TokenManager.php b/src/TokenManager.php index ad82d45f..d2670bdf 100644 --- a/src/TokenManager.php +++ b/src/TokenManager.php @@ -34,8 +34,10 @@ class TokenManager { /** * Construct a TokenManager instance. * - * @param Drupal\Core\Database\Connection $connection + * @param \Drupal\Core\Database\Connection $connection * The database connection. + * @param \Symfony\Component\HttpFoundation\RequestStack $request + * The current request stack. */ public function __construct(Connection $connection, RequestStack $request) { $this->connection = $connection; From 47c715a954aa03bafb30f39a3282d97812c0896c Mon Sep 17 00:00:00 2001 From: Stuart Rowlands Date: Mon, 12 Oct 2020 20:09:46 +1300 Subject: [PATCH 08/11] Throw 402 on invalid subscription. --- modules/quant_api/src/Client/QuantClient.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/quant_api/src/Client/QuantClient.php b/modules/quant_api/src/Client/QuantClient.php index 1f069c02..fbd22eb2 100644 --- a/modules/quant_api/src/Client/QuantClient.php +++ b/modules/quant_api/src/Client/QuantClient.php @@ -91,6 +91,11 @@ public function ping() { return TRUE; } + if ($response->getStatusCode() == 402) { + // Emit a subscription invalid warning. + \Drupal::messenger()->addError(t('Your Quant subscription is invalid. Please check the dashboard.')); + } + return FALSE; } From 70768ec8c13d204c71dd8ee6720b0185f884dd36 Mon Sep 17 00:00:00 2001 From: Stuart Rowlands Date: Tue, 13 Oct 2020 07:25:39 +1300 Subject: [PATCH 09/11] 410 Gone error code for deleted projects. --- modules/quant_api/src/Client/QuantClient.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/quant_api/src/Client/QuantClient.php b/modules/quant_api/src/Client/QuantClient.php index fbd22eb2..c9d345f8 100644 --- a/modules/quant_api/src/Client/QuantClient.php +++ b/modules/quant_api/src/Client/QuantClient.php @@ -2,7 +2,6 @@ namespace Drupal\quant_api\Client; -use Psr7\MultipartStream; use Drupal\Core\Config\ConfigFactoryInterface; use GuzzleHttp\Client; use GuzzleHttp\RequestOptions; @@ -11,6 +10,7 @@ use Drupal\quant_api\Exception\InvalidPayload; use GuzzleHttp\Psr7; use GuzzleHttp\Psr7\Request; +use GuzzleHttp\Psr7\MultipartStream; /** * Quant API client. @@ -96,6 +96,11 @@ public function ping() { \Drupal::messenger()->addError(t('Your Quant subscription is invalid. Please check the dashboard.')); } + if ($response->getStatusCode() == 410) { + // Emit a deleted project warning. + \Drupal::messenger()->addError(t('Project is deleted. Please check the dashboard for restoration options.')); + } + return FALSE; } From 4ece0099e9a7a230b7e14a938aa77adf81c8acc0 Mon Sep 17 00:00:00 2001 From: Stuart Rowlands Date: Tue, 13 Oct 2020 09:01:00 +1300 Subject: [PATCH 10/11] Save routes on seed form again. --- src/Form/SeedForm.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Form/SeedForm.php b/src/Form/SeedForm.php index 1faab2e8..a080c471 100644 --- a/src/Form/SeedForm.php +++ b/src/Form/SeedForm.php @@ -258,6 +258,8 @@ public function submitForm(array &$form, FormStateInterface $form_state) { } $config->set('routes', $form_state->getValue('routes'))->save(); + $config->set('routes_export', $form_state->getValue('routes_textarea'))->save(); + if ($form_state->getValue('routes_textarea')) { foreach (explode(PHP_EOL, $form_state->getValue('routes')) as $route) { if (strpos((trim($route)), '/') !== 0) { From 3e4450bfc528aae22421f0ea7f043bc7860b7aed Mon Sep 17 00:00:00 2001 From: Stuart Rowlands Date: Tue, 13 Oct 2020 17:02:37 +1300 Subject: [PATCH 11/11] Fixes php warning on file upload error. --- modules/quant_api/src/EventSubscriber/QuantApi.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/quant_api/src/EventSubscriber/QuantApi.php b/modules/quant_api/src/EventSubscriber/QuantApi.php index 9de976f1..a7be3430 100644 --- a/modules/quant_api/src/EventSubscriber/QuantApi.php +++ b/modules/quant_api/src/EventSubscriber/QuantApi.php @@ -240,9 +240,11 @@ public function onMedia(QuantFileEvent $event) { } catch (InvalidPayload $error) { $this->logger->error($error->getMessage()); + return; } catch (Exception $error) { $this->logger->error($error->getMessage()); + return; } return $res;