# This patch file was generated by NetBeans IDE
# This patch can be applied using context Tools: Apply Diff Patch action on respective folder.
# It uses platform neutral UTF-8 encoding.
# Above lines and this line are ignored by the patching process.
Index: moodle/blocks/search/db/install.xml
--- moodle/blocks/search/db/install.xml Base (1.8)
+++ moodle/blocks/search/db/install.xml Locally Modified (Based On 1.8)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="blocks/search/db" VERSION="20070811" COMMENT="XMLDB file for Moodle search engine"
+<XMLDB PATH="blocks/search/db" VERSION="20101012" COMMENT="XMLDB file for Moodle search engine"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
 >
@@ -12,8 +12,8 @@
         <FIELD NAME="itemtype" TYPE="char" LENGTH="32" NOTNULL="true" DEFAULT="standard" SEQUENCE="false" PREVIOUS="doctype" NEXT="title"/>
         <FIELD NAME="title" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" PREVIOUS="itemtype" NEXT="url"/>
         <FIELD NAME="url" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" PREVIOUS="title" NEXT="docdate"/>
-        <FIELD NAME="docdate" TYPE="datetime" NOTNULL="true" SEQUENCE="false" PREVIOUS="url" NEXT="updated"/>
-        <FIELD NAME="updated" TYPE="datetime" NOTNULL="true" SEQUENCE="false" PREVIOUS="docdate" NEXT="courseid"/>
+        <FIELD NAME="docdate" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="url" NEXT="updated"/>
+        <FIELD NAME="updated" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="docdate" NEXT="courseid"/>
\ No newline at end of file
         <FIELD NAME="courseid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="updated" NEXT="groupid"/>
         <FIELD NAME="groupid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="courseid"/>
       </FIELDS>
Index: moodle/blocks/search/db/upgrade.php
--- moodle/blocks/search/db/upgrade.php No Base Revision
+++ moodle/blocks/search/db/upgrade.php Locally New
@@ -0,0 +1,98 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Keeps track of upgrades to the global search block
+ *
+ * @package    blocks
+ * @subpackage search
+ * @copyright  2010 Aparup Banerjee <aparup@moodle.com>
+ * @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;
+
+    $result = TRUE;
+    $dbman = $DB->get_manager();
+
+    if ($oldversion < 2010101200) {
+        // 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($sd->docdate);
+                $sd->updated_new = convert_datetime($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, 2010101200, 'search');
+    }
+
+
+    return $result;
+}
+
+/*
+* Function to turn a mysql datetime (YYYY-MM-DD HH:MM:SS) into a unix timestamp
+* @param str
+* The string to be formatted
+*/
+
+function convert_datetime($str) {
+
+    list($date, $time) = explode(' ', $str);
+    list($year, $month, $day) = explode('-', $date);
+    list($hour, $minute, $second) = explode(':', $time);
+
+    $timestamp = mktime($hour, $minute, $second, $month, $day, $year);
+
+    return $timestamp;
+}
\ No newline at end of file
Index: moodle/blocks/search/version.php
--- moodle/blocks/search/version.php Base (1.1)
+++ moodle/blocks/search/version.php Locally Modified (Based On 1.1)
@@ -15,5 +15,5 @@
 // You should have received a copy of the GNU General Public License
 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
 
-$plugin->version = 2008031500;
+$plugin->version = 2010101200;
 $plugin->cron = 1;
