MDL-15402: delete a type now delete all its instances, fix confirmation xhtml and...
authorjerome <jerome>
Wed, 3 Sep 2008 11:02:25 +0000 (11:02 +0000)
committerjerome <jerome>
Wed, 3 Sep 2008 11:02:25 +0000 (11:02 +0000)
admin/repository.php
lang/en_utf8/repository.php
repository/lib.php

index 113e3ae8e3235c0a4ca520c3a94c6595250d8304..003d40cb1b116e49f9ed1bf90b1a695b926daa24 100644 (file)
@@ -119,7 +119,7 @@ if (!empty($edit) || !empty($new)) {
         }
         exit;
     }
-    notice_yesno(get_string('confirmremove', 'repository', $repositorytype->get_readablename()), $sesskeyurl . '&delete=' . $delete . '&sure=yes', $baseurl);
+    notice_yesno(get_string('confirmremove', 'repository', $repositorytype->get_readablename()), $sesskeyurl . '&amp;delete=' . $delete . '&amp;sure=yes', $baseurl);
     $return = false;
 }
 else if (!empty($move) && !empty($type)) {
index 20e7d75236c093df26400edaeb03869e513d828e..52a8bf83117c0d3a4efea8df7c7cac5749e12d01 100644 (file)
@@ -11,7 +11,7 @@ $string['copying'] = 'Copying';
 $string['configcacheexpire'] = 'Configurate the cache expired time (in minutes).';
 $string['configsaved'] = 'Configuration saved!';
 $string['confirmdelete'] = 'Are you sure you want to delete this repository - $a?';
-$string['confirmremove'] = 'Are you sure you want to remove this repository plugin - $a?';
+$string['confirmremove'] = 'Are you sure you want to remove this repository plugin and <strong style=color:red>all of its instances</strong> - $a?';
 $string['create'] = 'Create';
 $string['createrepository'] = 'Create a repository instance';
 $string['date'] = 'Date';
index 510ed105cf5fd04a6dbd66df31a69ad1010f6246..aa2b02dec1b46320600c1b357a5ffccfe0ab081a 100644 (file)
@@ -115,7 +115,7 @@ class repository_type {
         $this->_typename = $typename;
         $this->_visible = $visible;
         $this->_sortorder = $sortorder;
-        
+
         //set options attribut
         $this->_options = array();
         //check that the type can be setup
@@ -337,6 +337,13 @@ class repository_type {
      */
     public function delete(){
         global $DB;
+
+        //delete all instances of this type
+        $instances = repository_get_instances(null,null,false,$this->_typename);
+        foreach($instances as $instance){
+            $instance->delete();
+        }
+
         return $DB->delete_records('repository', array('type' => $this->_typename));
     }
 }
@@ -386,10 +393,7 @@ function repository_get_types(){
 
     if($records = $DB->get_records('repository',null,'sortorder')) {
         foreach($records as $type) {
-            $typename = $type->type;
-            $visible = $type->visible;
-            $sortorder = $type->sortorder;
-            $types[] = new repository_type($typename, (array)get_config($typename), $visible, $sortorder);
+            $types[] = new repository_type($type->type, (array)get_config($type->type), $type->visible, $type->sortorder);
         }
     }
 
@@ -864,29 +868,31 @@ class repository_exception extends moodle_exception {
  * @global object $USER
  * @param object $context
  * @param integer $userid
- * @param boolean $visible if visible == true, return visible instances only,
+ * @param boolean $onlyvisible if visible == true, return visible instances only,
  *                otherwise, return all instances
  * @param string $type a type name to retrieve
  * @return array repository instances
  */
-function repository_get_instances($context, $userid = null, $visible = true, $type=null){
+function repository_get_instances($context=null, $userid = null, $onlyvisible = true, $type=null){
     global $DB, $CFG, $USER;
     $params = array();
     $sql = 'SELECT i.*, r.type AS repositorytype, r.visible FROM {repository} r, {repository_instances} i WHERE ';
-    $sql .= 'i.typeid = r.id AND ';
+    $sql .= 'i.typeid = r.id ';
     if (!empty($userid) && is_numeric($userid)) {
-        $sql .= ' (i.userid = 0 or i.userid = ?) AND ';
+        $sql .= ' AND (i.userid = 0 or i.userid = ?)';
         $params[] = $userid;
     }
-    if($context->id == SYSCONTEXTID) {
-        $sql .= ' (i.contextid = ?)';
-        $params[] = SYSCONTEXTID;
-    } else {
-        $sql .= ' (i.contextid = ? or i.contextid = ?)';
-        $params[] = SYSCONTEXTID;
-        $params[] = $context->id;
+    if (!empty($context)){
+        if($context->id == SYSCONTEXTID) {
+            $sql .= ' AND (i.contextid = ?)';
+            $params[] = SYSCONTEXTID;
+        } else {
+            $sql .= ' AND (i.contextid = ? or i.contextid = ?)';
+            $params[] = SYSCONTEXTID;
+            $params[] = $context->id;
+        }
     }
-    if($visible == true) {
+    if($onlyvisible == true) {
         $sql .= ' AND (r.visible = 1)';
     }
     if(isset($type)) {
@@ -1878,7 +1884,7 @@ final class repository_instance_form extends moodleform {
             }
             $this->set_data($data);
         }
-        $this->add_action_buttons(true, get_string('submit'));
+        $this->add_action_buttons(true, get_string('save','repository'));
     }
 
     /**
@@ -1960,7 +1966,7 @@ final class repository_admin_form extends moodleform {
             $this->set_data($data);
         }
 
-        $this->add_action_buttons(true, get_string('submit'));
+        $this->add_action_buttons(true, get_string('save','repository'));
     }
 
 }
@@ -2032,7 +2038,7 @@ function repository_display_instances_list($context, $admin = false, $typename =
         //create a unique type of instance
         else {
             if (repository_static_function($typename, 'has_multiple_instances')){
-                $addable = 1;
+                $addable = 1;               
                 $instancehtml .= '<li><a href="'.$baseurl.'&amp;new='.$typename.'">'.get_string('create', 'repository')
                                   .' "'.get_string('repositoryname', 'repository_'.$typename).'" '
                                   .get_string('instance', 'repository').'</a></li>';