# 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,82 @@
+<?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;
+
+    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
Index: moodle/blocks/search/db/upgradelib.php
--- moodle/blocks/search/db/upgradelib.php No Base Revision
+++ moodle/blocks/search/db/upgradelib.php Locally New
@@ -0,0 +1,46 @@
+<?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/>.
+
+/**
+ * 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;
+    }
+}
+
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 = 2010101800;
 $plugin->cron = 1;
