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

ISAICP-9062: Fix the state of OSS Catalogue.

parent ee97a546
No related branches found
No related tags found
1 merge request!187ISAICP-9062: Fix the state of OSS Catalogue
......@@ -14,17 +14,14 @@ upgrade_commands:
- rm disable-config-readonly
- vendor/bin/drush joinup:unpublish-alert --category
- scripts/check_status_report.php
# TODO: Remove this command in ISAICP-9053.
- vendor/bin/drush state:set joinup.oss_catalogue_is_disabled 1 --input-format=boolean
append:
production:
# TODO: Remove this command in ISAICP-9053.
- vendor/bin/drush state:set joinup.oss_catalogue_is_disabled 1 --input-format=boolean
acceptance:
- touch disable-config-readonly
- vendor/bin/drush joinup:acc
- vendor/bin/drush cache:rebuild
- rm disable-config-readonly
# TODO: Remove this command in ISAICP-9053.
- vendor/bin/drush state:set joinup.oss_catalogue_is_disabled 1 --input-format=boolean
ephemeral:
- touch disable-config-readonly
- vendor/bin/drush joinup:acc
......
......@@ -7,44 +7,6 @@ Feature: Test EU OSS Catalogue killswitch
| title | oss_development_status | oss_source | oss_categories | oss_short_description | status |
| The Opensource Panacea | development | developers_italia | content-management | The cure | published |
When I go to "/eu-oss-catalogue"
Then the response status code should be 200
But I should not see "Sign in to continue"
And I go to "/eu-oss-catalogue/solutions"
Then the response status code should be 200
But I should not see "Sign in to continue"
And I go to the content page of the type "oss_solution" with the title "The Opensource Panacea"
Then the response status code should be 200
But I should not see "Sign in to continue"
Given I am logged in as an "authenticated"
When I go to "/eu-oss-catalogue"
And I check "I agree to the Legal notice document"
And I press "Submit"
Then the response status code should be 200
And I go to "/eu-oss-catalogue/solutions"
Then the response status code should be 200
And I go to the content page of the type "oss_solution" with the title "The Opensource Panacea"
Then the response status code should be 200
Given I am logged in as a "developer"
When I go to "/eu-oss-catalogue"
Then the response status code should be 200
And I go to "/eu-oss-catalogue/solutions"
Then the response status code should be 200
And I go to "/admin/content/eu-oss-catalogue"
Then the response status code should be 200
And I go to "/admin/content/eu-oss-catalogue/oss-solutions"
Then the response status code should be 200
And I go to "/admin/content/eu-oss-catalogue/log"
Then the response status code should be 200
And I go to the content page of the type "oss_solution" with the title "The Opensource Panacea"
Then the response status code should be 200
Given I visit "/dashboard"
When I press "Disable EU OSS Catalogue"
Then I should see the success message "EU OSS Catalogue has been disabled"
Given I am an anonymous user
When I go to "/eu-oss-catalogue"
Then I should see the heading "Sign in to continue"
......@@ -52,6 +14,8 @@ Feature: Test EU OSS Catalogue killswitch
Then I should see the heading "Sign in to continue"
And I go to the content page of the type "oss_solution" with the title "The Opensource Panacea"
Then I should see the heading "Sign in to continue"
When I am on the homepage
Then I should not see "EU Open Source Solutions Catalogue"
Given I am logged in as an "authenticated"
When I go to "/eu-oss-catalogue"
......@@ -62,6 +26,8 @@ Feature: Test EU OSS Catalogue killswitch
Then the response status code should be 403
And I go to the content page of the type "oss_solution" with the title "The Opensource Panacea"
Then the response status code should be 403
When I am on the homepage
Then I should not see "EU Open Source Solutions Catalogue"
Given I am logged in as a "developer"
When I go to "/eu-oss-catalogue"
......@@ -77,6 +43,8 @@ Feature: Test EU OSS Catalogue killswitch
# Developer is and amin role, they can still see the node.
And I go to the content page of the type "oss_solution" with the title "The Opensource Panacea"
Then the response status code should be 200
When I am on the homepage
Then I should not see "EU Open Source Solutions Catalogue"
Given I visit "/dashboard"
When I press "Enable EU OSS Catalogue"
......@@ -105,6 +73,8 @@ Feature: Test EU OSS Catalogue killswitch
And I go to the content page of the type "oss_solution" with the title "The Opensource Panacea"
Then the response status code should be 200
But I should not see "Sign in to continue"
When I am on the homepage
Then I should see "EU Open Source Solutions Catalogue"
Given I am logged in as an "authenticated"
When I go to "/eu-oss-catalogue"
......@@ -115,3 +85,48 @@ Feature: Test EU OSS Catalogue killswitch
Then the response status code should be 200
And I go to the content page of the type "oss_solution" with the title "The Opensource Panacea"
Then the response status code should be 200
When I am on the homepage
Then I should see "EU Open Source Solutions Catalogue"
Given I am logged in as a "developer"
When I visit "/dashboard"
And I press "Disable EU OSS Catalogue"
Then I should see the success message "EU OSS Catalogue has been disabled"
When I go to "/eu-oss-catalogue"
Then the response status code should be 403
And I go to "/eu-oss-catalogue/solutions"
Then the response status code should be 403
And I go to "/admin/content/eu-oss-catalogue"
Then the response status code should be 403
And I go to "/admin/content/eu-oss-catalogue/oss-solutions"
Then the response status code should be 403
And I go to "/admin/content/eu-oss-catalogue/log"
Then the response status code should be 403
# Developer is and amin role, they can still see the node.
And I go to the content page of the type "oss_solution" with the title "The Opensource Panacea"
Then the response status code should be 200
When I am on the homepage
Then I should not see "EU Open Source Solutions Catalogue"
Given I am an anonymous user
When I go to "/eu-oss-catalogue"
Then I should see the heading "Sign in to continue"
And I go to "/eu-oss-catalogue/solutions"
Then I should see the heading "Sign in to continue"
And I go to the content page of the type "oss_solution" with the title "The Opensource Panacea"
Then I should see the heading "Sign in to continue"
When I am on the homepage
Then I should not see "EU Open Source Solutions Catalogue"
Given I am logged in as an "authenticated"
When I go to "/eu-oss-catalogue"
And I check "I agree to the Legal notice document"
And I press "Submit"
Then the response status code should be 403
And I go to "/eu-oss-catalogue/solutions"
Then the response status code should be 403
And I go to the content page of the type "oss_solution" with the title "The Opensource Panacea"
Then the response status code should be 403
When I am on the homepage
Then I should not see "EU Open Source Solutions Catalogue"
......@@ -6,6 +6,8 @@
use Drupal\Core\Access\AccessResultInterface;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Database\Connection;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
......@@ -13,6 +15,9 @@
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;
/**
......@@ -23,6 +28,9 @@ class DashboardForm extends FormBase {
public function __construct(
protected StateInterface $state,
protected CacheBackendInterface $pageCache,
protected EntityTypeManagerInterface $entityTypeManager,
protected RdfSyncConnectionInterface $rdfSyncConnection,
protected Connection $db,
) {
}
......@@ -33,6 +41,9 @@ public static function create(ContainerInterface $container): self {
return new static(
$container->get('state'),
$container->get('cache.page'),
$container->get('entity_type.manager'),
$container->get('rdf_sync.connection'),
$container->get('database'),
);
}
......@@ -125,6 +136,10 @@ public function buildForm(array $form, FormStateInterface $form_state): array {
*/
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();
// Only clear cache for anonymous.
$this->pageCache->deleteAll();
$this->messenger()->addStatus($this->t('EU OSS Catalogue has been enabled'));
......@@ -137,6 +152,35 @@ public function enableEuOssCatalogueSubmitForm(): void {
*/
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();
// Only clear cache for anonymous.
$this->pageCache->deleteAll();
$this->messenger()->addStatus($this->t('EU OSS Catalogue has been disabled'));
......
......@@ -8,6 +8,7 @@
declare(strict_types=1);
use Drupal\joinup_oss_catalogue\OssCatalogueCollectionInterface;
use Solarium\Core\Query\Helper;
/**
* Publish the EU OSS Catalogue collection.
......@@ -18,3 +19,46 @@ function joinup_oss_catalogue_update_200001(): void {
$collection->skip_notification = TRUE;
$collection->set('field_ar_state', 'published')->save();
}
/**
* 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();
// 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();
\Drupal::getContainer()->get('entity.repository')
->loadEntityByUuid('node', OssCatalogueCollectionInterface::LANDING_PAGE)
->set('field_topic', 11195)
->save();
}
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