Skip to content
Snippets Groups Projects
Commit ac9c50f5 authored by Zoltan Horvath's avatar Zoltan Horvath
Browse files

ISAICP-9076: Add update hook.

parent 0b3ac231
No related branches found
No related tags found
1 merge request!188Patch release v1.112.3
......@@ -13,3 +13,50 @@
*/
declare(strict_types=1);
use Drupal\joinup_release\Entity\ReleaseInterface;
use Drupal\pathauto\PathautoState;
/**
* Fix releases without version string and regenerate their path aliases.
*/
function joinup_core_deploy_111300(): string {
$entityTypeManager = \Drupal::entityTypeManager();
$nodeStorage = \Drupal::entityTypeManager()->getStorage('node');
$pathAliasStorage = $entityTypeManager->getStorage('path_alias');
$releaseIdsWithoutVersion = $nodeStorage
->getQuery()
->accessCheck(FALSE)
->condition('type', 'release')
->notExists('release_number')
->execute();
$changedReleaseCount = 0;
foreach ($nodeStorage->loadMultiple($releaseIdsWithoutVersion) as $release) {
assert($release instanceof ReleaseInterface);
assert($release->get('release_number')->isEmpty());
// Skip doing anything to releases whose alias does not end with /release -
// so we don't touch releases having aliases ending with /release-0,
// /release-1 etc.: these aliases are harmless.
$pathField = $release->get('path');
if (!is_string($pathField->alias) || !str_ends_with($pathField->alias, '/release')) {
continue;
}
// Delete the preexisting alias so Redirect module won't create a redirect
// (which causes the same issue what we're solving here).
if ($aliasId = $pathField->pid) {
$pathAliasStorage->load($aliasId)->delete();
}
$release->skip_notification = TRUE;
$release
->set('release_number', 'no-version')
->set('path', ['pathauto' => PathautoState::CREATE])
->save();
$changedReleaseCount++;
}
return sprintf(
"Added 'no-version' to %s releases which lack version number with an alias ending with '/release'; and re-generated their aliases",
$changedReleaseCount,
);
}
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