Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Commit

Permalink
Merge pull request #2321 from ec-europa/ISAICP-6287
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiu-cristea authored Nov 17, 2020
2 parents d2f21a4 + 9f72f68 commit 7a9bfe5
Show file tree
Hide file tree
Showing 34 changed files with 142 additions and 585 deletions.
82 changes: 41 additions & 41 deletions tests/features/communities/eupl/jlc.feature

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions tests/src/Context/EuplContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ protected function toggleLicenceForComparison(bool $compare, string $spdx_id): v
* @When I choose :spdx_id as the :label licence
*/
public function selectRadioButtonForLicenceCompatibilityCheck(string $spdx_id, string $label): void {
assert(in_array($label, ['Use', 'Distribute']), 'The purpose should be either "Use" or "Distribute".');
assert(in_array($label, ['Inbound', 'Outbound']), 'The purpose should be either "Use" or "Distribute".');
$licence = $this->findLicenceTile($spdx_id);
$this->selectMaterialDesignRadioButton($label, $licence);
}
Expand Down Expand Up @@ -350,14 +350,14 @@ public function assertLicenceCompatibility(TableNode $table) {
/** @var \Drupal\joinup_licence\JoinupLicenceCompatibilityRulePluginManager $plugin_manager */
$plugin_manager = \Drupal::service('plugin.manager.joinup_licence_compatibility_rule');
foreach ($table->getColumnsHash() as $test_case) {
$use_label = $test_case['use'];
$redistribute_as_label = $test_case['redistribute as'];
$use_label = $test_case['inbound'];
$redistribute_as_label = $test_case['outbound'];
$expected_result = $test_case['document ID'];

$use_licence = static::loadLicenceByLabel($use_label);
$redistribute_as_licence = static::loadLicenceByLabel($redistribute_as_label);
$inbound_licence = static::loadLicenceByLabel($use_label);
$outbound_licence = static::loadLicenceByLabel($redistribute_as_label);

$result = $plugin_manager->getCompatibilityDocumentId($use_licence, $redistribute_as_licence);
$result = $plugin_manager->getCompatibilityDocumentId($inbound_licence, $outbound_licence);

// Check that the returned document ID matches the expected ID.
if ($expected_result !== $result) {
Expand Down
191 changes: 0 additions & 191 deletions web/modules/custom/joinup_core/joinup_core.install
Original file line number Diff line number Diff line change
Expand Up @@ -6,194 +6,3 @@
*/

declare(strict_types = 1);

use Drupal\Core\Database\Database;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Site\Settings;
use Drupal\collection\Entity\CollectionInterface;
use Drupal\joinup_community_content\CommunityContentHelper;
use Drupal\solution\Entity\SolutionInterface;
use Drupal\user\Entity\User;

/**
* Implements hook_requirements().
*
* Adds some additional security related warnings to the status report:
* - UID1 should be blocked.
* - Config Read Only should be enabled.
*/
function joinup_core_requirements($phase): array {
$requirements = [];

if ($phase === 'runtime') {
// Check if UID 1 is blocked. Not allowing to log in as the root user
// greatly decreases the chances of a privilege escalation bug to do real
// damage on production.
/** @var \Drupal\user\UserInterface $uid1 */
$uid1 = User::load(1);
if ($uid1->isActive()) {
$requirements['joinup_core_root_user_blocked'] = [
'title' => t('Root user access'),
'description' => t('Allowing to log in as the root user on production is a security risk.'),
'severity' => REQUIREMENT_ERROR,
'value' => t('Root user is not blocked'),
];
}

// Check that the Config Read Only module is enabled and activated. This
// module ensures that the site configuration is immutable. This greatly
// enhances the security of the production environment, and ensures that no
// changes are made on production which can be overwritten on a subsequent
// update.
/** @var \Drupal\Core\Extension\ModuleHandlerInterface $module_handler */
$module_handler = \Drupal::service('module_handler');
if (!$module_handler->moduleExists('config_readonly') || !Settings::get('config_readonly')) {
$requirements['joinup_core_config_readonly'] = [
'title' => t('Config Read Only'),
'description' => t('On production environments the site configuration should be read-only.'),
'severity' => REQUIREMENT_ERROR,
'value' => t('Config is writable'),
];

// Check that database logging is disabled on production. Writing log
// entries to the database on every request puts unnecessary load on the
// database server.
if ($module_handler->moduleExists('dblog')) {
$requirements['joinup_core_dblog'] = [
'title' => t('Database logging'),
'description' => t('On production environments logs should be written to a file, not to the database.'),
'severity' => REQUIREMENT_ERROR,
'value' => t('Database logging is enabled'),
];
}
}

$requirements_helper = \Drupal::getContainer()->get('joinup_core.requirements_helper');

// Ensure that a cache state inconsistency will not cause also
// inconsistencies with the published revisions of the entities.
//
// @see: \joinup_core_post_update_set_news_default_version
// @see: \Drupal\joinup_core\RequirementsHelper::getNodesWithProblematicRevisions
// @see: ISAICP-5191
$requirements['joinup_core_forward_revisions'] = [
'title' => t('Forward published revisions'),
'description' => t('In all content, the last published revision should be the latest of the published revisions.'),
'severity' => REQUIREMENT_OK,
'value' => t('No entities were found without a parent.'),
];

$results = $requirements_helper->getNodesWithProblematicRevisions();
if (!empty($results)) {
$nids = array_keys($results);
$error = t('Issues with the latest revision have been found in the following nid(s): :nids', [
':nids' => implode(', ', $nids),
]);
$requirements['joinup_core_forward_revisions']['severity'] = REQUIREMENT_ERROR;
$requirements['joinup_core_forward_revisions']['value'] = $error;
}
}

return $requirements;
}

/**
* Migrate data about pinned entities into meta entities (stage 1).
*/
function joinup_core_update_0106500(): void {
$entity_type_manager = \Drupal::entityTypeManager();

$get_storage = function (string $entity_type_id) use ($entity_type_manager): EntityStorageInterface {
return $entity_type_manager->getStorage($entity_type_id);
};

$entity_ids = [];

// Retrieve community content to migrate.
$entity_ids['node'] = array_values($get_storage('node')
->getQuery()
->condition('type', CommunityContentHelper::BUNDLES, 'IN')
->condition('sticky', TRUE)
->execute());

// Retrieve solutions to migrate.
$entity_ids['rdf_entity'] = array_values($get_storage('rdf_entity')
->getQuery()
->condition('rid', 'solution')
->exists('field_is_pinned_in')
->execute());

$solutions = [];
$get_pinned_groups = function (SolutionInterface $solution): array {
return array_map(
function (CollectionInterface $collection) {
return $collection->id();
},
$solution->get('field_is_pinned_in')->referencedEntities()
);
};
/** @var \Drupal\solution\Entity\SolutionInterface $solution */
foreach ($get_storage('rdf_entity')->loadMultiple($entity_ids['rdf_entity']) as $solution) {
if ($pinned_groups = $get_pinned_groups($solution)) {
$solutions[$solution->id()] = $pinned_groups;
}
}

// Save data to be restored in a post-update script.
// @see joinup_core_post_update_0106503()
\Drupal::state()->set('joinup_core_update_0106501', [
'entity_ids' => $entity_ids,
'solutions' => $solutions,
]);

// During config import, the Search API indexes are loaded when creating the
// `block.block.eifrecomendationsselector` and `block.block.category` configs
// but the field `field_is_pinned_in` is not yet removed from the Search API
// indexes. This causes an error, as Search API tries to load the field
// definition but the field has been removed already during the config import.
// Explicitly remove the field from indexes in this phase to prevent errors.
foreach (['published', 'unpublished'] as $index_id) {
\Drupal::configFactory()->getEditable("search_api.index.{$index_id}")
->clear('field_settings.field_is_pinned_in')
->save(TRUE);
}
}

/**
* Change the 'only_facilitators' option to 'facilitators_and_authors'.
*/
function joinup_core_update_0106501(): void {
$connection = \Drupal::getContainer()->get('sparql.endpoint');
$query = <<<QUERY
SELECT ?entity
WHERE {
?entity ?content_creation_predicate "only_facilitators" .
VALUES ?content_creation_predicate { <http://joinup.eu/solution/content_creation> <http://joinup.eu/solution/content_creation> }
}
QUERY;

$results = $connection->query($query)->getArrayCopy();
$results = array_map(function (stdClass $result): string {
return $result->entity->getUri();
}, $results);

$update_query = <<<QUERY
DELETE { GRAPH ?g { ?entity ?content_creation_predicate "only_facilitators" } }
INSERT { GRAPH ?g { ?entity ?content_creation_predicate "facilitators_and_authors" } }
WHERE { GRAPH ?g { ?entity ?content_creation_predicate "only_facilitators" } }
QUERY;
$connection->query($update_query);
\Drupal::entityTypeManager()->getStorage('rdf_entity')->resetCache($results);
}

/**
* Create the table for the new Compatibility Document entity type.
*/
function joinup_core_update_0106502(): void {
if (!Database::getConnection()->schema()->tableExists('compatibility_document')) {
$entity_type_manager = \Drupal::entityTypeManager();
$entity_type_manager->clearCachedDefinitions();
$definition = $entity_type_manager->getDefinition('compatibility_document');
\Drupal::entityDefinitionUpdateManager()->installEntityType($definition);
}
}
Loading

0 comments on commit 7a9bfe5

Please sign in to comment.