ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilMDCopyrightMigration Class Reference
+ Inheritance diagram for ilMDCopyrightMigration:
+ Collaboration diagram for ilMDCopyrightMigration:

Public Member Functions

 getLabel ()
 
 getDefaultAmountOfStepsPerRun ()
 
 getPreconditions (Environment $environment)
 
 prepare (Environment $environment)
 
 step (Environment $environment)
 
 getRemainingAmountOfSteps ()
 

Protected Member Functions

 extractFields (string $title, string $copyright)
 
 translatePreInstalledLinksToSVG (string $image_link)
 
 updatePreInstalledTitles (string $link, string $title)
 see https://mantis.ilias.de/view.php?id=41301 More...
 
 cleanupPreInstalledPublicDomainFullName (string $full_name)
 see https://mantis.ilias.de/view.php?id=41301 More...
 

Protected Attributes

ilDBInterface $db
 

Detailed Description

Definition at line 25 of file class.ilMDCopyrightMigration.php.

Member Function Documentation

◆ cleanupPreInstalledPublicDomainFullName()

ilMDCopyrightMigration::cleanupPreInstalledPublicDomainFullName ( string  $full_name)
protected

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

Definition at line 189 of file class.ilMDCopyrightMigration.php.

189 : string
190 {
191 if ($full_name === 'This work has all rights reserved by the owner.') {
192 return 'All rights reserved';
193 }
194 return $full_name;
195 }

◆ extractFields()

ilMDCopyrightMigration::extractFields ( string  $title,
string  $copyright 
)
protected

Definition at line 86 of file class.ilMDCopyrightMigration.php.

89 : array {
90 $full_name = '';
91 $link = '';
92 $image_link = '';
93 $alt_text = '';
94
95 //find the image
96 if (preg_match('/<\s*img((?:.|\n)*?)\/>/i', $copyright, $img_matches)) {
97 if (preg_match('/src\s*=\s*(?:"|\')(.*?)(?:"|\')/i', $img_matches[1], $src_matches)) {
98 $image_link = strip_tags($src_matches[1]);
99 }
100 if (preg_match('/alt\s*=\s*(?:"|\')(.*?)(?:"|\')/i', $img_matches[1], $alt_matches)) {
101 $alt_text = strip_tags($alt_matches[1]);
102 }
103 }
104
105 //find the link
106 if (preg_match('/<\s*a((?:.|\n)[^<]*?)<\s*\/a>/i', $copyright, $link_matches)) {
107 if (preg_match('/href\s*=\s*(?:"|\')(.*?)(?:"|\')/i', $link_matches[1], $name_matches)) {
108 $link = strip_tags($name_matches[1]);
109 }
110 if (preg_match('/>((?:\n|.)*)/i', $link_matches[1], $href_matches)) {
111 $full_name = strip_tags($href_matches[1]);
112 }
113 } else {
114 $full_name = strip_tags($copyright);
115 }
116
117 $image_link = $this->translatePreInstalledLinksToSVG($image_link);
118 $full_name = $this->cleanupPreInstalledPublicDomainFullName($full_name);
119 $title = $this->updatePreInstalledTitles($link, $title);
120
121 return [
122 'title' => [\ilDBConstants::T_TEXT, $title],
123 'full_name' => [\ilDBConstants::T_TEXT, $full_name],
124 'link' => [\ilDBConstants::T_TEXT, $link],
125 'image_link' => [\ilDBConstants::T_TEXT, $image_link],
126 'alt_text' => [\ilDBConstants::T_TEXT, $alt_text]
127 ];
128 }
translatePreInstalledLinksToSVG(string $image_link)
cleanupPreInstalledPublicDomainFullName(string $full_name)
see https://mantis.ilias.de/view.php?id=41301
updatePreInstalledTitles(string $link, string $title)
see https://mantis.ilias.de/view.php?id=41301

Referenced by step().

+ Here is the caller graph for this function:

◆ getDefaultAmountOfStepsPerRun()

ilMDCopyrightMigration::getDefaultAmountOfStepsPerRun ( )

Definition at line 34 of file class.ilMDCopyrightMigration.php.

34 : int
35 {
36 return Migration::INFINITE;
37 }

◆ getLabel()

ilMDCopyrightMigration::getLabel ( )

Definition at line 29 of file class.ilMDCopyrightMigration.php.

29 : string
30 {
31 return "Migration of available copyrights.";
32 }

◆ getPreconditions()

◆ getRemainingAmountOfSteps()

ilMDCopyrightMigration::getRemainingAmountOfSteps ( )

Definition at line 76 of file class.ilMDCopyrightMigration.php.

76 : int
77 {
78 $res = $this->db->query(
79 'SELECT COUNT(*) AS count FROM il_md_cpr_selections WHERE migrated = 0'
80 );
81
82 $row = $this->db->fetchAssoc($res);
83 return (int) $row['count'];
84 }
$res
Definition: ltiservices.php:69

References $res.

◆ prepare()

ilMDCopyrightMigration::prepare ( Environment  $environment)

Definition at line 48 of file class.ilMDCopyrightMigration.php.

48 : void
49 {
50 $this->db = $environment->getResource(Environment::RESOURCE_DATABASE);
51 }
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.

References ILIAS\Setup\Environment\getResource().

+ Here is the call graph for this function:

◆ step()

ilMDCopyrightMigration::step ( Environment  $environment)

Definition at line 53 of file class.ilMDCopyrightMigration.php.

53 : void
54 {
55 $res = $this->db->query(
56 'SELECT entry_id, title, copyright FROM il_md_cpr_selections WHERE migrated = 0 LIMIT 1'
57 );
58
59 if ($row = $this->db->fetchAssoc($res)) {
60 if (!isset($row['entry_id'])) {
61 return;
62 }
63 $fields = $this->extractFields(
64 (string) ($row['title'] ?? ''),
65 (string) ($row['copyright'] ?? '')
66 );
67 $fields['migrated'] = [\ilDBConstants::T_INTEGER, 1];
68 $this->db->update(
69 'il_md_cpr_selections',
70 $fields,
71 ['entry_id' => [\ilDBConstants::T_INTEGER, (int) $row['entry_id']]]
72 );
73 }
74 }
extractFields(string $title, string $copyright)

References $res, extractFields(), and ilDBConstants\T_INTEGER.

+ Here is the call graph for this function:

◆ translatePreInstalledLinksToSVG()

ilMDCopyrightMigration::translatePreInstalledLinksToSVG ( string  $image_link)
protected

Definition at line 130 of file class.ilMDCopyrightMigration.php.

130 : string
131 {
132 $mapping = [
133 // 4.0
134 'https://i.creativecommons.org/l/by-nc-nd/4.0/88x31.png' => 'https://mirrors.creativecommons.org/presskit/buttons/88x31/svg/by-nc-nd.svg',
135 'https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png' => 'https://mirrors.creativecommons.org/presskit/buttons/88x31/svg/by-nc-sa.svg',
136 'https://i.creativecommons.org/l/by-nc/4.0/88x31.png' => 'https://mirrors.creativecommons.org/presskit/buttons/88x31/svg/by-nc.svg',
137 'https://i.creativecommons.org/l/by-nd/4.0/88x31.png' => 'https://mirrors.creativecommons.org/presskit/buttons/88x31/svg/by-nd.svg',
138 'https://i.creativecommons.org/l/by-sa/4.0/88x31.png' => 'https://mirrors.creativecommons.org/presskit/buttons/88x31/svg/by-sa.svg',
139 'https://i.creativecommons.org/l/by/4.0/88x31.png' => 'https://mirrors.creativecommons.org/presskit/buttons/88x31/svg/by.svg',
140 // 3.0
141 'http://i.creativecommons.org/l/by-nc-nd/3.0/88x31.png' => 'https://mirrors.creativecommons.org/presskit/buttons/88x31/svg/by-nc-nd.svg',
142 'http://i.creativecommons.org/l/by-nc-sa/3.0/88x31.png' => 'https://mirrors.creativecommons.org/presskit/buttons/88x31/svg/by-nc-sa.svg',
143 'http://i.creativecommons.org/l/by-nc/3.0/88x31.png' => 'https://mirrors.creativecommons.org/presskit/buttons/88x31/svg/by-nc.svg',
144 'http://i.creativecommons.org/l/by-nd/3.0/88x31.png' => 'https://mirrors.creativecommons.org/presskit/buttons/88x31/svg/by-nd.svg',
145 'http://i.creativecommons.org/l/by-sa/3.0/88x31.png' => 'https://mirrors.creativecommons.org/presskit/buttons/88x31/svg/by-sa.svg',
146 'http://i.creativecommons.org/l/by/3.0/88x31.png' => 'https://mirrors.creativecommons.org/presskit/buttons/88x31/svg/by.svg'
147 ];
148
149 if (key_exists($image_link, $mapping)) {
150 return $mapping[$image_link];
151 }
152 return $image_link;
153 }

◆ updatePreInstalledTitles()

ilMDCopyrightMigration::updatePreInstalledTitles ( string  $link,
string  $title 
)
protected

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

Definition at line 158 of file class.ilMDCopyrightMigration.php.

158 : string
159 {
160 $old_titles_by_link = [
161 'http://creativecommons.org/licenses/by-nc-nd/4.0/' => 'Attribution Non-commercial No Derivatives (by-nc-nd)',
162 'http://creativecommons.org/licenses/by-nc-sa/4.0/' => 'Attribution Non-commercial Share Alike (by-nc-sa)',
163 'http://creativecommons.org/licenses/by-nc/4.0/' => 'Attribution Non-commercial (by-nc)',
164 'http://creativecommons.org/licenses/by-nd/4.0/' => 'Attribution No Derivatives (by-nd)',
165 'http://creativecommons.org/licenses/by-sa/4.0/' => 'Attribution Share Alike (by-sa)',
166 'http://creativecommons.org/licenses/by/4.0/' => 'Attribution (by)'
167 ];
168 $new_titles_by_link = [
169 'http://creativecommons.org/licenses/by-nc-nd/4.0/' => 'Attribution Non-commercial No Derivatives (BY-NC-ND) 4.0',
170 'http://creativecommons.org/licenses/by-nc-sa/4.0/' => 'Attribution Non-commercial Share Alike (BY-NC-SA) 4.0',
171 'http://creativecommons.org/licenses/by-nc/4.0/' => 'Attribution Non-commercial (BY-NC) 4.0',
172 'http://creativecommons.org/licenses/by-nd/4.0/' => 'Attribution No Derivatives (BY-ND) 4.0',
173 'http://creativecommons.org/licenses/by-sa/4.0/' => 'Attribution Share Alike (BY-SA) 4.0',
174 'http://creativecommons.org/licenses/by/4.0/' => 'Attribution (BY) 4.0'
175 ];
176 if (
177 key_exists($link, $old_titles_by_link) &&
178 $old_titles_by_link[$link] === $title &&
179 key_exists($link, $new_titles_by_link)
180 ) {
181 return $new_titles_by_link[$link];
182 }
183 return $title;
184 }

Field Documentation

◆ $db

ilDBInterface ilMDCopyrightMigration::$db
protected

Definition at line 27 of file class.ilMDCopyrightMigration.php.


The documentation for this class was generated from the following file: