diff --git a/blocks/search/db/install.xml b/blocks/search/db/install.xml
index 2f784c518c9..c5c2b52d29c 100644
--- a/blocks/search/db/install.xml
+++ b/blocks/search/db/install.xml
@@ -1,5 +1,5 @@
-
@@ -12,8 +12,8 @@
-
-
+
+
@@ -27,4 +27,4 @@
-
+
\ No newline at end of file
diff --git a/blocks/search/db/upgrade.php b/blocks/search/db/upgrade.php
new file mode 100644
index 00000000000..18af760c0cb
--- /dev/null
+++ b/blocks/search/db/upgrade.php
@@ -0,0 +1,82 @@
+.
+
+/**
+ * Keeps track of upgrades to the global search block
+ *
+ * @package blocks
+ * @subpackage search
+ * @copyright 2010 Aparup Banerjee
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+function xmldb_block_search_upgrade($oldversion) {
+ global $CFG, $DB;
+
+ require('upgradelib.php');
+ $result = TRUE;
+ $dbman = $DB->get_manager();
+
+ if ($oldversion < 2010101800) {
+ // See MDL-24374
+ // Changing type of field docdate on table block_search_documents to int
+ // Changing type of field updated on table block_search_documents to int
+ $table = new xmldb_table('block_search_documents');
+
+ $field_docdate_new = new xmldb_field('docdate_new', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'docdate');
+ $field_updated_new = new xmldb_field('updated_new', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'updated');
+ $field_docdate_old = new xmldb_field('docdate');
+ $field_updated_old = new xmldb_field('updated');
+
+ // Conditionally launch add temporary fields
+ if (!$dbman->field_exists($table, $field_docdate_new)) {
+ $dbman->add_field($table, $field_docdate_new);
+ }
+ if (!$dbman->field_exists($table, $field_updated_new)) {
+ $dbman->add_field($table, $field_updated_new);
+ }
+
+ $sql = "SELECT id, docdate, updated FROM {block_search_documents}";
+ $search_documents = $DB->get_records_sql($sql);
+ if ($search_documents) {
+ foreach ($search_documents as $sd) {
+ $sd->docdate_new = convert_datetime_upgrade($sd->docdate);
+ $sd->updated_new = convert_datetime_upgrade($sd->updated);
+ $DB->update_record('block_search_documents', $sd);
+ }
+ }
+ // Conditionally launch drop the old fields
+ if ($dbman->field_exists($table, $field_docdate_old)) {
+ $dbman->drop_field($table, $field_docdate_old);
+ }
+ if ($dbman->field_exists($table, $field_updated_old)) {
+ $dbman->drop_field($table, $field_updated_old);
+ }
+
+ //rename the new fields to the original field names.
+ $dbman->rename_field($table, $field_docdate_new, 'docdate');
+ $dbman->rename_field($table, $field_updated_new, 'updated');
+
+ // search savepoint reached
+ upgrade_block_savepoint(true, 2010101800, 'search');
+ }
+
+
+ return $result;
+}
\ No newline at end of file
diff --git a/blocks/search/db/upgradelib.php b/blocks/search/db/upgradelib.php
new file mode 100644
index 00000000000..a85c452b5b3
--- /dev/null
+++ b/blocks/search/db/upgradelib.php
@@ -0,0 +1,46 @@
+.
+
+/**
+ * Global search block upgrade related helper functions
+ *
+ * @package blocks
+ * @subpackage search
+ * @copyright 2010 Aparup Banerjee
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+/*
+* Function to turn a mysql(datetime) or postgres(timestamp without timezone data) or any generic date string (YYYY-MM-DD HH:MM:SS)
+* read in from a database's date/time field (ie:valid) into a unix timestamp
+* @param str The string to be converted to timestamp
+* @return timestamp or 0
+*/
+
+function convert_datetime_upgrade($str) {
+
+ $timestamp = strtotime($str);
+ //process different failure returns due to different php versions
+ if ($timestamp === false || $timestamp < 1) {
+ return 0;
+ } else {
+ return $timestamp;
+ }
+}
+
diff --git a/blocks/search/version.php b/blocks/search/version.php
index 93d21828aa7..84d4c91bd82 100644
--- a/blocks/search/version.php
+++ b/blocks/search/version.php
@@ -15,5 +15,5 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-$plugin->version = 2008031500;
+$plugin->version = 2010101800;
$plugin->cron = 1;