Bug 24157: New permission - merge_invoices
[srvgit] / C4 / Tags.pm
index d7d2ee1..a337a7a 100644 (file)
@@ -25,15 +25,14 @@ use Exporter;
 
 use C4::Context;
 use C4::Debug;
+use Module::Load::Conditional qw/check_install/;
 #use Data::Dumper;
 use constant TAG_FIELDS => qw(tag_id borrowernumber biblionumber term language date_created);
 use constant TAG_SELECT => "SELECT " . join(',', TAG_FIELDS) . "\n FROM   tags_all\n";
 
 use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
-our $ext_dict;
 
 BEGIN {
-    $VERSION = 3.07.00.049;
        @ISA = qw(Exporter);
     @EXPORT_OK = qw(
       &get_tag &get_tags &get_tag_rows
@@ -51,7 +50,11 @@ BEGIN {
       stratify_tags
     );
        # %EXPORT_TAGS = ();
-       $ext_dict = C4::Context->preference('TagsExternalDictionary');
+    my $ext_dict = C4::Context->preference('TagsExternalDictionary');
+    if ( $ext_dict && ! check_install( module => 'Lingua::Ispell' ) ) {
+        warn "Ignoring TagsExternalDictionary, because Lingua::Ispell is not installed.";
+        $ext_dict = q{};
+    }
        if ($debug) {
                require Data::Dumper;
                import Data::Dumper qw(:DEFAULT);
@@ -59,7 +62,9 @@ BEGIN {
        }
        if ($ext_dict) {
                require Lingua::Ispell;
-               import Lingua::Ispell qw(spellcheck add_word_lc save_dictionary);
+        import Lingua::Ispell qw(spellcheck add_word_lc);
+        $Lingua::Ispell::path = $ext_dict;
+        $debug and print STDERR "\$Lingua::Ispell::path = $Lingua::Ispell::path\n";
        }
 }
 
@@ -69,11 +74,6 @@ More verose debugging messages are sent in the presence of non-zero $ENV{"DEBUG"
 
 =cut
 
-INIT {
-    $ext_dict and $Lingua::Ispell::path = $ext_dict;
-    $debug and print STDERR "\$Lingua::Ispell::path = $Lingua::Ispell::path\n";
-}
-
 sub get_filters {
        my $query = "SELECT * FROM tags_filters ";
        my ($sth);
@@ -192,7 +192,7 @@ sub get_tag_rows {
                        carp "Empty argument key to get_tag_rows: ignoring!";
                        next;
                }
-               unless (1 == scalar grep {/^ $key $/x} @ok_fields) {
+               unless (1 == scalar grep { $_ eq $key } @ok_fields) {
                        carp "get_tag_rows received unreconized argument key '$key'.";
                        next;
                }
@@ -233,7 +233,7 @@ sub get_tags {              # i.e., from tags_index
                        carp "Empty argument key to get_tags: ignoring!";
                        next;
                }
-               unless (1 == scalar grep {/^ $key $/x} @ok_fields) {
+               unless (1 == scalar grep { $_ eq $key } @ok_fields) {
                        carp "get_tags received unreconized argument key '$key'.";
                        next;
                }
@@ -302,7 +302,7 @@ sub get_approval_rows {             # i.e., from tags_approval
                        carp "Empty argument key to get_approval_rows: ignoring!";
                        next;
                }
-               unless (1 == scalar grep {/^ $key $/x} @ok_fields) {
+               unless (1 == scalar grep { $_ eq $key } @ok_fields) {
                        carp "get_approval_rows received unreconized argument key '$key'.";
                        next;
                }
@@ -368,6 +368,7 @@ sub is_approved {
        my $term = shift or return;
        my $sth = C4::Context->dbh->prepare("SELECT approved FROM tags_approval WHERE term = ?");
        $sth->execute($term);
+    my $ext_dict = C4::Context->preference('TagsExternalDictionary');
        unless ($sth->rows) {
                $ext_dict and return (spellcheck($term) ? 0 : 1);       # spellcheck returns empty on OK word
                return 0;
@@ -391,6 +392,7 @@ sub get_tag_index {
 sub whitelist {
        my $operator = shift;
        defined $operator or return; # have to test defined to allow =0 (kohaadmin)
+    my $ext_dict = C4::Context->preference('TagsExternalDictionary');
        if ($ext_dict) {
                foreach (@_) {
                        spellcheck($_) or next;