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

Analytics: Upgrade can break if core module is deleted

XMLWordPrintable

    • MOODLE_405_STABLE
    • MOODLE_405_STABLE
    • MDL-83529-m405
    • MDL-83529-main
    • Hide

      To avoid having to install and delete separate Moodle versions, the easiest way to test this is using a Behat setup. So you need a working Behat installation to run this test, even though it doesn't use a Behat feature/scenario. It is also possible to do the same thing manually without using Behat but then you have to keep changing your database prefix and it's annoying, so I wrote the instructions this way.

      There are two parts to the test, first that install still works with a deleted module plugin (no change), and second that upgrade works with a deleted module plugin (the fix).

      INSTALL

      1 Delete the core Chat module from the code:

      rm -rf mod/chat
      

      2 Reinstall the Behat site:

      php admin/tool/behat/cli/init.php
      

      EXPECTED (no change): The installation should complete successfully.

      UPGRADE

      3 Put back deleted mod/chat files; if you are using git then you can do

      git restore mod/chat
      

      4 Reinstall the Behat site

      php admin/tool/behat/cli/init.php
      

      5 Delete mod/chat again

      rm -rf mod/chat
      

      6 Edit the 'version.php' file in Moodle root directory. It should contain a line like below (but with different date and a comment). Increment the last part of the version number, for example change .00 into .01.

      $version  = 2099010101.00;
      

      7 To run the upgrade in a web browser, visit (your behat site URL)/admin/

      EXPECTED (no change): You should get the 'Upgrading Moodle database from version' screen.

      8 Click Continue past this initial upgrade prompt.
      9 Click Continue past the environment check page.

      EXPECTED (no change): The 'Plugins check' page should show that the chat activity module is 'Missing from disk'.

      10 Click 'Upgrade Moodle database now'.

      EXPECTED: The upgrade should now run and should complete successfully without showing an 'Invalid indicator classname' error

      11 After you finish testing, you may want to put back the missing files and changed version number, which you can do with these commands if using Git:

      git restore mod/chat
      git restore version.php
      

      Show
      To avoid having to install and delete separate Moodle versions, the easiest way to test this is using a Behat setup. So you need a working Behat installation to run this test, even though it doesn't use a Behat feature/scenario. It is also possible to do the same thing manually without using Behat but then you have to keep changing your database prefix and it's annoying, so I wrote the instructions this way. There are two parts to the test, first that install still works with a deleted module plugin (no change), and second that upgrade works with a deleted module plugin (the fix). INSTALL 1 Delete the core Chat module from the code: rm -rf mod/chat 2 Reinstall the Behat site: php admin/tool/behat/cli/init.php EXPECTED (no change): The installation should complete successfully. UPGRADE 3 Put back deleted mod/chat files; if you are using git then you can do git restore mod/chat 4 Reinstall the Behat site php admin/tool/behat/cli/init.php 5 Delete mod/chat again rm -rf mod/chat 6 Edit the 'version.php' file in Moodle root directory. It should contain a line like below (but with different date and a comment). Increment the last part of the version number, for example change .00 into .01. $version = 2099010101.00; 7 To run the upgrade in a web browser, visit (your behat site URL)/admin/ EXPECTED (no change): You should get the 'Upgrading Moodle database from version' screen. 8 Click Continue past this initial upgrade prompt. 9 Click Continue past the environment check page. EXPECTED (no change): The 'Plugins check' page should show that the chat activity module is 'Missing from disk'. 10 Click 'Upgrade Moodle database now'. EXPECTED : The upgrade should now run and should complete successfully without showing an 'Invalid indicator classname' error 11 After you finish testing, you may want to put back the missing files and changed version number, which you can do with these commands if using Git: git restore mod/chat git restore version.php
    • Hide

      Code verified against automated checks.

      Checked MDL-83529 using repository: https://github.com/sammarshallou/moodle.git

      More information about this report

      Built on: Fri 25 Oct 2024 12:47:18 PM UTC

      Show
      Code verified against automated checks. Checked MDL-83529 using repository: https://github.com/sammarshallou/moodle.git MOODLE_405_STABLE (0 errors / 0 warnings) [branch: MDL-83529-m405 | CI Job ] main (0 errors / 0 warnings) [branch: MDL-83529-main | CI Job ] More information about this report Built on: Fri 25 Oct 2024 12:47:18 PM UTC
    • Show
      Launching automatic jobs for branch MDL-83529 -m405 https://ci.moodle.org/view/Testing/job/DEV.02%20-%20Developer-requested%20PHPUnit/17127/ PHPUnit (sqlsrv) https://ci.moodle.org/view/Testing/job/DEV.01%20-%20Developer-requested%20Behat/58282/ Behat (NonJS - boost and classic) https://ci.moodle.org/view/Testing/job/DEV.01%20-%20Developer-requested%20Behat/58283/ Behat (Firefox - boost) Launching automatic jobs for branch MDL-83529 -main https://ci.moodle.org/view/Testing/job/DEV.02%20-%20Developer-requested%20PHPUnit/17128/ PHPUnit (sqlsrv) https://ci.moodle.org/view/Testing/job/DEV.01%20-%20Developer-requested%20Behat/58284/ Behat (NonJS - boost and classic) https://ci.moodle.org/view/Testing/job/DEV.01%20-%20Developer-requested%20Behat/58285/ Behat (Firefox - boost) https://ci.moodle.org/view/Testing/job/DEV.01%20-%20Developer-requested%20Behat/58286/ Behat (Firefox - classic) https://ci.moodle.org/view/Testing/job/DEV.01%20-%20Developer-requested%20Behat/58287/ App tests (stable app version) Built on: Fri Oct 25 10:25:17 AM UTC 2024

      The analytics code includes a list of classes to use from core module plugins. This can cause problems during install or upgrade if the core module plugin has been removed, because it tries to use a class which does not exist.

      When implementing MDL-82359, I fixed the situation where you do a fresh install with a missing plugin. Example sequence that works:

      rm -rf mod/chat
      (install Moodle)

      However there is still a way to reproduce a similar problem if you delete a module, without uninstalling it properly, and then do a Moodle upgrade:

      (install Moodle)
      rm -rf mod/chat
      (upgrade to a newer Moodle version, e.g. for testing just edit version.php to increment the number)
      (upgrade Moodle)

      The fix I put in to make this work the first time uses \core_plugin_manager::instance() function get_plugins_of_type('mod'), which uses the installed plugin list. Since the situation here is not related to whether plugins have been officially installed, but whether they exist on disk, the correct function to use would be get_present_plugins('mod'). Changing to this function makes it work on both upgrade and initial install.

      When it fails, the error in install/upgrade looks like this:

      Coding error detected, it must be fixed by a programmer: Invalid indicator classname
      Debug info: \mod_chat\analytics\indicator\cognitive_depth
      Stack trace:
          line 890 of \analytics\classes\manager.php: coding_exception thrown
          line 811 of \analytics\classes\manager.php: call to core_analytics\manager::validate_models_declaration()
          line 737 of \analytics\classes\manager.php: call to core_analytics\manager::load_default_models_for_component()
          line 615 of \lib\upgradelib.php: call to core_analytics\manager::update_default_models_for_component()
          line 1877 of \lib\upgradelib.php: call to upgrade_component_updated()
          line 532 of \admin\index.php: call to upgrade_core()
      

        1. (1) 10 Passed -- (Main)MDL-83529.png
          37 kB
          Kim Jared Lucas
        2. (1) 2 Passed -- (Main)MDL-83529.png
          70 kB
          Kim Jared Lucas
        3. (1) 7 Passed -- (Main)MDL-83529.png
          83 kB
          Kim Jared Lucas
        4. (1) 9 Passed -- (Main)MDL-83529.png
          81 kB
          Kim Jared Lucas

            quen Sam Marshall
            quen Sam Marshall
            Katie Ransom Katie Ransom
            Huong Nguyen Huong Nguyen
            Kim Jared Lucas Kim Jared Lucas
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 hour, 1 minute
                1h 1m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.