]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-15402: implement readonly repository instances (support flickr_public)
authorjerome <jerome>
Tue, 16 Sep 2008 09:08:36 +0000 (09:08 +0000)
committerjerome <jerome>
Tue, 16 Sep 2008 09:08:36 +0000 (09:08 +0000)
admin/repositoryinstance.php
lang/en_utf8/repository.php
lib/db/install.xml
lib/db/upgrade.php
repository/flickr_public/repository.class.php
repository/lib.php
repository/manage_instances.php
version.php

index ac8da10cb837d49b228f306a592f9ce62fb9a9b3..d5a2aff2ff584d102b7120f58fa6afa747ae84f2 100644 (file)
@@ -10,19 +10,15 @@ $new     = optional_param('new', '', PARAM_FORMAT);
 $hide    = optional_param('hide', 0, PARAM_INT);
 $delete  = optional_param('delete', 0, PARAM_INT);
 $sure    = optional_param('sure', '', PARAM_ALPHA);
-$move    = optional_param('move', '', PARAM_ALPHA);
-$type    = optional_param('type', '', PARAM_ALPHA);
+$type    = optional_param('type', '', PARAM_ALPHAEXT);
 
 $context = get_context_instance(CONTEXT_SYSTEM);
 
-$display = true; // fall through to normal display
-
 $pagename = 'repositorycontroller';
 
 if ($edit){
     $pagename = 'repositoryinstanceedit';
-}else
-if ($delete) {
+} else if ($delete) {
     $pagename = 'repositorydelete';
 } else if ($new) {
     $pagename = 'repositoryinstancenew';
@@ -47,6 +43,10 @@ $return = true;
 if (!empty($edit) || !empty($new)) {
     if (!empty($edit)) {
         $instance = repository_get_instance($edit);
+        //if you try to edit an instance set as readonly, display an error message
+        if ($instance->readonly) {
+            throw new repository_exception('readonlyinstance', 'repository');
+        }
         $instancetype = repository_get_type_by_id($instance->typeid);
         $classname = 'repository_' . $instancetype->get_typename();
         $configs  = $instance->get_instance_option_names();
@@ -109,6 +109,10 @@ if (!empty($edit) || !empty($new)) {
 } else if (!empty($delete)) { 
     admin_externalpage_print_header();
     $instance = repository_get_instance($delete);
+    //if you try to delete an instance set as readonly, display an error message
+    if ($instance->readonly) {
+            throw new repository_exception('readonlyinstance', 'repository');
+     }
     if ($sure) {
         if (!confirm_sesskey()) {
             print_error('confirmsesskeybad', '', $baseurl);
index 988fcb37b0e06ecb19d50007da6b9f677dc7b185..082eabd0d4bb816fb46e1e704d9df7b511d4ab51 100644 (file)
@@ -61,6 +61,7 @@ $string['personalrepositories'] = 'Personal repositories';
 $string['plugin'] = 'Repository plug-ins';
 $string['preview'] = 'Preview';
 $string['popup'] = 'Open a popup window to login';
+$string['readonlyinstance'] = 'You cannot edit/delete a read-only instance';
 $string['refresh'] = 'Refresh';
 $string['removed'] = 'Repository removed';
 $string['repository'] = 'Repository';
index 516b751bb68436906609df18e8a93e6d64e80aa0..81e28831a6d9b3530a975513fff709b2972e9181 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="lib/db" VERSION="20080826" COMMENT="XMLDB file for core Moodle tables"
+<XMLDB PATH="lib/db" VERSION="20080916" COMMENT="XMLDB file for core Moodle tables"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
 >
         <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
       </KEYS>
     </TABLE>
-    <TABLE NAME="repository_instances" COMMENT="This table contains one entry for every configured external repository instance. " PREVIOUS="repository" NEXT="repository_instance_config">
+    <TABLE NAME="repository_instances" COMMENT="This table contains one entry for every configured external repository instance." PREVIOUS="repository" NEXT="repository_instance_config">
       <FIELDS>
         <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="name"/>
         <FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="typeid"/>
         <FIELD NAME="username" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" ENUM="false" PREVIOUS="contextid" NEXT="password"/>
         <FIELD NAME="password" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" ENUM="false" PREVIOUS="username" NEXT="timecreated"/>
         <FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" ENUM="false" PREVIOUS="password" NEXT="timemodified"/>
-        <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" ENUM="false" PREVIOUS="timecreated"/>
+        <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" ENUM="false" PREVIOUS="timecreated" NEXT="readonly"/>
+        <FIELD NAME="readonly" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="timemodified"/>
       </FIELDS>
       <KEYS>
         <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
       </SENTENCES>
     </STATEMENT>
   </STATEMENTS>
-</XMLDB>
+</XMLDB>
\ No newline at end of file
index bc191fcdade820ecfe18f3ff2ba35eeb92a6f79c..f40ac1fd7cf983483a450bd179067cebbff1e662 100644 (file)
@@ -825,6 +825,23 @@ function xmldb_main_upgrade($oldversion) {
         upgrade_main_savepoint($result, 2008091000);
     }
 
+    //Add a readonly field to the repository_instances table
+    //in order to support instance created automatically by a repository plugin
+     if ($result && $oldversion < 2008091611) {
+
+    /// Define field readonly to be added to repository_instances
+        $table = new xmldb_table('repository_instances');
+        $field = new xmldb_field('readonly', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'timemodified');
+
+    /// Conditionally launch add field readonly
+        if (!$dbman->field_exists($table, $field)) {
+            $dbman->add_field($table, $field);
+        }
+
+    /// Main savepoint reached
+        upgrade_main_savepoint($result, 2008091611);
+    }
+
     return $result;
 }
 
index 9868c52389162ad844caa9c228d4c2557cfb1b87..beab04675e289a61d1c906e107d3522f8e284798 100644 (file)
@@ -43,10 +43,10 @@ class repository_flickr_public extends repository {
         }
     }
 
-    public function __construct($repositoryid, $context = SITEID, $options = array()) {
+    public function __construct($repositoryid, $context = SITEID, $options = array(), $readonly=0) {
         global $CFG;
         $options['page'] = optional_param('p', 1, PARAM_INT);
-        parent::__construct($repositoryid, $context, $options);
+        parent::__construct($repositoryid, $context, $options,$readonly);
         $this->api_key = $this->get_option('api_key');
         $this->flickr = new phpFlickr($this->api_key);
         $this->flickr_account = $this->get_option('email_address');
@@ -182,7 +182,7 @@ class repository_flickr_public extends repository {
 
     public function instance_config_form(&$mform) {
         $mform->addElement('text', 'email_address', get_string('emailaddress', 'repository_flickr_public'));
-        //$mform->addRule('email_address', get_string('required'), 'required', null, 'client');
+        $mform->addRule('email_address', get_string('required'), 'required', null, 'client');
     }
 
     public static function get_instance_option_names() {
@@ -203,8 +203,15 @@ class repository_flickr_public extends repository {
         return array('api_key');
     }
 
-    public static function type_init() {
+
+    public static function plugin_init() {
         //here we create a default instances for this type
+        repository_static_function('flickr_public','create', 'flickr_public', 0, get_system_context(), array('name' => 'default instance','email_address' => null),1);
+        //create(0, get_system_context(), array('name' => 'default instance'),1);
+        /*
+        $success = repository_static_function($plugin, 'create', $plugin, 0, get_context_instance_by_id($contextid), $fromform);
+        $defaultinstance = new repository ();
+         * */
     }
 
 }
index 01a820b63f8d7d6d7ed830a73112ba534c2d4b0d..704bcfcbb999b0133086f24a5eef96efbd36f813 100644 (file)
@@ -207,6 +207,10 @@ class repository_type {
                 $instanceoptions['name'] = $this->_typename;
                 repository_static_function($this->_typename, 'create', $this->_typename, 0, get_system_context(), $instanceoptions);
             }
+
+            //run init function
+            repository_static_function($this->_typename,"plugin_init");
+
         } else {
             throw new repository_exception('existingrepository', 'repository');
         }
@@ -441,6 +445,7 @@ abstract class repository {
     public $id;
     public $context;
     public $options;
+    public $readonly;
 
     /**
      * 1. Initialize context and options
@@ -450,9 +455,10 @@ abstract class repository {
      * @param integer $contextid
      * @param array $options
      */
-    public function __construct($repositoryid, $contextid = SITEID, $options = array()) {
+    public function __construct($repositoryid, $contextid = SITEID, $options = array(), $readonly = 0) {
         $this->id = $repositoryid;
         $this->context = get_context_instance_by_id($contextid);
+        $this->readonly = $readonly;
         $this->options = array();
         if (is_array($options)) {
             $options = array_merge($this->get_option(), $options);
@@ -621,7 +627,7 @@ abstract class repository {
      * @param array $params the options for this instance
      * @return <type>
      */
-    final public static function create($type, $userid, $context, $params) {
+    final public static function create($type, $userid, $context, $params, $readonly=0) {
         global $CFG, $DB;
         $params = (array)$params;
         require_once($CFG->dirroot . '/repository/'. $type . '/repository.class.php');
@@ -633,6 +639,7 @@ abstract class repository {
             $record->timecreated  = time();
             $record->timemodified = time();
             $record->contextid = $context->id;
+            $record->readonly = $readonly;
             $record->userid    = $userid;
             $id = $DB->insert_record('repository_instances', $record);
             $options = array();
@@ -902,7 +909,7 @@ abstract class repository {
      * a class extended from repository class, the init() for type has been placed
      * into the repository.
      */
-    public static function type_init(){
+    public static function plugin_init(){
 
     }
 
@@ -1069,7 +1076,7 @@ function repository_get_instances($contexts=array(), $userid = null, $onlyvisibl
         $options['type']    = $repo->repositorytype;
         $options['typeid']  = $repo->typeid;
         $classname = 'repository_' . $repo->repositorytype;
-        $ret[] = new $classname($repo->id, $repo->contextid, $options);
+        $ret[] = new $classname($repo->id, $repo->contextid, $options, $repo->readonly);
     }
     return $ret;
 }
@@ -1096,7 +1103,7 @@ function repository_get_instance($id) {
     $options['typeid'] = $instance->typeid;
     $options['type']   = $instance->repositorytype;
     $options['name']   = $instance->name;
-    return new $classname($instance->id, $instance->contextid, $options);
+    return new $classname($instance->id, $instance->contextid, $options, $instance->readonly);
 }
 
 /**
@@ -1412,8 +1419,11 @@ function repository_display_instances_list($context, $typename = null) {
 
     foreach ($instances as $i) {
         $settings = '';
-        $settings .= '<a href="' . $baseurl . '&amp;type='.$typename.'&amp;edit=' . $i->id . '">' . $settingsstr . '</a>' . "\n";
-        $delete = '<a href="' . $baseurl . '&amp;type='.$typename.'&amp;delete=' .  $i->id . '">' . $deletestr . '</a>' . "\n";
+        $delete = '';
+        if (!$i->readonly) {
+            $settings .= '<a href="' . $baseurl . '&amp;type='.$typename.'&amp;edit=' . $i->id . '">' . $settingsstr . '</a>' . "\n";
+            $delete .= '<a href="' . $baseurl . '&amp;type='.$typename.'&amp;delete=' .  $i->id . '">' . $deletestr . '</a>' . "\n";
+        }
 
         $type = repository_get_type_by_id($i->typeid);
         $table->data[] = array($i->name, $type->get_readablename(), $delete, $settings);
index 44fc8b65a1821c15e8f500f9ef311b48c4a8bfce..3b70f58942998b05933442544e2751dca3bfc7da 100644 (file)
@@ -10,8 +10,6 @@
     $sure    = optional_param('sure', '', PARAM_ALPHA);
     $contextid = optional_param('contextid', 0, PARAM_INT);
 
-    $display = true; // fall through to normal display
-
     if ($edit){
         $pagename = 'repositoryinstanceedit';
     } else if ($delete) {
     if (!empty($edit) || !empty($new)) {
         if (!empty($edit)) {
             $instance = repository_get_instance($edit);
+            //if you try to edit an instance set as readonly, display an error message
+            if ($instance->readonly) {
+                throw new repository_exception('readonlyinstance', 'repository');
+            }
             $instancetype = repository_get_type_by_id($instance->typeid);
             $classname = 'repository_' . $instancetype->get_typename();
             $configs  = $instance->get_instance_option_names();
     } else if (!empty($delete)) {
         // admin_externalpage_print_header();
         $instance = repository_get_instance($delete);
+         //if you try to delete an instance set as readonly, display an error message
+        if ($instance->readonly) {
+            throw new repository_exception('readonlyinstance', 'repository');
+        }
         if ($sure) {
             if (!confirm_sesskey()) {
                 print_error('confirmsesskeybad', '', $baseurl);
index 697ceacf235d72623f52532ce110d68b6dbcce9a..1b5c4157cf8f20653b70a382e358e8e6a60eb6f6 100644 (file)
@@ -6,7 +6,7 @@
 // This is compared against the values stored in the database to determine
 // whether upgrades should be performed (see lib/db/*.php)
 
-    $version = 2008091500;  // YYYYMMDD   = date of the last version bump
+    $version = 2008091611;  // YYYYMMDD   = date of the last version bump
                             //         XX = daily increments
 
     $release = '2.0 dev (Build: 20080916)';  // Human-friendly version name