Language customization report uses proper plugin prefix for table names
authorDavid Mudrak <david.mudrak@gmail.com>
Fri, 12 Nov 2010 14:53:38 +0000 (14:53 +0000)
committerDavid Mudrak <david.mudrak@gmail.com>
Fri, 12 Nov 2010 14:53:38 +0000 (14:53 +0000)
admin/report/customlang/db/install.xml
admin/report/customlang/db/upgrade.php [new file with mode: 0644]
admin/report/customlang/edit.php
admin/report/customlang/locallib.php
admin/report/customlang/version.php

index 1366439..3729c6c 100644 (file)
@@ -1,10 +1,10 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="admin/report/customlang/db" VERSION="20100825" COMMENT="XMLDB file for Moodle admin/report/customlang"
+<XMLDB PATH="admin/report/customlang/db" VERSION="20101112" COMMENT="XMLDB file for Moodle admin/report/customlang"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="../../../../lib/xmldb/xmldb.xsd"
 >
   <TABLES>
-    <TABLE NAME="customlang" COMMENT="Contains the working checkout of all strings and their customization" NEXT="customlang_components">
+    <TABLE NAME="report_customlang" COMMENT="Contains the working checkout of all strings and their customization" NEXT="report_customlang_components">
       <FIELDS>
         <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="lang"/>
         <FIELD NAME="lang" TYPE="char" LENGTH="20" NOTNULL="true" SEQUENCE="false" COMMENT="The code of the language this string belongs to. Like en, cs or es" PREVIOUS="id" NEXT="componentid"/>
@@ -26,7 +26,7 @@
         <INDEX NAME="uq_lang_component_string" UNIQUE="true" FIELDS="lang, componentid, stringid" COMMENT="For a given language and component, string identifiers must be unique"/>
       </INDEXES>
     </TABLE>
-    <TABLE NAME="customlang_components" COMMENT="Contains the list of all installed plugins that provide their own language pack" PREVIOUS="customlang">
+    <TABLE NAME="report_customlang_components" COMMENT="Contains the list of all installed plugins that provide their own language pack " PREVIOUS="report_customlang">
       <FIELDS>
         <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="name"/>
         <FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="The normalized name of the plugin" PREVIOUS="id" NEXT="version"/>
diff --git a/admin/report/customlang/db/upgrade.php b/admin/report/customlang/db/upgrade.php
new file mode 100644 (file)
index 0000000..48ac4fb
--- /dev/null
@@ -0,0 +1,47 @@
+<?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/>.
+
+/**
+ * Language customization report upgrades
+ *
+ * @package    report
+ * @subpackage customlang
+ * @copyright  2010 David Mudrak <david.mudrak@gmail.com>
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+function xmldb_report_customlang_upgrade($oldversion) {
+    global $CFG, $DB, $OUTPUT;
+
+    $dbman = $DB->get_manager();
+    $result = true;
+
+    /**
+     * Use proper plugin prefix for tables
+     */
+    if ($oldversion < 2010111200) {
+        if ($dbman->table_exists('customlang')) {
+            $dbman->rename_table(new xmldb_table('customlang'), 'report_customlang');
+        }
+        if ($dbman->table_exists('customlang_components')) {
+            $dbman->rename_table(new xmldb_table('customlang_components'), 'report_customlang_components');
+        }
+        upgrade_plugin_savepoint(true, 2010111200, 'report', 'customlang');
+    }
+
+    return $result;
+}
index ad3e8ca..b68b565 100644 (file)
@@ -72,7 +72,7 @@ if ($translatorsubmitted) {
     if (!is_array($strings)) {
         $strings = array();
     }
-    $current = $DB->get_records_list('customlang', 'id', array_keys($strings));
+    $current = $DB->get_records_list('report_customlang', 'id', array_keys($strings));
     $now = time();
 
     foreach ($strings as $recordid => $customization) {
@@ -83,7 +83,7 @@ if ($translatorsubmitted) {
             $current[$recordid]->modified = 1;
             $current[$recordid]->outdated = 0;
             $current[$recordid]->timecustomized = null;
-            $DB->update_record('customlang', $current[$recordid]);
+            $DB->update_record('report_customlang', $current[$recordid]);
             continue;
         }
 
@@ -96,7 +96,7 @@ if ($translatorsubmitted) {
             $current[$recordid]->modified = 1;
             $current[$recordid]->outdated = 0;
             $current[$recordid]->timecustomized = $now;
-            $DB->update_record('customlang', $current[$recordid]);
+            $DB->update_record('report_customlang', $current[$recordid]);
             continue;
         }
     }
@@ -106,7 +106,7 @@ if ($translatorsubmitted) {
     }
     if (!empty($updates)) {
         list($sql, $params) = $DB->get_in_or_equal($updates);
-        $DB->set_field_select('customlang', 'outdated', 0, "local IS NOT NULL AND id $sql", $params);
+        $DB->set_field_select('report_customlang', 'outdated', 0, "local IS NOT NULL AND id $sql", $params);
     }
 
     redirect($nexturl);
index bdd375a..2d0b200 100644 (file)
@@ -88,7 +88,7 @@ class report_customlang_utils {
         global $DB;
 
         // make sure that all components are registered
-        $current = $DB->get_records('customlang_components', null, 'name', 'name,version,id');
+        $current = $DB->get_records('report_customlang_components', null, 'name', 'name,version,id');
         foreach (self::list_components() as $component) {
             if (empty($current[$component])) {
                 $record = new stdclass();
@@ -98,10 +98,10 @@ class report_customlang_utils {
                 } else {
                     $record->version = $version;
                 }
-                $DB->insert_record('customlang_components', $record);
+                $DB->insert_record('report_customlang_components', $record);
             } elseif ($version = get_component_version($component)) {
                 if (is_null($current[$component]->version) or ($version > $current[$component]->version)) {
-                    $DB->set_field('customlang_components', 'version', $version, array('id' => $current[$component]->id));
+                    $DB->set_field('report_customlang_components', 'version', $version, array('id' => $current[$component]->id));
                 }
             }
         }
@@ -109,10 +109,10 @@ class report_customlang_utils {
 
         // reload components and fetch their strings
         $stringman  = get_string_manager();
-        $components = $DB->get_records('customlang_components');
+        $components = $DB->get_records('report_customlang_components');
         foreach ($components as $component) {
             $sql = "SELECT stringid, s.*
-                      FROM {customlang} s
+                      FROM {report_customlang} s
                      WHERE lang = ? AND componentid = ?
                   ORDER BY stringid";
             $current = $DB->get_records_sql($sql, array($lang, $component->id));
@@ -150,7 +150,7 @@ class report_customlang_utils {
                     }
 
                     if ($needsupdate) {
-                        $DB->update_record('customlang', $current[$stringid]);
+                        $DB->update_record('report_customlang', $current[$stringid]);
                         continue;
                     }
 
@@ -171,7 +171,7 @@ class report_customlang_utils {
                         $record->timecustomized = null;
                     }
 
-                    $DB->insert_record('customlang', $record);
+                    $DB->insert_record('report_customlang', $record);
                 }
             }
         }
@@ -192,8 +192,8 @@ class report_customlang_utils {
 
         // get all customized strings from updated components
         $sql = "SELECT s.*, c.name AS component
-                  FROM {customlang} s
-                  JOIN {customlang_components} c ON s.componentid = c.id
+                  FROM {report_customlang} s
+                  JOIN {report_customlang_components} c ON s.componentid = c.id
                  WHERE s.lang = ?
                        AND (s.local IS NOT NULL OR s.modified = 1)
               ORDER BY componentid, stringid";
@@ -211,7 +211,7 @@ class report_customlang_utils {
             self::dump_strings($lang, $component, $strings);
         }
 
-        $DB->set_field_select('customlang', 'modified', 0, 'lang = ?', array($lang));
+        $DB->set_field_select('report_customlang', 'modified', 0, 'lang = ?', array($lang));
         $sm = get_string_manager();
         $sm->reset_caches();
     }
@@ -341,7 +341,7 @@ EOF
     public static function get_count_of_modified($lang) {
         global $DB;
 
-        return $DB->count_records('customlang', array('lang'=>$lang, 'modified'=>1));
+        return $DB->count_records('report_customlang', array('lang'=>$lang, 'modified'=>1));
     }
 
     /**
@@ -472,8 +472,8 @@ class report_customlang_translator implements renderable {
 
         $csql = "SELECT COUNT(*)";
         $fsql = "SELECT s.id, s.*, c.name AS component";
-        $sql  = "  FROM {customlang_components} c
-                   JOIN {customlang} s ON s.componentid = c.id
+        $sql  = "  FROM {report_customlang_components} c
+                   JOIN {report_customlang} s ON s.componentid = c.id
                   WHERE s.lang = :lang
                         AND c.name $insql";
 
index 150306d..b060233 100644 (file)
@@ -24,5 +24,5 @@
 
 defined('MOODLE_INTERNAL') || die();
 
-$plugin->version  = 2010082500;
-$plugin->requires = 2010080901;
+$plugin->version  = 2010111200;
+$plugin->requires = 2010111002;