From 5836e4cf9cd1814fba810b41b367c6139804112a Mon Sep 17 00:00:00 2001 From: Frode Petterson <frode.andre.petterson@gmail.com> Date: Tue, 1 Nov 2016 16:16:59 +0100 Subject: [PATCH] Bump version number + double check hash --- db/upgrade.php | 11 +++++++---- version.php | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/db/upgrade.php b/db/upgrade.php index 4162891..bb73e18 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -149,7 +149,7 @@ function xmldb_hvp_upgrade($oldversion) { upgrade_mod_savepoint(true, 2016051000, 'hvp'); } - if ($oldversion < 2016080903) { + if ($oldversion < 2016110100) { // Change context of activity files from COURSE to MODULE. @@ -172,12 +172,15 @@ function xmldb_hvp_upgrade($oldversion) { // Need to re-hash pathname after changing context $pathnamehash = file_storage::get_pathname_hash($hvp->id, $component, $filearea, $hvp->itemid, $hvp->filepath, $hvp->filename); - // Update context ID and pathname hash for files - $DB->execute("UPDATE {files} SET contextid = {$hvp->id}, pathnamehash = '{$pathnamehash}' WHERE pathnamehash = '{$hvp->pathnamehash}'"); + // Double check that hash doesn't exist (avoid duplicate entries) + if (!$DB->get_field_sql("SELECT contextid FROM {files} WHERE pathnamehash = '{$pathnamehash}'")) { + // Update context ID and pathname hash for files + $DB->execute("UPDATE {files} SET contextid = {$hvp->id}, pathnamehash = '{$pathnamehash}' WHERE pathnamehash = '{$hvp->pathnamehash}'"); + } } // Hvp savepoint reached. - upgrade_mod_savepoint(true, 2016080903, 'hvp'); + upgrade_mod_savepoint(true, 2016110100, 'hvp'); } return true; diff --git a/version.php b/version.php index 0d6d7e5..1ba7ded 100644 --- a/version.php +++ b/version.php @@ -23,7 +23,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2016092100; +$plugin->version = 2016110100; $plugin->requires = 2013051403; $plugin->cron = 0; $plugin->component = 'mod_hvp'; -- GitLab