Commit 5aa8aa02 authored by Nigel McNie's avatar Nigel McNie Committed by Nigel McNie
Browse files
parents 17f69cd2 ed5a4e45
......@@ -1135,11 +1135,13 @@ function get_views($users, $userlooking=null, $limit=5) {
$list[$row->owner][$row->id] = $row;
}
}
// bail if we've filled all users to the limit
if (_get_views_trim_list($list, $users, $limit)) {
return $list;
}
// check individual user access
if ($results = get_records_sql_array(
'SELECT
v.*,
......@@ -1162,8 +1164,68 @@ function get_views($users, $userlooking=null, $limit=5) {
}
}
log_debug('Users remaing');
log_debug($users);
// bail if we've filled all users to the limit
if (_get_views_trim_list($list, $users, $limit)) {
return $list;
}
// check group access
if ($results = get_records_sql_array(
'SELECT
v.*,
' . db_format_tsfield('v.atime','atime') . ',
' . db_format_tsfield('v.mtime','mtime') . ',
' . db_format_tsfield('v.ctime','ctime') . '
FROM
' . $prefix . 'view v
INNER JOIN view_access_group a ON v.id=a.view
INNER JOIN usr_group_member m ON m.grp=a.grp AND m.member=?
WHERE
v.owner IN (' . join(',',array_map('db_quote', array_keys($users))) . ')
AND ( v.startdate IS NULL OR v.startdate < ? )
AND ( v.stopdate IS NULL OR v.stopdate < ? )
',
array($userlooking, $dbnow, $dbnow)
)
) {
foreach ($results as &$row) {
$list[$row->owner][$row->id] = $row;
}
}
// bail if we've filled all users to the limit
if (_get_views_trim_list($list, $users, $limit)) {
return $list;
}
// check community access
if ($results = get_records_sql_array(
'SELECT
v.*,
' . db_format_tsfield('v.atime','atime') . ',
' . db_format_tsfield('v.mtime','mtime') . ',
' . db_format_tsfield('v.ctime','ctime') . '
FROM
' . $prefix . 'view v
INNER JOIN view_access_community a ON v.id=a.view
INNER JOIN community_member m ON m.community=a.community AND m.member=?
WHERE
v.owner IN (' . join(',',array_map('db_quote', array_keys($users))) . ')
AND ( v.startdate IS NULL OR v.startdate < ? )
AND ( v.stopdate IS NULL OR v.stopdate < ? )
',
array($userlooking, $dbnow, $dbnow)
)
) {
foreach ($results as &$row) {
$list[$row->owner][$row->id] = $row;
}
}
// bail if we've filled all users to the limit
if (_get_views_trim_list($list, $users, $limit)) {
return $list;
}
return $list;
}
......
......@@ -72,14 +72,14 @@ $_ = $m->content;
my $components = /var todo = \[(".*",?)+\]/s;
my @things = split(/","/, substr($1, 1, -1));
for my $thing (@things) {
debug("Installing $thing...");
debug("Installing $thing ... ", 1);
$m->get($CFG->{url} . 'admin/upgrade.json.php?name=' . $thing);
$json_response = my_jsonToObj($m->content());
if ( $json_response->{error} ) {
croak qq{Failed to install $thing} . Dumper($json_response);
}
if ( defined $json_response->{message} ) {
print 'MESSAGE:', $json_response->{message};
debug('MESSAGE:' . $json_response->{message}{newversion});
}
}
......@@ -124,7 +124,12 @@ else {
}
sub debug {
print shift() . "\n" if $CFG->{debug};
my ($message, $nonewline) = @_;
return unless $CFG->{debug};
print $message;
print "\n" unless $nonewline;
}
sub my_jsonToObj {
......
......@@ -208,6 +208,8 @@ sub insert_random_communities {
my $prefix = $self->{config}->get('dbprefix');
my $user_id = $self->{dbh}->selectall_arrayref('SELECT id FROM ' . $prefix . 'usr WHERE username = ?', undef, $user)->[0][0];
my $existing_users = $self->{dbh}->selectall_hashref('SELECT id, username FROM ' . $prefix . 'usr WHERE id != 0', 'username');
unless ( defined $user_id ) {
croak qq{User '$user' doesn't exist\n};
}
......@@ -225,7 +227,20 @@ sub insert_random_communities {
$self->{dbh}->do(
'INSERT INTO ' . $prefix . 'community (name, description, owner, ctime, mtime) VALUES (?, ?, ?, current_timestamp, current_timestamp)',
undef,
$cname, $cdesc, $user_id);
$cname, $cdesc, $user_id
);
my $members = {};
foreach (1..(int(rand(20)) + 5)) {
$members->{$existing_users->{((keys %$existing_users)[int(rand(keys %$existing_users))])}{id}} = 1;
}
foreach my $id (keys %$members) {
$self->{dbh}->do(
'INSERT INTO ' . $prefix . 'community_member (community,member,ctime) VALUES (currval(\'' . $prefix . 'community_id_seq\'),?,current_timestamp)',
undef,
$id,
);
}
}
$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