ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilMDCopyrightUpdateSteps.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
23 protected \ilDBInterface $db;
24
25 public function prepare(\ilDBInterface $db): void
26 {
27 $this->db = $db;
28 }
29
33 public function step_1(): void
34 {
35 if (!$this->db->tableColumnExists('il_md_cpr_selections', 'full_name')) {
36 $this->db->addTableColumn(
37 'il_md_cpr_selections',
38 'full_name',
39 ['type' => ilDBConstants::T_CLOB]
40 );
41 }
42 }
43
47 public function step_2(): void
48 {
49 if (!$this->db->tableColumnExists('il_md_cpr_selections', 'link')) {
50 $this->db->addTableColumn(
51 'il_md_cpr_selections',
52 'link',
53 ['type' => ilDBConstants::T_CLOB]
54 );
55 }
56 }
57
61 public function step_3(): void
62 {
63 if (!$this->db->tableColumnExists('il_md_cpr_selections', 'image_link')) {
64 $this->db->addTableColumn(
65 'il_md_cpr_selections',
66 'image_link',
67 ['type' => ilDBConstants::T_CLOB]
68 );
69 }
70 }
71
75 public function step_4(): void
76 {
77 if (!$this->db->tableColumnExists('il_md_cpr_selections', 'alt_text')) {
78 $this->db->addTableColumn(
79 'il_md_cpr_selections',
80 'alt_text',
81 ['type' => ilDBConstants::T_CLOB]
82 );
83 }
84 }
85
89 public function step_5(): void
90 {
91 if (!$this->db->tableColumnExists('il_md_cpr_selections', 'migrated')) {
92 $this->db->addTableColumn(
93 'il_md_cpr_selections',
94 'migrated',
95 [
97 'length' => 4,
98 'default' => 0
99 ]
100 );
101 }
102 }
103
108 public function step_6(): void
109 {
110 if (!$this->db->tableColumnExists('il_md_cpr_selections', 'image_file')) {
111 $this->db->addTableColumn(
112 'il_md_cpr_selections',
113 'image_file',
114 ['type' => ilDBConstants::T_CLOB]
115 );
116 }
117 }
118
122 public function step_7(): void
123 {
124 $title = "Public Domain";
125 $full_name = "This work is free of known copyright restrictions.";
126 $link = "http://creativecommons.org/publicdomain/zero/1.0/";
127 $image_link = "https://licensebuttons.net/p/zero/1.0/88x31.png";
128 $alt_text = "CC0";
129
130 $next_id = $this->db->nextId('il_md_cpr_selections');
131
132 $res = $this->db->query(
133 'SELECT MAX(position) AS max FROM il_md_cpr_selections WHERE is_default = 0'
134 );
135 $row = $this->db->fetchAssoc($res);
136 $position = isset($row['max']) ? $row['max'] + 1 : 0;
137
138 $this->db->insert(
139 'il_md_cpr_selections',
140 [
141 'entry_id' => [\ilDBConstants::T_INTEGER, $next_id],
142 'title' => [\ilDBConstants::T_TEXT, $title],
143 'description' => [\ilDBConstants::T_TEXT, ''],
144 'is_default' => [\ilDBConstants::T_INTEGER, 0],
145 'outdated' => [\ilDBConstants::T_INTEGER, 0],
146 'position' => [\ilDBConstants::T_INTEGER, $position],
147 'full_name' => [\ilDBConstants::T_TEXT, $full_name],
148 'link' => [\ilDBConstants::T_TEXT, $link],
149 'image_link' => [\ilDBConstants::T_TEXT, $image_link],
150 'image_file' => [\ilDBConstants::T_TEXT, ''],
151 'alt_text' => [\ilDBConstants::T_TEXT, $alt_text],
152 'migrated' => [\ilDBConstants::T_INTEGER, 1]
153 ]
154 );
155 }
156
160 public function step_8(): void
161 {
162 $title = "Public Domain";
163 $full_name = "This work is free of known copyright restrictions.";
164 $old_image_link = "https://licensebuttons.net/p/zero/1.0/88x31.png";
165 $new_image_link = "https://mirrors.creativecommons.org/presskit/buttons/88x31/svg/cc-zero.svg";
166
167 $res = $this->db->query(
168 'SELECT entry_id FROM il_md_cpr_selections WHERE title = ' .
169 $this->db->quote($title, ilDBConstants::T_TEXT) . ' AND full_name = ' .
170 $this->db->quote($full_name, ilDBConstants::T_TEXT) . ' AND image_link = ' .
171 $this->db->quote($old_image_link, ilDBConstants::T_TEXT)
172 );
173 if (($row = $this->db->fetchAssoc($res)) && isset($row['entry_id'])) {
174 $this->db->update(
175 'il_md_cpr_selections',
176 ['image_link' => [\ilDBConstants::T_TEXT, $new_image_link]],
177 ['entry_id' => [\ilDBConstants::T_INTEGER, $row['entry_id']]]
178 );
179 }
180 }
181
186 public function step_9(): void
187 {
188 $title = "All rights reserved";
189 $old_full_name = "This work has all rights reserved by the owner.";
190 $new_full_name = "All rights reserved";
191 $new_description = "The copyright holder reserves, or holds for their own use, all the rights provided by copyright law.";
192
193 $res = $this->db->query(
194 'SELECT entry_id FROM il_md_cpr_selections WHERE title = ' .
195 $this->db->quote($title, ilDBConstants::T_TEXT) . ' AND full_name = ' .
196 $this->db->quote($old_full_name, ilDBConstants::T_TEXT) .
197 " AND COALESCE(link, '') = '' AND COALESCE(description, '') = ''"
198 );
199 if (($row = $this->db->fetchAssoc($res)) && isset($row['entry_id'])) {
200 $this->db->update(
201 'il_md_cpr_selections',
202 [
203 'full_name' => [\ilDBConstants::T_TEXT, $new_full_name],
204 'description' => [\ilDBConstants::T_TEXT, $new_description]
205 ],
206 ['entry_id' => [\ilDBConstants::T_INTEGER, $row['entry_id']]]
207 );
208 }
209 }
210
215 public function step_10(): void
216 {
217 $title = "Public Domain";
218 $link = "http://creativecommons.org/publicdomain/zero/1.0/";
219 $old_full_name = "This work is free of known copyright restrictions.";
220 $new_full_name = "Public Domain";
221 $new_description = "Creative work to which no exclusive intellectual property rights apply.";
222
223 $res = $this->db->query(
224 'SELECT entry_id FROM il_md_cpr_selections WHERE title = ' .
225 $this->db->quote($title, ilDBConstants::T_TEXT) . ' AND full_name = ' .
226 $this->db->quote($old_full_name, ilDBConstants::T_TEXT) . ' AND link = ' .
227 $this->db->quote($link, ilDBConstants::T_TEXT) .
228 " AND COALESCE(description, '') = ''"
229 );
230 if (($row = $this->db->fetchAssoc($res)) && isset($row['entry_id'])) {
231 $this->db->update(
232 'il_md_cpr_selections',
233 [
234 'full_name' => [\ilDBConstants::T_TEXT, $new_full_name],
235 'description' => [\ilDBConstants::T_TEXT, $new_description]
236 ],
237 ['entry_id' => [\ilDBConstants::T_INTEGER, $row['entry_id']]]
238 );
239 }
240 }
241
245 public function step_11(): void
246 {
247 $old_titles_by_link = [
248 'http://creativecommons.org/licenses/by-nc-nd/4.0/' => 'Attribution Non-commercial No Derivatives (by-nc-nd)',
249 'http://creativecommons.org/licenses/by-nc-sa/4.0/' => 'Attribution Non-commercial Share Alike (by-nc-sa)',
250 'http://creativecommons.org/licenses/by-nc/4.0/' => 'Attribution Non-commercial (by-nc)',
251 'http://creativecommons.org/licenses/by-nd/4.0/' => 'Attribution No Derivatives (by-nd)',
252 'http://creativecommons.org/licenses/by-sa/4.0/' => 'Attribution Share Alike (by-sa)',
253 'http://creativecommons.org/licenses/by/4.0/' => 'Attribution (by)'
254 ];
255 $new_titles_by_link = [
256 'http://creativecommons.org/licenses/by-nc-nd/4.0/' => 'Attribution Non-commercial No Derivatives (BY-NC-ND) 4.0',
257 'http://creativecommons.org/licenses/by-nc-sa/4.0/' => 'Attribution Non-commercial Share Alike (BY-NC-SA) 4.0',
258 'http://creativecommons.org/licenses/by-nc/4.0/' => 'Attribution Non-commercial (BY-NC) 4.0',
259 'http://creativecommons.org/licenses/by-nd/4.0/' => 'Attribution No Derivatives (BY-ND) 4.0',
260 'http://creativecommons.org/licenses/by-sa/4.0/' => 'Attribution Share Alike (BY-SA) 4.0',
261 'http://creativecommons.org/licenses/by/4.0/' => 'Attribution (BY) 4.0'
262 ];
263
264 foreach ($old_titles_by_link as $link => $old_title) {
265 $res = $this->db->query(
266 'SELECT entry_id FROM il_md_cpr_selections WHERE title = ' .
267 $this->db->quote($old_title, ilDBConstants::T_TEXT) . ' AND link = ' .
268 $this->db->quote($link, ilDBConstants::T_TEXT)
269 );
270 if (
271 ($row = $this->db->fetchAssoc($res)) &&
272 isset($row['entry_id']) &&
273 isset($new_titles_by_link[$link])
274 ) {
275 $this->db->update(
276 'il_md_cpr_selections',
277 ['title' => [\ilDBConstants::T_TEXT, $new_titles_by_link[$link]]],
278 ['entry_id' => [\ilDBConstants::T_INTEGER, $row['entry_id']]]
279 );
280 }
281 }
282 }
283
288 public function step_12(): void
289 {
290 $title = "All rights reserved";
291 $old_copyright = "This work has all rights reserved by the owner.";
292 $new_description = "The copyright holder reserves, or holds for their own use, all the rights provided by copyright law.";
293
294 $res = $this->db->query(
295 'SELECT entry_id FROM il_md_cpr_selections WHERE title = ' .
296 $this->db->quote($title, ilDBConstants::T_TEXT) . ' AND copyright = ' .
297 $this->db->quote($old_copyright, ilDBConstants::T_TEXT) .
298 " AND COALESCE(description, '') = ''"
299 );
300 if (($row = $this->db->fetchAssoc($res)) && isset($row['entry_id'])) {
301 $this->db->update(
302 'il_md_cpr_selections',
303 ['description' => [\ilDBConstants::T_TEXT, $new_description]],
304 ['entry_id' => [\ilDBConstants::T_INTEGER, $row['entry_id']]]
305 );
306 }
307 }
308}
step_8()
Replace CC0 image link by svg.
step_9()
Change title, description and full name of 'All rights reserved', see https://mantis....
step_12()
Also change description of unmigrated 'All rights reserved', see https://mantis.ilias....
step_3()
Add a column to il_md_cpr_selections for the link to the licence's image.
step_6()
Add a column to il_md_cpr_selections for the string identifier for the licence's image,...
step_7()
Add CC0 to the available copyrights.
step_11()
Change title of CC licences, see https://mantis.ilias.de/view.php?id=41898.
step_5()
Add a column to il_md_cpr_selections to track which licences have been migrated.
step_4()
Add a column to il_md_cpr_selections for the alt text of the licence's image.
step_10()
Change title, description and full name of 'Public Domain', see https://mantis.ilias....
prepare(\ilDBInterface $db)
Prepare the execution of the steps.
step_2()
Add a column to il_md_cpr_selections for the link to the licence.
step_1()
Add a column to il_md_cpr_selections for the full name of the licence.
Interface ilDBInterface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$res
Definition: ltiservices.php:69