Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename content_type column #549 #552

Open
wants to merge 1 commit into
base: stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions backup/moodle2/backup_hvp_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected function define_structure() {
'json_content',
'embed_type',
'disable',
'content_type',
'contenttype',
'source',
'year_from',
'year_to',
Expand Down Expand Up @@ -103,7 +103,7 @@ protected function define_structure() {
h.json_content,
h.embed_type,
h.disable,
h.content_type,
h.contenttype,
h.slug,
h.timecreated,
h.timemodified,
Expand Down
6 changes: 6 additions & 0 deletions backup/moodle2/restore_hvp_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ protected function process_hvp($data) {
$data->timecreated = $this->apply_date_offset($data->timecreated);
$data->timemodified = $this->apply_date_offset($data->timemodified);

// Allow old backups to work after renaming content_type.
if (property_exists($data, 'content_type')) {
$data->contenttype = $data->content_type;
unset($data->content_type);
}

// Insert the hvp record.
$newitemid = $DB->insert_record('hvp', $data);
// Immediately after inserting "activity" record, call this.
Expand Down
2 changes: 1 addition & 1 deletion db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<FIELD NAME="embed_type" TYPE="char" LENGTH="127" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="disable" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="main_library_id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="The library we first instanciate for this node"/>
<FIELD NAME="content_type" TYPE="char" LENGTH="127" NOTNULL="false" SEQUENCE="false" COMMENT="Content type as defined in h5p.json"/>
<FIELD NAME="contenttype" TYPE="char" LENGTH="127" NOTNULL="false" SEQUENCE="false" COMMENT="Content type as defined in h5p.json"/>
<FIELD NAME="authors" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="List of authors in json format"/>
<FIELD NAME="source" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" COMMENT="Link to the source, could also be citation"/>
<FIELD NAME="year_from" TYPE="int" LENGTH="4" NOTNULL="false" SEQUENCE="false" COMMENT="Start year for copyright"/>
Expand Down
18 changes: 18 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,23 @@ function hvp_upgrade_2020112600() {
}
}

/**
* Rename content_type since it was added as a reserved word in Aurora MySQL version 3.06.0.
*/
function hvp_upgrade_2023122501() {
global $DB;
$dbman = $DB->get_manager();

// Rename field content_type on table hvp to contenttype.
$table = new xmldb_table('hvp');
$field = new xmldb_field('content_type', XMLDB_TYPE_CHAR, '127', null, null, null, null, 'main_library_id');

// Launch rename field content_type.
if ($dbman->field_exists($table, $field)) {
$dbman->rename_field($table, $field, 'contenttype');
}
}

/**
* Hvp module upgrade function.
*
Expand All @@ -593,6 +610,7 @@ function xmldb_hvp_upgrade($oldversion) {
2020082800,
2020091500,
2020112600,
2023122501,
];

foreach ($upgrades as $version) {
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

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

$plugin->version = 2023122500;
$plugin->version = 2023122501;
$plugin->requires = 2013051403;
$plugin->cron = 0;
$plugin->component = 'mod_hvp';
Expand Down