Skip to content

Commit

Permalink
MetaData: also rename preinstalled copyrights for fresh installations…
Browse files Browse the repository at this point in the history
… (41301)
  • Loading branch information
schmitz-ilias committed Oct 29, 2024
1 parent be43bd6 commit 6fe1d2d
Showing 1 changed file with 42 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,17 @@ public function prepare(Environment $environment): void
public function step(Environment $environment): void
{
$res = $this->db->query(
'SELECT entry_id, copyright FROM il_md_cpr_selections WHERE migrated = 0 LIMIT 1'
'SELECT entry_id, title, copyright FROM il_md_cpr_selections WHERE migrated = 0 LIMIT 1'
);

if ($row = $this->db->fetchAssoc($res)) {
if (!isset($row['entry_id'])) {
return;
}
$fields = $this->extractFields((string) ($row['copyright'] ?? ''));
$fields = $this->extractFields(
(string) ($row['title'] ?? ''),
(string) ($row['copyright'] ?? '')
);
$fields['migrated'] = [\ilDBConstants::T_INTEGER, 1];
$this->db->update(
'il_md_cpr_selections',
Expand All @@ -80,8 +83,10 @@ public function getRemainingAmountOfSteps(): int
return (int) $row['count'];
}

protected function extractFields(string $copyright): array
{
protected function extractFields(
string $title,
string $copyright
): array {
$full_name = '';
$link = '';
$image_link = '';
Expand Down Expand Up @@ -111,8 +116,10 @@ protected function extractFields(string $copyright): array

$image_link = $this->translatePreInstalledLinksToSVG($image_link);
$full_name = $this->cleanupPreInstalledPublicDomainFullName($full_name);
$title = $this->updatePreInstalledTitles($link, $title);

return [
'title' => [\ilDBConstants::T_TEXT, $full_name],
'full_name' => [\ilDBConstants::T_TEXT, $full_name],
'link' => [\ilDBConstants::T_TEXT, $link],
'image_link' => [\ilDBConstants::T_TEXT, $image_link],
Expand Down Expand Up @@ -145,6 +152,37 @@ protected function translatePreInstalledLinksToSVG(string $image_link): string
return $image_link;
}

/**
* see https://mantis.ilias.de/view.php?id=41301
*/
protected function updatePreInstalledTitles(string $link, string $title): string
{
$old_titles_by_link = [
'http://creativecommons.org/licenses/by-nc-nd/4.0/' => 'Attribution Non-commercial No Derivatives (by-nc-nd)',
'http://creativecommons.org/licenses/by-nc-sa/4.0/' => 'Attribution Non-commercial Share Alike (by-nc-sa)',
'http://creativecommons.org/licenses/by-nc/4.0/' => 'Attribution Non-commercial (by-nc)',
'http://creativecommons.org/licenses/by-nd/4.0/' => 'Attribution No Derivatives (by-nd)',
'http://creativecommons.org/licenses/by-sa/4.0/' => 'Attribution Share Alike (by-sa)',
'http://creativecommons.org/licenses/by/4.0/' => 'Attribution (by)'
];
$new_titles_by_link = [
'http://creativecommons.org/licenses/by-nc-nd/4.0/' => 'Attribution Non-commercial No Derivatives (BY-NC-ND) 4.0',
'http://creativecommons.org/licenses/by-nc-sa/4.0/' => 'Attribution Non-commercial Share Alike (BY-NC-SA) 4.0',
'http://creativecommons.org/licenses/by-nc/4.0/' => 'Attribution Non-commercial (BY-NC) 4.0',
'http://creativecommons.org/licenses/by-nd/4.0/' => 'Attribution No Derivatives (BY-ND) 4.0',
'http://creativecommons.org/licenses/by-sa/4.0/' => 'Attribution Share Alike (BY-SA) 4.0',
'http://creativecommons.org/licenses/by/4.0/' => 'Attribution (BY) 4.0'
];
if (
key_exists($link, $old_titles_by_link) &&
$old_titles_by_link[$link] === $title &&
key_exists($link, $new_titles_by_link)
) {
return $new_titles_by_link[$link];
}
return $title;
}

/**
* see https://mantis.ilias.de/view.php?id=41301
*/
Expand Down

0 comments on commit 6fe1d2d

Please sign in to comment.