Details

    • Type: New Feature New Feature
    • Status: Development in progress
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: 1.8, 1.8.1, 1.8.2, 1.9, 2.0.2, 2.1, 2.2, 2.6
    • Fix Version/s: DEV backlog
    • Component/s: Course
    • Labels:
    • Rank:
      3720

      Description

      This has been discussed before, notably in bug 2245. There is no way to delete a section (e.g. week or topic) from a Moodle course. There seems to be general agreement that this is A Good Thing, but I can't really see why. I understand the argument that you don't want the teacher deleting a populated section by accident, but you can't even delete an empty section.

      The usual workaround is to move the offending section to the bottom of the course page, and reduce the number of sections the course displays. However, bug 4719 indicates the drawbacks in this approach. If a teacher wants to add a new section by increasing this number, the "deleted" block reappears. This is irksome.

      If a teacher/editor has powers to delete a resource or activity, shouldn't they have the power to delete an entire section? You are asked for confirmation in cautionary terms every time you attempt to delete a resource, so why not have the same for a section, e.g. "Are you absolutely sure you want to completely delete the section 'foo'?"

      1. delete.section.part1.diff
        9 kB
        Daniel Neis
      2. delete.section.part2.diff
        3 kB
        Daniel Neis
      3. MDL-10405.diff
        4 kB
        Daniel Neis
      4. MDL-10405.full.diff
        9 kB
        Daniel Neis

        Issue Links

          Activity

          Hide
          eric stephan added a comment -

          OOooof, if there ever was a time that I wanted to stuff a ballot box, this is it.

          This has just generated a real, and ridiculous, problem for me.

          In a course, a fellow administrator wrongheadedly added a bunch of new topics to the course, like 10 of them, thinking that new material would be added.

          He was wrong. But these topics are interspersed throughout the course. To delete these 10 topics, I am going to (1) move each of them to the bottom one topic at a time, one step at a time – because there is no "move to this location box" feature for moving topics? ... and then do the silly limit-the-number-of-topics feature?

          I'm hoping there is some other way – but this could be hours of ridiculous clicking, to delete 10 topics?

          thx
          eric

          Show
          eric stephan added a comment - OOooof, if there ever was a time that I wanted to stuff a ballot box, this is it. This has just generated a real, and ridiculous, problem for me. In a course, a fellow administrator wrongheadedly added a bunch of new topics to the course, like 10 of them, thinking that new material would be added. He was wrong. But these topics are interspersed throughout the course. To delete these 10 topics, I am going to (1) move each of them to the bottom one topic at a time, one step at a time – because there is no "move to this location box" feature for moving topics? ... and then do the silly limit-the-number-of-topics feature? I'm hoping there is some other way – but this could be hours of ridiculous clicking, to delete 10 topics? thx eric
          Hide
          Steve Bond added a comment -

          The way it works at present is effectively duplicating functionality. There is already a way to hide sections. Reducing the number of sections is like a stronger version of the same thing (i.e. you're hiding them from all users, not just students), but it adds nothing in terms of usefulness.

          Another reason why it is annoying is that because (rightly) you cannot delete a file from the file store when it is being referenced by a resource. But that goes for the resources in non-visible (as opposed to hidden - you see how crazy this is!) sections as well. So if, for example, an editor inherits a course from a predecessor and tries to revamp it, they are find that they are unable to delete files that do not appear to be in use. Then they extend the number of topics to 25 and realise that they are going to spend the rest of the day clicking red crosses...

          Show
          Steve Bond added a comment - The way it works at present is effectively duplicating functionality. There is already a way to hide sections. Reducing the number of sections is like a stronger version of the same thing (i.e. you're hiding them from all users, not just students), but it adds nothing in terms of usefulness. Another reason why it is annoying is that because (rightly) you cannot delete a file from the file store when it is being referenced by a resource. But that goes for the resources in non-visible (as opposed to hidden - you see how crazy this is!) sections as well. So if, for example, an editor inherits a course from a predecessor and tries to revamp it, they are find that they are unable to delete files that do not appear to be in use. Then they extend the number of topics to 25 and realise that they are going to spend the rest of the day clicking red crosses...
          Hide
          Daniel Neis added a comment -

          the related issue has a patch that works on 1.9.5

          Show
          Daniel Neis added a comment - the related issue has a patch that works on 1.9.5
          Hide
          Daniel Neis added a comment -

          The patches (delete.section.part1.diff and delete.section.part2.diff, which should be applied in this order) implement the code to remove a section of a course (both in weekly and topics format, ajax and not) with all it's modules. Hope you like the solution.

          Show
          Daniel Neis added a comment - The patches (delete.section.part1.diff and delete.section.part2.diff, which should be applied in this order) implement the code to remove a section of a course (both in weekly and topics format, ajax and not) with all it's modules. Hope you like the solution.
          Hide
          Anthony Borrow added a comment -

          As requested by Daniel - I am adding 1.9 as an affected version. Peace - Anthony

          Show
          Anthony Borrow added a comment - As requested by Daniel - I am adding 1.9 as an affected version. Peace - Anthony
          Hide
          Swaroop Kumar added a comment -

          Functions that are written in patches will delete the modules of section from section sequence and course_modules table but they doesn't delete the instance record from the module specific table. In other words it doesn't execute the $deleteinstancefunction for the module.

          Show
          Swaroop Kumar added a comment - Functions that are written in patches will delete the modules of section from section sequence and course_modules table but they doesn't delete the instance record from the module specific table. In other words it doesn't execute the $deleteinstancefunction for the module.
          Hide
          Daniel Neis added a comment -

          Hello, Swaroop Kumar

          thanks for your comments. I have made some modifications in the deletesection system since i've uploaded the patches to correct what you said but forgot to re-upload them.

          So now, MDL-10405.diff is a new patch that should be applied INSTEAD of the other two.

          Thank you again and good luck.

          Show
          Daniel Neis added a comment - Hello, Swaroop Kumar thanks for your comments. I have made some modifications in the deletesection system since i've uploaded the patches to correct what you said but forgot to re-upload them. So now, MDL-10405 .diff is a new patch that should be applied INSTEAD of the other two. Thank you again and good luck.
          Hide
          Gary Greer added a comment -

          I've applied the patch, but can't see any change to the UI. How is this exposed to the user?

          Show
          Gary Greer added a comment - I've applied the patch, but can't see any change to the UI. How is this exposed to the user?
          Hide
          Swaroop Kumar added a comment -

          Third patch doesn't include the delete section link in the course page. Applying the first patch and then the third one shud work i guess.

          Show
          Swaroop Kumar added a comment - Third patch doesn't include the delete section link in the course page. Applying the first patch and then the third one shud work i guess.
          Hide
          Daniel Neis added a comment -

          Yes, Swaroop

          you're right. I forgot that part on the last patch, and also the rest.php part.
          The new file MDL-10405.full.diff has the complete implementation.

          Sorry for the trouble.

          Show
          Daniel Neis added a comment - Yes, Swaroop you're right. I forgot that part on the last patch, and also the rest.php part. The new file MDL-10405 .full.diff has the complete implementation. Sorry for the trouble.
          Hide
          Basil Gohar added a comment -

          I would like to see this feature added to Moodle 2.0, as well. There is still no way to do this without a patch, and I am not sure this patch will work for 2.0 at the moment.

          Show
          Basil Gohar added a comment - I would like to see this feature added to Moodle 2.0, as well. There is still no way to do this without a patch, and I am not sure this patch will work for 2.0 at the moment.
          Hide
          Daniel Neis added a comment -

          Hello,

          i've rewritten the patch to work on Moodle 2.1.1+.
          You can see the code on github and also download a patch version.

          Hope you like,
          Daniel

          Show
          Daniel Neis added a comment - Hello, i've rewritten the patch to work on Moodle 2.1.1+. You can see the code on github and also download a patch version . Hope you like, Daniel
          Show
          Daniel Neis added a comment - http://moodle.org/mod/forum/discuss.php?d=186801
          Hide
          Tim Hunt added a comment -

          Nothing to do with me guv.

          Show
          Tim Hunt added a comment - Nothing to do with me guv.
          Hide
          Daniel Neis added a comment -

          Hello,

          i've rebased the patch to last MOODLE_22_STABLE. See the full patch at: https://github.com/danielneis/moodle/compare/MOODLE_22_STABLE...MDL-10405

          Show
          Daniel Neis added a comment - Hello, i've rebased the patch to last MOODLE_22_STABLE. See the full patch at: https://github.com/danielneis/moodle/compare/MOODLE_22_STABLE...MDL-10405
          Hide
          Jean-Philippe Gaudreau added a comment -

          Hi Daniel,

          I merged the diff you gave and it seems there's a bug when deleting the first section and trying to add a file resource in the last one. The file resource is put in the section "Orphaned activities".

          Just to let you know. Maybe it's my merge.. I did it pretty fast just to check what it looks like. Anyway great job it will sure be a great improvement!

          Show
          Jean-Philippe Gaudreau added a comment - Hi Daniel, I merged the diff you gave and it seems there's a bug when deleting the first section and trying to add a file resource in the last one. The file resource is put in the section "Orphaned activities". Just to let you know. Maybe it's my merge.. I did it pretty fast just to check what it looks like. Anyway great job it will sure be a great improvement!
          Hide
          Jean-Philippe Gaudreau added a comment -

          Seems like no one's assign for "Peer review in progress". Status must be changed.

          Show
          Jean-Philippe Gaudreau added a comment - Seems like no one's assign for "Peer review in progress". Status must be changed.
          Hide
          Daniel Neis added a comment -

          Hello, Jean-Philippe

          unfortunately, i could not reproduce your problem. I've deleted some sections and added a file resource to the last section and it seems ok. If the "first section" is the section 0, it should not be able to remove (there shouldn't be a link at session 0) because the code tests this before deleting.

          Kind regards,
          Daniel

          Show
          Daniel Neis added a comment - Hello, Jean-Philippe unfortunately, i could not reproduce your problem. I've deleted some sections and added a file resource to the last section and it seems ok. If the "first section" is the section 0, it should not be able to remove (there shouldn't be a link at session 0) because the code tests this before deleting. Kind regards, Daniel
          Hide
          Jean-Philippe Gaudreau added a comment -

          Hi Daniel,

          Sorry, by first section I meant the first one removeable. Ok well like I said, I only made a quick tour so it might be my integration of your fix that is wrong. I'll take more time in the next days to check it the right way.

          Was there anyone assigned as peer reviewer before it was "moodle.com"?

          Show
          Jean-Philippe Gaudreau added a comment - Hi Daniel, Sorry, by first section I meant the first one removeable. Ok well like I said, I only made a quick tour so it might be my integration of your fix that is wrong. I'll take more time in the next days to check it the right way. Was there anyone assigned as peer reviewer before it was "moodle.com"?
          Hide
          Daniel Neis added a comment -

          Hi, Jean-Philippe

          there was no peer reviewer before moodle.com =T
          Also, this patch is on production at moodle.ufsc.br since mid-february and we have around 900 sections deleted on logs =D

          Kind regards,
          Daniel

          Show
          Daniel Neis added a comment - Hi, Jean-Philippe there was no peer reviewer before moodle.com =T Also, this patch is on production at moodle.ufsc.br since mid-february and we have around 900 sections deleted on logs =D Kind regards, Daniel
          Hide
          Jean-Philippe Gaudreau added a comment -

          Hi Daniel,

          It's seems there's a bug afterall... Just to be clear, I merged the code you gave in https://github.com/danielneis/moodle/compare/MOODLE_22_STABLE...MDL-10405. Could it be that there's only a problem with the modification you did on github and not on your production server?

          Here's my testing instructions :
          1- Create a new course
          2- Delete the first section removeable
          3- Add a file resource in the last section
          4- Save and return to the course
          You should see the resource in a new section called "Orphaned activities"

          I tested on Firefox 11.0 with ajax ON.

          Another problem on my side : In the confirmation box of deleting a section, I get "undefined" instead of "Are you sure you want to delete section ...? All activities and resources within this section will be deleted. This operation cannot be undone.". Problem is there even after purging all caches.

          Hope it helps!

          Jean-Philippe

          Show
          Jean-Philippe Gaudreau added a comment - Hi Daniel, It's seems there's a bug afterall... Just to be clear, I merged the code you gave in https://github.com/danielneis/moodle/compare/MOODLE_22_STABLE...MDL-10405 . Could it be that there's only a problem with the modification you did on github and not on your production server? Here's my testing instructions : 1- Create a new course 2- Delete the first section removeable 3- Add a file resource in the last section 4- Save and return to the course You should see the resource in a new section called "Orphaned activities" I tested on Firefox 11.0 with ajax ON. Another problem on my side : In the confirmation box of deleting a section, I get "undefined" instead of "Are you sure you want to delete section ...? All activities and resources within this section will be deleted. This operation cannot be undone.". Problem is there even after purging all caches. Hope it helps! Jean-Philippe
          Hide
          PEDRO HENRIQUE DIAS added a comment -

          Hi Daniel,

          I'm Pedro, from PUCRS.

          I had exactly the same problems as Jean-Philippe.
          After introductions tests, we see the "Orphaned activities" on last section. I also see another problem like Jean, and I click on Delete button, the message of confirmation box is "undefined".

          I think the ideia is very useful, we had already used it in version 1.9, and now we want use in Moodle 2.x.

          Congratulations for the initiative and I hope we can solve this problem.

          Pedro Dias

          Show
          PEDRO HENRIQUE DIAS added a comment - Hi Daniel, I'm Pedro, from PUCRS. I had exactly the same problems as Jean-Philippe. After introductions tests, we see the "Orphaned activities" on last section. I also see another problem like Jean, and I click on Delete button, the message of confirmation box is "undefined". I think the ideia is very useful, we had already used it in version 1.9, and now we want use in Moodle 2.x. Congratulations for the initiative and I hope we can solve this problem. Pedro Dias
          Hide
          Daniel Neis added a comment -

          Hello,

          i've managed to reproduce the bug: it occurred only with ajax (and thats why i couldn't reproduce it first time). The incorrect behaviour was because i was not updating the "jumpto" URLs of the "add resource" and "add activity" menus.
          The branch is updated on github with the fix.

          During the tests i noted two other minor problems: in the weekly format, after a delete numbers are added to sections (easy to solve, i guess) and the dates are not updated (not so easy, i guess, beacuse in 1.9 the move section didn't updates the dates too).

          Kind regards,
          Daniel

          Show
          Daniel Neis added a comment - Hello, i've managed to reproduce the bug: it occurred only with ajax (and thats why i couldn't reproduce it first time). The incorrect behaviour was because i was not updating the "jumpto" URLs of the "add resource" and "add activity" menus. The branch is updated on github with the fix. During the tests i noted two other minor problems: in the weekly format, after a delete numbers are added to sections (easy to solve, i guess) and the dates are not updated (not so easy, i guess, beacuse in 1.9 the move section didn't updates the dates too). Kind regards, Daniel
          Hide
          Daniel Neis added a comment -

          Hello,

          i've also solved the problem with the confirmation message

          Kind regards,
          Daniel

          Show
          Daniel Neis added a comment - Hello, i've also solved the problem with the confirmation message Kind regards, Daniel
          Hide
          Jean-Philippe Gaudreau added a comment -

          Hi Daniel,

          First of all, thx for the great work! It seems the two bugs are fixed now! Like you said, there's still those two minor problems. I think that the one with the dates that are not updated after deletion should be fix even though it maybe hard to do...

          Just a suggestion : In my opinion it would be better to put the delete button before the visible one to match the order they are shown for the resources/activities.

          Anyway thx again! I think this task isn't far from being completed.

          Jean-Philippe

          Show
          Jean-Philippe Gaudreau added a comment - Hi Daniel, First of all, thx for the great work! It seems the two bugs are fixed now! Like you said, there's still those two minor problems. I think that the one with the dates that are not updated after deletion should be fix even though it maybe hard to do... Just a suggestion : In my opinion it would be better to put the delete button before the visible one to match the order they are shown for the resources/activities. Anyway thx again! I think this task isn't far from being completed. Jean-Philippe
          Hide
          Daniel Neis added a comment -

          Hi, Jean-Philippe

          sorry for the hiatus, but i was busy with my undergraduate course...

          i've fixed the problems with the section ids, the weekdates (based on swap_dates) and also reordered the icon as you said.

          Also, i've rebased to the last MOODLE_22_STABLE branch. The diff is on the same link: https://github.com/danielneis/moodle/compare/MOODLE_22_STABLE...MDL-10405

          Kind regards,
          Daniel

          Show
          Daniel Neis added a comment - Hi, Jean-Philippe sorry for the hiatus, but i was busy with my undergraduate course... i've fixed the problems with the section ids, the weekdates (based on swap_dates) and also reordered the icon as you said. Also, i've rebased to the last MOODLE_22_STABLE branch. The diff is on the same link: https://github.com/danielneis/moodle/compare/MOODLE_22_STABLE...MDL-10405 Kind regards, Daniel
          Hide
          Daniel Neis added a comment -

          Hello,

          i've started the work in rebase to MOODLE_23_STABLE :

          https://github.com/danielneis/moodle/compare/MOODLE_23_STABLE...MDL-10405-v23

          It is not updating the IDs correctly, so we have the same ajax bugs of the first version: topicnames not updated and incorrect ids after first delete (adding activities, deleting more than one topic will not work correctly). Any help woul be appreciated.

          Kind regards,
          Daniel

          Show
          Daniel Neis added a comment - Hello, i've started the work in rebase to MOODLE_23_STABLE : https://github.com/danielneis/moodle/compare/MOODLE_23_STABLE...MDL-10405-v23 It is not updating the IDs correctly, so we have the same ajax bugs of the first version: topicnames not updated and incorrect ids after first delete (adding activities, deleting more than one topic will not work correctly). Any help woul be appreciated. Kind regards, Daniel
          Hide
          Michael Aherne added a comment -

          I'm not sure if it's important, but this patch could leave orphaned records in the course_sections_availability table.

          Show
          Michael Aherne added a comment - I'm not sure if it's important, but this patch could leave orphaned records in the course_sections_availability table.
          Hide
          Derek Chirnside added a comment -

          Just in case someone stumbles on this, there is a fix written up here which will work for some needs: https://moodle.org/mod/forum/discuss.php?d=243077

          ie backup and restore, but don't restore the sections you want.

          -Derek

          Show
          Derek Chirnside added a comment - Just in case someone stumbles on this, there is a fix written up here which will work for some needs: https://moodle.org/mod/forum/discuss.php?d=243077 ie backup and restore, but don't restore the sections you want. -Derek
          Hide
          Robert Puffer added a comment -

          Or you could try my Quickset block which has been available for the past three years:
          https://moodle.org/plugins/view.php?plugin=block_quickset

          Show
          Robert Puffer added a comment - Or you could try my Quickset block which has been available for the past three years: https://moodle.org/plugins/view.php?plugin=block_quickset
          Hide
          Derek Chirnside added a comment -

          @Robert. Never noticed this. I think I was misled by the title. There are now too many blocks for me to keep track of. Docs for V2.6 tweaked: http://docs.moodle.org/26/en/Course_homepage#To_delete_a_course_section

          -Derek

          Show
          Derek Chirnside added a comment - @Robert. Never noticed this. I think I was misled by the title. There are now too many blocks for me to keep track of. Docs for V2.6 tweaked: http://docs.moodle.org/26/en/Course_homepage#To_delete_a_course_section -Derek
          Hide
          Daniel Neis added a comment -

          Hello,

          the workaround to delete sections that is describe in the forum (move to all activities and resources to a section in the end and reduce numsections) is not really good and the current behaviour of the quickset block is "if resources exist in that section they will be moved to the "Zero" section", so it is not really what we want in this issue.

          I have updated the patch to the latest 2.6 stable branch and also fixed the "orphaned records in the course_sections_availability table." as noted by Michael.

          I still don't have the titles updating correcting maybe due some misunderstanding of the "M.course.format.process_sections" function. I would appreciate very much if someone could help with it.

          The new version is available at https://github.com/danielneis/moodle/tree/MDL-10405-v26

          Hope you like.

          Daniel

          Show
          Daniel Neis added a comment - Hello, the workaround to delete sections that is describe in the forum (move to all activities and resources to a section in the end and reduce numsections) is not really good and the current behaviour of the quickset block is "if resources exist in that section they will be moved to the "Zero" section", so it is not really what we want in this issue. I have updated the patch to the latest 2.6 stable branch and also fixed the "orphaned records in the course_sections_availability table." as noted by Michael. I still don't have the titles updating correcting maybe due some misunderstanding of the "M.course.format.process_sections" function. I would appreciate very much if someone could help with it. The new version is available at https://github.com/danielneis/moodle/tree/MDL-10405-v26 Hope you like. Daniel
          Hide
          Marina Glancy added a comment -

          Hello Daniel. I quickly reviewed your code. This is a very nice work.

          Something that you don't keep in mind is that each course format handles sections as it wishes. In 2.4 doing the course format refactoring I took the field 'numsections' out of 'course' table and defined it as a course format option. Topics and Weeks formats support it but, for example, Social or Single Activity formats not. Contributed course formats that supports sections do not need to have 'numsections'.
          As the author of https://moodle.org/plugins/view.php?plugin=format_flexsections I can tell you that your code would not work with my course format. I can not tell for other contributed formats but I'm pretty sure some of them have already implemented deleting sections the way they want.

          Another thing is that the word "section" is internal. Each course format defines the language string that describes "sections" in it. For example, they are "weeks" in weeks format and "topics" in topics format. This means that we can not put language strings in the core, they should be in each course format.

          What I would strongly recommend you is to define all functions and strings inside a particular course format. Actually IMO only topics format needs it. Ideally your branch should have changes only in files that are inside course/format/topics/ folder. Instead of changes in course/rest.php and course/yui/toolboxes/toolboxes.js there should be (probably new) scripts inside the plugin.

          Also regarding your implementation of function course_delete_section(), it should use the API functions to delete modules. Also when you write SQL queries it should not be:

          $DB->execute("UPDATE {$CFG->prefix}course_sections
                               SET section = section - 1
                             WHERE course = {$courseid}
                               AND section > {$section->section}");
          

          but instead:

          $DB->execute("UPDATE {course_sections}
                               SET section = section - 1
                             WHERE course = ?
                               AND section > ?", array($courseid, $section->section));
          
          Show
          Marina Glancy added a comment - Hello Daniel. I quickly reviewed your code. This is a very nice work. Something that you don't keep in mind is that each course format handles sections as it wishes. In 2.4 doing the course format refactoring I took the field 'numsections' out of 'course' table and defined it as a course format option. Topics and Weeks formats support it but, for example, Social or Single Activity formats not. Contributed course formats that supports sections do not need to have 'numsections'. As the author of https://moodle.org/plugins/view.php?plugin=format_flexsections I can tell you that your code would not work with my course format. I can not tell for other contributed formats but I'm pretty sure some of them have already implemented deleting sections the way they want. Another thing is that the word "section" is internal. Each course format defines the language string that describes "sections" in it. For example, they are "weeks" in weeks format and "topics" in topics format. This means that we can not put language strings in the core, they should be in each course format. What I would strongly recommend you is to define all functions and strings inside a particular course format. Actually IMO only topics format needs it. Ideally your branch should have changes only in files that are inside course/format/topics/ folder. Instead of changes in course/rest.php and course/yui/toolboxes/toolboxes.js there should be (probably new) scripts inside the plugin. Also regarding your implementation of function course_delete_section(), it should use the API functions to delete modules. Also when you write SQL queries it should not be: $DB->execute("UPDATE {$CFG->prefix}course_sections SET section = section - 1 WHERE course = {$courseid} AND section > {$section->section}"); but instead: $DB->execute("UPDATE {course_sections} SET section = section - 1 WHERE course = ? AND section > ?", array($courseid, $section->section));
          Hide
          Debra Thayer added a comment -

          I don't see any mention of plans for 2.4 or 2.5. Will either of these versions eventually have this feature?

          Show
          Debra Thayer added a comment - I don't see any mention of plans for 2.4 or 2.5. Will either of these versions eventually have this feature?
          Hide
          Mary Cooch added a comment - - edited

          2.4 and 2.5 won't be treated any differently; they just were not added to the list, Debra.

          Show
          Mary Cooch added a comment - - edited 2.4 and 2.5 won't be treated any differently; they just were not added to the list, Debra.
          Hide
          Derek Chirnside added a comment -

          @Daniel. Any movement on this and Marina's comments?

          -Derek

          Show
          Derek Chirnside added a comment - @Daniel. Any movement on this and Marina's comments? -Derek

            People

            • Votes:
              72 Vote for this issue
              Watchers:
              44 Start watching this issue

              Dates

              • Created:
                Updated: