OpenInteract2/Manage/Website/ReindexObjects.pm

filter: Statementstmt 55.8% 24 / 43 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 8 / 10 Podpod 0.0% 0 / 4 totaltotal 50.7% 32 / 63 CC 4 SCAR 19.3
CC
4
Cov
49%
run_task
20.0
get_brief_description
2.0
BEGIN
1.0
CRAP 6.9
« OpenInteract2/Response/Apache2.pm ↑ Summary OpenInteract2/Setup/InitializeControllers.pm »
1 package OpenInteract2::Manage::Website::ReindexObjects;
2  
3 # $Id: ReindexObjects.pm,v 1.7 2005/03/18 04:09:50 lachoy Exp $
4  
5 87 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 87 ▶use base qw( OpenInteract2::Manage::Website );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 87 ▶use Log::Log4perl qw( get_logger );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 87 ▶use OpenInteract2::Constants qw( :log );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 87 ▶use OpenInteract2::Context qw( CTX );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 87 ▶use OpenInteract2::Exception qw( oi_error );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 87 $OpenInteract2::Manage::Website::ReindexObjects::VERSION = sprintf("%d.%02d", q$Revision: 1.7 $ =~ /(\d+)\.(\d+)/);
13  
14 87 ▶sub get_name {
Subroutine get_name: called CC=1 SCAR=0.0
Pod undocumented
15 87 return 'reindex_objects';
16 }
17  
18 0 ▶sub get_brief_description {
Subroutine get_brief_description: not called CC=1 SCAR=6.9
Pod undocumented
19 0 return "Add all objects of a class, or objects matching a " .
20 "particular query, to the full-text index. This can " .
21 "be an intensive operation if you have a lot of objects.";
22 }
23  
24 1 ▶sub get_parameters {
Subroutine get_parameters: called CC=1 SCAR=0.0
Pod undocumented
25 1 my ( $self ) = @_;
26 return {
27 1 website_dir => $self->_get_website_dir_param,
28 spops => {
29 description =>
30 "Tag for class you'd like to index -- for example " .
31 "use 'news' for 'OpenInteract2::News'",
32 is_required => 'yes',
33 },
34 query => {
35 description =>
36 "WHERE clause used to filter objects to add to the " .
37 "index. This is passed directly to the database.",
38 },
39 }
40 }
41  
42 # cannot define validate_param() for 'spops' since we need the context
43 # to be created... wait for run_task()
44  
45 0 ▶sub run_task {
Subroutine run_task: not called CC=4 SCAR=30.0
Pod undocumented
46 0 my ( $self ) = @_;
47 0 my $action = 'reindex objects';
48 0 my $object_tag = $self->param( 'spops' );
49  
50 0 my $obj_class = eval { $self->_check_spops_key( $object_tag ) };
51 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
52 0 return $self->_fail( $action, "$@" );
53 }
54  
55 # Ensure the object class is currently indexable
56  
57 0 ▶ unless ( $obj_class->isa( 'OpenInteract2::FullTextRules' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($obj_class->isa("OpenInteract2::FullTextRules")) 0 0 0
58 0 my $msg = "Failed! The class '$obj_class' is not indexable. " .
59 "Please set its 'is_searchable' configuration key " .
60 "to 'yes' and list its content field(s) in " .
61 "'fulltext_field'.";
62 0 return $self->_fail( $action, $msg );
63 }
64  
65 0 my $where_clause = $self->param( 'query' );
66 0 my $indexer = CTX->fulltext_indexer;
67 0 my ( $count );
68 0 eval {
69 0 $indexer->create_class_index(
70 $obj_class, { skip_security => 1,
71 where => $where_clause })
72 };
73 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
74 0 return $self->_fail( $action, "$@" );
75 }
76 0 return $self->_ok( $action, "Added $count objects to index" );
77 }
78  
79 87 OpenInteract2::Manage->register_factory_type( get_name() => __PACKAGE__ );
80  
81 87 1;
82  
83 __END__
« OpenInteract2/Response/Apache2.pm ↑ Summary OpenInteract2/Setup/InitializeControllers.pm »