Moodle
  1. Moodle
  2. MDL-37943

upgrade_plugins_blocks gets confused by cron frequency changes.

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.3.4, 2.4.1, 2.5
    • Fix Version/s: 2.3.5, 2.4.2
    • Component/s: Installation
    • Labels:
    • Testing Instructions:
      Hide

      1. Create a test block (e.g. block_test) with

      $plugin->version = 1;
      $plugin->cron = 0;
      

      2. Go to admin/notifications, so that the block is installed.

      3. Add an upgrade.php to the test block, that calls upgrade_block_savepoint(true, 2, 'test');

      4. Update the test block, so that

      $plugin->version = 3;
      $plugin->cron = 1;
      

      5. Go to admin/notifications, so that the block is upgraded. Ensure the upgrade runs normally. (Before this fix, block_test would appear to be upgraded twice.)

      Show
      1. Create a test block (e.g. block_test) with $plugin->version = 1; $plugin->cron = 0; 2. Go to admin/notifications, so that the block is installed. 3. Add an upgrade.php to the test block, that calls upgrade_block_savepoint(true, 2, 'test'); 4. Update the test block, so that $plugin->version = 3; $plugin->cron = 1; 5. Go to admin/notifications, so that the block is upgraded. Ensure the upgrade runs normally. (Before this fix, block_test would appear to be upgraded twice.)
    • Affected Branches:
      MOODLE_23_STABLE, MOODLE_24_STABLE, MOODLE_25_STABLE
    • Fixed Branches:
      MOODLE_23_STABLE, MOODLE_24_STABLE
    • Pull from Repository:
    • Pull 2.4 Branch:
    • Pull Master Branch:
    • Rank:
      47706

      Description

      Here is some brilliant detective work by Derek Woolhead:

      Say the the current block version is 1, the upgrade.php version is 2, version.php is 3 and current block cron is 0 and version.php cron is 1. the sequence of code in upgrade_plugins_blocks is:

      i) current block version (1) < version.php (3) so upgrade function executed
      ii) upgrade function updates block version to the value in upgrade.php (2)
      ii) current block data is re-read from database
      iii) current block version (2) < version.php (3) so block version updated to value in version.php (3)
      iv) current block cron (0) < version.php cron (1) so current block written to database with cron value
      in version.php (1) * BUT this also sets block version number in database back to (2) *

      Therefore the version number in the current block variable ($currblock) needs setting to the value from version.php before the block is updated with the cron value. I suggest the code change, which should be after the upgrade_block_savepoint before the cron update should be either to re-read $currblock from the database or set $currblock->version = $block->version.

      I prefer the later looking at the upgrade_block_savepoint function.

        Activity

        Hide
        Tim Hunt added a comment -

        This should fix it.

        Show
        Tim Hunt added a comment - This should fix it.
        Hide
        Tim Hunt added a comment -

        Derek just told me verbally that he had destsed this, and it worked for him, so submitting for integration.

        Show
        Tim Hunt added a comment - Derek just told me verbally that he had destsed this, and it worked for him, so submitting for integration.
        Hide
        Eloy Lafuente (stronk7) added a comment -

        Integrated (23, 24 & master), thanks!

        Show
        Eloy Lafuente (stronk7) added a comment - Integrated (23, 24 & master), thanks!
        Hide
        Rajesh Taneja added a comment -

        Thanks Tim and Derek,

        Upgrade worked fine.

        Show
        Rajesh Taneja added a comment - Thanks Tim and Derek, Upgrade worked fine.
        Hide
        Damyon Wiese added a comment -

        Congratulations this fix has been added to Moodle!

        You may want to dedicate this issue to someone special on this Valentines day.

        Thanks!

        Show
        Damyon Wiese added a comment - Congratulations this fix has been added to Moodle! You may want to dedicate this issue to someone special on this Valentines day. Thanks!

          People

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

            Dates

            • Created:
              Updated:
              Resolved: