From e9c0b9ecbf5d4930f4f29214dcb1fa2398cf1a3f Mon Sep 17 00:00:00 2001 From: bobopinna Date: Wed, 24 Jan 2007 15:33:46 +0000 Subject: [PATCH] Changed drop and add with rename Fixed a problem with md5hash field --- mod/scorm/db/upgrade.php | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/mod/scorm/db/upgrade.php b/mod/scorm/db/upgrade.php index 653b78ebf6df9..3d428c57d579a 100644 --- a/mod/scorm/db/upgrade.php +++ b/mod/scorm/db/upgrade.php @@ -223,28 +223,24 @@ function xmldb_scorm_upgrade($oldversion=0) { $table = new XMLDBTable('scorm'); $field = new XMLDBField('external'); - /// Launch drop field external - $result = $result && drop_field($table, $field); - - $field = new XMLDBField('updatefreq'); $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'maxattempt'); - /// Launch add field updatefreq - $result = $result && add_field($table, $field); + /// Launch rename field updatefreq + $result = $result && rename_field($table, $field, 'updatefreq'); + /// Rename field md5_result on table scorm to md5hash $field = new XMLDBField('md5_result'); - - /// Launch drop field md5_result - $result = $result && drop_field($table, $field); - - - /// Define field md5hash to be added to scorm - $field = new XMLDBField('md5hash'); - $field->setAttributes(XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null, null, null, 'updatefreq'); - - /// Launch add field md5hash - $result = $result && add_field($table, $field); - + if (field_exists($table, $field)) { + $field->setAttributes(XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null, null, null, 'updatefreq'); + + /// Launch rename field md5hash + $result = $result && rename_field($table, $field, 'md5hash'); + } else { + $field = new XMLDBField('md5hash'); + $field->setAttributes(XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null, null, '', 'updatefreq'); + + $result = $result && add_field($table, $field); + } } return $result;