Blogs backup added. MDL-9089 ; merged from 19_STABLE
This commit is contained in:
@@ -66,7 +66,7 @@
|
||||
}
|
||||
|
||||
//Here we check if backup_users = None. Then, we switch off every module
|
||||
//user info, user_files, logs and exercises, workshop and messages backups. A Warning is showed to
|
||||
//user info, user_files, logs and exercises, workshop and messages & blogs backups. A Warning is showed to
|
||||
//inform the user.
|
||||
// TODO: Move this logic to one function to be shared by any (manual, scheduled) backup
|
||||
if ($backupprefs->backup_users == 2) {
|
||||
@@ -114,6 +114,7 @@
|
||||
$backupprefs->backup_user_files = 0;
|
||||
$backupprefs->backup_logs = 0;
|
||||
$backupprefs->backup_messages = 0;
|
||||
$backupprefs->backup_blogs = 0;
|
||||
$backupprefs->backuproleassignments = array();
|
||||
|
||||
print_simple_box("<font color=\"red\">".get_string("backupnoneusersinfo")."</font>","center", "70%", '', "20", "noticebox");
|
||||
@@ -195,7 +196,7 @@
|
||||
$user_options[2] = get_string("includenoneusers");
|
||||
echo $user_options[$backupprefs->backup_users].'</b>';
|
||||
//Print info
|
||||
$table->data = user_check_backup($id,$backupprefs->backup_unique_code,$backupprefs->backup_users,$backupprefs->backup_messages);
|
||||
$table->data = user_check_backup($id,$backupprefs->backup_unique_code,$backupprefs->backup_users,$backupprefs->backup_messages, $backupprefs->backup_blogs);
|
||||
print_table($table);
|
||||
echo "</td></tr>";
|
||||
|
||||
|
||||
@@ -67,6 +67,7 @@
|
||||
$backup_site_files = optional_param('backup_site_files',1);
|
||||
$backup_gradebook_history = optional_param('backup_gradebook_history', 0, PARAM_INT);
|
||||
$backup_messages = optional_param('backup_messages',1);
|
||||
$backup_blogs = optional_param('backup_blogs',1);
|
||||
|
||||
if ($count == 0) {
|
||||
notice("No backupable modules are installed!");
|
||||
@@ -304,6 +305,21 @@ function selectItemInCheckboxByName(formId, checkName, checked ) {
|
||||
else {
|
||||
$hidden_options .= '<input type="hidden" name="backup_messages" value="0" />';
|
||||
}
|
||||
|
||||
if (empty($to) && $course->id == SITEID && !empty($CFG->bloglevel)) {
|
||||
//If we are in a SITEID backup and blogs are enabled print the Blogs tr
|
||||
echo "<tr>";
|
||||
echo "<td align=\"right\" colspan=\"2\"><b>";
|
||||
echo get_string ('blogs','blog').":";
|
||||
echo "</b></td><td colspan=\"2\">";
|
||||
$blog_options[0] = get_string("no");
|
||||
$blog_options[1] = get_string("yes");
|
||||
choose_from_menu($blog_options, "backup_blogs", $backup_blogs, "");
|
||||
echo "</td></tr>";
|
||||
}
|
||||
else {
|
||||
$hidden_options .= '<input type="hidden" name="backup_blogs" value="0" />';
|
||||
}
|
||||
}
|
||||
|
||||
//Now print a place to select which role assignments to back up.
|
||||
|
||||
+129
-4
@@ -12,9 +12,11 @@
|
||||
* @param int $backup_unique_code setting specifying what users to export (0=all, 1=needed, 2=none)
|
||||
* @param int $backup_messages flag (true/false) defining if messages must be
|
||||
* considered to extract needed users
|
||||
* @param int $backup_blogs flag (true/false) defining if blogs must be
|
||||
* considered to extract needed users
|
||||
* @return array one array (key, value) sumarizing the result of the function (number of users)
|
||||
*/
|
||||
function user_check_backup($courseid,$backup_unique_code,$backup_users,$backup_messages) {
|
||||
function user_check_backup($courseid,$backup_unique_code,$backup_users,$backup_messages,$backup_blogs) {
|
||||
|
||||
$context = get_context_instance(CONTEXT_COURSE, $courseid);
|
||||
$count_users = 0;
|
||||
@@ -25,8 +27,9 @@
|
||||
|
||||
} else if ($backup_users == 1) { /// Needed users
|
||||
|
||||
/// Calculate needed users (calling every xxxx_get_participants function + scales users)
|
||||
$needed_users = backup_get_needed_users($courseid, $backup_messages);
|
||||
/// Calculate needed users (calling every xxxx_get_participants function + scales users
|
||||
/// + messages users + blogs users)
|
||||
$needed_users = backup_get_needed_users($courseid, $backup_messages, $backup_blogs);
|
||||
|
||||
/// Calculate enrolled users (having course:view cap)
|
||||
$enrolled_users = backup_get_enrolled_users($courseid);
|
||||
@@ -83,11 +86,13 @@
|
||||
//Returns every needed user (participant) in a course
|
||||
//It uses the xxxx_get_participants() function
|
||||
//plus users needed to backup scales.
|
||||
//Also it search for users having messages and
|
||||
//users having blogs
|
||||
//WARNING: It returns only NEEDED users, not every
|
||||
// every student and teacher in the course, so it
|
||||
//must be merged with backup_get_enrrolled_users !!
|
||||
|
||||
function backup_get_needed_users ($courseid, $includemessages=false) {
|
||||
function backup_get_needed_users ($courseid, $includemessages=false, $includeblogs=false) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
@@ -150,6 +155,22 @@
|
||||
}
|
||||
}
|
||||
|
||||
//Now, add blog users if necessary
|
||||
if ($includeblogs) {
|
||||
include_once("$CFG->dirroot/blog/lib.php");
|
||||
//Get users
|
||||
$blogusers = blog_get_participants();
|
||||
//Add blog users to results
|
||||
if ($blogusers) {
|
||||
foreach ($blogusers as $bloguser) {
|
||||
//If id != 0
|
||||
if ($bloguser->id !=0) {
|
||||
$result[$bloguser->id]->id = $bloguser->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
@@ -916,6 +937,92 @@
|
||||
|
||||
}
|
||||
|
||||
//Print blogs info (post table, module=blog, course=0)
|
||||
function backup_blogs($bf, $preferences) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
$status = true;
|
||||
|
||||
/// Check we have something to backup
|
||||
$siteblogs = count_records('post', 'module', 'blog', 'courseid', 0);
|
||||
|
||||
if ($siteblogs) {
|
||||
$counter = 0;
|
||||
/// blogs open tag
|
||||
fwrite ($bf, start_tag("BLOGS",2,true));
|
||||
|
||||
if ($siteblogs) {
|
||||
$rs_blogs = get_recordset_sql("SELECT * from {$CFG->prefix}post
|
||||
WHERE module = 'blog'
|
||||
AND courseid = 0");
|
||||
/// Iterate over every blog
|
||||
while ($blog = rs_fetch_next_record($rs_blogs)) {
|
||||
/// start blog
|
||||
fwrite($bf, start_tag("BLOG",3,true));
|
||||
/// blog body
|
||||
fwrite ($bf,full_tag("ID",4,false,$blog->id));
|
||||
fwrite ($bf,full_tag("MODULE",4,false,$blog->module));
|
||||
fwrite ($bf,full_tag("USERID",4,false,$blog->userid));
|
||||
fwrite ($bf,full_tag("COURSEID",4,false,$blog->courseid));
|
||||
fwrite ($bf,full_tag("GROUPID",4,false,$blog->groupid));
|
||||
fwrite ($bf,full_tag("MODULEID",4,false,$blog->moduleid));
|
||||
fwrite ($bf,full_tag("COURSEMODULEID",4,false,$blog->coursemoduleid));
|
||||
fwrite ($bf,full_tag("SUBJECT",4,false,$blog->subject));
|
||||
fwrite ($bf,full_tag("SUMMARY",4,false,$blog->summary));
|
||||
fwrite ($bf,full_tag("CONTENT",4,false,$blog->content));
|
||||
fwrite ($bf,full_tag("UNIQUEHASH",4,false,$blog->uniquehash));
|
||||
fwrite ($bf,full_tag("RATING",4,false,$blog->rating));
|
||||
fwrite ($bf,full_tag("FORMAT",4,false,$blog->format));
|
||||
fwrite ($bf,full_tag("ATTACHMENT",4,false,$blog->attachment));
|
||||
fwrite ($bf,full_tag("PUBLISHSTATE",4,false,$blog->publishstate));
|
||||
fwrite ($bf,full_tag("LASTMODIFIED",4,false,$blog->lastmodified));
|
||||
fwrite ($bf,full_tag("CREATED",4,false,$blog->created));
|
||||
fwrite ($bf,full_tag("USERMODIFIED",4,false,$blog->usermodified));
|
||||
|
||||
/// Blog tags
|
||||
/// Check if we have blog tags to backup
|
||||
if (!empty($CFG->usetags)) {
|
||||
if ($tags = tag_get_tags('post', $blog->id)) { //This return them ordered by default
|
||||
/// Start BLOG_TAGS tag
|
||||
fwrite ($bf,start_tag("BLOG_TAGS",4,true));
|
||||
/// Write blog tags fields
|
||||
foreach ($tags as $tag) {
|
||||
fwrite ($bf,start_tag("BLOG_TAG",5,true));
|
||||
fwrite ($bf,full_tag("NAME",6,false,$tag->name));
|
||||
fwrite ($bf,full_tag("RAWNAME",6,false,$tag->rawname));
|
||||
fwrite ($bf,end_tag("BLOG_TAG",5,true));
|
||||
}
|
||||
/// End BLOG_TAGS tag
|
||||
fwrite ($bf,end_tag("BLOG_TAGS",4,true));
|
||||
}
|
||||
}
|
||||
|
||||
/// Blog comments
|
||||
/// TODO: Blog comments go here (2.0)
|
||||
|
||||
/// end blog
|
||||
fwrite($bf, end_tag("BLOG",3,true));
|
||||
|
||||
/// Do some output
|
||||
$counter++;
|
||||
if ($counter % 20 == 0) {
|
||||
echo ".";
|
||||
if ($counter % 400 == 0) {
|
||||
echo "<br />";
|
||||
}
|
||||
backup_flush(300);
|
||||
}
|
||||
}
|
||||
rs_close($rs_blogs);
|
||||
}
|
||||
/// blogs close tag
|
||||
$status = fwrite($bf, end_tag("BLOGS",2,true));
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
//Prints course's blocks info (table block_instance)
|
||||
function backup_course_blocks ($bf,$preferences) {
|
||||
|
||||
@@ -2599,6 +2706,7 @@
|
||||
$preferences->backup_gradebook_history = optional_param('backup_gradebook_history', 1, PARAM_INT);
|
||||
$preferences->backup_site_files = optional_param('backup_site_files',1,PARAM_INT);
|
||||
$preferences->backup_messages = optional_param('backup_messages',1,PARAM_INT);
|
||||
$preferences->backup_blogs = optional_param('backup_blogs',1,PARAM_INT);
|
||||
$preferences->backup_course = $course->id;
|
||||
$preferences->backup_name = required_param('backup_name',PARAM_FILE);
|
||||
$preferences->backup_unique_code = required_param('backup_unique_code');
|
||||
@@ -2916,6 +3024,23 @@
|
||||
}
|
||||
}
|
||||
|
||||
//If we have selected to backup blogs and we are
|
||||
//doing a SITE backup, let's do it
|
||||
if ($status && $preferences->backup_blogs && $preferences->backup_course == SITEID) {
|
||||
if (!defined('BACKUP_SILENTLY')) {
|
||||
echo "<li>".get_string("writingblogsinfo").'</li>';
|
||||
}
|
||||
if (!$status = backup_blogs($backup_file,$preferences)) {
|
||||
if (!defined('BACKUP_SILENTLY')) {
|
||||
notify("An error occurred while backing up blogs");
|
||||
}
|
||||
else {
|
||||
$errorstr = "An error occurred while backing up blogs";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//If we have selected to backup quizzes or other modules that use questions
|
||||
//we've already added ids of categories and questions to backup to backup_ids table
|
||||
if ($status) {
|
||||
|
||||
Reference in New Issue
Block a user