Skip to content

Commit

Permalink
Released version 3.4.20 for Omeka S v4.1.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Berthereau authored and Daniel Berthereau committed Jul 1, 2024
1 parent 0689dde commit 5beca8c
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 6 deletions.
4 changes: 2 additions & 2 deletions config/module.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ author_link = "https://gitlab.com/Daniel-KM"
module_link = "https://gitlab.com/Daniel-KM/Omeka-S-module-Timeline"
support_link = "https://gitlab.com/Daniel-KM/Omeka-S-module-Timeline/-/issues"
configurable = false
version = "3.4.18"
omeka_version_constraint = "^3.1.0 || ^4.0.0"
version = "3.4.20"
omeka_version_constraint = "^4.1.0"
97 changes: 93 additions & 4 deletions data/scripts/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,98 @@
$entityManager->persist($block);
}
$entityManager->flush();
}

$message = new Message(
'The next version (3.4.20) will require Omeka S v4.1.' // @translate
);
$messenger->addWarning($message);
if (version_compare($oldVersion, '3.4.20', '<')) {
/** @see /BlockPlus/data/scripts/upgrade.php */

$logger = $services->get('Omeka\Logger');

$pageRepository = $entityManager->getRepository(\Omeka\Entity\SitePage::class);
$blocksRepository = $entityManager->getRepository(\Omeka\Entity\SitePageBlock::class);

/**
* Replace filled setttings "heading" by a specific block "Heading" or "Html".
*/

$hasBlockPlus = class_exists('BlockPlus\Module', false);
$viewHelpers = $services->get('ViewHelperManager');
$escape = $viewHelpers->get('escapeHtml');

$blockTemplates = [
'timeline' => 'common/block-layout/timeline',
'timelineExhibit' => 'common/block-layout/timeline-exhibit',
];
$blockTemplatesHeading = $blockTemplates;

$pagesWithHeading = [];
$processedBlocksId = [];
foreach ($pageRepository->findAll() as $page) {
$pageSlug = $page->getSlug();
$siteSlug = $page->getSite()->getSlug();
$position = 0;
foreach ($page->getBlocks() as $block) {
$block->setPosition(++$position);
$layout = $block->getLayout();
if (!isset($blockTemplatesHeading[$layout])) {
continue;
}
$blockId = $block->getId();
$data = $block->getData() ?: [];
$heading = $data['heading'] ?? '';
if (strlen($heading) && !isset($processedBlocksId[$blockId])) {
$b = new \Omeka\Entity\SitePageBlock();
$b->setLayout($hasBlockPlus ? 'heading' : 'html');
$b->setPage($page);
$b->setPosition(++$position);
$b->setData($hasBlockPlus
? ['text' => $heading, 'level' => 2]
: ['html' => '<h2>' . $escape($heading) . '</h2>']
);
$entityManager->persist($b);
$block->setPosition(++$position);
$pagesWithHeading[$siteSlug][$pageSlug] = $pageSlug;
$processedBlocksId[$blockId] = $blockId;
}
unset($data['heading']);
$block->setData($data);
}
}

// Do a clear to fix issues with new blocks created during migration.
$entityManager->flush();
$entityManager->clear();

if (!empty($pagesWithHeading)) {
$pagesWithHeading = array_map('array_values', $pagesWithHeading);
$message = new Message(
'The setting "heading" was removed from blocks. A new block "Heading" (module BlockPlus) or "Html" was prepended to all blocks that had a filled heading. You may check pages for styles: %s', // @translate
json_encode($pagesWithHeading, 448)
);
$messenger->addWarning($message);
$logger->warn((string) $message);
}

/**
* Replace filled settings "template" by the new layout data for timeline.
*/

$blockTemplatesRenamed = [
'simile_online' => 'timeline-simile-online', // @translate
'knightlab' => 'timeline-knightlab', // @translate
];

foreach ($blocksRepository->findBy(['layout' => 'timeline']) as $block) {
$data = $block->getData();
$library = $data['library'] ?? null;
if (isset($blockTemplatesRenamed[$library])) {
$layoutData = $block->getLayoutData();
$layoutData['template_name'] = $blockTemplatesRenamed[$library];
$block->setLayoutData($layoutData);
}
unset($data['library']);
$block->setData($data);
}

$entityManager->flush();
}

0 comments on commit 5beca8c

Please sign in to comment.