Can't edit course if I move it.

Can't edit course if I move it.

by Ross Stanbridge -
Number of replies: 12

Hi,

I've got a strange problem where if I move a course between course categories I can no longer edit the contents of that course!  I can still see the contents of the course but the editing buttons don't appear when I click "Turn Editing On", although I can add new content.  NB: course can always be edited by Moodle Administrator.

I'm currently running Moodle 1.9.2 (20080820).

Cheers,

Ross

Average of ratings: -
In reply to Ross Stanbridge

Re: Can't edit course if I move it.

by John White -
Ross,

If the course can still be edited by your Administrator even after the move, then surely it must be role assignments in the new course category that are the problem, or, possibly the change in the course's category is not matched by a change in the role 'context' for those who previously had a role of some kind in the course.

I would suggest asking the Administrator to try removing all the role assignments (or at least those that affect you to start with) from both the course and its new category, and then re-applying them to see if that fixes it.

Regards,

John
In reply to John White

Re: Can't edit course if I move it.

by Ross Stanbridge -

Hi John,

thanks for your reply.  The courses are still editable by the Administrator User.  Just not the tutors of that course!!  Have removed all role assignments and re-set them again (using the administrator account) but with no joy.  The only fix at this time seems to be moving the course back to where it was created.

Cheers,

Ross

In reply to Ross Stanbridge

Re: Can't edit course if I move it.

by John White -
Ross,

Suggest you install Tim Hunt's User Roles Report, and see what IT says about the permissions people have in the courses...

http://moodle.org/mod/data/view.php?d=13&rid=1005

Can a tutor from a course originally in the new category (the recipient category) edit the course after the move, even though a tutor from the donor category cannot?
In other words, does the block hit all tutors?

Regards,

John
In reply to John White

Re: Can't edit course if I move it.

by Bill Yorker -

I'm having the same problem running 1.9.2 but I had the problem running 1.9.1 as well, upgraded hoping it would solve it.

I added in Tim Hunts User Roles reports but all it comes back with is a blank page.

Once the course is moved to a different category nobody but an administrator is able to see the editing tools. Move it back and they see the tools just fine.

My Moodle is running on Windows 2003 with SQL 2005 if that is any indicator.

In reply to Bill Yorker

Re: Can't edit course if I move it.

by Ross Stanbridge -

Hi Bill,

Sounds like we are both having exactly the same problem!  I also tried running the User Roles reports and just get a blank page.

Our Moodle setup is as follows:

  • Moodle 1.9.2
  • Apache 2.2
  • PHP 5.2.6
  • MS SQL 2005 (on seperate server)
  • FreeTDS (for communication between Moodle and MS SQL)

You mentioned you had MS SQL 2005.  How similar is the rest of your setup to ours?

I have noticed that if you turn on debugging (server > debuggin) and set the level to ALL you get the following error when you move your course.

'SUBSTR' is not a recognized built-in function name.

UPDATE mdl_context SET path = CAST('/1/3/12' AS VARCHAR(255))+CAST(SUBSTR(path, 8 +1) AS VARCHAR(255)) WHERE path LIKE '/1/11/12/%'
  • line 103 of lib\dmllib.php: call to debugging()
  • line 5438 of lib\accesslib.php: call to execute_sql()
  • line 3158 of course\lib.php: call to context_moved()
  • line 122 of course\edit.php: call to update_course()
Error output, so disabling automatic redirect.
Cheers,

Ross

In reply to Ross Stanbridge

Re: Can't edit course if I move it.

by John White -
Ross / Bill,

Ross - you have nailed it!

The fault is in the code, as debug shows, because SUBSTR is not a legal call on MS SQL, which requires SUBSTRING. See article at: http://www.1keydata.com/sql/sql-substring.html

And the debug list shows the function calls in reverse order, so the faulty call is in lib/accesslib.php in the function context_moved()...

Use you PHP/HTML editor to open the file and look for the lines:

$sql = "UPDATE {$CFG->prefix}context
SET path = ".sql_concat("'$newpath'", 'SUBSTR(path, '.$len.' +1)')."
$setdepth
WHERE path LIKE '{$frompath}/%'";
execute_sql($sql,false);

and change SUBSTR to SUBSTRING.

Notes:
Move you courses back first before editing the PHP and moving them again.
This bug can only affect MSSQL servers, and this is the only instance of the use of this call I can find in the whole of 1.9.1!!!
This call should not be confused with the legitimate PHP function substr() used very frequently wherever it appears other than in an SQL statement.

Finally, as for the white page from User Roles Report...
This happened to me when I first installed it because I didn't read all the instructions and apply them carefully!

Best regards,

John
Average of ratings: Useful (2)
In reply to John White

Re: Can't edit course if I move it.

by Ross Stanbridge -

Hi John,

Have applied the change on our test server and it works!! I'll double check on our live server then post the updated accesslib.php file for anyone else that wants it (or is too lazy to edit the code by hand! tongueout).

For anyone that wants to do the change by hand using John's instructions above note that you will also need to put a ,0 after the +1 as substring requires this variable.

Cheers for the help - much appreciated .

Ross

Average of ratings: Useful (2)
In reply to Ross Stanbridge

Re: Can't edit course if I move it.

by Bill Yorker -

John/Ross thank you both for the extreme help. Except for the fact that I run IIS instead of Apache my setup is exactly the same as Ross's.

I modified the access.php file as John suggested (with Ross's change) and it worked perfectly. Thanks guys!

In reply to Bill Yorker

Re: Can't edit course if I move it.

by Ross Stanbridge -

Just talked to our database guy and it looks like the error I reported above is related to MS SQL.  MS SQL doesn't know what SUBSTR is.  In MS SQL it is called SUBSTRING.  However the MS SQL version need to have a length parameter set.

I'll hopefully run some tests on this today.  I'll post the results as soon as I have.  Maybe this will solve the issue with the non-editable course content?!  Fingers crossed eh! smile

Cheers,

Ross

In reply to Ross Stanbridge

Re: Can't edit course if I move it.

by John White -
Ross - you and I were typing at the same time! JW
In reply to Ross Stanbridge

Re: Can't edit course if I move it.

by Eloy Lafuente (stronk7) -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Peer reviewers Picture of Plugin developers Picture of Testers
Hi,

just working on MDL-16655 now... will be fixed ASAP. Just wanted to comment that the 3rd parameter (length) commented above cannot be 0 AFAIK. That way MSSQL returns 0 characters, while the expected behaviour is to return ALL the remaining (right) characters.

So, I'd prevent you to add that ", 0" and instead will add ", len(path)" that will cause all the remaining characters to be returned (standard behaviour in all other DBs when the 3rd parameter isn't used).

Thanks for the bug finding and tracking, of course! cool

Ciao smile
Average of ratings: Useful (2)