diff --git a/db/upgrade.php b/db/upgrade.php
index 41628914d506e7a5fa3f2eb22e612ed34391ca1e..bb73e188f97fb3af0f4e5ba7d32962542cb2cd6f 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 0d6d7e5af142bceea73b37e25c591c785a21cddf..1ba7ded85272b816e3eb69db0c709e21dd3c7c07 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';