mirror of
https://github.com/moodle/moodle.git
synced 2025-04-25 10:26:17 +02:00
MDL-14679 fixed multiple old style insert_record calls, we throw exceptions now from DML
This commit is contained in:
parent
0424cfe307
commit
9d97f08e99
@ -896,9 +896,8 @@ class generator {
|
||||
$entry->timemodified = time();
|
||||
$entry->teacherentry = 0;
|
||||
$entry->approved = 1;
|
||||
if ($DB->insert_record('glossary_entries', $entry)) {
|
||||
$entries_count++;
|
||||
}
|
||||
$DB->insert_record('glossary_entries', $entry);
|
||||
$entries_count++;
|
||||
}
|
||||
}
|
||||
if ($entries_count > 0 && !$this->get('quiet')) {
|
||||
|
@ -340,18 +340,17 @@ class blog_entry {
|
||||
$this->created = time();
|
||||
|
||||
// Insert the new blog entry.
|
||||
if ($this->id = $DB->insert_record('post', $this)) {
|
||||
$this->id = $DB->insert_record('post', $this);
|
||||
|
||||
// Update tags.
|
||||
$this->add_tags_info();
|
||||
// Update tags.
|
||||
$this->add_tags_info();
|
||||
|
||||
if (!empty($CFG->useblogassociations)) {
|
||||
$this->add_associations();
|
||||
add_to_log(SITEID, 'blog', 'add', 'index.php?userid='.$this->userid.'&entryid='.$this->id, $this->subject);
|
||||
}
|
||||
|
||||
tag_set('post', $this->id, $this->tags);
|
||||
if (!empty($CFG->useblogassociations)) {
|
||||
$this->add_associations();
|
||||
add_to_log(SITEID, 'blog', 'add', 'index.php?userid='.$this->userid.'&entryid='.$this->id, $this->subject);
|
||||
}
|
||||
|
||||
tag_set('post', $this->id, $this->tags);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -374,12 +374,9 @@ function process_group_tag($tagcontents){
|
||||
// Else if we're allowed to create new categories, let's create this one
|
||||
$newcat->name = $group->category;
|
||||
$newcat->visible = 0;
|
||||
if($catid = $DB->insert_record('course_categories', $newcat)){
|
||||
$course->category = $catid;
|
||||
$this->log_line("Created new (hidden) category, #$catid: $newcat->name");
|
||||
}else{
|
||||
$this->log_line('Failed to create new category: '.$newcat->name);
|
||||
}
|
||||
$catid = $DB->insert_record('course_categories', $newcat);
|
||||
$course->category = $catid;
|
||||
$this->log_line("Created new (hidden) category, #$catid: $newcat->name");
|
||||
}else{
|
||||
// If not found and not allowed to create, stick with default
|
||||
$this->log_line('Category '.$group->category.' not found in Moodle database, so using default category instead.');
|
||||
@ -394,24 +391,21 @@ function process_group_tag($tagcontents){
|
||||
// Choose a sort order that puts us at the start of the list!
|
||||
$course->sortorder = 0;
|
||||
|
||||
if ($courseid = $DB->insert_record('course', $course)) {
|
||||
$courseid = $DB->insert_record('course', $course);
|
||||
|
||||
// Setup the blocks
|
||||
$course = $DB->get_record('course', array('id' => $courseid));
|
||||
blocks_add_default_course_blocks($course);
|
||||
// Setup the blocks
|
||||
$course = $DB->get_record('course', array('id' => $courseid));
|
||||
blocks_add_default_course_blocks($course);
|
||||
|
||||
$section = new object();
|
||||
$section->course = $course->id; // Create a default section.
|
||||
$section->section = 0;
|
||||
$section->summaryformat = FORMAT_HTML;
|
||||
$section->id = $DB->insert_record("course_sections", $section);
|
||||
$section = new object();
|
||||
$section->course = $course->id; // Create a default section.
|
||||
$section->section = 0;
|
||||
$section->summaryformat = FORMAT_HTML;
|
||||
$section->id = $DB->insert_record("course_sections", $section);
|
||||
|
||||
add_to_log(SITEID, "course", "new", "view.php?id=$course->id", "$course->fullname (ID $course->id)");
|
||||
add_to_log(SITEID, "course", "new", "view.php?id=$course->id", "$course->fullname (ID $course->id)");
|
||||
|
||||
$this->log_line("Created course $coursecode in Moodle (Moodle ID is $course->id)");
|
||||
}else{
|
||||
$this->log_line('Failed to create course '.$coursecode.' in Moodle');
|
||||
}
|
||||
$this->log_line("Created course $coursecode in Moodle (Moodle ID is $course->id)");
|
||||
}
|
||||
}elseif($recstatus==3 && ($courseid = $DB->get_field('course', 'id', array('idnumber'=>$coursecode)))){
|
||||
// If course does exist, but recstatus==3 (delete), then set the course as hidden
|
||||
@ -512,7 +506,7 @@ function process_person_tag($tagcontents){
|
||||
$person->confirmed = 1;
|
||||
$person->timemodified = time();
|
||||
$person->mnethostid = $CFG->mnet_localhost_id;
|
||||
if($id = $DB->insert_record('user', $person)){
|
||||
$id = $DB->insert_record('user', $person);
|
||||
/*
|
||||
Photo processing is deactivated until we hear from Moodle dev forum about modification to gdlib.
|
||||
|
||||
@ -531,10 +525,7 @@ function process_person_tag($tagcontents){
|
||||
}
|
||||
}
|
||||
*/
|
||||
$this->log_line("Created user record for user '$person->username' (ID number $person->idnumber).");
|
||||
}else{
|
||||
$this->log_line("Database error while trying to create user record for user '$person->username' (ID number $person->idnumber).");
|
||||
}
|
||||
$this->log_line("Created user record for user '$person->username' (ID number $person->idnumber).");
|
||||
}
|
||||
} elseif ($createnewusers) {
|
||||
$this->log_line("User record already exists for user '$person->username' (ID number $person->idnumber).");
|
||||
|
@ -136,9 +136,8 @@ function message_send($eventdata) {
|
||||
|
||||
//if there is no more processors that want to process this we can move message to message_read
|
||||
if ( $DB->count_records('message_working', array('unreadmessageid' => $messageid)) == 0){
|
||||
if ($DB->insert_record('message_read', $savemessage)) {
|
||||
$DB->delete_records('message', array('id' => $messageid));
|
||||
}
|
||||
$DB->insert_record('message_read', $savemessage);
|
||||
$DB->delete_records('message', array('id' => $messageid));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -343,9 +343,8 @@
|
||||
$messageid = $message->id;
|
||||
unset($message->id);
|
||||
$message->timeread = time();
|
||||
if ($DB->insert_record('message_read', $message)) {
|
||||
$DB->delete_records('message', array('id'=>$messageid));
|
||||
}
|
||||
$DB->insert_record('message_read', $message);
|
||||
$DB->delete_records('message', array('id'=>$messageid));
|
||||
if ($message->timecreated < $start) {
|
||||
$start = $message->timecreated; // move start back so that we see all current history
|
||||
}
|
||||
|
@ -1643,12 +1643,9 @@ function message_move_userfrom_unread2read($userid) {
|
||||
$message->timeread = 0; //the message was never read
|
||||
$messageid = $message->id;
|
||||
unset($message->id);
|
||||
if ($DB->insert_record('message_read', $message)) {
|
||||
$DB->delete_records('message', array('id' => $messageid));
|
||||
$DB->delete_records('message_working', array('unreadmessageid' => $messageid));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
$DB->insert_record('message_read', $message);
|
||||
$DB->delete_records('message', array('id' => $messageid));
|
||||
$DB->delete_records('message_working', array('unreadmessageid' => $messageid));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@ -1678,9 +1675,8 @@ function message_get_popup_messages($destuserid, $fromuserid=NULL){
|
||||
//delete what we've processed and check if can move message
|
||||
$DB->delete_records('message_working', array('id' => $msgp->id));
|
||||
if ( $DB->count_records('message_working', array('unreadmessageid'=>$messageid)) == 0){
|
||||
if ($DB->insert_record('message_read', $message)) {
|
||||
$DB->delete_records('message', array('id' => $messageid));
|
||||
}
|
||||
$DB->insert_record('message_read', $message);
|
||||
$DB->delete_records('message', array('id' => $messageid));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1706,9 +1702,8 @@ function message_mark_messages_read($touserid, $fromuserid){
|
||||
|
||||
//have all message processors completed dealing with this message?
|
||||
if ( $DB->count_records('message_working', array('unreadmessageid'=>$messageid)) == 0){
|
||||
if ($DB->insert_record('message_read', $message)) {
|
||||
$DB->delete_records('message', array('id' => $messageid));
|
||||
}
|
||||
$DB->insert_record('message_read', $message);
|
||||
$DB->delete_records('message', array('id' => $messageid));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -441,29 +441,26 @@ class assignment_base {
|
||||
$assignment->timemodified = time();
|
||||
$assignment->courseid = $assignment->course;
|
||||
|
||||
if ($returnid = $DB->insert_record("assignment", $assignment)) {
|
||||
$assignment->id = $returnid;
|
||||
$returnid = $DB->insert_record("assignment", $assignment);
|
||||
$assignment->id = $returnid;
|
||||
|
||||
if ($assignment->timedue) {
|
||||
$event = new object();
|
||||
$event->name = $assignment->name;
|
||||
$event->description = format_module_intro('assignment', $assignment, $assignment->coursemodule);
|
||||
$event->courseid = $assignment->course;
|
||||
$event->groupid = 0;
|
||||
$event->userid = 0;
|
||||
$event->modulename = 'assignment';
|
||||
$event->instance = $returnid;
|
||||
$event->eventtype = 'due';
|
||||
$event->timestart = $assignment->timedue;
|
||||
$event->timeduration = 0;
|
||||
|
||||
calendar_event::create($event);
|
||||
}
|
||||
|
||||
assignment_grade_item_update($assignment);
|
||||
if ($assignment->timedue) {
|
||||
$event = new object();
|
||||
$event->name = $assignment->name;
|
||||
$event->description = format_module_intro('assignment', $assignment, $assignment->coursemodule);
|
||||
$event->courseid = $assignment->course;
|
||||
$event->groupid = 0;
|
||||
$event->userid = 0;
|
||||
$event->modulename = 'assignment';
|
||||
$event->instance = $returnid;
|
||||
$event->eventtype = 'due';
|
||||
$event->timestart = $assignment->timedue;
|
||||
$event->timeduration = 0;
|
||||
|
||||
calendar_event::create($event);
|
||||
}
|
||||
|
||||
assignment_grade_item_update($assignment);
|
||||
|
||||
return $returnid;
|
||||
}
|
||||
|
@ -117,21 +117,21 @@ function choice_add_instance($choice) {
|
||||
}
|
||||
|
||||
//insert answers
|
||||
if ($choice->id = $DB->insert_record("choice", $choice)) {
|
||||
foreach ($choice->option as $key => $value) {
|
||||
$value = trim($value);
|
||||
if (isset($value) && $value <> '') {
|
||||
$option = new object();
|
||||
$option->text = $value;
|
||||
$option->choiceid = $choice->id;
|
||||
if (isset($choice->limit[$key])) {
|
||||
$option->maxanswers = $choice->limit[$key];
|
||||
}
|
||||
$option->timemodified = time();
|
||||
$DB->insert_record("choice_options", $option);
|
||||
$choice->id = $DB->insert_record("choice", $choice);
|
||||
foreach ($choice->option as $key => $value) {
|
||||
$value = trim($value);
|
||||
if (isset($value) && $value <> '') {
|
||||
$option = new object();
|
||||
$option->text = $value;
|
||||
$option->choiceid = $choice->id;
|
||||
if (isset($choice->limit[$key])) {
|
||||
$option->maxanswers = $choice->limit[$key];
|
||||
}
|
||||
$option->timemodified = time();
|
||||
$DB->insert_record("choice_options", $option);
|
||||
}
|
||||
}
|
||||
|
||||
return $choice->id;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user