Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-74991

Implement a script to delete courses via CLI

XMLWordPrintable

    • MOODLE_400_STABLE, MOODLE_401_STABLE
    • MOODLE_401_STABLE
    • master-MDL-74991
    • Hide
      1. Access Site administration > Development > Make test course admin page.
      2. Create 3 Small courses.
      3. Turn off debugging (if it's turned on).
      4. Run the script to delete the first test course via CLI (replace 5 by your course id), but hit n when asked if you're sure to delete the course:

        root@6a74e8efd623:/var/www/vanilla-moodle-master# php admin/cli/delete_course.php --courseid=5                    
        Deleting course id 5
        Course name:  Course 1 for MDL-74991
        Short name:  Course 1 for MDL-74991
         
        Are you sure you wish to delete this course? (y/N)
        : n
        

      5. Confirm, that the course wasn't deleted.
      6. Re-run the command, but this time answer y:

        root@6a74e8efd623:/var/www/vanilla-moodle-master# php admin/cli/delete_course.php --courseid=5                    
        Deleting course id 5
        Course name:  Course 1 for MDL-74991
        Short name:  Course 1 for MDL-74991
         
        Are you sure you wish to delete this course? (y/N)
        : y
        ++ Deleted - Completion tracking ++
        ++ Deleted - Grades, Items, Categories ++
        ++ Deleted - Outcomes ++
        ++ Deleted - Scales ++
        ++ Deleted - Settings ++
        ++ Deleted - Letters ++
        ++ Deleted - Blocks ++
        ++ Deleted - Assignment ++
        ++ Deleted - Forum ++
        ++ Deleted - Page ++
        ++ Deleted - File ++
        ++ Deleted - Activity modules ++
        ++ Deleted - Questions ++
        ++ Deleted - Content bank ++
        ++ Deleted - Enrolment methods ++
        ++ Deleted - Groupings ++
        ++ Deleted - Groups ++
        Updating course count in categories...
        Done!
        

      7. Confirm, that the course was successfully deleted.
      8. Delete the second test course via CLI with enabled debugging (replace 6 by your course id):

        root@6a74e8efd623:/var/www/vanilla-moodle-master# php admin/cli/delete_course.php --courseid=6 --showdebugging
        Enabling debugging...
        Deleting course id 6
        Course name:  Course 2 for MDL-74991
        Short name:  Course 2 for MDL-74991
         
        Are you sure you wish to delete this course? (y/N)
        : y
        instantiating backup controller a30499349ab6e94f70014f9d7fb94458
        setting controller status to 100
        loading controller plan
        setting controller status to 300
        applying plan defaults
        setting controller status to 400
        setting file inclusion to 
        checking plan security
        setting controller status to 700
        saving controller to db
        calculating controller checksum 30bea806d68b14b0cdbf079f1540e01c
        loading controller from db
        setting file inclusion to 1
        setting controller status to 800
        saving controller to db
        calculating controller checksum 83b692a6472ba2f7adc344519fee7903
        loading controller from db
        setting controller status to 1000
        saving controller to db
        ++ Deleted - Completion tracking ++
        ++ Deleted - Grades, Items, Categories ++
        ++ Deleted - Outcomes ++
        ++ Deleted - Scales ++
        ++ Deleted - Settings ++
        ++ Deleted - Letters ++
        ++ Deleted - Blocks ++
        ++ Deleted - Assignment ++
        ++ Deleted - Forum ++
        ++ Deleted - Page ++
        ++ Deleted - File ++
        ++ Deleted - Activity modules ++
        ++ Deleted - Questions ++
        ++ Deleted - Content bank ++
        ++ Deleted - Enrolment methods ++
        ++ Deleted - Groupings ++
        ++ Deleted - Groups ++
        Updating course count in categories...
        Done!
        

      9. Confirm, that debugging messages for the course backup were printed and the course was successfully deleted.
      10. Delete the third test course via CLI with enabled debugging and disabled recycle bin (replace 7 by your course id):

        root@6a74e8efd623:/var/www/vanilla-moodle-master# php admin/cli/delete_course.php --courseid=7 --showdebugging --disablerecyclebin
        Enabling debugging...
        Deleting course id 7
        Course name:  Course 3 for MDL-74991
        Short name:  Course 3 for MDL-74991
         
        Are you sure you wish to delete this course? (y/N)
        : y
        Disabling recycle bin...
        ++ Deleted - Completion tracking ++
        ++ Deleted - Grades, Items, Categories ++
        ++ Deleted - Outcomes ++
        ++ Deleted - Scales ++
        ++ Deleted - Settings ++
        ++ Deleted - Letters ++
        ++ Deleted - Blocks ++
        ++ Deleted - Assignment ++
        ++ Deleted - Forum ++
        ++ Deleted - Page ++
        ++ Deleted - File ++
        ++ Deleted - Activity modules ++
        ++ Deleted - Questions ++
        ++ Deleted - Content bank ++
        ++ Deleted - Enrolment methods ++
        ++ Deleted - Groupings ++
        ++ Deleted - Groups ++
        Updating course count in categories...
        Done!
        

      11. Confirm, that backup wasn't taken and the course was successfully deleted.
      12. Run the command to delete the last course one more time:

        root@6a74e8efd623:/var/www/vanilla-moodle-master# php admin/cli/delete_course.php --courseid=7
        Course not found
        

      13. Confirm, that Course not found message is printed.
      Show
      Access Site administration > Development > Make test course admin page. Create 3 Small courses. Turn off debugging (if it's turned on). Run the script to delete the first test course via CLI (replace 5 by your course id), but hit n when asked if you're sure to delete the course: root @6a74e8efd623 :/var/www/vanilla-moodle-master# php admin/cli/delete_course.php --courseid= 5 Deleting course id 5 Course name: Course 1 for MDL- 74991 Short name: Course 1 for MDL- 74991   Are you sure you wish to delete this course? (y/N) : n Confirm , that the course wasn't deleted. Re-run the command, but this time answer y : root @6a74e8efd623 :/var/www/vanilla-moodle-master# php admin/cli/delete_course.php --courseid= 5 Deleting course id 5 Course name: Course 1 for MDL- 74991 Short name: Course 1 for MDL- 74991   Are you sure you wish to delete this course? (y/N) : y ++ Deleted - Completion tracking ++ ++ Deleted - Grades, Items, Categories ++ ++ Deleted - Outcomes ++ ++ Deleted - Scales ++ ++ Deleted - Settings ++ ++ Deleted - Letters ++ ++ Deleted - Blocks ++ ++ Deleted - Assignment ++ ++ Deleted - Forum ++ ++ Deleted - Page ++ ++ Deleted - File ++ ++ Deleted - Activity modules ++ ++ Deleted - Questions ++ ++ Deleted - Content bank ++ ++ Deleted - Enrolment methods ++ ++ Deleted - Groupings ++ ++ Deleted - Groups ++ Updating course count in categories... Done! Confirm , that the course was successfully deleted. Delete the second test course via CLI with enabled debugging (replace 6 by your course id): root @6a74e8efd623 :/var/www/vanilla-moodle-master# php admin/cli/delete_course.php --courseid= 6 --showdebugging Enabling debugging... Deleting course id 6 Course name: Course 2 for MDL- 74991 Short name: Course 2 for MDL- 74991   Are you sure you wish to delete this course? (y/N) : y instantiating backup controller a30499349ab6e94f70014f9d7fb94458 setting controller status to 100 loading controller plan setting controller status to 300 applying plan defaults setting controller status to 400 setting file inclusion to checking plan security setting controller status to 700 saving controller to db calculating controller checksum 30bea806d68b14b0cdbf079f1540e01c loading controller from db setting file inclusion to 1 setting controller status to 800 saving controller to db calculating controller checksum 83b692a6472ba2f7adc344519fee7903 loading controller from db setting controller status to 1000 saving controller to db ++ Deleted - Completion tracking ++ ++ Deleted - Grades, Items, Categories ++ ++ Deleted - Outcomes ++ ++ Deleted - Scales ++ ++ Deleted - Settings ++ ++ Deleted - Letters ++ ++ Deleted - Blocks ++ ++ Deleted - Assignment ++ ++ Deleted - Forum ++ ++ Deleted - Page ++ ++ Deleted - File ++ ++ Deleted - Activity modules ++ ++ Deleted - Questions ++ ++ Deleted - Content bank ++ ++ Deleted - Enrolment methods ++ ++ Deleted - Groupings ++ ++ Deleted - Groups ++ Updating course count in categories... Done! Confirm , that debugging messages for the course backup were printed and the course was successfully deleted. Delete the third test course via CLI with enabled debugging and disabled recycle bin (replace 7 by your course id): root @6a74e8efd623 :/var/www/vanilla-moodle-master# php admin/cli/delete_course.php --courseid= 7 --showdebugging --disablerecyclebin Enabling debugging... Deleting course id 7 Course name: Course 3 for MDL- 74991 Short name: Course 3 for MDL- 74991   Are you sure you wish to delete this course? (y/N) : y Disabling recycle bin... ++ Deleted - Completion tracking ++ ++ Deleted - Grades, Items, Categories ++ ++ Deleted - Outcomes ++ ++ Deleted - Scales ++ ++ Deleted - Settings ++ ++ Deleted - Letters ++ ++ Deleted - Blocks ++ ++ Deleted - Assignment ++ ++ Deleted - Forum ++ ++ Deleted - Page ++ ++ Deleted - File ++ ++ Deleted - Activity modules ++ ++ Deleted - Questions ++ ++ Deleted - Content bank ++ ++ Deleted - Enrolment methods ++ ++ Deleted - Groupings ++ ++ Deleted - Groups ++ Updating course count in categories... Done! Confirm , that backup wasn't taken and the course was successfully deleted. Run the command to delete the last course one more time: root @6a74e8efd623 :/var/www/vanilla-moodle-master# php admin/cli/delete_course.php --courseid= 7 Course not found Confirm , that Course not found message is printed.

      There is a couple of cases whne this script would be useful:

      1. Course deletion fails in production site and you'd need to get more details by enabling debugging mode but you can't do this at site-level,
      2. Course to be deleted is huge and you don't want to waste time backing it up (when recycle bin is enabled at site-level).

        1. 1_MDL-74991.png
          1_MDL-74991.png
          19 kB
        2. 2_MDL-74991.png
          2_MDL-74991.png
          48 kB
        3. 3_MDL-74991.png
          3_MDL-74991.png
          92 kB
        4. 4_MDL-74991.png
          4_MDL-74991.png
          55 kB
        5. 5_MDL-74991.png
          5_MDL-74991.png
          12 kB

            mikhailgolenkov Misha Golenkov
            mikhailgolenkov Misha Golenkov
            Stevani Andolo Stevani Andolo
            Andrew Lyons Andrew Lyons
            John Edward Pedregosa John Edward Pedregosa
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 hour, 40 minutes
                1h 40m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.