Skip to content

Commit aafbdf7

Browse files
committed
MDL-43195 license: upgrading cc core licenses to version 4.0
The short name of the cc licenses are trailed with a suffix containing the version number (current 3.0 and 4.0). The old cc* licenses become the new cc-*-3.0 licenses and are disables, because the new cc*-4.0 licenses are the current ones.
1 parent 478abd6 commit aafbdf7

File tree

8 files changed

+203
-151
lines changed

8 files changed

+203
-151
lines changed

admin/tool/licensemanager/tests/behat/license_manager.feature

+14-14
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ Feature: Licence manager
1010
Then I should see "Licence not specified" in the "unknown" "table_row"
1111
And I should see "All rights reserved" in the "allrightsreserved" "table_row"
1212
And I should see "Public domain" in the "public" "table_row"
13-
And I should see "Creative Commons" in the "cc" "table_row"
14-
And I should see "Creative Commons - NoDerivs" in the "cc-nd" "table_row"
15-
And I should see "Creative Commons - No Commercial NoDerivs" in the "cc-nc-nd" "table_row"
16-
And I should see "Creative Commons - No Commercial" in the "cc-nc" "table_row"
17-
And I should see "Creative Commons - No Commercial ShareAlike" in the "cc-nc-sa" "table_row"
18-
And I should see "Creative Commons - ShareAlike" in the "cc-sa" "table_row"
13+
And I should see "Creative Commons - 4.0 International" in the "cc-4.0" "table_row"
14+
And I should see "Creative Commons - NoDerivatives 4.0 International" in the "cc-nd-4.0" "table_row"
15+
And I should see "Creative Commons - NonCommercial-NoDerivatives 4.0 International" in the "cc-nc-nd-4.0" "table_row"
16+
And I should see "Creative Commons - NonCommercial-ShareAlike 4.0 International" in the "cc-nc-sa-4.0" "table_row"
17+
And I should see "Creative Commons - ShareAlike 4.0 International" in the "cc-sa-4.0" "table_row"
18+
And I should see "Creative Commons - NonCommercial 4.0 International" in the "cc-nc-4.0" "table_row"
1919

2020
Scenario: I should be able to enable and disable licences
2121
Given I log in as "admin"
@@ -25,25 +25,25 @@ Feature: Licence manager
2525
And I navigate to "Licence > Licence manager" in site administration
2626
Then "This is the site default licence" "icon" should exist in the "public" "table_row"
2727
And "Enable licence" "icon" should not exist in the "public" "table_row"
28-
And "This is the site default licence" "icon" should not exist in the "cc" "table_row"
28+
And "This is the site default licence" "icon" should not exist in the "cc-4.0" "table_row"
2929
And I navigate to "Licence > Licence settings" in site administration
3030
And I set the field "Default site licence" to "Creative Commons"
3131
And I press "Save changes"
3232
And I navigate to "Licence > Licence manager" in site administration
33-
And "This is the site default licence" "icon" should exist in the "cc" "table_row"
34-
And "Enable licence" "icon" should not exist in the "cc" "table_row"
33+
And "This is the site default licence" "icon" should exist in the "cc-4.0" "table_row"
34+
And "Enable licence" "icon" should not exist in the "cc-4.0" "table_row"
3535
And "This is the site default licence" "icon" should not exist in the "public" "table_row"
3636

3737
@javascript @_file_upload
3838
Scenario Outline: User licence preference is remembered depending of setting value
3939
Given the following config values are set as admin:
40-
| sitedefaultlicense | cc |
40+
| sitedefaultlicense | cc-4.0 |
4141
| rememberuserlicensepref | <rememberuserlicensepref> |
4242
And I log in as "admin"
4343
And I follow "Private files" in the user menu
4444
And I follow "Add..."
4545
And I follow "Upload a file"
46-
And the field with xpath "//select[@name='license']" matches value "Creative Commons"
46+
And the field with xpath "//select[@name='license']" matches value "Creative Commons - 4.0 International"
4747
And I click on "Close" "button" in the "File picker" "dialogue"
4848
When I upload "lib/tests/fixtures/empty.txt" file to "Files" filemanager as:
4949
| Save as | empty_copy.txt |
@@ -53,6 +53,6 @@ Feature: Licence manager
5353
Then the field with xpath "//select[@name='license']" matches value "<expectedlicence>"
5454

5555
Examples:
56-
| rememberuserlicensepref | expectedlicence |
57-
| 0 | Creative Commons |
58-
| 1 | Public domain |
56+
| rememberuserlicensepref | expectedlicence |
57+
| 0 | Creative Commons - 4.0 International |
58+
| 1 | Public domain |

admin/tool/licensemanager/tests/manager_test.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -174,24 +174,24 @@ public function test_change_license_order() {
174174
$this->resetAfterTest();
175175

176176
$licenseorder = array_keys(license_manager::get_licenses());
177-
$initialposition = array_search('cc-nc', $licenseorder);
177+
$initialposition = array_search('cc-nc-4.0', $licenseorder);
178178

179179
$manager = new tool_licensemanager\manager();
180180

181181
// We're testing a private method, so we need to setup reflector magic.
182182
$method = new ReflectionMethod('\tool_licensemanager\manager', 'change_license_order');
183183
$method->setAccessible(true); // Allow accessing of private method.
184-
$method->invoke($manager, \tool_licensemanager\manager::ACTION_MOVE_UP, 'cc-nc');
184+
$method->invoke($manager, \tool_licensemanager\manager::ACTION_MOVE_UP, 'cc-nc-4.0');
185185

186186
$licenseorder = array_keys(license_manager::get_licenses());
187-
$newposition = array_search('cc-nc', $licenseorder);
187+
$newposition = array_search('cc-nc-4.0', $licenseorder);
188188

189189
$this->assertLessThan($initialposition, $newposition);
190190

191191
$initialposition = array_search('allrightsreserved', $licenseorder);
192192
$method->invoke($manager, \tool_licensemanager\manager::ACTION_MOVE_DOWN, 'allrightsreserved');
193193
$licenseorder = array_keys(license_manager::get_licenses());
194-
$newposition = array_search('cc-nc', $licenseorder);
194+
$newposition = array_search('cc-nc-4.0', $licenseorder);
195195

196196
$this->assertGreaterThan($initialposition, $newposition);
197197
}

lang/en/license.php

+16-7
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,27 @@
2121
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
2222
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2323
*/
24-
2524
// Core licenses.
2625
$string['allrightsreserved'] = 'All rights reserved';
27-
$string['cc'] = 'Creative Commons';
28-
$string['cc-nc'] = 'Creative Commons - No Commercial';
29-
$string['cc-nc-nd'] = 'Creative Commons - No Commercial NoDerivs';
30-
$string['cc-nc-sa'] = 'Creative Commons - No Commercial ShareAlike';
31-
$string['cc-nd'] = 'Creative Commons - NoDerivs';
32-
$string['cc-sa'] = 'Creative Commons - ShareAlike';
3326
$string['public'] = 'Public domain';
3427
$string['unknown'] = 'Licence not specified';
3528

29+
// Old cc-* 3.0 licenses that should be disabled and replaces by the 4.0 licenses from above.
30+
$string['cc'] = 'Creative Commons - 3.0 International';
31+
$string['cc-nc'] = 'Creative Commons - NonCommercial 3.0 International';
32+
$string['cc-nc-nd'] = 'Creative Commons - NonCommercial-NoDerivatives 3.0 International';
33+
$string['cc-nc-sa'] = 'Creative Commons - NonCommercial-ShareAlike 3.0 International';
34+
$string['cc-nd'] = 'Creative Commons - NoDerivatives 3.0 International';
35+
$string['cc-sa'] = 'Creative Commons - ShareAlike 3.0 International';
36+
37+
// The new 4.0 licenses.
38+
$string['cc-4.0'] = 'Creative Commons - 4.0 International';
39+
$string['cc-nc-4.0'] = 'Creative Commons - NonCommercial 4.0 International';
40+
$string['cc-nc-nd-4.0'] = 'Creative Commons - NonCommercial-NoDerivatives 4.0 International';
41+
$string['cc-nc-sa-4.0'] = 'Creative Commons - NonCommercial-ShareAlike 4.0 International';
42+
$string['cc-nd-4.0'] = 'Creative Commons - NoDerivatives 4.0 International';
43+
$string['cc-sa-4.0'] = 'Creative Commons - ShareAlike 4.0 International';
44+
3645
// Error messages.
3746
$string['cannotdeletecore'] = 'Cannot delete a standard licence';
3847
$string['cannotdeletelicenseinuse'] = 'Cannot delete a licence which is currently assigned to one or more files';

lib/db/upgrade.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -3326,12 +3326,16 @@ function xmldb_main_upgrade($oldversion) {
33263326
$sql = 'UPDATE {external_tokens}
33273327
SET name = ' . $DB->sql_concat(
33283328
// We only need the prefix, so leave the third param with an empty string.
3329-
"'" . get_string('tokennameprefix', 'webservice', '') . "'",
3330-
"id");
3329+
"'" . get_string('tokennameprefix', 'webservice', '') . "'",
3330+
"id");
33313331
$DB->execute($sql);
33323332
// Main savepoint reached.
33333333
upgrade_main_savepoint(true, 2023062700.01);
33343334
}
3335+
if ($oldversion < 2023062700.06) {
3336+
upgrade_core_licenses();
3337+
upgrade_main_savepoint(true, 2023062700.06);
3338+
}
33353339

33363340
if ($oldversion < 2023062900.01) {
33373341

lib/db/upgradelib.php

+50-96
Original file line numberDiff line numberDiff line change
@@ -537,105 +537,59 @@ function upgrade_delete_orphaned_file_records() {
537537
function upgrade_core_licenses() {
538538
global $CFG, $DB;
539539

540-
$corelicenses = [];
541-
542-
$license = new stdClass();
543-
$license->shortname = 'unknown';
544-
$license->fullname = 'Licence not specified';
545-
$license->source = '';
546-
$license->enabled = 1;
547-
$license->version = '2010033100';
548-
$license->custom = 0;
549-
$corelicenses[] = $license;
550-
551-
$license = new stdClass();
552-
$license->shortname = 'allrightsreserved';
553-
$license->fullname = 'All rights reserved';
554-
$license->source = 'https://en.wikipedia.org/wiki/All_rights_reserved';
555-
$license->enabled = 1;
556-
$license->version = '2010033100';
557-
$license->custom = 0;
558-
$corelicenses[] = $license;
559-
560-
$license = new stdClass();
561-
$license->shortname = 'public';
562-
$license->fullname = 'Public domain';
563-
$license->source = 'https://en.wikipedia.org/wiki/Public_domain';
564-
$license->enabled = 1;
565-
$license->version = '2010033100';
566-
$license->custom = 0;
567-
$corelicenses[] = $license;
568-
569-
$license = new stdClass();
570-
$license->shortname = 'cc';
571-
$license->fullname = 'Creative Commons';
572-
$license->source = 'https://creativecommons.org/licenses/by/3.0/';
573-
$license->enabled = 1;
574-
$license->version = '2010033100';
575-
$license->custom = 0;
576-
$corelicenses[] = $license;
577-
578-
$license = new stdClass();
579-
$license->shortname = 'cc-nd';
580-
$license->fullname = 'Creative Commons - NoDerivs';
581-
$license->source = 'https://creativecommons.org/licenses/by-nd/3.0/';
582-
$license->enabled = 1;
583-
$license->version = '2010033100';
584-
$license->custom = 0;
585-
$corelicenses[] = $license;
586-
587-
$license = new stdClass();
588-
$license->shortname = 'cc-nc-nd';
589-
$license->fullname = 'Creative Commons - No Commercial NoDerivs';
590-
$license->source = 'https://creativecommons.org/licenses/by-nc-nd/3.0/';
591-
$license->enabled = 1;
592-
$license->version = '2010033100';
593-
$license->custom = 0;
594-
$corelicenses[] = $license;
595-
596-
$license = new stdClass();
597-
$license->shortname = 'cc-nc';
598-
$license->fullname = 'Creative Commons - No Commercial';
599-
$license->source = 'https://creativecommons.org/licenses/by-nc/3.0/';
600-
$license->enabled = 1;
601-
$license->version = '2010033100';
602-
$license->custom = 0;
603-
$corelicenses[] = $license;
604-
605-
$license = new stdClass();
606-
$license->shortname = 'cc-nc-sa';
607-
$license->fullname = 'Creative Commons - No Commercial ShareAlike';
608-
$license->source = 'https://creativecommons.org/licenses/by-nc-sa/3.0/';
609-
$license->enabled = 1;
610-
$license->version = '2010033100';
611-
$license->custom = 0;
612-
$corelicenses[] = $license;
613-
614-
$license = new stdClass();
615-
$license->shortname = 'cc-sa';
616-
$license->fullname = 'Creative Commons - ShareAlike';
617-
$license->source = 'https://creativecommons.org/licenses/by-sa/3.0/';
618-
$license->enabled = 1;
619-
$license->version = '2010033100';
620-
$license->custom = 0;
621-
$corelicenses[] = $license;
622-
623-
foreach ($corelicenses as $corelicense) {
624-
// Check for current license to maintain idempotence.
625-
$currentlicense = $DB->get_record('license', ['shortname' => $corelicense->shortname]);
626-
if (!empty($currentlicense)) {
627-
$corelicense->id = $currentlicense->id;
628-
// Remember if the license was enabled before upgrade.
629-
$corelicense->enabled = $currentlicense->enabled;
630-
$DB->update_record('license', $corelicense);
631-
} else if (!isset($CFG->upgraderunning) || during_initial_install()) {
632-
// Only install missing core licenses if not upgrading or during initial install.
633-
$DB->insert_record('license', $corelicense);
540+
$expectedlicenses = json_decode(file_get_contents($CFG->dirroot . '/lib/licenses.json'))->licenses;
541+
if (!is_array($expectedlicenses)) {
542+
$expectedlicenses = [];
543+
}
544+
$corelicenses = $DB->get_records('license', ['custom' => 0]);
545+
546+
// Disable core licenses which are no longer current.
547+
$todisable = array_diff(
548+
array_map(fn ($license) => $license->shortname, $corelicenses),
549+
array_map(fn ($license) => $license->shortname, $expectedlicenses),
550+
);
551+
552+
// Disable any old *core* license that does not exist in the licenses.json file.
553+
if (count($todisable)) {
554+
[$where, $params] = $DB->get_in_or_equal($todisable, SQL_PARAMS_NAMED);
555+
$DB->set_field_select(
556+
'license',
557+
'enabled',
558+
0,
559+
"shortname {$where}",
560+
$params
561+
);
562+
}
563+
564+
// Add any new licenses.
565+
foreach ($expectedlicenses as $expectedlicense) {
566+
if (!$expectedlicense->enabled) {
567+
// Skip any license which is no longer enabled.
568+
continue;
569+
}
570+
if (!$DB->record_exists('license', ['shortname' => $expectedlicense->shortname])) {
571+
// If the license replaces an older one, check whether this old license was enabled or not.
572+
$isreplacement = false;
573+
foreach (array_reverse($expectedlicense->replaces ?? []) as $item) {
574+
foreach ($corelicenses as $corelicense) {
575+
if ($corelicense->shortname === $item) {
576+
$expectedlicense->enabled = $corelicense->enabled;
577+
// Also, keep the old sort order.
578+
$expectedlicense->sortorder = $corelicense->sortorder * 100;
579+
$isreplacement = true;
580+
break 2;
581+
}
582+
}
583+
}
584+
if (!isset($CFG->upgraderunning) || during_initial_install() || $isreplacement) {
585+
// Only install missing core licenses if not upgrading or during initial installation.
586+
$DB->insert_record('license', $expectedlicense);
587+
}
634588
}
635589
}
636590

637-
// Add sortorder to all licenses.
638-
$licenses = $DB->get_records('license');
591+
// Add/renumber sortorder to all licenses.
592+
$licenses = $DB->get_records('license', null, 'sortorder');
639593
$sortorder = 1;
640594
foreach ($licenses as $license) {
641595
$license->sortorder = $sortorder++;

lib/licenses.json

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
{
2+
"licenses": [
3+
{
4+
"shortname": "unknown",
5+
"fullname": "Licence not specified",
6+
"source": "",
7+
"enabled": 1,
8+
"version": "2010033100",
9+
"custom": 0
10+
},
11+
{
12+
"shortname": "allrightsreserved",
13+
"fullname": "All rights reserved",
14+
"source": "https://en.wikipedia.org/wiki/All_rights_reserved",
15+
"enabled": 1,
16+
"version": "2010033100",
17+
"custom": 0
18+
},
19+
{
20+
"shortname": "public",
21+
"fullname": "Public domain",
22+
"source": "https://en.wikipedia.org/wiki/Public_domain",
23+
"enabled": 1,
24+
"version": "2010033100",
25+
"custom": 0
26+
},
27+
{
28+
"shortname": "cc-4.0",
29+
"fullname": "Creative Commons - 4.0 International",
30+
"source": "https://creativecommons.org/licenses/by/4.0/",
31+
"enabled": 1,
32+
"version": "2022120100",
33+
"custom": 0,
34+
"replaces": ["cc"]
35+
},
36+
{
37+
"shortname": "cc-nc-4.0",
38+
"fullname": "Creative Commons - NonCommercial 4.0 International",
39+
"source": "https://creativecommons.org/licenses/by-nc/4.0/",
40+
"enabled": 1,
41+
"version": "2022120100",
42+
"custom": 0,
43+
"replaces": ["cc-nc"]
44+
},
45+
{
46+
"shortname": "cc-nd-4.0",
47+
"fullname": "Creative Commons - NoDerivatives 4.0 International",
48+
"source": "https://creativecommons.org/licenses/by-nd/4.0/",
49+
"enabled": 1,
50+
"version": "2022120100",
51+
"custom": 0,
52+
"replaces": ["cc-nd"]
53+
},
54+
{
55+
"shortname": "cc-nc-nd-4.0",
56+
"fullname": "Creative Commons - NonCommercial-NoDerivatives 4.0 International",
57+
"source": "https://creativecommons.org/licenses/by-nc-nd/4.0/",
58+
"enabled": 1,
59+
"version": "2022120100",
60+
"custom": 0,
61+
"replaces": ["cc-nc-nd"]
62+
},
63+
{
64+
"shortname": "cc-nc-sa-4.0",
65+
"fullname": "Creative Commons - NonCommercial-ShareAlike 4.0 International",
66+
"source": "https://creativecommons.org/licenses/by-nc-sa/4.0/",
67+
"enabled": 1,
68+
"version": "2022120100",
69+
"custom": 0,
70+
"replaces": ["cc-nc-sa"]
71+
},
72+
{
73+
"shortname": "cc-sa-4.0",
74+
"fullname": "Creative Commons - ShareAlike 4.0 International",
75+
"source": "https://creativecommons.org/licenses/by-sa/4.0/",
76+
"enabled": 1,
77+
"version": "2022120100",
78+
"custom": 0,
79+
"replaces": ["cc-sa"]
80+
}
81+
]
82+
}

0 commit comments

Comments
 (0)