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

ISAICP-8568: Fix update order.

parent b1d70161
No related branches found
No related tags found
1 merge request!176Release v1.109.0
...@@ -14,21 +14,10 @@ ...@@ -14,21 +14,10 @@
declare(strict_types=1); declare(strict_types=1);
use Drupal\Component\Utility\Variable;
use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\Sql\SqlEntityStorageInterface; use Drupal\Core\Entity\Sql\SqlEntityStorageInterface;
use Drupal\Core\Session\AccountSwitcherInterface;
use Drupal\Core\Utility\UpdateException;
use Drupal\joinup_core\DeployAndSmokeTestHelper; use Drupal\joinup_core\DeployAndSmokeTestHelper;
use Drupal\joinup_document\Entity\DocumentInterface; use Drupal\joinup_document\Entity\DocumentInterface;
use Drupal\joinup_workflow\WorkflowHelperInterface;
use Drupal\solution\Entity\Solution;
use Drupal\user\Entity\User;
use Drupal\user\UserInterface;
// Temporary constant.
// phpcs:ignore DrupalPractice.Constants.GlobalConstant.GlobalConstant
const SOLUTION_ARCHIVAL_ACTOR_ID = 744195;
/** /**
* Create Interoperable Europe Act document as custom page. * Create Interoperable Europe Act document as custom page.
...@@ -91,97 +80,3 @@ function joinup_core_deploy_110901(): string { ...@@ -91,97 +80,3 @@ function joinup_core_deploy_110901(): string {
Cache::invalidateTags($node->getCacheTagsToInvalidate()); Cache::invalidateTags($node->getCacheTagsToInvalidate());
return "Orphan archived revision of document node with ID '{$node->id()}' was programmatically changed to published."; return "Orphan archived revision of document node with ID '{$node->id()}' was programmatically changed to published.";
} }
/**
* Archives solutions specified by Functional Team.
*/
function joinup_core_deploy_110902(&$sandbox): string {
if (!isset($sandbox['remaining'])) {
$stream = fopen(__DIR__ . '/solutions-to-archive.csv', 'r');
// CSV is small enough to store it in memory.
while (is_array($item = fgetcsv($stream))) {
$sandbox['remaining'][$item[0]] = $item[1] ?? $item[0];
}
// Drop header.
unset($sandbox['remaining']['ID']);
fclose($stream);
$sandbox['total'] = count($sandbox['remaining']);
$sandbox['processed'] = 0;
}
$accountSwitcher = \Drupal::service('account_switcher');
assert($accountSwitcher instanceof AccountSwitcherInterface);
$storage = \Drupal::entityTypeManager()->getStorage('rdf_entity');
$storage->resetCache();
$logger = Drupal::logger('joinup_core');
$workflowHelper = \Drupal::service('joinup_workflow.workflow_helper');
assert($workflowHelper instanceof WorkflowHelperInterface);
// We need a moderator account to perform the workflow state change.
if (!($actor = User::load(SOLUTION_ARCHIVAL_ACTOR_ID)) instanceof UserInterface) {
throw new UpdateException(sprintf(
"Cannot find the predefined actor for the operation. Was looking for user account with id '%s'.",
SOLUTION_ARCHIVAL_ACTOR_ID
));
}
if (!$actor->hasRole('moderator')) {
throw new UpdateException('The predefined actor does not have the moderator role.');
}
$items = array_splice($sandbox['remaining'], 0, 50);
$solutions = $storage->loadMultiple(array_keys($items));
$notLoadableSolutions = array_diff_key($items, $solutions);
$accountSwitcher->switchTo($actor);
foreach ($solutions as $id => $solution) {
if (!$solution instanceof Solution) {
$logger->warning(sprintf(
"The RDF entity with ID '%s' is not a solution (referred with title '%s' in the spreadsheet)",
$id,
$items[$id],
));
continue;
}
if ($solution->isArchived() || !$solution->isTargetWorkflowStateAllowed('archived')) {
$logger->warning(sprintf(
"The solution with ID '%s' (referred with title '%s' in the spreadsheet) cannot be archived. Its current state is '%s'.",
$id,
$items[$id],
$solution->getWorkflowState(),
));
continue;
}
try {
$solution->skip_notification = TRUE;
$solution->notifyContactOnly = TRUE;
$workflowHelper->archiveEntity($solution);
}
catch (\Exception $exception) {
$logger->error(sprintf(
"The solution with ID '%s' (referred with title '%s' in the spreadsheet) cannot be archived:\n%s",
$id,
$items[$id],
$exception->getMessage(),
));
}
}
if (!empty($notLoadableSolutions)) {
$logger->warning(sprintf(
"The following solutions were not found:\n%s",
Variable::export($notLoadableSolutions),
));
}
$accountSwitcher->switchBack();
$sandbox['processed'] += count($items);
$sandbox['#finished'] = (int) empty($sandbox['remaining']);
return sprintf(
"Processed %s solutions from total %s items to archive.",
$sandbox['processed'],
$sandbox['total'],
);
}
...@@ -7,11 +7,22 @@ ...@@ -7,11 +7,22 @@
declare(strict_types=1); declare(strict_types=1);
use Drupal\Component\Utility\Variable;
use Drupal\Core\Session\AccountSwitcherInterface;
use Drupal\Core\Utility\UpdateException;
use Drupal\joinup_taxonomy\Entity\MappedTerm; use Drupal\joinup_taxonomy\Entity\MappedTerm;
use Drupal\joinup_workflow\WorkflowHelperInterface;
use Drupal\node\Entity\Node; use Drupal\node\Entity\Node;
use Drupal\pathauto\PathautoState; use Drupal\pathauto\PathautoState;
use Drupal\search_api\Entity\Index; use Drupal\search_api\Entity\Index;
use Drupal\solution\Entity\Solution;
use Drupal\sparql_entity_storage\UriEncoder; use Drupal\sparql_entity_storage\UriEncoder;
use Drupal\user\Entity\User;
use Drupal\user\UserInterface;
// Temporary constant.
// phpcs:ignore DrupalPractice.Constants.GlobalConstant.GlobalConstant
const SOLUTION_ARCHIVAL_ACTOR_ID = 744195;
/** /**
* Disable RDF Sync for the deployment. * Disable RDF Sync for the deployment.
...@@ -277,3 +288,97 @@ function _joinup_rdf_deploy_flatten_rdf_values(array $data): array { ...@@ -277,3 +288,97 @@ function _joinup_rdf_deploy_flatten_rdf_values(array $data): array {
} }
return $values; return $values;
} }
/**
* Archives solutions specified by Functional Team.
*/
function joinup_rdf_deploy_110906(&$sandbox): string {
if (!isset($sandbox['remaining'])) {
$stream = fopen(__DIR__ . '/solutions-to-archive.csv', 'r');
// CSV is small enough to store it in memory.
while (is_array($item = fgetcsv($stream))) {
$sandbox['remaining'][$item[0]] = $item[1] ?? $item[0];
}
// Drop header.
unset($sandbox['remaining']['ID']);
fclose($stream);
$sandbox['total'] = count($sandbox['remaining']);
$sandbox['processed'] = 0;
}
$accountSwitcher = \Drupal::service('account_switcher');
assert($accountSwitcher instanceof AccountSwitcherInterface);
$storage = \Drupal::entityTypeManager()->getStorage('rdf_entity');
$storage->resetCache();
$logger = Drupal::logger('joinup_core');
$workflowHelper = \Drupal::service('joinup_workflow.workflow_helper');
assert($workflowHelper instanceof WorkflowHelperInterface);
// We need a moderator account to perform the workflow state change.
if (!($actor = User::load(SOLUTION_ARCHIVAL_ACTOR_ID)) instanceof UserInterface) {
throw new UpdateException(sprintf(
"Cannot find the predefined actor for the operation. Was looking for user account with id '%s'.",
SOLUTION_ARCHIVAL_ACTOR_ID
));
}
if (!$actor->hasRole('moderator')) {
throw new UpdateException('The predefined actor does not have the moderator role.');
}
$items = array_splice($sandbox['remaining'], 0, 50);
$solutions = $storage->loadMultiple(array_keys($items));
$notLoadableSolutions = array_diff_key($items, $solutions);
$accountSwitcher->switchTo($actor);
foreach ($solutions as $id => $solution) {
if (!$solution instanceof Solution) {
$logger->warning(sprintf(
"The RDF entity with ID '%s' is not a solution (referred with title '%s' in the spreadsheet)",
$id,
$items[$id],
));
continue;
}
if ($solution->isArchived() || !$solution->isTargetWorkflowStateAllowed('archived')) {
$logger->warning(sprintf(
"The solution with ID '%s' (referred with title '%s' in the spreadsheet) cannot be archived. Its current state is '%s'.",
$id,
$items[$id],
$solution->getWorkflowState(),
));
continue;
}
try {
$solution->skip_notification = TRUE;
$solution->notifyContactOnly = TRUE;
$workflowHelper->archiveEntity($solution);
}
catch (\Exception $exception) {
$logger->error(sprintf(
"The solution with ID '%s' (referred with title '%s' in the spreadsheet) cannot be archived:\n%s",
$id,
$items[$id],
$exception->getMessage(),
));
}
}
if (!empty($notLoadableSolutions)) {
$logger->warning(sprintf(
"The following solutions were not found:\n%s",
Variable::export($notLoadableSolutions),
));
}
$accountSwitcher->switchBack();
$sandbox['processed'] += count($items);
$sandbox['#finished'] = (int) empty($sandbox['remaining']);
return sprintf(
"Processed %s solutions from total %s items to archive.",
$sandbox['processed'],
$sandbox['total'],
);
}
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