Commit 9d224f2f authored by Richard Mansfield's avatar Richard Mansfield
Browse files
parents 192897d5 cfaf6af4
......@@ -710,7 +710,10 @@ class ArtefactTypeBlogPost extends ArtefactType {
$data->blogpost = $this->id;
$data->file = $fileid;
insert_record('artefact_blog_blogpost_file', $data);
$data->artefact = $data->file;
$data->parent = $data->blogpost;
$data->dirty = true;
insert_record('artefact_parent_cache', $data);
return $fileid;
}
......
......@@ -108,7 +108,7 @@ abstract class ArtefactType {
if (!empty($id)) {
if (empty($data)) {
if (!$data = get_record('artefact','id',$id)) {
throw new ArtefactNotFoundException("Artefact with id $id not found");
throw new ArtefactNotFoundException(get_string('artefactnotfound', 'error', $id));
}
}
$this->id = $id;
......
......@@ -128,11 +128,8 @@ if (!isset($CFG->wwwroot) && isset($_SERVER['HTTP_HOST'])) {
set_config('wwwroot', $wwwroot);
}
catch (Exception $e) {
// Just set it directly. The system will most likely not be installed, so we don't care
$CFG->wwwroot = $wwwroot;
// Do nothing. The system will most likely not be installed, so we don't care
//if (!defined('INSTALLER')) {
// throw $e;
//}
}
}
if (!isset($CFG->noreplyaddress) && isset($_SERVER['HTTP_HOST'])) {
......
......@@ -58,4 +58,6 @@ $string['accessdeniedexception'] = 'You do not have access to view this page';
$string['viewnotfoundexceptiontitle'] = 'View not found';
$string['viewnotfoundexceptionmessage'] = 'You tried to access a view that didn\'t exist!';
$string['artefactnotfound'] = "Artefact with id %s not found (maybe it has been deleted already?)";
?>
......@@ -76,7 +76,7 @@ function activity_occurred($activitytype, $data) {
* - <b>newview</b> must contain $owner userid of view owner AND $view (id of new view)
* - <b>viewaccess</b> must contain $owner userid of view owner AND $view (id of view) and $oldusers array of userids before access change was committed.
*/
function handle_activity($activitytype, $data) {
function handle_activity($activitytype, $data, $cron=false) {
$data = (object)$data;
if (is_string($activitytype)) {
......@@ -246,7 +246,10 @@ function handle_activity($activitytype, $data) {
if (!$ainfo = get_record_sql('SELECT u.*, a.title FROM ' . $prefix . 'usr u
JOIN ' . $prefix . 'artefact a ON a.owner = u.id
WHERE a.id = ?', array($data->artefact))) {
throw new InvalidArgumentException("Couldn't find artefact with id " . $data->artefact);
if (!empty($cron)) { // probably deleted already
return;
}
throw new InvalidArgumentException(get_string('artefactnotfound', 'error', $data->artefact));
}
$data->message = get_string('onartefact', 'activity')
. ' ' . $ainfo->title . ' ' . get_string('ownedby', 'activity');
......@@ -437,7 +440,7 @@ function activity_process_queue() {
db_begin();
if ($toprocess = get_records_array('activity_queue')) {
foreach ($toprocess as $activity) {
handle_activity($activity->type, unserialize($activity->data));
handle_activity($activity->type, unserialize($activity->data), true);
}
delete_records('activity_queue');
}
......@@ -463,7 +466,10 @@ function activity_get_viewaccess_users($view, $owner) {
) AS userlist
JOIN ' . $prefix . 'usr u ON u.id = userlist.userid
LEFT JOIN ' . $prefix . 'usr_activity_preference p ON p.usr = u.id';
return get_records_sql_assoc($sql, array($owner, $owner, $owner, $view, $view));
if (!$u = get_records_sql_assoc($sql, array($owner, $owner, $owner, $view, $view))) {
$u = array();
}
return $u;
}
?>
......@@ -58,9 +58,10 @@ function artefact_check_plugin_sanity($pluginname) {
function rebuild_artefact_parent_cache_dirty() {
// this will give us a list of artefacts, as the first returned column
// is not unqiue, but that's ok, it's what we want.
if (!$dirty = get_records_array('artefact_parent_cache', 'dirty', 1)) {
if (!$dirty = get_records_array('artefact_parent_cache', 'dirty', 1, '', 'DISTINCT(artefact)')) {
return;
}
$blogsinstalled = get_field('artefact_installed', 'active', 'name', 'blog');
db_begin();
delete_records('artefact_parent_cache', 'dirty', 1);
foreach ($dirty as $d) {
......@@ -74,6 +75,15 @@ function rebuild_artefact_parent_cache_dirty() {
break;
}
$parentids[] = $parent->parent;
// get any blog posts it may be attached to
if ($parent->artefacttype == 'file' && $blogsinstalled
&& $associated = get_column('artefact_blog_blogpost_file', 'blogpost', 'file', $parent->id)) {
foreach ($associated as $a) {
if (!in_array($a, $parentids)) {
$parentids[] = $a;
}
}
}
$current = $parent->parent;
}
foreach ($parentids as $p) {
......@@ -90,26 +100,36 @@ function rebuild_artefact_parent_cache_dirty() {
function rebuild_artefact_parent_cache_complete() {
db_begin();
delete_records('artefact_parent_cache');
$artefacts = get_records_array('artefact');
foreach ($artefacts as $a) {
$parentids = array();
$current = $a->id;
while (true) {
if (!$parent = get_record('artefact', 'id', $current)) {
break;
if ($artefacts = get_records_array('artefact')) {
foreach ($artefacts as $a) {
$parentids = array();
$current = $a->id;
while (true) {
if (!$parent = get_record('artefact', 'id', $current)) {
break;
}
if (!$parent->parent) {
break;
}
$parentids[] = $parent->parent;
// get any blog posts it may be attached to
if ($parent->artefacttype == 'file' && $blogsinstalled
&& $associated = get_column('artefact_blog_blogpost_file', 'blogpost', 'file', $parent->id)) {
foreach ($associated as $a) {
if (!in_array($a, $parentids)) {
$parentids[] = $a;
}
}
}
$current = $parent->parent;
}
if (!$parent->parent) {
break;
foreach ($parentids as $p) {
$apc = new StdClass;
$apc->artefact = $a->id;
$apc->parent = $p;
$apc->dirty = 0;
insert_record('artefact_parent_cache', $apc);
}
$parentids[] = $parent->parent;
$current = $parent->parent;
}
foreach ($parentids as $p) {
$apc = new StdClass;
$apc->artefact = $a->id;
$apc->parent = $p;
$apc->dirty = 0;
insert_record('artefact_parent_cache', $apc);
}
}
db_commit();
......
......@@ -24,8 +24,9 @@
*
*/
define('INTERNAL',1);
define('PUBLIC',1);
define('INTERNAL', 1);
define('PUBLIC', 1);
define('CRON', 1);
/**
* This defines (in seconds) how far PAST the next run time of a cron job
......
......@@ -464,6 +464,11 @@ class MaharaException extends Exception {
echo json_encode(array('error' => true, 'message' => $this->render_exception()));
exit;
}
if (defined('CRON')) {
echo $this->render_exception();
exit;
}
$outputtitle = $this->get_string('title');
$outputmessage = $this->render_exception();
......@@ -566,7 +571,7 @@ class ConfigException extends MaharaException implements MaharaThrowable {
array('message' => $this->get_sitename()
. ' is misconfigured and this is causing problems. '
. 'You probably need to contact an administrator to get this fixed. '
. ' Details, if any, follow'));
. ' Details, if any, follow:'));
}
}
......@@ -585,7 +590,7 @@ class UserException extends MaharaException implements MaharaThrowable {
return array_merge(parent::strings(),
array('message' => 'Something in the way you\'re interacting with '
. $this->get_sitename()
.' is causing an error.<br>Details if any, follow'));
.' is causing an error.<br>Details if any, follow:'));
}
}
......
......@@ -75,9 +75,7 @@ function createview4_submit(Pieform $form, $values) {
$view->startdate = db_format_timestamp($data['startdate']);
$view->stopdate = db_format_timestamp($data['stopdate']);
$view->ctime = $view->mtime = $view->atime = $time;
log_debug($view);
$viewid = insert_record('view', $view, 'id', true);
log_debug('inserted view as id ' . $viewid);
foreach ($data['artefacts'] as $block => $blockdata) {
if ($blockdata['type'] == 'label') {
......@@ -136,6 +134,11 @@ function createview4_submit(Pieform $form, $values) {
}
}
$data = new StdClass;
$data->owner = $USER->get('id');
$data->view = $viewid;
activity_occurred('newview', $data);
db_commit();
$SESSION->add_ok_msg(get_string('viewcreatedsuccessfully', 'view'));
redirect(get_config('wwwroot') . 'view/');
......
......@@ -148,6 +148,8 @@ function editviewaccess_submit(Pieform $form, $values) {
AND usr IN(' . $userids . ')');
}
$beforeusers = activity_get_viewaccess_users($viewid, $USER->get('id'));
// Procedure:
// get list of current friends - this is available in global $data
// compare with list of new friends
......@@ -192,6 +194,13 @@ function editviewaccess_submit(Pieform $form, $values) {
break;
}
}
$data = new StdClass;
$data->view = $viewid;
$data->owner = $USER->get('id');
$data->oldusers = $beforeusers;
activity_occurred('viewaccess', $data);
db_commit();
$SESSION->add_ok_msg(get_string('viewaccesseditedsuccessfully'));
redirect('view/');
......
Supports Markdown
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