Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-29218

repository plugin plugin_init call not blocking

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.0.3, 2.4.5, 2.5.1
    • Fix Version/s: 2.4.6, 2.5.2
    • Component/s: Repositories
    • Labels:
    • Database:
      MySQL
    • Testing Instructions:
      Hide

      (difficulty: moderate, requires to add one line of code to simulate a failure)

      Test 1: repository creation/initialization management

      1. Open the repository/flickr_public/lib.php file and change the plugin_init function as below:

        diff --git a/repository/flickr_public/lib.php b/repository/flickr_public/lib.php
        index a0a5c72..8ab8847 100644
        --- a/repository/flickr_public/lib.php
        +++ b/repository/flickr_public/lib.php
        @@ -527,6 +527,7 @@ class repository_flickr_public extends repository {
              * is run when moodle administrator add the plugin
              */
             public static function plugin_init() {
        +return false;
                 //here we create a default instance for this type
         
                 $id = repository::static_function('flickr_public','create', 'flickr_public', 0, get_system_context(), array('name'=>'', 'email_address' => null, 'usewatermarks' => false), 0);
        

      2. Go to Home ► Site administration ► Plugins ► Repositories ► Manage repositories, find Flickr public in the repositories list and choose Enabled and visible from the dropdown
      3. Put a valid or invalid API key in the filed and click Save
      4. You get an expected Call plugin_init failed exception error
      5. Press continue and you will be redirected to the home page
      6. Go to Home ► Site administration ► Plugins ► Repositories ► Manage repositories: the Flickr public repository is enabled but not visible

      Test 2: look for any regression

      1. Remove the hack added in the test above (return false;)
      2. Configure a repository as per the official docs, e.g. Flickr public. The operation must be successful
      3. Access that repository: again the operation must be successful
      Show
      (difficulty: moderate, requires to add one line of code to simulate a failure) Test 1: repository creation/initialization management Open the repository/flickr_public/lib.php file and change the plugin_init function as below: diff --git a/repository/flickr_public/lib.php b/repository/flickr_public/lib.php index a0a5c72..8ab8847 100644 --- a/repository/flickr_public/lib.php +++ b/repository/flickr_public/lib.php @@ -527,6 +527,7 @@ class repository_flickr_public extends repository { * is run when moodle administrator add the plugin */ public static function plugin_init() { +return false; //here we create a default instance for this type $id = repository::static_function('flickr_public','create', 'flickr_public', 0, get_system_context(), array('name'=>'', 'email_address' => null, 'usewatermarks' => false), 0); Go to Home ► Site administration ► Plugins ► Repositories ► Manage repositories , find Flickr public in the repositories list and choose Enabled and visible from the dropdown Put a valid or invalid API key in the filed and click Save You get an expected Call plugin_init failed exception error Press continue and you will be redirected to the home page Go to Home ► Site administration ► Plugins ► Repositories ► Manage repositories : the Flickr public repository is enabled but not visible Test 2: look for any regression Remove the hack added in the test above ( return false; ) Configure a repository as per the official docs, e.g. Flickr public . The operation must be successful Access that repository: again the operation must be successful
    • Difficulty:
      Easy
    • Affected Branches:
      MOODLE_20_STABLE, MOODLE_24_STABLE, MOODLE_25_STABLE
    • Fixed Branches:
      MOODLE_24_STABLE, MOODLE_25_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      m26_MDL-29218_plugin_init_not_blocking_when_false

      Description

      If you try to enable a repository plugin but some of the requirements in plugin_init function is not met (the function returns false), you correctly get an error message.
      But if you enter again in Home / Site administration / Plugins / Repositories / Manage repositories you will see that the repository plugin is enabled and you can add repository instances.

      I think that this should be blocking and the repository plugin shouldn't be enabled at all.

      To reproduce the issue I modified flickr_public repository plugin to force the plugin_init() function to return false (to simulate an error status). This is the modified version of plugin_init() function in repository/flickr_public/lib.php

       /**
       * is run when moodle administrator add the plugin
       */
      public static function plugin_init() {
          return false;
          //here we create a default instance for this type
       
          $id = repository::static_function('flickr_public','create', 'flickr_public', 0, get_system_context(), array('name'=>'', 'email_address' => null, 'usewatermarks' => false), 0);
          if (empty($id)) {
              return false;
          } else {
              return true;
          }
      }
      

      • Go to Home / Site administration / Plugins / Repositories / Manage repositories, find Flickr public in the repository list and choose Enabled and visible from dropdown
      • Put a valid or invalid API key in the filed and click Save
      • You get an "Call plugin_init failed" error (this is expected)
      • Press continue and you will be redirected to moodle home page
      • Go to Home / Site administration / Plugins / Repositories / Manage repositories
      • It is expected that Flickr public repository is not enabled but you can see that it is enabled instead and you can press settings and add repository instances

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Votes:
                1 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  9/Sep/13