Moodle
  1. Moodle
  2. MDL-21805

Moving blocks up/down causes blocks to disappear

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: 1.9.7
    • Fix Version/s: None
    • Component/s: Blocks
    • Labels:
      None
    • Environment:
      Linux, MySQL 5
    • Affected Branches:
      MOODLE_19_STABLE

      Description

      In the foreach on line 580, blockid is compared instead of id.
      As a result, when moving a block up or down, if the block next to it is of the same type, then the weight of that block is not updated.
      The result is that you end up with weights like:

      • 0
      • 1
      • 3
      • 3

      Instead of:

      • 0
      • 1
      • 2
      • 3

      If you have two weights the same and one missing, only one is shown.

        Gliffy Diagrams

          Activity

          Hide
          Dan Poltawski added a comment -

          Commited the patch, but need to think about whether we need to do something about blocks which may have been lost by this bug. Might need to be an upgrade seteping oint to discover blocks

          Show
          Dan Poltawski added a comment - Commited the patch, but need to think about whether we need to do something about blocks which may have been lost by this bug. Might need to be an upgrade seteping oint to discover blocks
          Hide
          Andrew Nicols added a comment -

          The following SQL queries can be used to select 'broken' block
          configurations.

          The following query will select the pageid and position for any blocks with
          colliding weights:

          SELECT DISTINCT pageid, position FROM (
            SELECT
            o.pageid,
            o.position,
            (
              SELECT COUNT(i.weight)
              FROM block_instance i
              WHERE i.pageid = o.pageid AND
              i.position = o.position AND
              i.weight = o.weight
            ) AS weightcount
            FROM block_instance o
          ) AS brokenweights
          WHERE brokenweights.weightcount > 1;
          

          And this one selects pageid and position for any group of blocks where the
          highest block number is higher or equal to the number of blocks (e.g.
          you've got blocks with weight 0,1,2,4,5) as this would also break things.

          SELECT DISTINCT pageid, position FROM (
            SELECT
              o.pageid,
              o.position,
              (
                SELECT MAX(weight)
                FROM block_instance mi
                WHERE
                  mi.pageid     = o.pageid AND
                  mi.position   = o.position
              ) AS highest,
              (
                SELECT COUNT(*)
                FROM block_instance ci
                WHERE
                  ci.pageid     = o.pageid AND
                  ci.position   = o.position
              ) AS number
            FROM block_instance o
            ORDER BY o.pageid, o.position
          ) AS brokenmaxval
          WHERE brokenmaxval.highest >= brokenmaxval.number;
          

          Show
          Andrew Nicols added a comment - The following SQL queries can be used to select 'broken' block configurations. The following query will select the pageid and position for any blocks with colliding weights: SELECT DISTINCT pageid, position FROM ( SELECT o.pageid, o.position, ( SELECT COUNT (i.weight) FROM block_instance i WHERE i.pageid = o.pageid AND i.position = o.position AND i.weight = o.weight ) AS weightcount FROM block_instance o ) AS brokenweights WHERE brokenweights.weightcount > 1; And this one selects pageid and position for any group of blocks where the highest block number is higher or equal to the number of blocks (e.g. you've got blocks with weight 0,1,2,4,5) as this would also break things. SELECT DISTINCT pageid, position FROM ( SELECT o.pageid, o.position, ( SELECT MAX (weight) FROM block_instance mi WHERE mi.pageid = o.pageid AND mi.position = o.position ) AS highest, ( SELECT COUNT (*) FROM block_instance ci WHERE ci.pageid = o.pageid AND ci.position = o.position ) AS number FROM block_instance o ORDER BY o.pageid, o.position ) AS brokenmaxval WHERE brokenmaxval.highest >= brokenmaxval.number;
          Hide
          Andrew Nicols added a comment -

          Here's a php script to fix the broken block instances.

          Show
          Andrew Nicols added a comment - Here's a php script to fix the broken block instances.
          Hide
          Andrew Nicols added a comment -

          Some corrected queries - When writing the attached script, I discovered that the pagetype is also particularly important.

          SELECT DISTINCT pageid, position, pagetype FROM (
          SELECT
          o.pageid,
          o.position,
          o.pagetype,
          (
          SELECT COUNT(i.weight)
          FROM block_instance i
          WHERE i.pageid = o.pageid AND
          i.position = o.position AND
          i.pagetype = o.pagetype AND
          i.weight = o.weight
          ) AS weightcount
          FROM block_instance o
          ) AS brokenweights
          WHERE brokenweights.weightcount > 1;

          SELECT DISTINCT pageid, position, pagetype FROM (
          SELECT
          o.pageid,
          o.position,
          o.pagetype,
          (
          SELECT MAX(weight)
          FROM block_instance mi
          WHERE
          mi.pageid = o.pageid AND
          mi.position = o.position AND
          mi.pagetype = o.pagetype
          ) AS highest,
          (
          SELECT COUNT
          FROM block_instance ci
          WHERE
          ci.pageid = o.pageid AND
          ci.position = o.position AND
          ci.pagetype = o.pagetype
          ) AS number
          FROM block_instance o
          ORDER BY o.pageid, o.position
          ) AS brokenmaxval
          WHERE brokenmaxval.highest >= brokenmaxval.number;

          Show
          Andrew Nicols added a comment - Some corrected queries - When writing the attached script, I discovered that the pagetype is also particularly important. SELECT DISTINCT pageid, position, pagetype FROM ( SELECT o.pageid, o.position, o.pagetype, ( SELECT COUNT(i.weight) FROM block_instance i WHERE i.pageid = o.pageid AND i.position = o.position AND i.pagetype = o.pagetype AND i.weight = o.weight ) AS weightcount FROM block_instance o ) AS brokenweights WHERE brokenweights.weightcount > 1; SELECT DISTINCT pageid, position, pagetype FROM ( SELECT o.pageid, o.position, o.pagetype, ( SELECT MAX(weight) FROM block_instance mi WHERE mi.pageid = o.pageid AND mi.position = o.position AND mi.pagetype = o.pagetype ) AS highest, ( SELECT COUNT FROM block_instance ci WHERE ci.pageid = o.pageid AND ci.position = o.position AND ci.pagetype = o.pagetype ) AS number FROM block_instance o ORDER BY o.pageid, o.position ) AS brokenmaxval WHERE brokenmaxval.highest >= brokenmaxval.number;
          Hide
          Andrew Nicols added a comment -

          And now with

           blocks around them...
          


          SELECT DISTINCT pageid, position, pagetype FROM (
          SELECT
          o.pageid,
          o.position,
          o.pagetype,
          (
          SELECT COUNT(i.weight)
          FROM block_instance i
          WHERE i.pageid = o.pageid AND
          i.position = o.position AND
          i.pagetype = o.pagetype AND
          i.weight = o.weight
          ) AS weightcount
          FROM block_instance o
          ) AS brokenweights
          WHERE brokenweights.weightcount > 1;

          And
          

          SELECT DISTINCT pageid, position, pagetype FROM (
          SELECT
          o.pageid,
          o.position,
          o.pagetype,
          (
          SELECT MAX(weight)
          FROM block_instance mi
          WHERE
          mi.pageid = o.pageid AND
          mi.position = o.position AND
          mi.pagetype = o.pagetype
          ) AS highest,
          (
          SELECT COUNT
          FROM block_instance ci
          WHERE
          ci.pageid = o.pageid AND
          ci.position = o.position AND
          ci.pagetype = o.pagetype
          ) AS number
          FROM block_instance o
          ORDER BY o.pageid, o.position
          ) AS brokenmaxval
          WHERE brokenmaxval.highest >= brokenmaxval.number;

           

          Show
          Andrew Nicols added a comment - And now with blocks around them... SELECT DISTINCT pageid, position, pagetype FROM ( SELECT o.pageid, o.position, o.pagetype, ( SELECT COUNT(i.weight) FROM block_instance i WHERE i.pageid = o.pageid AND i.position = o.position AND i.pagetype = o.pagetype AND i.weight = o.weight ) AS weightcount FROM block_instance o ) AS brokenweights WHERE brokenweights.weightcount > 1; And SELECT DISTINCT pageid, position, pagetype FROM ( SELECT o.pageid, o.position, o.pagetype, ( SELECT MAX(weight) FROM block_instance mi WHERE mi.pageid = o.pageid AND mi.position = o.position AND mi.pagetype = o.pagetype ) AS highest, ( SELECT COUNT FROM block_instance ci WHERE ci.pageid = o.pageid AND ci.position = o.position AND ci.pagetype = o.pagetype ) AS number FROM block_instance o ORDER BY o.pageid, o.position ) AS brokenmaxval WHERE brokenmaxval.highest >= brokenmaxval.number;  
          Hide
          Michael de Raadt added a comment -

          Thanks for reporting this issue.

          We have detected that this issue has been inactive for over a year has been recorded as affecting versions that are no longer supported.

          If you believe that this issue is still relevant to current versions (2.1 and beyond), please comment on the issue. Issues left inactive for a further month will be closed.

          Michael d;

          lqjjLKA0p6

          Show
          Michael de Raadt added a comment - Thanks for reporting this issue. We have detected that this issue has been inactive for over a year has been recorded as affecting versions that are no longer supported. If you believe that this issue is still relevant to current versions (2.1 and beyond), please comment on the issue. Issues left inactive for a further month will be closed. Michael d; lqjjLKA0p6
          Hide
          Michael de Raadt added a comment -

          I'm closing this issue as it appears to have become inactive and is probably not relevant to a current supported version. If you are encountering this problem or one similar, please launch a new issue.

          Show
          Michael de Raadt added a comment - I'm closing this issue as it appears to have become inactive and is probably not relevant to a current supported version. If you are encountering this problem or one similar, please launch a new issue.

            People

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

              Dates

              • Created:
                Updated:
                Resolved: