Commit 0af8ce9e authored by Melissa Draper's avatar Melissa Draper

Enable multipleblogs when copying journals from others (bug #820182)

Currently, copying journal does not ensure that the multipleblogs
setting is set. This means that the user must manually do this to
see their copied journal entries. This patch ensures that the
setting is set on, and reloads the session. It also notifies the
user that the journal has been made.

Change-Id: Ief724d0bb7f2aaf489b995e53194afa8382819c0
Signed-off-by: default avatarMelissa Draper <melissa@catalyst.net.nz>
parent 77c45fa7
......@@ -410,6 +410,35 @@ class ArtefactTypeBlog extends ArtefactType {
),
));
}
/**
* During the copying of a view, we might be allowed to copy
* blogs. Users need to have multipleblogs enabled for these
* to be visible.
*/
public function default_parent_for_copy(&$view, &$template, $artefactstoignore) {
global $USER, $SESSION;
$viewid = $view->get('id');
try {
$user = get_user($view->get('owner'));
set_account_preference($user->id, 'multipleblogs', 1);
$SESSION->add_ok_msg(get_string('copiedblogpoststonewjournal', 'collection'));
}
catch (Exception $e) {
$SESSION->add_error_msg(get_string('unabletosetmultipleblogs', 'error', $user->username, $viewid, get_config('wwwroot') . 'account/'), false);
}
try {
$USER->accountprefs = load_account_preferences($user->id);
}
catch (Exception $e) {
$SESSION->add_error_msg(get_string('pleaseloginforjournals', 'error'));
}
return null;
}
}
/**
......@@ -908,6 +937,7 @@ class ArtefactTypeBlogPost extends ArtefactType {
*/
public function default_parent_for_copy(&$view, &$template, $artefactstoignore) {
static $blogids;
global $USER, $SESSION;
$viewid = $view->get('id');
......@@ -928,6 +958,22 @@ class ArtefactTypeBlogPost extends ArtefactType {
$blogids[$viewid] = $blog->get('id');
try {
$user = get_user($view->get('owner'));
set_account_preference($user->id, 'multipleblogs', 1);
$SESSION->add_ok_msg(get_string('copiedblogpoststonewjournal', 'collection'));
}
catch (Exception $e) {
$SESSION->add_error_msg(get_string('unabletosetmultipleblogs', 'error', $user->username, $viewid, get_config('wwwroot') . 'account/'), false);
}
try {
$USER->accountprefs = load_account_preferences($user->id);
}
catch (Exception $e) {
$SESSION->add_error_msg(get_string('pleaseloginforjournals', 'error'));
}
return $blogids[$viewid];
}
......
......@@ -98,5 +98,6 @@ $string['viewstobeadded'] = 'Pages to be added';
$string['viewconfirmremove'] = 'Are you sure you wish to remove this page from the collection?';
$string['collectioncopywouldexceedquota'] = 'Copying this collection would exceed your file quota.';
$string['copiedpagesblocksandartefactsfromtemplate'] = 'Copied %d pages, %d blocks and %d artefacts from %s';
$string['copiedblogpoststonewjournal'] = 'Copied journal posts have been put into a new separate journal.';
$string['by'] = 'by';
$string['copycollection'] = 'Copy collection';
......@@ -76,6 +76,8 @@ $string['classmissing'] = "class %s for type %s in plugin %s was missing";
$string['artefacttypeclassmissing'] = "Artefact types must all implement a class. Missing %s";
$string['artefactpluginmethodmissing'] = "Artefact plugin %s must implement %s and doesn't";
$string['blocktypelibmissing'] = 'Missing lib.php for block %s in artefact plugin %s';
$string['unabletosetmultipleblogs'] = 'Enabling multiple blogs for the user %s when copying view %s has failed. This can be set manually on the <a href="%s">account</a> page.';
$string['pleaseloginforjournals'] = 'You need to log out and log back in before you will see all your journals and posts.';
$string['blocktypemissingconfigform'] = 'Block type %s must implement instance_config_form';
$string['versionphpmissing'] = 'Plugin %s %s is missing version.php!';
$string['blocktypeprovidedbyartefactnotinstallable'] = 'This will be installed as part of the installation of artefact plugin %s';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment