Skip to content
Snippets Groups Projects
Commit 921d68d5 authored by Claudiu Cristea's avatar Claudiu Cristea
Browse files

ISAICP-9062: Enable functionality during tests.

parent 3852bb10
No related branches found
No related tags found
1 merge request!187ISAICP-9062: Fix the state of OSS Catalogue
@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
......
@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
......
......@@ -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');
}
}
......@@ -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'));
......
......@@ -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)
......
......@@ -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();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment