Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bugs fixed in backup and restore. Dialogue now notifies if there are any
open dialogues.
  • Loading branch information
rkingdon committed Dec 24, 2003
1 parent b1b589b commit ae1d214
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 110 deletions.
12 changes: 6 additions & 6 deletions mod/dialogue/backuplib.php
Expand Up @@ -67,8 +67,8 @@ function backup_dialogue_conversations ($bf,$preferences,$dialogue) {

$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));
Expand Down Expand Up @@ -108,7 +108,7 @@ function backup_dialogue_entries ($bf,$preferences,$conversationid) {

$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
Expand All @@ -120,9 +120,9 @@ function backup_dialogue_entries ($bf,$preferences,$conversationid) {
//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));
}
Expand Down
71 changes: 69 additions & 2 deletions mod/dialogue/lib.php
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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");
}

Expand Down
201 changes: 99 additions & 102 deletions mod/dialogue/restorelib.php
Expand Up @@ -53,14 +53,6 @@ function dialogue_restore_mods($mod,$restore) {
$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);

Expand All @@ -75,7 +67,7 @@ function dialogue_restore_mods($mod,$restore) {
//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;
Expand All @@ -93,7 +85,7 @@ function dialogue_restore_mods($mod,$restore) {


//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;

Expand All @@ -102,61 +94,64 @@ function dialogue_conversations_restore_mods($old_dialogue_id, $new_dialogue_id,
//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

//We'll need this later!!
$oldid = backup_todb($sub_info['#']['ID']['0']['#']);
$olduserid = backup_todb($sub_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;
}
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($conversation_info['#']['ID']['0']['#']);
$olduserid = backup_todb($conversation_info['#']['USERID']['0']['#']);

//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;
}
$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);
//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>";
//Do some output
if (($i+1) % 50 == 0) {
echo ".";
if (($i+1) % 1000 == 0) {
echo "<br>";
}
backup_flush(300);
}
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_mods ($new_dialogue_id, $newid,$conversation,$restore);
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;
}

}
Expand All @@ -165,58 +160,60 @@ function dialogue_conversations_restore_mods($old_dialogue_id, $new_dialogue_id,
}

//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'];

//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']['#']);

//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']['#']);

//We have to recode the userid field
$user = backup_getid($restore->backup_unique_code,"user",$entry->userid);
if ($user) {
$entry->userid = $user->new_id;
}
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

//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 = $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);
//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>";
//Do some output
if (($i+1) % 50 == 0) {
echo ".";
if (($i+1) % 1000 == 0) {
echo "<br>";
}
backup_flush(300);
}
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;
if ($newid) {
//We have the newid, update backup_ids
backup_putid($restore->backup_unique_code,"dialogue_entry",$oldid,
$newid);
} else {
$status = false;
}
}
}

Expand Down

0 comments on commit ae1d214

Please sign in to comment.