"Re-sort courses by name" button doesn't always work

"Re-sort courses by name" button doesn't always work

by Donna Hrynkiw -
Number of replies: 21
Does this bug sound familiar to anyone?

Site Administration > Courses > Add/edit courses > (any category)

The "Re-sort courses by name" button doesn't work in all categories. And when it doesn't work, I can't even sort the courses manually by using the up/down arrow icons.

They're in a sub-sub category.
Term
Subject
(unsorted list of courses)

We're running Moodle v1.8 and I've got Admin privs. And despite claims by a co-worker that Moodle Tracker is "All-Seeing and All Knowing", I can't find any mention of this bug.

Reports of similar experiences and/or pointers to the appropriate entry in Moodle Tracker warmly welcome.

Donna Hrynkiw
Kwantlen University College

Average of ratings: -
In reply to Donna Hrynkiw

Re: "Re-sort courses by name" button doesn't always work

by Donna Hrynkiw -
Oh dear. Does no replies mean that nobody else is seeing this behaviour?

Alas!

Donna
Kwantlen
In reply to Donna Hrynkiw

Re: "Re-sort courses by name" button doesn't always work

by Jos Winkel -

We are experiecing the same problem for about 6 months. Altough we did some Moodle upgrades during this time (we now are using 1.9.5+) the problem still exists: in some categories the re-sort button and up-and-down-arrows don't work.
Jos Winkel

In reply to Donna Hrynkiw

Re: "Re-sort courses by name" button doesn't always work

by Anthony Borrow -
Picture of Core developers Picture of Plugin developers Picture of Testers
I thought I recalled an earlier bug in which there were some problems with courses in categories of categories. I would recommend upgrading to the latest version of 1.8 and see if that resolves the issue. If not, let me know and we can work on filing a good tracker issue. Peace - Anthony
In reply to Anthony Borrow

Re: "Re-sort courses by name" button doesn't always work

by Donna Hrynkiw -
Hello Anthony and thanks for the reply.

We're currently running 1.8.3 and won't be doing any upgrades before the end of next semester (Aug 2008, v1.9 is under consideration). Faculty get cranky if the site software changes mid-term...

However I believe we have a test instance of v1.9 around and will see if I can reproduce the problem there. If not, we'll just have to wait for the v1.9 upgrade to fix this.

Donna
Kwantlen
In reply to Donna Hrynkiw

Re: "Re-sort courses by name" button doesn't always work

by Anthony Borrow -
Picture of Core developers Picture of Plugin developers Picture of Testers
Donna - You may wish to encourage them to upgrade to 1.8+ which should not change the functionality for the teachers but it should correct some of the issues (bugs) you may be experiencing. Peace - Anthony
In reply to Donna Hrynkiw

Re: "Re-sort courses by name" button doesn't always work

by Donna Hrynkiw -
I'm back. We've upgraded to v1.9.2 and the "Re-sort courses by name" button still doesn't work.

- Only one of our instances is affected. Unfortunately, it's on our biggest production instance.
- No error message, not even in php.log
- It works only in categories where the course names are mostly-alphabetical
- It fails in categories where the course names are in this format: "ENGL 1100: English Literature 1 (S10)". Are the digits or punctuation characters breaking the sort code?

I'm pretty sure this is the code in question (below, from courses/category.php), but I'm only six weeks into my PHP course and some of the constructs are still beyond me.

/// Resort the category if requested

if ($resort and confirm_sesskey())
 if ($courses = get_courses($category->id, "fullname ASC", 'c.id,c.fullname,c.sortorder')) {
 // move it off the range
 $count = get_record_sql('SELECT MAX(sortorder) AS max, 1 FROM ' . $CFG->prefix . 'course WHERE category=' . $category->id);
 $count = $count->max + 100;
 begin_sql();
 foreach ($courses as $course) {
 set_field('course', 'sortorder', $count, 'id', $course->id);
 $count++;
 }
 commit_sql();
 fix_course_sortorder($category->id);
 }
}

If there are any developers out there with a secret yen to be a bit of a PHP lecturer, now's your chance. What's going on in this code and what might cause it to fail?

[ETA: Apologies. I can't get the code indenting to stick in this editor.]

Donna
Kwantlen Polytechnic University
In reply to Donna Hrynkiw

Re: "Re-sort courses by name" button doesn't always work

by Mark van Hoek -
Picture of Core developers Picture of Plugin developers
I've got exactly this issue in 1.9.4+

Any suggestions are welcome.
In reply to Mark van Hoek

Re: "Re-sort courses by name" button doesn't always work

by Дмитрий Данильченко -
Same story.
In reply to Дмитрий Данильченко

Re: "Re-sort courses by name" button doesn't always work

by Anthony Borrow -
Picture of Core developers Picture of Plugin developers Picture of Testers
Sorry for the delayed response, the first question that comes to mind is about your installation. What OS, which database, version of PHP, etc. I do not believe that this is something impacting everyone. It would be helpful, if I had access to a test site on which this was happening so please feel free to email me at anthony [a t] moodle [d o t] org. My guess is that it has to do with the way that a particular database is sorting the results. I would want to see what happens when we do something like:

SELECT * from mdl_course
WHERE category = 1
ORDER BY fullname ASC;

It may also help to have some sample data to see what is not being sorted correctly. Could you provide me a list of course names in the order you believe they should appear and another list in the order that they are appearing?

Peace - Anthony
In reply to Anthony Borrow

Re: "Re-sort courses by name" button doesn't always work

by Дмитрий Данильченко -
I sent you email. Thx for help.
In reply to Дмитрий Данильченко

Re: "Re-sort courses by name" button doesn't always work

by Anthony Borrow -
Picture of Core developers Picture of Plugin developers Picture of Testers
Sorry - I do not recall what was said in the email but it would be good to help folks work through this. Do we have an issue in the tracker? If so, I suspect I am watching it so please comment there. Using the tracker helps me to have one place to go to see the entire history of questions and answers. Emails get filed but are not easily accessible and take time to look up. Let me know what I can do to help folks resolve this issue. The first step is to figure out how to reproduce this error. Peace - Anthony
In reply to Donna Hrynkiw

Re: "Re-sort courses by name" button doesn't always work

by Vinny Stocker -
Picture of Plugin developers
Hi all,

Same problem here. have a look at my post here.

No solution yet.

Vinny

In reply to Vinny Stocker

Re: "Re-sort courses by name" button doesn't always work

by Дмитрий Данильченко -
bump
In reply to Дмитрий Данильченко

Re: "Re-sort courses by name" button doesn't always work

by Anthony Borrow -
Picture of Core developers Picture of Plugin developers Picture of Testers
Дмитрий Данильченко was good enough to do some searching in the tracker and came across MDL-14580 which has been marked as resolved for Moodle 2.0 (HEAD). A separate issue was created for Moodle 1.9 and is located at MDL-15265; however, it really looks like the issue to comment, vote, and/or watch is MDL-14718. Peace - Anthony
In reply to Anthony Borrow

Re: "Re-sort courses by name" button doesn't always work

by Дмитрий Данильченко -
bump
In reply to Дмитрий Данильченко

Re: "Re-sort courses by name" button doesn't always work

by Дмитрий Данильченко -
bump
In reply to Дмитрий Данильченко

Re: "Re-sort courses by name" button doesn't always work

by Tobias Marx -
We are using 1.9.5+ and this bug still exists. I have allready changed the "sortorder" field to bigint, but it is maxed out again.

Many subcategories can't be sorted (via sort-button or manually by arrows) anymore.

Any advice?
In reply to Tobias Marx

Re: "Re-sort courses by name" button doesn't always work

by Helen Foster -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Hi,

Rather than adding one-word replies to this discussion, please see Anthony's last post and comment, vote, and/or watch the issues mentioned.
In reply to Donna Hrynkiw

Re: "Re-sort courses by name" button doesn't always work

by Donna Hrynkiw -
I started this thread.
We're still experiencing the same problem in Moodle v1.9.6
I'm still unable to find an appropriate entry in Moodle Tracker.

So I've created a new issue: http://tracker.moodle.org/browse/MDL-21011

Go add your comments there, and vote.
In reply to Donna Hrynkiw

Re: "Re-sort courses by name" button doesn't always work

by Jason Dilworth -

I also got this problem on a production server, and so created a script to reset the sortorder to 1000 on all course records, then run the function to alphabetically sort a category for every category ID.  This worked fine on our test server, but on the production server it still broke - sortorder values were maxed out again.

Changing the initial value from 1000 to 10009999 worked though! After running with that value there was one course which had a sortorder value about 5000 less than that.  The course wasn't visible through the GUI, and when I changed the URL to view it I just got a bunch of phantom objects.  I think an incomplete course restore was what caused this.

Anyway, we're up and running now and can re-sort all our categories at once as a bonus.  I've attached the script, which was based on the moodle 1.9.12 sort category function - it may need reworking for different moodle versions.  I hope this is of some help to anyone still suffering from this problem.  It would benefit from some security as anyone can run it as it stands, if they know the URL...

Jason