Browse Source

Fix install plugin course field - refs BT#9413

Angel Fernando Quiroz Campos 9 years ago
parent
commit
818506d155
2 changed files with 46 additions and 3 deletions
  1. 26 0
      main/inc/lib/add_course.lib.inc.php
  2. 20 3
      main/inc/lib/plugin.class.php

+ 26 - 0
main/inc/lib/add_course.lib.inc.php

@@ -1508,4 +1508,30 @@ class AddCourse
         rmdir($tmp_dir_name);
         return $course_properties;
     }
+
+    /**
+     * Generate a new id for c_tool table 
+     * @param int $courseId The course id
+     * @return int the new id
+     */
+    public static function generateToolId($courseId)
+    {
+        $newIdResultData = Database::select(
+            'id + 1 AS new_id',
+            Database::get_course_table(TABLE_TOOL_LIST),
+            [
+                'where' => ['c_id = ?' => intval($courseId)],
+                'order' => 'id',
+                'limit' => 1
+            ],
+            'first'
+        );
+
+        if ($newIdResultData === false) {
+            return 1;
+        }
+
+        return $newIdResultData['new_id'] > 0 ? $newIdResultData['new_id'] : 1;
+    }
+
 }

+ 20 - 3
main/inc/lib/plugin.class.php

@@ -439,9 +439,26 @@ class Plugin
         if (!Database::num_rows($result)) {
             $tool_link = "$plugin_name/start.php";
             $visibility = AddCourse::string2binary(api_get_setting('course_create_active_tools', $plugin_name));
-            $sql = "INSERT INTO $t_tool VALUES
-            ($courseId, NULL, '$plugin_name', '$tool_link', '$plugin_name.png',' ".$visibility."','0', 'squaregrey.gif','NO','_self','plugin','0')";
-            Database::query($sql);
+
+            $cToolId = AddCourse::generateToolId($courseId);
+
+            Database::insert(
+                $t_tool,
+                [
+                    'id' => $cToolId,
+                    'c_id' => $courseId,
+                    'name' => $plugin_name,
+                    'link' => $tool_link,
+                    'image' => "$plugin_name.png",
+                    'visibility' => $visibility,
+                    'admin' => 0,
+                    'address' => 'squaregrey.gif',
+                    'added_tool' => 'NO',
+                    'target' => '_self',
+                    'category' => 'plugin',
+                    'session_id' => 0
+                ]
+            );
         }
     }