Move Views to core

hinted-selects
Vitaliy Filippov 2014-08-18 16:49:59 +04:00
parent e4d56b3ae8
commit 816e5efe9b
8 changed files with 27 additions and 58 deletions

View File

@ -355,7 +355,8 @@ sub savedsearch_post_update
# Refresh cached SQL code of checks at the end of checksetup.pl
sub install_before_final_checks
{
print "Refreshing Checkers SQL...\n";
my ($args) = @_;
print "Refreshing Checkers SQL...\n" if !$args->{silent};
Bugzilla->request_cache->{user} = Bugzilla::User->super_user;
for (Bugzilla::Checker->get_all)
{

View File

@ -31,6 +31,7 @@ use Bugzilla::User;
use Bugzilla::Util;
use Bugzilla::Search;
use Bugzilla::CheckerUtils;
use Bugzilla::Views;
use Scalar::Util qw(blessed);
@ -206,8 +207,9 @@ sub update
{
@r = scalar $self->SUPER::update(@_);
}
Bugzilla::CheckerUtils::savedsearch_post_update({ search => $self });
Bugzilla::Hook::process('savedsearch-post-update', { search => $self });
Bugzilla::CheckerUtils::savedsearch_post_update({ search => $self });
Bugzilla::Views::refresh_some_views([ $self->user->login ]);
return @r;
}

View File

@ -1,26 +1,17 @@
#!/usr/bin/perl
# External SQL interface to Bugzilla Saved Searches (CustIS Bug 61728)
# External SQL interface to Bugzilla Saved Searches (originally CustIS Bug 61728)
# License: Dual-license GPL 3.0+ or MPL 1.1+
# Author(s): Vitaliy Filippov
# Author(s): Vitaliy Filippov <vitalif@mail.ru>
# FIXME: Add UI for managing views
package FlushViews;
package Bugzilla::Views;
use strict;
use Bugzilla::Util;
use Bugzilla::User;
use Bugzilla::Search;
our @ISA = qw(Exporter);
our @EXPORT = qw(refresh_views);
sub refresh_views
{
refresh_some_views();
return 1;
}
# MySQL has a limitation on views! :-(
# Views in MySQL cannot include a subquery in the FROM clause.
# We bypass it by creating a view for every such subquery.
@ -52,12 +43,15 @@ sub recurse_create_view
}
# Refresh views, optionally only for $users = [ 'username@domain.org', ... ]
# FIXME @domain.org should not be stripped from the username in the name of view
sub refresh_some_views
{
my ($users) = @_;
return if Bugzilla->params->{ext_disable_refresh_views};
my %u;
for (@{$users || []})
{
s/\@.*$//so;
$_ = lc $_;
s/[^a-z0-9]+/_/giso;
$_ = "_$_" if !/^[a-z]/;
@ -120,34 +114,5 @@ sub refresh_some_views
Bugzilla->request_cache->{user} = $old_user;
}
# hooks:
sub savedsearch_post_update
{
my ($args) = @_;
my $name = $args->{search}->user->login;
$name =~ s/\@.*$//so;
refresh_some_views([ $name ]);
return 1;
}
sub editusers_post_update_delete
{
my ($args) = @_;
my $name = $args->{userid};
if ($name)
{
$name = user_id_to_login($name);
$name =~ s/\@.*$//so;
refresh_some_views([ $name ]);
}
return 1;
}
sub install_before_final_checks
{
print "Refreshing Views...\n";
refresh_views();
}
1;
__END__

View File

@ -233,7 +233,11 @@ Bugzilla::Install::reset_password($switch{'reset-password'})
Bugzilla::Install::create_default_product();
require Bugzilla::CheckerUtils;
Bugzilla::CheckerUtils::install_before_final_checks();
Bugzilla::CheckerUtils::install_before_final_checks({ silent => $silent });
require Bugzilla::Views;
print "Refreshing Views...\n" unless $silent;
Bugzilla::Views::refresh_some_views();
Bugzilla::Hook::process('install_before_final_checks', { silent => $silent });

View File

@ -37,6 +37,7 @@ use Bugzilla::Group;
use Bugzilla::Product;
use Bugzilla::User;
use Bugzilla::Token;
use Bugzilla::Views;
use constant SPECIAL_GROUPS => ('chartgroup', 'insidergroup', 'timetrackinggroup', 'querysharegroup');
@ -276,6 +277,7 @@ if ($action eq 'delete') {
delete_token($token);
Bugzilla::Hook::process('editgroups-post_delete', { group => $group });
Bugzilla::Views::refresh_some_views();
$vars->{'message'} = 'group_deleted';
ListGroups($vars);
@ -291,6 +293,7 @@ if ($action eq 'postchanges') {
my $changes = doGroupChanges();
Bugzilla::Hook::process('editgroups-post_edit', {});
Bugzilla::Views::refresh_some_views();
delete_token($token);
@ -345,6 +348,7 @@ if ($action eq 'remove_regexp') {
$vars->{'regexp'} = $regexp;
Bugzilla::Hook::process('editgroups-post_remove_regexp', { deleted => \@deleted });
Bugzilla::Views::refresh_some_views();
delete_token($token);

View File

@ -35,6 +35,7 @@ use Bugzilla::Flag;
use Bugzilla::Field;
use Bugzilla::Group;
use Bugzilla::Token;
use Bugzilla::Views;
my $user = Bugzilla->login(LOGIN_REQUIRED);
@ -344,6 +345,7 @@ if ($action eq 'search') {
delete_token($token);
Bugzilla::Hook::process('editusers-post_update', { userid => $otherUserID });
Bugzilla::Views::refresh_some_views([ $otherUser->login ]);
$vars->{'message'} = 'account_updated';
$vars->{'changed_fields'} = [keys %$changes];
@ -587,6 +589,7 @@ if ($action eq 'search') {
delete_token($token);
Bugzilla::Hook::process('editusers-post_delete', { userid => $otherUserID });
Bugzilla::Views::refresh_some_views([ $otherUser->login ]);
$vars->{'message'} = 'account_deleted';
$vars->{'otheruser'}{'login'} = $otherUser->login;

View File

@ -86,6 +86,10 @@ if (@add_members || @add_bless || @rm_members || @rm_bless)
group_id => $vars->{group}->id,
});
}
if (@add_members || @rm_members)
{
Bugzilla::Views::refresh_some_views();
}
delete_token($ARGS->{token});
my $url = "editusersingroup.cgi?group=".$vars->{group}->id;
print Bugzilla->cgi->redirect(-location => $url);

View File

@ -18,20 +18,6 @@ required_modules('custis', $REQUIRED_MODULES);
optional_modules('custis', $OPTIONAL_MODULES);
clear_hooks('custis');
# Hooks allowing to create MySQL Views representing saved searches for users
if (!Bugzilla->params->{ext_disable_refresh_views})
{
set_hook('custis', 'editgroups_post_create', 'FlushViews::refresh_views');
set_hook('custis', 'editgroups_post_delete', 'FlushViews::refresh_views');
set_hook('custis', 'editgroups_post_edit', 'FlushViews::refresh_views');
set_hook('custis', 'editgroups_post_remove_regexp', 'FlushViews::refresh_views');
set_hook('custis', 'editusersingroup_post_add', 'FlushViews::refresh_views');
set_hook('custis', 'editusers_post_delete', 'FlushViews::editusers_post_update_delete');
set_hook('custis', 'editusers_post_update', 'FlushViews::editusers_post_update_delete');
set_hook('custis', 'savedsearch_post_update', 'FlushViews::savedsearch_post_update');
add_hook('custis', 'install_before_final_checks', 'FlushViews::install_before_final_checks');
}
# Other hooks
set_hook('custis', 'flag_check_requestee_list', 'CustisMiscHooks::flag_check_requestee_list');
set_hook('custis', 'process_bug_after_move', 'CustisMiscHooks::process_bug_after_move');