]> git.mjollnir.org Git - moodle.git/commitdiff
wrap search/replace in a function so that it could be used in cron
authortoyomoyo <toyomoyo>
Mon, 3 Dec 2007 04:46:37 +0000 (04:46 +0000)
committertoyomoyo <toyomoyo>
Mon, 3 Dec 2007 04:46:37 +0000 (04:46 +0000)
admin/replace.php
lib/adminlib.php

index b47d26a3c72d2f4decfdfb7a1766f4756a0d4803..064b024c7a61ead619b83386e54c3c1f892ccc1a 100644 (file)
@@ -32,32 +32,10 @@ if (!data_submitted() or !$search or !$replace or !confirm_sesskey()) {   /// Pr
     die;
 }
 
-
-if (!$tables = $db->Metatables() ) {    // No tables yet at all.
-    error("no tables");
-}
-
 print_simple_box_start('center');
 
-/// Turn off time limits, sometimes upgrades can be slow.
-
-@set_time_limit(0);
-@ob_implicit_flush(true);
-while(@ob_end_flush());
-
-foreach ($tables as $table) {
-    if (in_array($table, array($CFG->prefix.'config'))) {      // Don't process these
-        continue;
-    }
-    if ($columns = $db->MetaColumns($table, false)) {
-        foreach ($columns as $column => $data) {
-            if (in_array($data->type, array('text','mediumtext','longtext','varchar'))) {  // Text stuff only
-                $db->debug = true;
-                execute_sql("UPDATE $table SET $column = REPLACE($column, '$search', '$replace');");
-                $db->debug = false;
-            }
-        }
-    }
+if (!db_replace($search, $replace)) {
+    error('An error has occured during this process'); 
 }
 
 print_simple_box_end();
index 360228d37beb875978ea1e1a0e5999bfe223726a..5f45718dfffd1df8503270f0b7f621f9c6bd4c3c 100644 (file)
@@ -3222,4 +3222,43 @@ function any_new_admin_settings(&$node) {
 
 }
 
+
+/**
+ * Moved from admin/replace.php so that we can use this in cron
+ * @param string $search - string to look for
+ * @param string $replace - string to replace
+ * @return bool - success or fail
+ */
+function db_replace($search, $replace) {
+    
+    global $db, $CFG;
+    
+    /// Turn off time limits, sometimes upgrades can be slow.
+    @set_time_limit(0);
+    @ob_implicit_flush(true);
+    while(@ob_end_flush());
+    
+    if (!$tables = $db->Metatables() ) {    // No tables yet at all.
+        return false;
+    }
+    foreach ($tables as $table) {
+    
+        if (in_array($table, array($CFG->prefix.'config'))) {      // Don't process these
+            continue;
+        }
+        
+        if ($columns = $db->MetaColumns($table, false)) {
+            foreach ($columns as $column => $data) {
+                if (in_array($data->type, array('text','mediumtext','longtext','varchar'))) {  // Text stuff only
+                    $db->debug = true;
+                    execute_sql("UPDATE $table SET $column = REPLACE($column, '$search', '$replace');");
+                    $db->debug = false;
+                }
+            }
+        }
+    }
+    
+    return true;
+}
+
 ?>