Skip to content

Commit 51489de

Browse files
authored
Merge pull request #54 from catalyst/rename-content-type-sc
Rename content_type column
2 parents b069f0f + 64c3bfc commit 51489de

File tree

6 files changed

+30
-5
lines changed

6 files changed

+30
-5
lines changed

backup/moodle2/backup_hvp_stepslib.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ protected function define_structure() {
5656
'json_content',
5757
'embed_type',
5858
'disable',
59-
'content_type',
59+
'contenttype',
6060
'source',
6161
'year_from',
6262
'year_to',
@@ -103,7 +103,7 @@ protected function define_structure() {
103103
h.json_content,
104104
h.embed_type,
105105
h.disable,
106-
h.content_type,
106+
h.contenttype,
107107
h.slug,
108108
h.timecreated,
109109
h.timemodified,

backup/moodle2/restore_hvp_stepslib.php

+6
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ protected function process_hvp($data) {
7373
$data->timecreated = $this->apply_date_offset($data->timecreated);
7474
$data->timemodified = $this->apply_date_offset($data->timemodified);
7575

76+
// Allow old backups to work after renaming content_type.
77+
if (property_exists($data, 'content_type')) {
78+
$data->contenttype = $data->content_type;
79+
unset($data->content_type);
80+
}
81+
7682
// Insert the hvp record.
7783
$newitemid = $DB->insert_record('hvp', $data);
7884
// Immediately after inserting "activity" record, call this.

db/install.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<FIELD NAME="embed_type" TYPE="char" LENGTH="127" NOTNULL="true" SEQUENCE="false"/>
1616
<FIELD NAME="disable" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
1717
<FIELD NAME="main_library_id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="The library we first instanciate for this node"/>
18-
<FIELD NAME="content_type" TYPE="char" LENGTH="127" NOTNULL="false" SEQUENCE="false" COMMENT="Content type as defined in h5p.json"/>
18+
<FIELD NAME="contenttype" TYPE="char" LENGTH="127" NOTNULL="false" SEQUENCE="false" COMMENT="Content type as defined in h5p.json"/>
1919
<FIELD NAME="authors" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="List of authors in json format"/>
2020
<FIELD NAME="source" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" COMMENT="Link to the source, could also be citation"/>
2121
<FIELD NAME="year_from" TYPE="int" LENGTH="4" NOTNULL="false" SEQUENCE="false" COMMENT="Start year for copyright"/>

db/upgrade.php

+19
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,24 @@ function hvp_upgrade_2022012001() {
609609
}
610610
}
611611

612+
/**
613+
* Rename content_type since it was added as a reserved word in Aurora MySQL version 3.06.0.
614+
*/
615+
function hvp_upgrade_2023122501() {
616+
global $DB;
617+
$dbman = $DB->get_manager();
618+
619+
// Rename field content_type on table hvp to contenttype.
620+
$table = new xmldb_table('hvp');
621+
$field = new xmldb_field('content_type', XMLDB_TYPE_CHAR, '127', null, null, null, null, 'main_library_id');
622+
623+
// Launch rename field content_type.
624+
if ($dbman->field_exists($table, $field)) {
625+
$dbman->rename_field($table, $field, 'contenttype');
626+
}
627+
}
628+
629+
612630
/**
613631
* Hvp module upgrade function.
614632
*
@@ -636,6 +654,7 @@ function xmldb_hvp_upgrade($oldversion) {
636654
2020091500,
637655
2020112600,
638656
2022012001,
657+
2023122501,
639658
];
640659

641660
foreach ($upgrades as $version) {

tests/generator/lib.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function create_instance($record = null, array $options = null) {
4242
'name' => 'Test activity',
4343
'json_content' => '',
4444
'embed_type' => 'div',
45-
'content_type' => null,
45+
'contenttype' => null,
4646
'authors' => '[]',
4747
'source' => null,
4848
'year_from' => null,

version.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
defined('MOODLE_INTERNAL') || die();
2525

26-
$plugin->version = 2023122500;
26+
$plugin->version = 2023122501;
2727
$plugin->requires = 2013051403;
2828
$plugin->cron = 0;
2929
$plugin->component = 'mod_hvp';

0 commit comments

Comments
 (0)