Commit 015f7a76 authored by Richard Mansfield's avatar Richard Mansfield
Browse files
parents 40cccd03 da2a4b97
......@@ -73,6 +73,15 @@ function handle_activity($activitytype, $data) {
if (empty($data->message)) {
throw new InvalidArgumentException("message was empty for $activitytype!");
}
if (is_string($activitytype)) {
$activitytype = get_record('activity_type', 'name', $activitytype);
}
if (!is_object($activitytype)) {
throw new InvalidArgumentException("Invalid activitytype $activitytype");
}
$users = array();
$prefix = get_config('dbprefix');
......@@ -99,43 +108,50 @@ function handle_activity($activitytype, $data) {
break;
// and now the harder ones
case 'watchlist':
if ($data->view) {
$sql = 'SELECT u.*, p.method
if (!empty($data->view)) {
$sql = 'SELECT u.*, p.method, ? AS url
FROM ' . $prefix . 'usr_watchlist_view wv
JOIN ' . $prefix . 'usr u
ON wa.user = u.id
JOIN ' . $prefix . 'usr_preference p
ON wa.usr = u.id
JOIN ' . $prefix . 'usr_activity_preference p
ON p.usr = u.id
WHERE pc.activity = ?
WHERE p.activity = ?
AND wv.view = ?
';
$users = get_records_sql_array($sql, array('watchlist', $data->view));
$users = get_records_sql_array($sql,
array(get_config('wwwroot') . 'view/view.php?id='
. $data->view, 'watchlist', $data->view));
}
else if ($data->artefact) {
$sql = 'SELECT DISTINCT u.*, p.method
else if (!empty($data->artefact)) {
$sql = 'SELECT DISTINCT u.*, p.method, ?||wa.view as url
FROM ' . $prefix . 'usr_watchlist_artefact wa
JOIN ' . $prefix . 'artefact_parent_cache pc
LEFT JOIN ' . $prefix . 'artefact_parent_cache pc
ON (pc.parent = wa.artefact OR pc.artefact = wa.artefact)
JOIN ' . $prefix . 'usr u
ON wa.user = u.id
JOIN ' . $prefix . 'usr_preference p
ON wa.usr = u.id
JOIN ' . $prefix . 'usr_activity_preference p
ON p.usr = u.id
WHERE pc.activity = ?
WHERE p.activity = ?
AND (pc.parent = ? OR wa.artefact = ?)
';
$users = get_records_sql_array($sql, array('watchlist', $data->artefact));
$users = get_records_sql_array($sql,
array(get_config('wwwroot') . 'view/artefact.php?id='
. $data->artefact . '&view=', 'watchlist',
$data->artefact, $data->artefact));
}
else if ($data->community) {
$sql = 'SELECT DISTINCT u.*, p.method
else if (!empty($data->community)) {
$sql = 'SELECT DISTINCT u.*, p.method, ? AS url,
FROM ' . $prefix . 'usr_watchlist_community c
JOIN ' . $prefix . 'usr u
ON c.usr = u.id
JOIN ' . $prefix . 'usr_preference p
JOIN ' . $prefix . 'usr_activity_preference p
ON p.usr = u.id
WHERE pc.activity = ?
WHERE p.activity = ?
AND c.community = ?
';
$users = get_records_sql_array($sql, array('watchlist', $data->community));
$users = get_records_sql_array($sql,
array(getconfig('wwwroot') . 'community/view.php?id='
. $data->community, 'watchlist', $data->community));
}
else {
throw new InvalidArgumentException("Invalid watchlist type");
......@@ -163,9 +179,15 @@ function handle_activity($activitytype, $data) {
break;
}
}
if (empty($users)) {
return;
}
safe_require('notification', 'internal', 'lib.php', 'require_once');
$data->type = $activitytype;
$data->type = $activitytype->name;
foreach ($users as $user) {
if (!empty($user->url) && empty($data->url)) {
$data->url = $user->url;
}
if ($user->method != 'internal') {
safe_require('notification', $method, 'lib.php', 'require_once');
call_static_method(generate_class_name('notification', $method), 'notify_user', $user, $data);
......
......@@ -714,12 +714,14 @@
<FIELDS>
<FIELD NAME="usr" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="artefact" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="view" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="ctime" TYPE="datetime" NOTNULL="true" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="usr,artefact" />
<KEY NAME="primary" TYPE="primary" FIELDS="usr,artefact,view" />
<KEY NAME="usrfk" TYPE="foreign" FIELDS="usr" REFTABLE="usr" REFFIELDS="id" />
<KEY NAME="artefactfk" TYPE="foreign" FIELDS="artefact" REFTABLE="artefact" REFFIELDS="id" />
<KEY NAME="viewfk" TYPE="foreign" FIELDS="view" REFTABLE="view" REFFIELDS="id" />
</KEYS>
</TABLE>
<TABLE NAME="usr_watchlist_view">
......
......@@ -373,11 +373,11 @@ sub insert_random_watchlist {
ORDER BY RANDOM() LIMIT ' . (int($count/3)+1) . ')' );
$self->{dbh}->do('DELETE FROM ' . $prefix . 'usr_watchlist_artefact WHERE usr = ?', undef, $user_id);
$self->{dbh}->do('INSERT INTO ' . $prefix . 'usr_watchlist_artefact (usr, artefact, ctime)
(SELECT ' . $user_id . ', id, current_timestamp FROM ' . $prefix . 'artefact
ORDER BY RANDOM() LIMIT ' . (int($count/3)+1) . ')' );
$self->{dbh}->do('INSERT INTO ' . $prefix . 'usr_watchlist_artefact (usr, artefact, view, ctime)
(SELECT DISTINCT usr, id, view, current_timestamp FROM
(SELECT DISTINCT ' . $user_id . ' as usr, a.id, v.view, random() FROM ' . $prefix . 'artefact a
JOIN ' . $prefix . 'view_artefact v ON v.artefact = a.id
ORDER BY RANDOM() LIMIT ' . (int($count/3)+1) . ') mess)' );
$self->{dbh}->commit();
}
......
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