Bug 18736: (follow-up) cast as UNSIGNED instead of INTEGER
[koha.git] / C4 / Tags.pm
index 619c692..1db7acc 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($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
-our $ext_dict;
+use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
 
 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);
@@ -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;