diff --git a/tests/features/communities/oss_catalogue/oss_catalogue.feature b/tests/features/communities/oss_catalogue/oss_catalogue.feature index fa76710b689b804a12101def8b008beeeb440c72..212e6362810f37b04b4be6e7b9eb1cd462850245 100644 --- a/tests/features/communities/oss_catalogue/oss_catalogue.feature +++ b/tests/features/communities/oss_catalogue/oss_catalogue.feature @@ -1,4 +1,4 @@ -@api @group-clone +@api @group-clone @eu-oss-catalogue Feature: In order to present the details about EU OSS catalogue I want to view a dedicated collection and landing page diff --git a/tests/features/communities/oss_catalogue/oss_catalogue.relevant_language.feature b/tests/features/communities/oss_catalogue/oss_catalogue.relevant_language.feature index db9bfc45038d0a0173186e98f8766f48d7a5f6ce..b4c5fb9ce17ea87e8b95a6cf5c9254aa27c8bad3 100644 --- a/tests/features/communities/oss_catalogue/oss_catalogue.relevant_language.feature +++ b/tests/features/communities/oss_catalogue/oss_catalogue.relevant_language.feature @@ -1,4 +1,4 @@ -@api @group-clone +@api @group-clone @eu-oss-catalogue Feature: In order to show the most data to visitors, EU OSS Catalogue provides a special equivalent of the OSS Solution's translatable fields which fetch and diff --git a/tests/src/Context/JoinupOSSSolutionContext.php b/tests/src/Context/JoinupOSSSolutionContext.php index 8f392676e1e91df6a6c9353b03da35ed8b95246b..1bc4b5a9807fe3848018967848c32f7c04296f1e 100644 --- a/tests/src/Context/JoinupOSSSolutionContext.php +++ b/tests/src/Context/JoinupOSSSolutionContext.php @@ -5,15 +5,12 @@ namespace Drupal\joinup\Context; use Drupal\DrupalExtension\Context\RawDrupalContext; -use Drupal\joinup\Traits\EntityTrait; /** * Behat step definitions for testing OSS solution. */ class JoinupOSSSolutionContext extends RawDrupalContext { - use EntityTrait; - /** * OSS welcome page path. */ @@ -52,4 +49,26 @@ public static function disableOssCron(): void { $state->set('eu_oss_catalogue.last_check', strtotime('- 1 hour')); } + /** + * Enables EU OSS Catalogue functionality. + * + * @BeforeScenario @api&&@eu-oss-catalogue + * + * @todo Remove this method and all @eu-oss-catalogue tags in ISAICP-9053. + */ + public function enableEuOssCatalogue(): void { + joinup_oss_catalogue_toggle('enable'); + } + + /** + * Disables EU OSS Catalogue functionality. + * + * @AfterScenario @api&&@eu-oss-catalogue + * + * @todo Remove this method and all @eu-oss-catalogue tags in ISAICP-9053. + */ + public function disableEuOssCatalogue(): void { + joinup_oss_catalogue_toggle('disable'); + } + } diff --git a/web/modules/custom/dashboard/src/Form/DashboardForm.php b/web/modules/custom/dashboard/src/Form/DashboardForm.php index 50bb8f838aac17738a6e4b1aaf810986bd50ce89..c06b5662e5caf07b78fac67aa059dfd32bb28a8b 100644 --- a/web/modules/custom/dashboard/src/Form/DashboardForm.php +++ b/web/modules/custom/dashboard/src/Form/DashboardForm.php @@ -15,9 +15,7 @@ use Drupal\Core\Url; use Drupal\joinup_core\Logger\Handler\MailHandler; use Drupal\joinup_core\Logger\Handler\TelegramHandler; -use Drupal\joinup_oss_catalogue\OssCatalogueCollectionInterface; use Drupal\rdf_sync\RdfSyncConnectionInterface; -use Solarium\Core\Query\Helper; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -135,11 +133,7 @@ public function buildForm(array $form, FormStateInterface $form_state): array { * @todo Remove this method in ISAICP-9053. */ public function enableEuOssCatalogueSubmitForm(): void { - $this->state->delete('joinup.oss_catalogue_is_disabled'); - $this->entityTypeManager->getStorage('rdf_entity') - ->load(OssCatalogueCollectionInterface::COLLECTION_ENTITY_ID) - ->set('field_ar_state', 'published') - ->save(); + joinup_oss_catalogue_toggle('enable'); // Only clear cache for anonymous. $this->pageCache->deleteAll(); $this->messenger()->addStatus($this->t('EU OSS Catalogue has been enabled')); @@ -151,36 +145,7 @@ public function enableEuOssCatalogueSubmitForm(): void { * @todo Remove this method in ISAICP-9053. */ public function disableEuOssCatalogueSubmitForm(): void { - $this->state->set('joinup.oss_catalogue_is_disabled', TRUE); - $uri = OssCatalogueCollectionInterface::COLLECTION_ENTITY_ID; - $collection = $this->entityTypeManager->getStorage('rdf_entity')->load($uri); - $collection->set('field_ar_state', 'draft')->save(); - - // Unfortunately, we cannot unpublish a collection. When setting the state - // to 'draft', we're creating a forward revision. In order to unpublish, we: - // - Remove the published triples. - // - Remove the document from Solr and from search_api_item table. - $sparql = <<<SPARQL - WITH <http://joinup.eu/collection/published> - DELETE { <$uri> ?p ?o } - WHERE { <$uri> ?p ?o } - SPARQL; - $this->rdfSyncConnection->update($sparql); - $sapiId = 'entity:rdf_entity/' . $uri; - $solrHelper = new Helper(); - /** @var \Drupal\search_api_solr\SolrConnectorInterface $connector */ - $connector = $this->entityTypeManager->getStorage('search_api_server') - ->load('joinup')->getBackend()->getSolrConnector(); - $updateQuery = $connector - ->getUpdateQuery() - ->addDeleteQuery('ss_search_api_id:' . $solrHelper->escapePhrase($sapiId)) - ->addCommit(); - $connector->update($updateQuery); - $this->db->delete('search_api_item') - ->condition('index_id', ['published', 'unpublished'], 'IN') - ->condition('item_id', $sapiId) - ->execute(); - + joinup_oss_catalogue_toggle('disable'); // Only clear cache for anonymous. $this->pageCache->deleteAll(); $this->messenger()->addStatus($this->t('EU OSS Catalogue has been disabled')); diff --git a/web/modules/custom/joinup_communities/joinup_oss_catalogue/joinup_oss_catalogue.install b/web/modules/custom/joinup_communities/joinup_oss_catalogue/joinup_oss_catalogue.install index bc81a4d60bc9f126a023eb2bc67fc723deb392c9..ce8d1aa03fb78eec2500b86aa789e44cc618ec3b 100644 --- a/web/modules/custom/joinup_communities/joinup_oss_catalogue/joinup_oss_catalogue.install +++ b/web/modules/custom/joinup_communities/joinup_oss_catalogue/joinup_oss_catalogue.install @@ -8,7 +8,6 @@ declare(strict_types=1); use Drupal\joinup_oss_catalogue\OssCatalogueCollectionInterface; -use Solarium\Core\Query\Helper; /** * Publish the EU OSS Catalogue collection. @@ -24,38 +23,12 @@ function joinup_oss_catalogue_update_200001(): void { * Fix OSS Catalogue collection fields. */ function joinup_oss_catalogue_update_200002(): void { - $entityTypeManger = \Drupal::entityTypeManager(); - $uri = OssCatalogueCollectionInterface::COLLECTION_ENTITY_ID; - $collection = $entityTypeManger->getStorage('rdf_entity')->load($uri); - $collection->skip_notification = TRUE; - $collection - ->set('field_ar_state', 'draft') - ->set('field_topic', 11195) - ->save(); + joinup_oss_catalogue_toggle('disable'); - // Unfortunately, we cannot unpublish a collection. When setting the state - // to 'draft', we're creating a forward revision. - $sparql = <<<SPARQL - WITH <http://joinup.eu/collection/published> - DELETE { <$uri> ?p ?o } - WHERE { <$uri> ?p ?o } - SPARQL; - \Drupal::getContainer()->get('rdf_sync.connection')->update($sparql); - $sapiId = 'entity:rdf_entity/' . $uri; - $solrHelper = new Helper(); - /** @var \Drupal\search_api_solr\SolrConnectorInterface $connector */ - $connector = $entityTypeManger->getStorage('search_api_server') - ->load('joinup')->getBackend()->getSolrConnector(); - $updateQuery = $connector - ->getUpdateQuery() - ->addDeleteQuery('ss_search_api_id:' . $solrHelper->escapePhrase($sapiId)) - ->addCommit(); - $connector->update($updateQuery); - // Update SAPI items. - \Drupal::database()->delete('search_api_item') - ->condition('index_id', ['published', 'unpublished'], 'IN') - ->condition('item_id', $sapiId) - ->execute(); + $collection = \Drupal::entityTypeManager()->getStorage('rdf_entity') + ->load(OssCatalogueCollectionInterface::COLLECTION_ENTITY_ID); + $collection->skip_notification = TRUE; + $collection->set('field_topic', 11195)->save(); \Drupal::getContainer()->get('entity.repository') ->loadEntityByUuid('node', OssCatalogueCollectionInterface::LANDING_PAGE) diff --git a/web/modules/custom/joinup_communities/joinup_oss_catalogue/joinup_oss_catalogue.module b/web/modules/custom/joinup_communities/joinup_oss_catalogue/joinup_oss_catalogue.module index 8212527be9fd2c44c856ef9a4e6facb2ff2bdd1f..0adfdf23795b4692060c7dcc107f83a9bb74319d 100644 --- a/web/modules/custom/joinup_communities/joinup_oss_catalogue/joinup_oss_catalogue.module +++ b/web/modules/custom/joinup_communities/joinup_oss_catalogue/joinup_oss_catalogue.module @@ -20,6 +20,7 @@ use Drupal\joinup_oss_catalogue\Entity\JoinupOssSolution; use Drupal\joinup_oss_catalogue\OssCatalogueCollectionInterface; use Drupal\node\NodeInterface; +use Solarium\Core\Query\Helper; /** * Implements hook_views_plugins_argument_alter(). @@ -247,3 +248,59 @@ function joinup_oss_catalogue_cron(): void { eu_oss_vitality_index_cron(); } } + +/** + * Toggles the state of EU OSS Catalogue functionality. + * + * @param string $toggle + * The state: 'enable', 'disable'. + * + * @todo Remove this function in ISAICP-9053. + */ +function joinup_oss_catalogue_toggle(string $toggle): void { + assert(in_array($toggle, ['enable', 'disable'], TRUE)); + $entityTypeManager = \Drupal::entityTypeManager(); + $state = \Drupal::state(); + + if ($toggle === 'enable') { + $state->delete('joinup.oss_catalogue_is_disabled'); + $collection = $entityTypeManager->getStorage('rdf_entity') + ->load(OssCatalogueCollectionInterface::COLLECTION_ENTITY_ID); + $collection->skip_notification = TRUE; + $collection->set('field_ar_state', 'published')->save(); + return; + } + + $state->set('joinup.oss_catalogue_is_disabled', TRUE); + + $uri = OssCatalogueCollectionInterface::COLLECTION_ENTITY_ID; + $collection = \Drupal::entityTypeManager()->getStorage('rdf_entity')->load($uri); + $collection->skip_notification = TRUE; + $collection->set('field_ar_state', 'draft')->save(); + + // Unfortunately, we cannot unpublish a collection. When setting the state + // to 'draft', we're creating a forward revision. In order to unpublish, we: + // - Remove the published triples. + // - Remove the document from Solr and from search_api_item table. + $sparql = <<<SPARQL + WITH <http://joinup.eu/collection/published> + DELETE { <$uri> ?p ?o } + WHERE { <$uri> ?p ?o } + SPARQL; + \Drupal::getContainer()->get('rdf_sync.connection')->update($sparql); + $sapiId = 'entity:rdf_entity/' . $uri; + $solrHelper = new Helper(); + /** @var \Drupal\search_api_solr\SolrConnectorInterface $connector */ + $connector = $entityTypeManager->getStorage('search_api_server')->load('joinup') + ->getBackend() + ->getSolrConnector(); + $deleteQuery = $connector + ->getUpdateQuery() + ->addDeleteQuery('ss_search_api_id:' . $solrHelper->escapePhrase($sapiId)) + ->addCommit(); + $connector->update($deleteQuery); + \Drupal::database()->delete('search_api_item') + ->condition('index_id', ['published', 'unpublished'], 'IN') + ->condition('item_id', $sapiId) + ->execute(); +}