need help in deleting old courses from moodle "a lot"

need help in deleting old courses from moodle "a lot"

by shpetim aliaj -
Number of replies: 28

Hi Guys,

I am trying to clean a cloned moodle server installation from all courses  and reuse it for the upcoming year.

I am deleting manually the courses from past years but it is slow and sometimes it timeouts.

Has anyone any steps procedures on how to clean all data from a moodle server courses,  /moodledata , DB

The current server is too big now it will go in archive and new data will be stored on the new server but we need to keep all the configs in place.


best regards,

Tim

Average of ratings: -
In reply to shpetim aliaj

Re: need help in deleting old courses from moodle "a lot"

by Ken Task -
Picture of Particularly helpful Moodlers

Install moosh

Then use mooh's course-delete command:

https://moosh-online.com/commands/
course-delete

Delete course(s) with ID(s) given as argument(s).

Example 1: delete courses id 2,3 and 4.

moosh course-delete 2 3 4

'SoS', Ken

Average of ratings: Useful (1)
In reply to Ken Task

Re: need help in deleting old courses from moodle "a lot"

by shpetim aliaj -
Hi Ken,

thamks for the help i am trying to use moosh but anyway when i do it fro the web gui it gives me: Invalid course module ID

Deleting 20010-PSY3301-201920
Deleted - Completion tracking
Deleted - Grades, Items, Categories
Deleted - Outcomes
Deleted - Scales
Deleted - Settings
Deleted - Letters
Deleted - Blocks

Invalid course module ID

More information about this error

https://docs.moodle.org/36/en/error/moodle/invalidcoursemodule
and on that link it says:

error/moodle/invalidcoursemodule

The ID for the course module is invalid. Please contact the site admin.

For some unknown reason, this happens sometimes when deleting a user. Clicking the back button of the browser and deleting the user again, makes the deleting process continue and delete the user.


i am not deleting a user i am deleting a course.

any idea why it might be doing it?


best regards,

Tim
In reply to shpetim aliaj

Re: need help in deleting old courses from moodle "a lot"

by shpetim aliaj -
on debug it show when i Delete category: 2014 Spring that has a lot of courses:

Debug info: SELECT cm.*, m.name, md.name AS modname
FROM {course_modules} cm
JOIN {modules} md ON md.id = cm.module
JOIN {assign} m ON m.id = cm.instance

WHERE m.id = :instance AND md.name = :modulename

[array (
'instance' => '18309',
'modulename' => 'assign',
)]
Error code: invalidrecordunknown
Stack trace:

line 1590 of /lib/dml/moodle_database.php: dml_missing_record_exception thrown
line 1357 of /lib/datalib.php: call to moodle_database->get_record_sql()
line 52 of /mod/assign/lib.php: call to get_coursemodule_from_instance()
line 5143 of /lib/moodlelib.php: call to assign_delete_instance()
line 5014 of /lib/moodlelib.php: call to remove_course_contents()
line 1796 of /course/classes/category.php: call to delete_course()
line 253 of /course/management.php: call to core_course_category->delete_full()
In reply to shpetim aliaj

Re: need help in deleting old courses from moodle "a lot"

by Ken Task -
Picture of Particularly helpful Moodlers

@shpetim aliaj - who's Tim?

2 persons in same thread but with similar (but causes could be different) makes is difficult ... on all.

In your case a course module ... something in that course is tied to a user.  In debug shows an assignment?

So, go to troubled course and manually delete assignments ...

Know you want mass delete ... course and content in course, which moosh will do ... GUI mass delete is finding something moosh doesn't ... moosh does a course at a time.

'SoS', Ken 


In reply to Ken Task

Re: need help in deleting old courses from moodle "a lot"

by shpetim aliaj -
my short name. :P
In reply to shpetim aliaj

Re: need help in deleting old courses from moodle "a lot"

by shpetim aliaj -
i went to a course and un enrolled everyone. and deleted all content from course.

when i tried to delete the course afterwards i get:

Debug info: SELECT cm.*, m.name, md.name AS modname
FROM {course_modules} cm
JOIN {modules} md ON md.id = cm.module
JOIN {assign} m ON m.id = cm.instance

WHERE m.id = :instance AND md.name = :modulename

[array (
'instance' => '18309',
'modulename' => 'assign',
)]
Error code: invalidrecordunknown
Stack trace:

line 1590 of /lib/dml/moodle_database.php: dml_missing_record_exception thrown
line 1357 of /lib/datalib.php: call to moodle_database->get_record_sql()
line 52 of /mod/assign/lib.php: call to get_coursemodule_from_instance()
line 5143 of /lib/moodlelib.php: call to assign_delete_instance()
line 5014 of /lib/moodlelib.php: call to remove_course_contents()
line 67 of /course/delete.php: call to delete_course()
In reply to shpetim aliaj

Re: need help in deleting old courses from moodle "a lot"

by Ken Task -
Picture of Particularly helpful Moodlers

Well, that's 'special'! :\ and am stumpted.

Error clearly says trying to delete a module that is an assignment but can't be found.

Can you find that ID number in 'mdl_assignment' table?

How about  'mdl_course_modules'?

If moosh won't delete might have to resort to direct database manipulation of tables ... last resort!

Anyone else have an idea?

'SoS', Ken

In reply to Ken Task

Re: need help in deleting old courses from moodle "a lot"

by Ken Task -
Picture of Particularly helpful Moodlers

Link about provides strange solution, but it works ... as you have already stated.

However ... vr 3.6.x ... bug fixes ended already (ended 11 November 2019).  Wonder if an upgrade to supported version will fix?

'SoS', Ken


In reply to Ken Task

Re: need help in deleting old courses from moodle "a lot"

by shpetim aliaj -
i will update the clone to 3.8 and see how it goes.

thanks a lot Ken.

best regards,
Tim
In reply to shpetim aliaj

Re: need help in deleting old courses from moodle "a lot"

by shpetim aliaj -
i did the upgrade and it didn't work on some of them, i used moosh to find and try and delete one and here is the error i am getting:
sudo -u apache /usr/local/bin/moosh course-list "fullname like '%Summer 2019%'"
"id","category","shortname","fullname","visible"
"45582","Top/dead classes","20010-PSY3301-201920","Health Psychology / Summer 2019 (CRN 20010)","0"


sudo -u apache /usr/local/bin/moosh course-delete 45582
About to delete course id=45582; shortname=20010-PSY3301-201920; category id=77++ Format plugin format_onetopic is not found. Using default format_weeks ++
* line 126 of /course/format/lib.php: call to debugging()
* line 187 of /course/format/lib.php: call to format_base::get_format_or_default()
* line 35 of /course/format/lib.php: call to format_base::instance()
* line 2257 of /course/lib.php: call to course_get_format()
* line 156 of /backup/moodle2/backup_section_task.class.php: call to get_section_name()
* line 153 of /backup/util/plan/base_task.class.php: call to backup_section_task->define_settings()
* line 60 of /backup/util/plan/base_plan.class.php: call to base_task->set_plan()
* line 161 of /backup/moodle2/backup_plan_builder.class.php: call to base_plan->add_task()
* line 188 of /backup/moodle2/backup_plan_builder.class.php: call to backup_plan_builder::build_section_plan()
* line 101 of /backup/moodle2/backup_plan_builder.class.php: call to backup_plan_builder::build_course_plan()
* line 163 of /backup/util/factories/backup_factory.class.php: call to backup_plan_builder::build_plan()
* line 61 of /backup/util/plan/backup_plan.class.php: call to backup_factory::build_plan()
* line 419 of /backup/controller/backup_controller.class.php: call to backup_plan->build()
* line 141 of /backup/controller/backup_controller.class.php: call to backup_controller->load_plan()
* line 130 of /admin/tool/recyclebin/classes/category_bin.php: call to backup_controller->__construct()
* line 185 of /admin/tool/recyclebin/lib.php: call to tool_recyclebin\category_bin->store_item()
* line 5097 of /lib/moodlelib.php: call to tool_recyclebin_pre_course_delete()
* line 41 of /opt/moosh/Moosh/Command/Moodle23/Course/CourseDelete.php: call to delete_course()
* line 354 of /opt/moosh/moosh.php: call to Moosh\Command\Moodle23\Course\CourseDelete->execute()
++ Deleted - Completion tracking ++
++ Deleted - Grades, Items, Categories ++
++ Deleted - Outcomes ++
++ Deleted - Scales ++
++ Deleted - Settings ++
++ Deleted - Letters ++
++ Deleted - Blocks ++
Default exception handler: Invalid course module ID Debug:
Error code: invalidcoursemodule
* line 236 of /lib/modinfolib.php: moodle_exception thrown
* line 1787 of /mod/assign/locallib.php: call to course_modinfo->get_cm()
* line 1679 of /mod/assign/locallib.php: call to assign->get_course_module()
* line 1697 of /mod/assign/locallib.php: call to assign->get_default_instance()
* line 951 of /mod/assign/submission/mahara/locallib.php: call to assign->get_instance()
* line 814 of /mod/assign/locallib.php: call to assign_submission_mahara->delete_instance()
* line 56 of /mod/assign/lib.php: call to assign->delete_instance()
* line 5242 of /lib/moodlelib.php: call to assign_delete_instance()
* line 5110 of /lib/moodlelib.php: call to remove_course_contents()
* line 41 of /opt/moosh/Moosh/Command/Moodle23/Course/CourseDelete.php: call to delete_course()
* line 354 of /opt/moosh/moosh.php: call to Moosh\Command\Moodle23\Course\CourseDelete->execute()

!!! Invalid course module ID !!!

if anyone can help out i am hitting a rock here.

best regards,
Tim
In reply to shpetim aliaj

Re: need help in deleting old courses from moodle "a lot"

by shpetim aliaj -
i also tried to rest the course and i got the error:

sudo -u apache /usr/local/bin/moosh course-reset 45582
++ Format plugin format_onetopic is not found. Using default format_weeks ++
* line 126 of /course/format/lib.php: call to debugging()
* line 187 of /course/format/lib.php: call to format_base::get_format_or_default()
* line 35 of /course/format/lib.php: call to format_base::instance()
* line 1031 of /lib/pagelib.php: call to course_get_format()
* line 2815 of /lib/moodlelib.php: call to moodle_page->set_course()
* line 33 of /opt/moosh/Moosh/Command/Moodle29/Course/CourseReset.php: call to require_login()
* line 354 of /opt/moosh/moosh.php: call to Moosh\Command\Moodle29\Course\CourseReset->execute()
Default exception handler: Invalid course module ID Debug:
Error code: invalidcoursemodule
* line 236 of /lib/modinfolib.php: moodle_exception thrown
* line 1860 of /lib/modinfolib.php: call to course_modinfo->get_cm()
* line 206 of /mod/assign/locallib.php: call to cm_info::create()
* line 83 of /mod/assign/lib.php: call to assign->__construct()
* line 5687 of /lib/moodlelib.php: call to assign_reset_userdata()
* line 65 of /opt/moosh/Moosh/Command/Moodle29/Course/CourseReset.php: call to reset_course_userdata()
* line 354 of /opt/moosh/moosh.php: call to Moosh\Command\Moodle29\Course\CourseReset->execute()

!!! Invalid course module ID !!!

best regards,
Tim
In reply to shpetim aliaj

Re: need help in deleting old courses from moodle "a lot"

by shpetim aliaj -
i opened the files for the errors:

* line 236 of /lib/modinfolib.php: moodle_exception thrown

228 /**
229 * Obtains a single course-module object (for a course-module that is on this course).
230 * @param int $cmid Course-module ID
231 * @return cm_info Information about that course-module
232 * @throws moodle_exception If the course-module does not exist
233 */
234 public function get_cm($cmid) {
235 if (empty($this->cms[$cmid])) {
236 throw new moodle_exception('invalidcoursemodule', 'error');
237 }
238 return $this->cms[$cmid];
239 }
=========================

* line 1787 of /mod/assign/locallib.php: call to course_modinfo->get_cm()
* line 1679 of /mod/assign/locallib.php: call to assign->get_course_module()
* line 1697 of /mod/assign/locallib.php: call to assign->get_default_instance()
1670
1671 /**
1672 * Get the settings for the current instance of this assignment.
1673 *
1674 * @return stdClass The settings
1675 * @throws dml_exception
1676 */
1677 public function get_default_instance() {
1678 global $DB;
1679 if (!$this->instance && $this->get_course_module()) {
1680 $params = array('id' => $this->get_course_module()->instance);
1681 $this->instance = $DB->get_record('assign', $params, '*', MUST_EXIST);
1682
1683 $this->userinstances = [];
1684 }
1685 return $this->instance;
1686 }
1687
.
.
.
1772 /**
1773 * Get the current course module.
1774 *
1775 * @return cm_info|null The course module or null if not known
1776 */
1777 public function get_course_module() {
1778 if ($this->coursemodule) {
1779 return $this->coursemodule;
1780 }
1781 if (!$this->context) {
1782 return null;
1783 }
1784
1785 if ($this->context->contextlevel == CONTEXT_MODULE) {
1786 $modinfo = get_fast_modinfo($this->get_course());
1787 $this->coursemodule = $modinfo->get_cm($this->context->instanceid);
1788 return $this->coursemodule;
1789 }
1790 return null;
1791 }


best regards,
Tim
In reply to shpetim aliaj

Re: need help in deleting old courses from moodle "a lot"

by Ken Task -
Picture of Particularly helpful Moodlers

I see in one of error lines at top:

'plugin format_onetopic is not found'

https://moodle.org/plugins/pluginversions.php?plugin=format_onetopic

Now that you have upgraded to 3.8.x get the 3.8 version of onetopic.

You might have to manually re-install onetopic format to get by errors in deleting.

Also ... recycle bin ... in config of recycle bin have it display all the time so you can see the recyclebin link in course admin menus as well as somewhere in course categories.  If you can still see this stubborn course go to it and check recyclebin link.

Allow listings and deletion of recyclebin backups.

'SoS', Ken


In reply to Ken Task

Re: need help in deleting old courses from moodle "a lot"

by shpetim aliaj -
i did it but still not working.

i found data in 39 rows in the mdl_assign but there is no assignment on the course.

very strange.


best regards,
Tim
In reply to shpetim aliaj

Re: need help in deleting old courses from moodle "a lot"

by Ken Task -
Picture of Particularly helpful Moodlers

"i did it but still not working." ... did which?  Reinstall of onetopic (missing) and setting recyclebin viewable?

Could we get a look at:

"data in 39 rows in the mdl_assign but there is no assignment on the course"

Well, since it failed once assignment may not show when looking at GUI of course ... that's a guess ... but if there are 39 rows associated with an assignment that had been in the course, sounds like failure happened before moosh or the routine it called to delete rows .... another guess.

And I saw something else ... require login ... one can use moosh commands with no sudo as apache user ... a -n ... which moosh will warn about.   Have used the -n switch and moosh still performs ... the only thing with -n ... ownerships and permissions need be checked after running -n on some commands.

'SoS', Ken


In reply to shpetim aliaj

Re: need help in deleting old courses from moodle "a lot"

by Ken Task -
Picture of Particularly helpful Moodlers

Missed this ... just noticed in looking again ... :|

* line 951 of /mod/assign/submission/mahara/locallib.php: call to assign->get_instance()
* line 814 of /mod/assign/locallib.php: call to assign_submission_mahara->delete_instance()

Looks like you have mahara installed and using for assignment submissions?
https://moodle.org/plugins/pluginversions.php?plugin=assignsubmission_mahara
shows combat up to 3.6

Could explain the confusion with users when deleting a module from a course ... maybe! smile

'SoS', Ken

In reply to Ken Task

Re: need help in deleting old courses from moodle "a lot"

by shpetim aliaj -
that plugin was disabled and i removed it. the error now looks like:

sudo -u apache /usr/local/bin/moosh course-delete 45582
About to delete course id=45582; shortname=20010-PSY3301-201920111; category id=77++ Deleted - Completion tracking ++
++ Deleted - Grades, Items, Categories ++
++ Deleted - Outcomes ++
++ Deleted - Scales ++
++ Deleted - Settings ++
++ Deleted - Letters ++
++ Deleted - Blocks ++
Default exception handler: Invalid course module ID Debug:
Error code: invalidcoursemodule
* line 236 of /lib/modinfolib.php: moodle_exception thrown
* line 1787 of /mod/assign/locallib.php: call to course_modinfo->get_cm()
* line 1679 of /mod/assign/locallib.php: call to assign->get_course_module()
* line 1697 of /mod/assign/locallib.php: call to assign->get_default_instance()
* line 588 of /mod/assign/submission/onlinetext/locallib.php: call to assign->get_instance()
* line 814 of /mod/assign/locallib.php: call to assign_submission_onlinetext->delete_instance()
* line 56 of /mod/assign/lib.php: call to assign->delete_instance()
* line 5242 of /lib/moodlelib.php: call to assign_delete_instance()
* line 5110 of /lib/moodlelib.php: call to remove_course_contents()
* line 41 of /opt/moosh/Moosh/Command/Moodle23/Course/CourseDelete.php: call to delete_course()
* line 354 of /opt/moosh/moosh.php: call to Moosh\Command\Moodle23\Course\CourseDelete->execute()

!!! Invalid course module ID !!!


the plugin " /mod/assign/submission/onlinetext/locallib.php" seems to be active and needed.

Please can you hel out.

best regards,
Tim
In reply to shpetim aliaj

Re: need help in deleting old courses from moodle "a lot"

by Ken Task -
Picture of Particularly helpful Moodlers

"Please can you hel out."

Yeah!  That's am trying to do!!!!

Well, getting closer!
Now we see invalidcoursemodule but this time ...
/assign/submission/onlinetext/

Yes, online submissions of assignments is part of core so no plugins
to remove.

The course module is the assignment.

So looks like we are down to manipulation with DB.

mysql> show tables like '%assign%';
shows all tables related to assignments - quite a few of them.

Below assign in the one that should be active ... the tables with assignment are the old assignments.

| mdl_assign                       |
| mdl_assign_grades                |
| mdl_assign_overrides             |
| mdl_assign_plugin_config         |
| mdl_assign_submission            |
| mdl_assign_user_flags            |
| mdl_assign_user_mapping          |
| mdl_assignfeedback_comments      |
| mdl_assignfeedback_editpdf_annot |
| mdl_assignfeedback_editpdf_cmnt  |
| mdl_assignfeedback_editpdf_queue |
| mdl_assignfeedback_editpdf_quick |
| mdl_assignfeedback_editpdf_rot   |
| mdl_assignfeedback_file          |
| mdl_assignment                   |
| mdl_assignment_submissions       |
| mdl_assignment_upgrade           |
| mdl_assignsubmission_file        |
| mdl_assignsubmission_onlinetext  |
| mdl_role_allow_assign            |
| mdl_role_assignments

One of them:
mdl_assignsubmission_onlinetext

mysql> explain mdl_assignsubmission_onlinetext;
+--------------+-------------+------+-----+---------+----------------+
| Field        | Type        | Null | Key | Default | Extra          |
+--------------+-------------+------+-----+---------+----------------+
| id           | bigint(10)  | NO   | PRI | NULL    | auto_increment |
| assignment   | bigint(10)  | NO   | MUL | 0       |                |
| submission   | bigint(10)  | NO   | MUL | 0       |                |
| onlinetext   | longtext    | YES  |     | NULL    |                |
| onlineformat | smallint(4) | NO   |     | 0       |                |
+--------------+-------------+------+-----+---------+----------------+

select * from mdl_assignsubmission_onlinetext;
will show data for those.
Looks like (example):
+----+------------+------------+-------------------------------+--------------+
| id | assignment | submission | onlinetext                    | onlineformat |
+----+------------+------------+-------------------------------+--------------+
|  2 |          5 |          6 | <p>2nd after cropping<br></p> |            1 |
+----+------------+------------+-------------------------------+--------------+

The error doesn't tell us id nor assignment number does it?

Can you still access via Web that course and hold your mouse over any assignment
to view an ID number?

Since this is a sandbox site, do a mysqldump of DB so we don't loose what we've gained to this point, then drop the row(s) via mysql dlient.   Try the moosh command again.

Course from hell, isn't it! :\  Am really keeping my fingers crossed for ya.

'SoS', Ken



In reply to Ken Task

Re: need help in deleting old courses from moodle "a lot"

by shpetim aliaj -
Hi Ken,

thank you soo much for your help. there is no assignment showing on the course.

i took a snapshot and will delete the records and see if i can delete via moosh.

course from hell , but good for learning new things smile



best regards,
Tim
In reply to shpetim aliaj

Re: need help in deleting old courses from moodle "a lot"

by shpetim aliaj -
i deleted the data from the "mdl_assignsubmission_onlinetext" :

SELECT * FROM `mdl_assignsubmission_onlinetext` LIMIT 50 (0.000 s) Edit

No rows.

but the erros seems to be the same

sudo -u apache /usr/local/bin/moosh cache-clear
sudo -u apache /usr/local/bin/moosh course-delete 45582
About to delete course id=45582; shortname=20010-PSY3301-201920111; category id=77++ Deleted - Completion tracking ++
++ Deleted - Grades, Items, Categories ++
++ Deleted - Outcomes ++
++ Deleted - Scales ++
++ Deleted - Settings ++
++ Deleted - Letters ++
++ Deleted - Blocks ++
Default exception handler: Invalid course module ID Debug:
Error code: invalidcoursemodule
* line 236 of /lib/modinfolib.php: moodle_exception thrown
* line 1787 of /mod/assign/locallib.php: call to course_modinfo->get_cm()
* line 1679 of /mod/assign/locallib.php: call to assign->get_course_module()
* line 1697 of /mod/assign/locallib.php: call to assign->get_default_instance()
* line 588 of /mod/assign/submission/onlinetext/locallib.php: call to assign->get_instance()
* line 814 of /mod/assign/locallib.php: call to assign_submission_onlinetext->delete_instance()
* line 56 of /mod/assign/lib.php: call to assign->delete_instance()
* line 5242 of /lib/moodlelib.php: call to assign_delete_instance()
* line 5110 of /lib/moodlelib.php: call to remove_course_contents()
* line 41 of /opt/moosh/Moosh/Command/Moodle23/Course/CourseDelete.php: call to delete_course()
* line 354 of /opt/moosh/moosh.php: call to Moosh\Command\Moodle23\Course\CourseDelete->execute()

!!! Invalid course module ID !!!


best regards,
Tim
In reply to shpetim aliaj

Re: need help in deleting old courses from moodle "a lot"

by shpetim aliaj -
Hi Ken,

i made progress. i went into mdl_assign and query for te course number. deleted those records and i could delete the course afterwards.

Now the issues is that i ahve 2 more dead courses that i need to remove. From the moosh cli i get this error on the second course"these courses are from 2014 very very old":

[root@ moodle2]# sudo -u apache /usr/local/bin/moosh course-delete 45582
About to delete course id=45582; shortname=20010-PSY3301-201920111; category id=77++ Deleted - Completion tracking ++
++ Deleted - Grades, Items, Categories ++
++ Deleted - Outcomes ++
++ Deleted - Scales ++
++ Deleted - Settings ++
++ Deleted - Letters ++
++ Deleted - Blocks ++
++ Deleted - Forum ++
++ Deleted - Label ++
++ Deleted - External tool ++
++ Deleted - Page ++
++ Deleted - File ++
++ Deleted - Turnitin Assignment 2 ++
++ Deleted - URL ++
++ Deleted - Activity modules ++
CategoryAction
topThis category has been deleted because, after deleting the course, its questions weren't used any more.
Default for 20010-PSY3301-201920111This category has been deleted because, after deleting the course, its questions weren't used any more.
++ Deleted - Questions ++
++ Deleted - Enrolment methods ++
++ Deleted - Groupings ++
++ Deleted - Groups ++
[root@ moodle2]# sudo -u apache /usr/local/bin/moosh course-list "fullname like '%%'"
"id","category","shortname","fullname","visible"
"7272","Top/dead classes","MTA SP 14","Marketing the Arts / GURALNIK (SP14)","0"
"7335","Top/dead classes","SP14-monks7335","Vertebrate Zoology / MONKS (SP14)","0"
[root@ moodle2]# sudo -u apache /usr/local/bin/moosh course-delete 7272
About to delete course id=7272; shortname=MTA SP 14; category id=77++ Deleted - Completion tracking ++
++ Deleted - Grades, Items, Categories ++
++ Deleted - Outcomes ++
++ Deleted - Scales ++
++ Deleted - Settings ++
++ Deleted - Letters ++
++ Deleted - Blocks ++
++ Did you remember to make the first column something unique in your call to get_records? Duplicate value '' found in column 'id'. ++
* line 1256 of /lib/dml/mysqli_native_moodle_database.php: call to debugging()
* line 5227 of /lib/moodlelib.php: call to mysqli_native_moodle_database->get_records_sql()
* line 5110 of /lib/moodlelib.php: call to remove_course_contents()
* line 41 of /opt/moosh/Moosh/Command/Moodle23/Course/CourseDelete.php: call to delete_course()
* line 354 of /opt/moosh/moosh.php: call to Moosh\Command\Moodle23\Course\CourseDelete->execute()
Default exception handler: Can't find data record in database. Debug: SELECT cm.*, m.name, md.name AS modname
FROM {course_modules} cm
JOIN {modules} md ON md.id = cm.module
JOIN {assign} m ON m.id = cm.instance

WHERE m.id = :instance AND md.name = :modulename

[array (
'instance' => '18309',
'modulename' => 'assign',
)]
Error code: invalidrecordunknown
* line 1590 of /lib/dml/moodle_database.php: dml_missing_record_exception thrown
* line 1281 of /lib/datalib.php: call to moodle_database->get_record_sql()
* line 52 of /mod/assign/lib.php: call to get_coursemodule_from_instance()
* line 5242 of /lib/moodlelib.php: call to assign_delete_instance()
* line 5110 of /lib/moodlelib.php: call to remove_course_contents()
* line 41 of /opt/moosh/Moosh/Command/Moodle23/Course/CourseDelete.php: call to delete_course()
* line 354 of /opt/moosh/moosh.php: call to Moosh\Command\Moodle23\Course\CourseDelete->execute()

!!! Can't find data record in database. !!!
[root@ moodle2]#
In reply to shpetim aliaj

Re: need help in deleting old courses from moodle "a lot"

by Ken Task -
Picture of Particularly helpful Moodlers

And this goes on and on and on ... 

Huh?

sudo -u apache /usr/local/bin/moosh course-list "fullname like '%%'"

is same as

moosh -n course-list

so what's the point?

2nd one: About to delete course id=7272 ... in that your clue is:

++ Did you remember to make the first column something unique in your call to get_records? Duplicate value '' found in column 'id'. ++


Correction ... course(s) from hell!

You're gonna have to dig more ... otherwise this exchange becomes a 1 to 1 consulting.   Open source software might be free, but it does not mean free support!  I do have a 'life' and sites I support on a commercial scale, however.

'SoS', Ken

In reply to shpetim aliaj

Re: need help in deleting old courses from moodle "a lot"

by Ken Task -
Picture of Particularly helpful Moodlers

A couple of *last* items ... cause there is no curriclum/course for sites with problems such as yours ....

Rather than using the moosh command to delete courses one at time, create a list of course ID's to delete.

Issue command with those course id's ... all of them.

moosh command 5 568 1099 30 20033 341

IF it dies at 30 ... jot down that CID .... reissue beginning with 20033 341 and so on.

IF it dies at 341 ... jot down that CID ... reissue beginning with next CID.

Then you have a list of troubled courses that will take some additional slutheing.

There is a hidden admin tool you need to run ...

site/admin/tool/health/

It will probably find issues but it tells you what they are and provides a button for suggested resolution to the problem.   Sometimes, the solution is an SQL query ... which you should have no problems running.

Fingers crossed ... things get fixed.

A module in a course could be anything ... a blog, a label, a quiz ... moosh doesn't report the module id number.

So more slutheing ... are there tables for 'modules'?

Check 'em out ... use explain to see structure ... a query selecting columns to see data.   Focus on any course ID that might be in those tables that match your troubled course.   And so on and so on ...

Come back here and blog about it ... for others who might have their own courses from hell ... do share back what worked ... and what didn't.

And continue making snapshots (DB dumps) after each and every one of your successes cause the next one might be  the final nail in the coffin!  When you save those dumps, name them with something to indicate a stage in your journey.

Remember to take the time to record info cause you will have to do all/any on your production server when you get brave enough to pull the trigger on that 'bad boy' ... and am going to assume, since you are working with a clone right now ... production will be a 'bad boy'.

Best of luck!

'SoS', Ken

In reply to Ken Task

Re: need help in deleting old courses from moodle "a lot"

by shpetim aliaj -
Hi Ken,

thans a lot for you time and support and sorry if i am a bit off on moodle. i opened the health link and i can see a lot of things that need attention. i am doing snapshots before all actions and will add here all the steps on courses from hell P.

thank a lot again for you help and support. i will follow your advice on the steps smile.

best regards,
Tim
In reply to shpetim aliaj

Re: need help in deleting old courses from moodle "a lot"

by shpetim aliaj -
i am getting the error:
i tired to see into it and i see that the field
mld_assign does not have a field instance

if i do:

SELECT cm.*, m.*
FROM mdl_course_modules cm
JOIN mdl_assign m ON m.course = cm.course

i get the rows.
query
does it mean i have a problem on the mdl_assign table?

=Tim
In reply to shpetim aliaj

Re: need help in deleting old courses from moodle "a lot"

by shpetim aliaj -
silly me.

i modified the query and it shows me two rows now:

SELECT cm.*, m.*, md.*
FROM mdl_course_modules cm


JOIN mdl_modules md ON md.id = cm.module
JOIN mdl_assign m ON m.course = cm.course

WHERE m.id = '18309' AND md.name = 'assign'

it shows two identical rows. i think it is related to the error:
Did you remember to make the first column something unique in your call to get_records? Duplicate value '' found in column 'id'. ++


Should i remove one of the record, and try again to delete it?

best regards,
Tim
Attachment moodle_query2.png
In reply to shpetim aliaj

Re: need help in deleting old courses from moodle "a lot"

by Ken Task -
Picture of Particularly helpful Moodlers

Am not responding to the question, (how lucky are you?) but had a thought ...

You've moved all the courses to be culled into a category and have been painfully deleting them.   No 2 have had the same issues ... each has had something unique.

If that is true, am wondering about courses not to be culled ... but reused/reset for next academic session.   How 'healthy' are they?  You are working on a clone of production yet had to update or re-install plugins (mahara/onetopic/) on clone in order to delete a course.

Even after you finish with culling, one could be looking at a very deep ice burg with other courses.

Are you sitting down?  calm?  Story ... there is a major uni on the west coast that avoided issues by starting a new fresh version of Moodle every year.  That new server is whatever the latest/greatest version of Moodle exist at the time.  They build the shell ... categories ... and setup users (asst. admins/managers) and then have teachers/managers (graduate assistants maybe) restore reset backups to new server or rebuild courses from scratch.

Read that they might do updates to that server ... not upgrades ... so the version of Moodle doesn't change ... just point release updates.  Server is used up to the close of 2nd semester of summer.   Then no new students ... etc.  Those servers remain for X and teachers/former students can still access but in kinda a 'read only mode'.

New server cranked up just prior to close of that last academic session.

Not suggesting you adopt and follow that from this day forward, but ... might want to consider it given situation ... especially, if the courses you've not checked for health have issues.

2 cents!

'SoS', Ken

In reply to Ken Task

Re: need help in deleting old courses from moodle "a lot"

by shpetim aliaj -
Hi Ken,

Thanks a lot, that is what i am trying to do, we have removed all courses apart from those 3 courses from hell. The plugins we removed where disabled already. Maybe from carrying over the years and upgrades it did not go smoothly at one point.

thanks a lot for your help.

=Tim