Bugs fixed in backup and restore. Dialogue now notifies if there are any
open dialogues.
This commit is contained in:
@@ -67,8 +67,8 @@
|
||||
|
||||
$status = true;
|
||||
|
||||
$dialogue_conversations = get_records("dialogue_conversations","dialogue",$dialogue,"id");
|
||||
//If there is conversationss
|
||||
$dialogue_conversations = get_records("dialogue_conversations","dialogueid",$dialogue,"id");
|
||||
//If there is conversations
|
||||
if ($dialogue_conversations) {
|
||||
//Write start tag
|
||||
$status =fwrite ($bf,start_tag("CONVERSATIONS",4,true));
|
||||
@@ -108,7 +108,7 @@
|
||||
|
||||
$status = true;
|
||||
|
||||
$dialogue_entries = get_records("dialogue_entries","conversationid",$conservationid,"id");
|
||||
$dialogue_entries = get_records("dialogue_entries","conversationid",$conversationid,"id");
|
||||
//If there is entries
|
||||
if ($dialogue_entries) {
|
||||
//Write start tag
|
||||
@@ -120,9 +120,9 @@
|
||||
//Print dialogue_entries contents
|
||||
fwrite ($bf,full_tag("ID",6,false,$entry->id));
|
||||
fwrite ($bf,full_tag("USERID",6,false,$entry->userid));
|
||||
fwrite ($bf,full_tag("TIMECREATED",6,false,$entry->modified));
|
||||
fwrite ($bf,full_tag("MAILED",6,false,$entry->text));
|
||||
fwrite ($bf,full_tag("TEXT",6,false,$entry->format));
|
||||
fwrite ($bf,full_tag("TIMECREATED",6,false,$entry->timecreated));
|
||||
fwrite ($bf,full_tag("MAILED",6,false,$entry->mailed));
|
||||
fwrite ($bf,full_tag("TEXT",6,false,$entry->text));
|
||||
//End entry
|
||||
$status =fwrite ($bf,end_tag("ENTRY",5,true));
|
||||
}
|
||||
|
||||
+69
-2
@@ -179,6 +179,40 @@ function dialogue_print_recent_activity($course, $isteacher, $timestart) {
|
||||
}
|
||||
}
|
||||
|
||||
// have a look for open conversations
|
||||
$opencontent = false;
|
||||
if ($logs = dialogue_get_open_conversations($course)) {
|
||||
// got some, see if any belong to a visible module
|
||||
foreach ($logs as $log) {
|
||||
// Create a temp valid module structure (only need courseid, moduleid)
|
||||
$tempmod->course = $course->id;
|
||||
$tempmod->id = $log->dialogueid;
|
||||
//Obtain the visible property from the instance
|
||||
if (instance_is_visible("dialogue",$tempmod)) {
|
||||
$opencontent = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// if we got some "live" ones then output them
|
||||
if ($opencontent) {
|
||||
$strftimerecent = get_string("strftimerecent");
|
||||
print_headline(get_string("opendialogueentries", "dialogue").":");
|
||||
foreach ($logs as $log) {
|
||||
//Create a temp valid module structure (only need courseid, moduleid)
|
||||
$tempmod->course = $course->id;
|
||||
$tempmod->id = $log->dialogueid;
|
||||
//Obtain the visible property from the instance
|
||||
if (instance_is_visible("dialogue",$tempmod)) {
|
||||
$date = userdate($log->time, $strftimerecent);
|
||||
echo "<p><font size=1>$date - $log->firstname $log->lastname<br />";
|
||||
echo "\"<a href=\"$CFG->wwwroot/mod/dialogue/$log->url\">";
|
||||
echo "$log->name";
|
||||
echo "</a>\"</font></p>";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// have a look for closed conversations
|
||||
$closedcontent = false;
|
||||
if ($logs = dialogue_get_closed_logs($course, $timestart)) {
|
||||
@@ -570,6 +604,39 @@ function dialogue_get_add_entry_logs($course, $timestart) {
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
function dialogue_get_open_conversations($course) {
|
||||
// get the conversations which are waiting for a response for this user.
|
||||
// Add the first and last names of the other participant
|
||||
global $CFG, $USER;
|
||||
if ($conversations = get_records_sql("SELECT d.name dialoguename, c.id, c.dialogueid, c.timemodified, c.lastid
|
||||
FROM {$CFG->prefix}dialogue d, {$CFG->prefix}dialogue_conversations c
|
||||
WHERE d.course = $course->id
|
||||
AND c.dialogueid = d.id
|
||||
AND (c.userid = $USER->id OR c.recipientid = $USER->id)
|
||||
AND c.lastid != $USER->id
|
||||
AND c.closed =0")) {
|
||||
|
||||
foreach ($conversations as $conversation) {
|
||||
if (!$user = get_record("user", "id", $conversation->lastid)) {
|
||||
error("Get open conversations: user record not found");
|
||||
}
|
||||
if (!$cm = get_coursemodule_from_instance("dialogue", $conversation->dialogueid, $course->id)) {
|
||||
error("Course Module ID was incorrect");
|
||||
}
|
||||
$entry[$conversation->id]->dialogueid = $conversation->dialogueid;
|
||||
$entry[$conversation->id]->time = $conversation->timemodified;
|
||||
$entry[$conversation->id]->url = "view.php?id=$cm->id";
|
||||
$entry[$conversation->id]->firstname = $user->firstname;
|
||||
$entry[$conversation->id]->lastname = $user->lastname;
|
||||
$entry[$conversation->id]->name = $conversation->dialoguename;
|
||||
}
|
||||
return $entry;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
function dialogue_get_closed_logs($course, $timestart) {
|
||||
// get the "closed" entries and add the first and last names, we are not interested in the entries
|
||||
@@ -657,10 +724,10 @@ function dialogue_list_conversations_other($dialogue) {
|
||||
// list the conversations of the current user awaiting response from the other person
|
||||
global $THEME, $USER;
|
||||
|
||||
if (! $course = get_record("course", "id", $dialogue->course)) {
|
||||
if (!$course = get_record("course", "id", $dialogue->course)) {
|
||||
error("Course is misconfigured");
|
||||
}
|
||||
if (! $cm = get_coursemodule_from_instance("dialogue", $dialogue->id, $course->id)) {
|
||||
if (!$cm = get_coursemodule_from_instance("dialogue", $dialogue->id, $course->id)) {
|
||||
error("Course Module ID was incorrect");
|
||||
}
|
||||
|
||||
|
||||
+97
-100
@@ -53,14 +53,6 @@
|
||||
$dialogue->maildefault = backup_todb($info['MOD']['#']['MAILDEFAULT']['0']['#']);
|
||||
$dialogue->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
|
||||
|
||||
//We have to recode the assessed field if it is <0 (scale)
|
||||
if ($dialogue->assessed < 0) {
|
||||
$scale = backup_getid($restore->backup_unique_code,"scale",abs($dialogue->assessed));
|
||||
if ($scale) {
|
||||
$dialogue->assessed = -($scale->new_id);
|
||||
}
|
||||
}
|
||||
|
||||
//The structure is equal to the db, so insert the dialogue
|
||||
$newid = insert_record ("dialogue",$dialogue);
|
||||
|
||||
@@ -75,7 +67,7 @@
|
||||
//Now check if want to restore user data and do it.
|
||||
if ($restore->mods['dialogue']->userinfo) {
|
||||
//Restore dialogue_conversations
|
||||
$status = dialogue_conversations_restore_mods ($mod->id, $newid,$info,$restore);
|
||||
$status = dialogue_conversations_restore($mod->id, $newid,$info,$restore);
|
||||
}
|
||||
} else {
|
||||
$status = false;
|
||||
@@ -93,7 +85,7 @@
|
||||
|
||||
|
||||
//This function restores the dialogue_conversations
|
||||
function dialogue_conversations_restore_mods($old_dialogue_id, $new_dialogue_id,$info,$restore) {
|
||||
function dialogue_conversations_restore($old_dialogue_id, $new_dialogue_id,$info,$restore) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
@@ -102,61 +94,64 @@
|
||||
//Get the entries array
|
||||
$conversations = $info['MOD']['#']['CONVERSATIONS']['0']['#']['CONVERSATION'];
|
||||
|
||||
//Iterate over conversations
|
||||
for($i = 0; $i < sizeof($converstions); $i++) {
|
||||
$conversation_info = $conversations[$i];
|
||||
//traverse_xmlize($conversation_info); //Debug
|
||||
//print_object ($GLOBALS['traverse_array']); //Debug
|
||||
//$GLOBALS['traverse_array']=""; //Debug
|
||||
if ($conversations) {
|
||||
//Iterate over conversations
|
||||
for($i = 0; $i < sizeof($conversations); $i++) {
|
||||
$conversation_info = $conversations[$i];
|
||||
//traverse_xmlize($conversation_info); //Debug
|
||||
//print_object ($GLOBALS['traverse_array']); //Debug
|
||||
//$GLOBALS['traverse_array']=""; //Debug
|
||||
|
||||
//We'll need this later!!
|
||||
$oldid = backup_todb($sub_info['#']['ID']['0']['#']);
|
||||
$olduserid = backup_todb($sub_info['#']['USERID']['0']['#']);
|
||||
//We'll need this later!!
|
||||
$oldid = backup_todb($conversation_info['#']['ID']['0']['#']);
|
||||
$olduserid = backup_todb($conversation_info['#']['USERID']['0']['#']);
|
||||
|
||||
//Now, build the dialogue_ENTRIES record structure
|
||||
$conversation->dialogue = $new_dialogue_id;
|
||||
$conversation->userid = backup_todb($conversation_info['#']['USERID']['0']['#']);
|
||||
$conversation->recipientid = backup_todb($conversation_info['#']['RECIPIENTID']['0']['#']);
|
||||
$conversation->lastid = backup_todb($conversation_info['#']['LASTID']['0']['#']);
|
||||
$conversation->timemodified = backup_todb($conversation_info['#']['TIMEMODIFIED']['0']['#']);
|
||||
$conversation->closed = backup_todb($conversation_info['#']['CLOSED']['0']['#']);
|
||||
$conversation->seenon = backup_todb($conversation_info['#']['SEENON']['0']['#']);
|
||||
$conversation->ctype = backup_todb($conversation_info['#']['CTYPE']['0']['#']);
|
||||
$conversation->format = backup_todb($conversation_info['#']['FORMAT']['0']['#']);
|
||||
$conversation->subject = backup_todb($conversation_info['#']['SUBJECT']['0']['#']);
|
||||
//We have to recode the userid and recipientid fields
|
||||
$user = backup_getid($restore->backup_unique_code,"user",$conversation->userid);
|
||||
if ($user) {
|
||||
$conversation->userid = $user->new_id;
|
||||
}
|
||||
$user = backup_getid($restore->backup_unique_code,"user",$conversation->recipientid);
|
||||
if ($user) {
|
||||
$conversation->recipientid = $user->new_id;
|
||||
}
|
||||
|
||||
//The structure is equal to the db, so insert the dialogue_conversation
|
||||
$newid = insert_record ("dialogue_conversations",$conversation);
|
||||
|
||||
//Do some output
|
||||
if (($i+1) % 50 == 0) {
|
||||
echo ".";
|
||||
if (($i+1) % 1000 == 0) {
|
||||
echo "<br>";
|
||||
//Now, build the dialogue_ENTRIES record structure
|
||||
$conversation->dialogueid = $new_dialogue_id;
|
||||
$conversation->userid = backup_todb($conversation_info['#']['USERID']['0']['#']);
|
||||
$conversation->recipientid = backup_todb($conversation_info['#']['RECIPIENTID']['0']['#']);
|
||||
$conversation->lastid = backup_todb($conversation_info['#']['LASTID']['0']['#']);
|
||||
$conversation->timemodified = backup_todb($conversation_info['#']['TIMEMODIFIED']['0']['#']);
|
||||
$conversation->closed = backup_todb($conversation_info['#']['CLOSED']['0']['#']);
|
||||
$conversation->seenon = backup_todb($conversation_info['#']['SEENON']['0']['#']);
|
||||
$conversation->ctype = backup_todb($conversation_info['#']['CTYPE']['0']['#']);
|
||||
$conversation->format = backup_todb($conversation_info['#']['FORMAT']['0']['#']);
|
||||
$conversation->subject = backup_todb($conversation_info['#']['SUBJECT']['0']['#']);
|
||||
//We have to recode the userid and recipientid fields
|
||||
$user = backup_getid($restore->backup_unique_code,"user",$conversation->userid);
|
||||
if ($user) {
|
||||
$conversation->userid = $user->new_id;
|
||||
}
|
||||
backup_flush(300);
|
||||
}
|
||||
$user = backup_getid($restore->backup_unique_code,"user",$conversation->recipientid);
|
||||
if ($user) {
|
||||
$conversation->recipientid = $user->new_id;
|
||||
}
|
||||
|
||||
if ($newid) {
|
||||
//We have the newid, update backup_ids
|
||||
backup_putid($restore->backup_unique_code, "dialogue_conversations",
|
||||
$oldid, $newid);
|
||||
//Now check if want to restore user data and do it.
|
||||
if ($status) {
|
||||
//Restore dialogue_entries
|
||||
$status = dialogue_entries_restore_mods ($new_dialogue_id, $newid,$conversation,$restore);
|
||||
//The structure is equal to the db, so insert the dialogue_conversation
|
||||
$newid = insert_record ("dialogue_conversations",$conversation);
|
||||
|
||||
//Do some output
|
||||
if (($i+1) % 50 == 0) {
|
||||
echo ".";
|
||||
if (($i+1) % 1000 == 0) {
|
||||
echo "<br>";
|
||||
}
|
||||
backup_flush(300);
|
||||
}
|
||||
|
||||
if ($newid) {
|
||||
//We have the newid, update backup_ids
|
||||
backup_putid($restore->backup_unique_code, "dialogue_conversations",
|
||||
$oldid, $newid);
|
||||
//Now check if want to restore user data and do it.
|
||||
if ($status) {
|
||||
//Restore dialogue_entries
|
||||
$status = dialogue_entries_restore($new_dialogue_id, $newid,$conversation_info,
|
||||
$restore);
|
||||
}
|
||||
} else {
|
||||
$status = false;
|
||||
}
|
||||
} else {
|
||||
$status = false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -165,58 +160,60 @@
|
||||
}
|
||||
|
||||
//This function restores the dialogue_entries
|
||||
function dialogue_entries_restore_mods($old_dialogue_id, $new_dialogue_id,$conversation,$restore) {
|
||||
function dialogue_entries_restore($new_dialogue_id, $new_conversation_id,$info,$restore) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
$status = true;
|
||||
|
||||
//Get the entries array
|
||||
$entries = $info['MOD']['#']['ENTRIES']['0']['#']['ENTRY'];
|
||||
if (isset($info['#']['ENTRIES']['0']['#']['ENTRY'])) {
|
||||
$entries = $info['#']['ENTRIES']['0']['#']['ENTRY'];
|
||||
|
||||
//Iterate over entries
|
||||
for($i = 0; $i < sizeof($entries); $i++) {
|
||||
$entry_info = $entries[$i];
|
||||
//traverse_xmlize($entry_info); //Debug
|
||||
//print_object ($GLOBALS['traverse_array']); //Debug
|
||||
//$GLOBALS['traverse_array']=""; //Debug
|
||||
//Iterate over entries
|
||||
for($i = 0; $i < sizeof($entries); $i++) {
|
||||
$entry_info = $entries[$i];
|
||||
//traverse_xmlize($entry_info); //Debug
|
||||
//print_object ($GLOBALS['traverse_array']); //Debug
|
||||
//$GLOBALS['traverse_array']=""; //Debug
|
||||
|
||||
//We'll need this later!!
|
||||
$oldid = backup_todb($sub_info['#']['ID']['0']['#']);
|
||||
$olduserid = backup_todb($sub_info['#']['USERID']['0']['#']);
|
||||
//We'll need this later!!
|
||||
$oldid = backup_todb($entry_info['#']['ID']['0']['#']);
|
||||
$olduserid = backup_todb($entry_info['#']['USERID']['0']['#']);
|
||||
|
||||
//Now, build the dialogue_ENTRIES record structure
|
||||
$entry->dialogue = $new_dialogue_id;
|
||||
$entry->conversationid = $conversation->id;
|
||||
$entry->userid = backup_todb($entry_info['#']['USERID']['0']['#']);
|
||||
$entry->timecreated = backup_todb($entry_info['#']['TIMECREATED']['0']['#']);
|
||||
$entry->mailed = backup_todb($entry_info['#']['MAILED']['0']['#']);
|
||||
$entry->text = backup_todb($entry_info['#']['TEXT']['0']['#']);
|
||||
//Now, build the dialogue_ENTRIES record structure
|
||||
$entry->dialogue = $new_dialogue_id;
|
||||
$entry->conversationid = $new_conversation_id;
|
||||
$entry->userid = backup_todb($entry_info['#']['USERID']['0']['#']);
|
||||
$entry->timecreated = backup_todb($entry_info['#']['TIMECREATED']['0']['#']);
|
||||
$entry->mailed = backup_todb($entry_info['#']['MAILED']['0']['#']);
|
||||
$entry->text = backup_todb($entry_info['#']['TEXT']['0']['#']);
|
||||
|
||||
//We have to recode the userid field
|
||||
$user = backup_getid($restore->backup_unique_code,"user",$entry->userid);
|
||||
if ($user) {
|
||||
$entry->userid = $user->new_id;
|
||||
}
|
||||
|
||||
//The structure is equal to the db, so insert the dialogue_entry
|
||||
$newid = insert_record ("dialogue_entries",$entry);
|
||||
|
||||
//Do some output
|
||||
if (($i+1) % 50 == 0) {
|
||||
echo ".";
|
||||
if (($i+1) % 1000 == 0) {
|
||||
echo "<br>";
|
||||
//We have to recode the userid field
|
||||
$user = backup_getid($restore->backup_unique_code,"user",$entry->userid);
|
||||
if ($user) {
|
||||
$entry->userid = $user->new_id;
|
||||
}
|
||||
backup_flush(300);
|
||||
}
|
||||
|
||||
if ($newid) {
|
||||
//We have the newid, update backup_ids
|
||||
backup_putid($restore->backup_unique_code,"dialogue_entry",$oldid,
|
||||
$newid);
|
||||
} else {
|
||||
$status = false;
|
||||
//The structure is equal to the db, so insert the dialogue_entry
|
||||
$newid = insert_record ("dialogue_entries",$entry);
|
||||
|
||||
//Do some output
|
||||
if (($i+1) % 50 == 0) {
|
||||
echo ".";
|
||||
if (($i+1) % 1000 == 0) {
|
||||
echo "<br>";
|
||||
}
|
||||
backup_flush(300);
|
||||
}
|
||||
|
||||
if ($newid) {
|
||||
//We have the newid, update backup_ids
|
||||
backup_putid($restore->backup_unique_code,"dialogue_entry",$oldid,
|
||||
$newid);
|
||||
} else {
|
||||
$status = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user