Moodle
  1. Moodle
  2. MDL-15265

Backport course sortorder rewrite to 1.9.x

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: 1.8.4, 1.8.5, 1.9
    • Fix Version/s: None
    • Component/s: Other
    • Labels:
      None
    • Environment:
      Debian Etch PHP Version 5.2.0-8+etch7
    • Database:
      MySQL
    • Affected Branches:
      MOODLE_18_STABLE, MOODLE_19_STABLE

      Description

      I have an installation which when using the page /course/category.php to reorder courses, when you click on the arrows to change the order of a course the page refreshes but nothing else happens. On investigation this seems to be due to the sortorder value in the mdl_course table being set to the maximum allowed for an int field, ie 4294967295.

      I reset the values to 1,2,3 and 4 and then tried the arrows buttons again and the values did not change as I had expected, ie the values swapped around but 1000 was added to each value, eg they changed to 1001, 1002 etc. Use one of the arrow buttons again and 1000 was added. E.g. 2001, 2002 etc

      I then tried with a set of courses on another installation which I hadn't fiddled with whose values were 13005, 13006 and 13007, I then used the reordering buttons and they changed to 14006, 14005, 14007.

      I accept that a user will have to re-order courses quite a few times to reach the int field maximum, but somehow on this site they have. I don't understand why Moodle is adding 1000 to each number, surely it only has to swap the existing values around.

      Thanks

      Richard

        Gliffy Diagrams

        1. sortorders-moodle192.txt
          39 kB
          Dani Ureña
        2. sortorders-moodle192.txt
          39 kB
          Dani Ureña
        3. sortorders-moodle195_2.txt
          37 kB
          Tobias Marx
        4. sortorders-moodle195.txt
          37 kB
          Dani Ureña

          Issue Links

            Activity

            Hide
            Anthony Borrow added a comment -

            Nicolas - This was initially assigned to Petr who worked on the patch for HEAD found at MDL-14580; however, it has been marked as being resolved by MDL-14718. A quick glance makes me think that rather than being resolved by MDL-14718 that perhaps this might be a duplicate of MDL-14718. I figured I would assign this to you since it was assigned to nobody simply to determine if it is in fact a duplicate. The issues (or at least something very similar) has been discussed at http://moodle.org/mod/forum/discuss.php?d=93618. If it is a duplicate, then we can resolve this issue in favor or MDL-14718. If it is not a duplicate a comment about what makes it different would be helpful as well. Peace - Anthony

            Show
            Anthony Borrow added a comment - Nicolas - This was initially assigned to Petr who worked on the patch for HEAD found at MDL-14580 ; however, it has been marked as being resolved by MDL-14718 . A quick glance makes me think that rather than being resolved by MDL-14718 that perhaps this might be a duplicate of MDL-14718 . I figured I would assign this to you since it was assigned to nobody simply to determine if it is in fact a duplicate. The issues (or at least something very similar) has been discussed at http://moodle.org/mod/forum/discuss.php?d=93618 . If it is a duplicate, then we can resolve this issue in favor or MDL-14718 . If it is not a duplicate a comment about what makes it different would be helpful as well. Peace - Anthony
            Hide
            Dani Ureña added a comment -

            I made the backport of MDL-15265 into a 192 version (Build: 20080711) of moodle.
            I hope this helps

            Show
            Dani Ureña added a comment - I made the backport of MDL-15265 into a 192 version (Build: 20080711) of moodle. I hope this helps
            Hide
            Anthony Borrow added a comment -

            Thanks Dani - that helps a great deal. Hopefully Nicolas will get a moment to look at it. It is much quicker to check a proposed patch than to produce one. Peace - Anthony

            Show
            Anthony Borrow added a comment - Thanks Dani - that helps a great deal. Hopefully Nicolas will get a moment to look at it. It is much quicker to check a proposed patch than to produce one. Peace - Anthony
            Hide
            Dani Ureña added a comment -

            I made a small change in the course/index.php file.

            Show
            Dani Ureña added a comment - I made a small change in the course/index.php file.
            Hide
            Dani Ureña added a comment -

            I created the version 1.9.5 of the patch, that I needed.
            I hope you be of help

            Show
            Dani Ureña added a comment - I created the version 1.9.5 of the patch, that I needed. I hope you be of help
            Hide
            Anthony Borrow added a comment -

            Dani - A definite help. I know the 1.9.5 /lib/accesslib.php file was giving me trouble with an older 1.9 patch so having something more recent is great. Thanks again! Peace - Anthony

            Show
            Anthony Borrow added a comment - Dani - A definite help. I know the 1.9.5 /lib/accesslib.php file was giving me trouble with an older 1.9 patch so having something more recent is great. Thanks again! Peace - Anthony
            Hide
            Tobias Marx added a comment -

            I have applied the Dani's patch for 1.9.5 to our 1.9.5+ (Build: 20090909) installation (testing system). While it has correctly "compressed" the values in "sortorder" I still can't move courses by clicking on those arrows.
            I have enabled debugging and get the following errors:

            Duplicate entry '201-7573007' for key 2

            UPDATE mdl_course SET sortorder = '7573007' WHERE id = '1176'

            Show
            Tobias Marx added a comment - I have applied the Dani's patch for 1.9.5 to our 1.9.5+ (Build: 20090909) installation (testing system). While it has correctly "compressed" the values in "sortorder" I still can't move courses by clicking on those arrows. I have enabled debugging and get the following errors: Duplicate entry '201-7573007' for key 2 UPDATE mdl_course SET sortorder = '7573007' WHERE id = '1176'
            Hide
            Tobias Marx added a comment -

            added:

            set_field('course', 'sortorder', $max, 'id', $swapcourse->id);

            this fixes a problem where courses can't be moved up or down, due to an unique index violation.

            Show
            Tobias Marx added a comment - added: set_field('course', 'sortorder', $max, 'id', $swapcourse->id); this fixes a problem where courses can't be moved up or down, due to an unique index violation.
            Hide
            Tobias Marx added a comment -

            doh!

            my above comment relates to the edited patch file that i've attached to this bug. it fixes an issue that we had with Dani's patch.

            Show
            Tobias Marx added a comment - doh! my above comment relates to the edited patch file that i've attached to this bug. it fixes an issue that we had with Dani's patch.
            Hide
            Anthony Borrow added a comment -

            Tobias - Is this issue resolved for your site? I would like to chat with you about this so that I can better understand what is happening. Peace - Anthony

            Show
            Anthony Borrow added a comment - Tobias - Is this issue resolved for your site? I would like to chat with you about this so that I can better understand what is happening. Peace - Anthony
            Hide
            Sean Keogh added a comment -

            hey guys, I have a site that has this exact problem. The site is running 1.9.6+ (Build: 20091028)

            Has this been put into CVS yet? I'm going to have to update this site to 1.9.7 very soon, and I suspect that the patches above won't work with 1.9.7.

            cheers

            Sean K

            Show
            Sean Keogh added a comment - hey guys, I have a site that has this exact problem. The site is running 1.9.6+ (Build: 20091028) Has this been put into CVS yet? I'm going to have to update this site to 1.9.7 very soon, and I suspect that the patches above won't work with 1.9.7. cheers Sean K
            Hide
            Tobias Marx added a comment -

            Hi Sean,

            I wouldn't advice using those patches. We ran into a lot of problems with them. Though you could try to use them to get rid of your problems for the time beeing.

            When you apply the patches a function will "compress" the sortorder values the first time you try to move a course around. This seems to work just fine. But after that a lot of errors occured (index violations when moving courses (only with some), etc.), so I've reinstalled the standard Moodle files (just copied them over the patched ones).

            This left me with a Moodle installation which will run "out of numbers" sometime in the future, but for the time beeing everything works fine.

            I know this is not really a fix, but at least we have a working Moodle installation. I will cope with sortorder fix when it emerges again.

            Btw.: Please don't use "sortorders-moodle195_2.txt", I might have "fixed it to be broken"...

            Show
            Tobias Marx added a comment - Hi Sean, I wouldn't advice using those patches. We ran into a lot of problems with them. Though you could try to use them to get rid of your problems for the time beeing. When you apply the patches a function will "compress" the sortorder values the first time you try to move a course around. This seems to work just fine. But after that a lot of errors occured (index violations when moving courses (only with some), etc.), so I've reinstalled the standard Moodle files (just copied them over the patched ones). This left me with a Moodle installation which will run "out of numbers" sometime in the future, but for the time beeing everything works fine. I know this is not really a fix, but at least we have a working Moodle installation. I will cope with sortorder fix when it emerges again. Btw.: Please don't use "sortorders-moodle195_2.txt", I might have "fixed it to be broken"...
            Hide
            Sean Keogh added a comment -

            I tried the 195 set of patches, and it failed on the category.php bit. Could this be because the 1.9.6 version of this file is too different for the patch program to recognise it?

            Show
            Sean Keogh added a comment - I tried the 195 set of patches, and it failed on the category.php bit. Could this be because the 1.9.6 version of this file is too different for the patch program to recognise it?
            Hide
            Michael Blake added a comment -

            Can we get a fix ported to 1.9x for this please?

            Show
            Michael Blake added a comment - Can we get a fix ported to 1.9x for this please?
            Hide
            Sean McKay added a comment -

            We are running 1.9.9 and are experiencing similar problems. We have not been able to sort our courses for some time (since 1.9.3, at least). An example error is:

            PHP Notice: Duplicate entry '12-4294967295' for key 2<br /><br />UPDATE mdl_course SET sortorder = '4294968296' WHERE id = '2557'<ul style="text-align: left"><li>line 1328 of lib/dmllib.php: call to debugging()</li><li>line 1254 of lib/dmllib.php: call to set_field_select()</li><li>line 1385 of lib/datalib.php: call to set_field()</li><li>line 1411 of lib/datalib.php: call to fix_course_sortorder()</li><li>line 195 of enrol/database/enrol.php: call to fix_course_sortorder()</li><li>line 34 of enrol/database/enrol_database_sync.php: call to enrolment_plugin_database->sync_enrolments()</li></ul> in /path/to/moodle/lib/weblib.php on line 7005
            PHP Notice: Duplicate entry '12-4294967295' for key 2<br /><br />UPDATE mdl_course
            SET sortorder=sortorder+8589937600
            WHERE category=12<ul style="text-align: left"><li>line 103 of lib/dmllib.php: call to debugging()</li><li>line 1376 of lib/datalib.php: call to execute_sql()</li><li>line 1396 of lib/datalib.php: call to fix_course_sortorder()</li><li>line 1411 of lib/datalib.php: call to fix_course_sortorder()</li><li>line 195 of enrol/database/enrol.php: call to fix_course_sortorder()</li><li>line 34 of enrol/database/enrol_database_sync.php: call to enrolment_plugin_database->sync_enrolments()</li></ul> in /path/to/moodle/lib/weblib.php on line 7005
            PHP Notice: Duplicate entry '12-4294967295' for key 2<br /><br />UPDATE mdl_course SET sortorder = '4294969305' WHERE id = '2557'<ul style="text-align: left"><li>line 1328 of lib/dmllib.php: call to debugging()</li><li>line 1254 of lib/dmllib.php: call to set_field_select()</li><li>line 1385 of lib/datalib.php: call to set_field()</li><li>line 1396 of lib/datalib.php: call to fix_course_sortorder()</li><li>line 1411 of lib/datalib.php: call to fix_course_sortorder()</li><li>line 195 of enrol/database/enrol.php: call to fix_course_sortorder()</li><li>line 34 of enrol/database/enrol_database_sync.php: call to enrolment_plugin_database->sync_enrolments()</li></ul> in /path/to/moodle/lib/weblib.php on line 7005
            PHP Notice: Duplicate entry '22-4294967295' for key 2<br /><br />UPDATE mdl_course
            SET sortorder=sortorder+8589938609
            WHERE category=22<ul style="text-align: left"><li>line 103 of lib/dmllib.php: call to debugging()</li><li>line 1376 of lib/datalib.php: call to execute_sql()</li><li>line 1411 of lib/datalib.php: call to fix_course_sortorder()</li><li>line 1396 of lib/datalib.php: call to fix_course_sortorder()</li><li>line 1411 of lib/datalib.php: call to fix_course_sortorder()</li><li>line 195 of enrol/database/enrol.php: call to fix_course_sortorder()</li><li>line 34 of enrol/database/enrol_database_sync.php: call to enrolment_plugin_database->sync_enrolments()</li></ul> in /path/to/moodle/lib/weblib.php on line 7005
            PHP Notice: Duplicate entry '22-4294967295' for key 2<br /><br />UPDATE mdl_course SET sortorder = '4294970314' WHERE id = '2746'<ul style="text-align: left"><li>line 1328 of lib/dmllib.php: call to debugging()</li><li>line 1254 of lib/dmllib.php: call to set_field_select()</li><li>line 1385 of lib/datalib.php: call to set_field()</li><li>line 1411 of lib/datalib.php: call to fix_course_sortorder()</li><li>line 1396 of lib/datalib.php: call to fix_course_sortorder()</li><li>line 1411 of lib/datalib.php: call to fix_course_sortorder()</li><li>line 195 of enrol/database/enrol.php: call to fix_course_sortorder()</li><li>line 34 of enrol/database/enrol_database_sync.php: call to enrolment_plugin_database->sync_enrolments()</li></ul> in /path/to/moodle/lib/weblib.php on line 7005

            Show
            Sean McKay added a comment - We are running 1.9.9 and are experiencing similar problems. We have not been able to sort our courses for some time (since 1.9.3, at least). An example error is: PHP Notice: Duplicate entry '12-4294967295' for key 2<br /><br />UPDATE mdl_course SET sortorder = '4294968296' WHERE id = '2557'<ul style="text-align: left"><li>line 1328 of lib/dmllib.php: call to debugging()</li><li>line 1254 of lib/dmllib.php: call to set_field_select()</li><li>line 1385 of lib/datalib.php: call to set_field()</li><li>line 1411 of lib/datalib.php: call to fix_course_sortorder()</li><li>line 195 of enrol/database/enrol.php: call to fix_course_sortorder()</li><li>line 34 of enrol/database/enrol_database_sync.php: call to enrolment_plugin_database->sync_enrolments()</li></ul> in /path/to/moodle/lib/weblib.php on line 7005 PHP Notice: Duplicate entry '12-4294967295' for key 2<br /><br />UPDATE mdl_course SET sortorder=sortorder+8589937600 WHERE category=12<ul style="text-align: left"><li>line 103 of lib/dmllib.php: call to debugging()</li><li>line 1376 of lib/datalib.php: call to execute_sql()</li><li>line 1396 of lib/datalib.php: call to fix_course_sortorder()</li><li>line 1411 of lib/datalib.php: call to fix_course_sortorder()</li><li>line 195 of enrol/database/enrol.php: call to fix_course_sortorder()</li><li>line 34 of enrol/database/enrol_database_sync.php: call to enrolment_plugin_database->sync_enrolments()</li></ul> in /path/to/moodle/lib/weblib.php on line 7005 PHP Notice: Duplicate entry '12-4294967295' for key 2<br /><br />UPDATE mdl_course SET sortorder = '4294969305' WHERE id = '2557'<ul style="text-align: left"><li>line 1328 of lib/dmllib.php: call to debugging()</li><li>line 1254 of lib/dmllib.php: call to set_field_select()</li><li>line 1385 of lib/datalib.php: call to set_field()</li><li>line 1396 of lib/datalib.php: call to fix_course_sortorder()</li><li>line 1411 of lib/datalib.php: call to fix_course_sortorder()</li><li>line 195 of enrol/database/enrol.php: call to fix_course_sortorder()</li><li>line 34 of enrol/database/enrol_database_sync.php: call to enrolment_plugin_database->sync_enrolments()</li></ul> in /path/to/moodle/lib/weblib.php on line 7005 PHP Notice: Duplicate entry '22-4294967295' for key 2<br /><br />UPDATE mdl_course SET sortorder=sortorder+8589938609 WHERE category=22<ul style="text-align: left"><li>line 103 of lib/dmllib.php: call to debugging()</li><li>line 1376 of lib/datalib.php: call to execute_sql()</li><li>line 1411 of lib/datalib.php: call to fix_course_sortorder()</li><li>line 1396 of lib/datalib.php: call to fix_course_sortorder()</li><li>line 1411 of lib/datalib.php: call to fix_course_sortorder()</li><li>line 195 of enrol/database/enrol.php: call to fix_course_sortorder()</li><li>line 34 of enrol/database/enrol_database_sync.php: call to enrolment_plugin_database->sync_enrolments()</li></ul> in /path/to/moodle/lib/weblib.php on line 7005 PHP Notice: Duplicate entry '22-4294967295' for key 2<br /><br />UPDATE mdl_course SET sortorder = '4294970314' WHERE id = '2746'<ul style="text-align: left"><li>line 1328 of lib/dmllib.php: call to debugging()</li><li>line 1254 of lib/dmllib.php: call to set_field_select()</li><li>line 1385 of lib/datalib.php: call to set_field()</li><li>line 1411 of lib/datalib.php: call to fix_course_sortorder()</li><li>line 1396 of lib/datalib.php: call to fix_course_sortorder()</li><li>line 1411 of lib/datalib.php: call to fix_course_sortorder()</li><li>line 195 of enrol/database/enrol.php: call to fix_course_sortorder()</li><li>line 34 of enrol/database/enrol_database_sync.php: call to enrolment_plugin_database->sync_enrolments()</li></ul> in /path/to/moodle/lib/weblib.php on line 7005
            Hide
            Lu Pa added a comment -

            Here similar problem. We couldn't sort courses any more.. anda sort order of al courses in category x is: 35201964276705000

            we are running moodle 1.9.9

            Show
            Lu Pa added a comment - Here similar problem. We couldn't sort courses any more.. anda sort order of al courses in category x is: 35201964276705000 we are running moodle 1.9.9
            Hide
            Rosario Carcò added a comment -

            I reported the same issue months/years ago in a post and in another tracker issue where the same bug is discussed.

            Show
            Rosario Carcò added a comment - I reported the same issue months/years ago in a post and in another tracker issue where the same bug is discussed.
            Hide
            Lu Pa added a comment -

            What post? Could you paste the link?

            Show
            Lu Pa added a comment - What post? Could you paste the link?
            Hide
            Dan Poltawski added a comment -

            Hi,

            I'm afraid that 1.9 is out of support for a fix like this to go in. Maybe someone in the community could create a script to fix this problem for others to use (without changing core).

            General bugfix support for 1.9 ended in June 2011, security support by HQ ended in June 2012, and now Catalyst IT are doing security support until Dec 2013 (6 years of 1.9).

            Show
            Dan Poltawski added a comment - Hi, I'm afraid that 1.9 is out of support for a fix like this to go in. Maybe someone in the community could create a script to fix this problem for others to use (without changing core). General bugfix support for 1.9 ended in June 2011, security support by HQ ended in June 2012, and now Catalyst IT are doing security support until Dec 2013 (6 years of 1.9).

              People

              • Votes:
                11 Vote for this issue
                Watchers:
                12 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: