display itemnote on check-out (added, was not here) & check-in (red-ed, was already...
[koha.git] / Makefile.PL
index 79c0375..29dc039 100644 (file)
@@ -48,10 +48,10 @@ Makefile.PL - Koha packager and installer
     sudo make install
 
 =head2 UPGRADE INSTALLATION
+    
+    NOTE: This option is only available if koha-install-log exists.
 
     perl Makefile.PL --prev-install-log /path/to/koha-install-log
-    -OR-
-    perl Makefile.PL # if no koha-install-log available
 
     make
     make test
@@ -197,7 +197,14 @@ things the translation toolkit and RSS feed tools.
 
 =item SCRIPT_DIR
 
-Directory for command-line scripts and daemons.
+Directory for command-line scripts and daemons to
+be set up all for installation modes.
+
+=item SCRIPT_NONDEV_DIR
+
+Directory for command-line scripts that should
+be installed in the same directory as the
+SCRIPT_DIR target except 'dev' installs.
 
 =item MAN_DIR
 
@@ -250,7 +257,7 @@ my $target_map = {
   './help.pl'                   => 'INTRANET_CGI_DIR', 
   './installer-CPAN.pl'         => 'NONE',
   './installer'                 => 'INTRANET_CGI_DIR',
-  './koha-tmpl/errors'          => {target => 'INTRANET_CGI_DIR', trimdir => 2},
+  './errors'                    => {target => 'INTRANET_CGI_DIR'},
   './koha-tmpl/intranet-tmpl'   => {target => 'INTRANET_TMPL_DIR', trimdir => -1},
   './koha-tmpl/opac-tmpl'       => {target => 'OPAC_TMPL_DIR', trimdir => -1},
   './kohaversion.pl'            => 'INTRANET_CGI_DIR', 
@@ -259,7 +266,7 @@ my $target_map = {
   './Makefile.PL'               => 'NONE',
   './MANIFEST.SKIP'             => 'NONE',
   './members'                   => 'INTRANET_CGI_DIR',
-  './misc'                      => { target => 'SCRIPT_DIR', trimdir => -1 }, 
+  './misc'                      => { target => 'SCRIPT_NONDEV_DIR', trimdir => -1 }, 
   './misc/bin'                  => { target => 'SCRIPT_DIR', trimdir => -1 }, 
   './misc/release_notes'        => { target => 'DOC_DIR', trimdir => 2 },
   './misc/translator'           => { target => 'MISC_DIR', trimdir => 2 }, 
@@ -403,6 +410,8 @@ my %config_defaults = (
   'MERGE_SERVER_PORT' => '11001',
   'PAZPAR2_HOST' => 'localhost',
   'PAZPAR2_PORT' => '11002',
+  'RUN_DATABASE_TESTS' => 'no',
+  'PATH_TO_ZEBRA' => '',
 );
 
 # set some default configuratio options based on OS
@@ -438,6 +447,7 @@ my %valid_config_values = (
   'AUTH_INDEX_MODE' => { 'grs1' => 1, 'dom' => 1 },
   'ZEBRA_MARC_FORMAT' => { 'marc21' => 1, 'unimarc' => 1 }, # FIXME should generate from contents of distributation
   'ZEBRA_LANGUAGE'    => { 'en' => 1, 'fr' => 1 }, # FIXME should generate from contents of distribution
+  'RUN_DATABASE_TESTS' => { 'yes' => 1, 'no' => 1 },
 );
 
 # get settings from command-line
@@ -480,13 +490,11 @@ if ($config{'INSTALL_ZEBRA'} eq "yes") {
         'blib/ZEBRA_CONF_DIR/retrieval-info-auth-grs1.xml',
         'blib/ZEBRA_CONF_DIR/retrieval-info-auth-dom.xml',
     );
-    if ($config{'INSTALL_MODE'} ne 'dev') {
-        push @{ $pl_files->{'rewrite-config.PL'} }, (
-            'blib/SCRIPT_DIR/koha-zebra-ctl.sh',
-            'blib/SCRIPT_DIR/koha-pazpar2-ctl.sh',
-            'blib/SCRIPT_DIR/koha-zebraqueue-ctl.sh',
-        );
-    }
+    push @{ $pl_files->{'rewrite-config.PL'} }, (
+        'blib/SCRIPT_DIR/koha-zebra-ctl.sh',
+        'blib/SCRIPT_DIR/koha-pazpar2-ctl.sh',
+        'blib/SCRIPT_DIR/koha-zebraqueue-ctl.sh',
+    );
     if ($config{'INSTALL_PAZPAR2'} eq 'yes') {
         push @{ $pl_files->{'rewrite-config.PL'} }, (
             'blib/PAZPAR2_CONF_DIR/koha-biblios.xml',
@@ -501,10 +509,20 @@ if ($config{'INSTALL_ZEBRA'} eq "yes") {
 if ($config{'INSTALL_MODE'} ne "dev") {
     push @{ $pl_files->{'rewrite-config.PL'} }, (
         'blib/PERL_MODULE_DIR/C4/Context.pm',
-        'blib/SCRIPT_DIR/kohalib.pl'
+        'blib/SCRIPT_NONDEV_DIR/kohalib.pl'
     );
 }
 
+my %test_suite_override_dirs = (
+    KOHA_CONF_DIR  => ['etc'],
+    ZEBRA_CONF_DIR => ['etc', 'zebradb'],
+    LOG_DIR        => ['var', 'log'],
+    SCRIPT_DIR     => ['bin'],
+    ZEBRA_LOCK_DIR => ['var', 'lock', 'zebradb'],
+    ZEBRA_DATA_DIR => ['var', 'lib', 'zebradb'],
+    ZEBRA_RUN_DIR  => ['var', 'run', 'zebradb'],
+);
 WriteMakefile(
     NAME => 'koha',
     #VERSION => strftime('2.9.%Y%m%d%H',gmtime),
@@ -525,7 +543,7 @@ WriteMakefile(
 'DBD::mysql' => 4.004,
 'DBI' => 1.53,
 'Data::ICal' => 0.13,
-'Data::Dumper' => 2.121_08,
+'Data::Dumper' => 2.121,
 'Date::Calc' => 5.4,
 'Date::ICal' => 1.72,
 'Date::Manip' => 5.44,
@@ -534,9 +552,11 @@ WriteMakefile(
 'GD::Barcode::UPCE' => 1.1,
 'Getopt::Long' => 2.35,
 'Getopt::Std' => 1.05,
-'HTML::Template::Pro' => 0.65,
+'HTML::Template::Pro' => 0.69,
+'HTML::Scrubber' => 0.08,
 'HTTP::Cookies' => 1.39,
 'HTTP::Request::Common' => 1.26,
+'Image::Magick' => 6.2,
 'LWP::Simple' => 1.41,
 'LWP::UserAgent' => 2.033,
 'Lingua::Stem' => 0.82,
@@ -929,6 +949,21 @@ Install the Zebra configuration files?);
     $config{'INSTALL_ZEBRA'} = _get_value('INSTALL_ZEBRA', $msg, $defaults->{'INSTALL_ZEBRA'}, $valid_values, $install_log_values);
 
     if ($config{'INSTALL_ZEBRA'} eq 'yes') {
+
+        if (defined(my $zebra_path = find_zebra())) {
+            $config{'PATH_TO_ZEBRA'} = $zebra_path;
+            print qq(
+Found 'zebrasrv' and 'zebraidx' in $zebra_path.
+);
+        } else {
+            print q(
+Unable to find the Zebra programs 'zebrasrv' and 'zebraidx'
+in your PATH or in some of the usual places.  If you haven't
+installed Zebra yet, please do so and run Makefile.PL again.
+
+);
+        }
+
         $msg = q(
 Since you've chosen to use Zebra with Koha,
 you must specify the primary MARC format of the
@@ -1039,6 +1074,44 @@ PazPar2 port?);
         }
     }
 
+  $msg = q(
+Would you like to run the database-dependent test suite?);
+  $msg .= _add_valid_values_disp( 'RUN_DATABASE_TESTS', $valid_values );
+    $config{'RUN_DATABASE_TESTS'} = _get_value( 'RUN_DATABASE_TESTS', $msg, $defaults->{'RUN_DATABASE_TESTS'}, $valid_values, $install_log_values );
+
+  if ( $config{'RUN_DATABASE_TESTS'} eq 'yes' ) {
+      $config{'TEST_DB_TYPE'} = $config{'DB_TYPE'};
+      $config{'TEST_DB_HOST'} = $config{'DB_HOST'};
+      $msg = q(TEST DATABASE
+
+THE DATA IN THIS DATABASE WILL BE DESTROYED during the process of
+testing. Please don't do this on your production database. It is not
+reversable.
+
+YOU WILL SUFFER DATA LOSS if you run this test suite on your test
+database. You are better off not running this optional test suite than
+doing it in a database that you don't want to lose.
+
+Please specify the name of the test database to be
+used by Koha);
+      
+      $config{'TEST_DB_NAME'} = _get_value('TEST_DB_NAME', $msg, $defaults->{'TEST_DB_NAME'}, $valid_values, $install_log_values);
+      while ( $config{'TEST_DB_NAME'} eq $config{'DB_NAME'} ) {
+          $msg = q(Please do not use the same database for testing as you do for production. You run the severe risk of data loss.);
+          $config{'TEST_DB_NAME'} = _get_value('TEST_DB_NAME', $msg, $defaults->{'TEST_DB_NAME'}, $valid_values, $install_log_values);
+      }
+
+      $msg = q(
+Please specify the user that owns the database to be
+used by Koha);
+    $config{'TEST_DB_USER'} = _get_value('TEST_DB_USER', $msg, $defaults->{'TEST_DB_USER'}, $valid_values, $install_log_values);
+      
+      $msg = q(
+Please specify the password of the user that owns the 
+database to be used by Koha);
+      $config{'TEST_DB_PASS'} = _get_value('TEST_DB_PASS', $msg, $defaults->{'TEST_DB_PASS'}, $valid_values, $install_log_values);
+  }
+
     print "\n\n";
 
     # add version number
@@ -1139,6 +1212,7 @@ sub get_target_directories {
         $dirmap{'PAZPAR2_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc', 'pazpar2');
         $dirmap{'MISC_DIR'} = File::Spec->catdir(@basedir, $package, 'misc');
         $dirmap{'SCRIPT_DIR'} = File::Spec->catdir(@basedir, $package, 'bin');
+        $dirmap{'SCRIPT_NONDEV_DIR'} = $dirmap{'SCRIPT_DIR'};
         $dirmap{'MAN_DIR'} = File::Spec->catdir(@basedir, $package, 'man');
         $dirmap{'DOC_DIR'} = File::Spec->catdir(@basedir, $package, 'doc');
         $dirmap{'ZEBRA_LOCK_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lock', 'zebradb');
@@ -1166,7 +1240,8 @@ sub get_target_directories {
         $dirmap{'PAZPAR2_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc', 'pazpar2');
         $dirmap{'MISC_DIR'} = File::Spec->catdir(@basedir, $package, 'misc');
         $dirmap{'SCRIPT_DIR'} = File::Spec->catdir(@basedir, $package, 'bin');
-        $skipdirs{'SCRIPT_DIR'} = 1;
+        $dirmap{'SCRIPT_NONDEV_DIR'} = $dirmap{'SCRIPT_DIR'};
+        $skipdirs{'SCRIPT_NONDEV_DIR'} = 1;
         $dirmap{'MAN_DIR'} = File::Spec->catdir(@basedir, $package, 'man');
         $dirmap{'DOC_DIR'} = File::Spec->catdir(@basedir, $package, 'doc');
         $dirmap{'ZEBRA_LOCK_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lock', 'zebradb');
@@ -1187,6 +1262,7 @@ sub get_target_directories {
         $dirmap{'PAZPAR2_CONF_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'etc', $package, 'pazpar2');
         $dirmap{'MISC_DIR'} = File::Spec->catdir(@basedir, $package, 'misc');
         $dirmap{'SCRIPT_DIR'} = File::Spec->catdir(@basedir, $package, 'bin');
+        $dirmap{'SCRIPT_NONDEV_DIR'} = $dirmap{'SCRIPT_DIR'};
         $dirmap{'MAN_DIR'} = File::Spec->catdir(@basedir, $package, 'man');
         $dirmap{'DOC_DIR'} = File::Spec->catdir(@basedir, $package, 'doc');
         $dirmap{'ZEBRA_LOCK_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'lock', $package, 'zebradb');
@@ -1201,6 +1277,25 @@ sub get_target_directories {
     return \%dirmap, \%skipdirs;
 }
 
+=head2 get_test_dir 
+
+Map a directory target to the corresponding path for
+the test suite.
+
+=cut
+
+sub get_test_dir {
+    my ($dirname) = @_;
+  
+    my @basedir = (File::Spec->rel2abs(File::Spec->curdir()), 't', 'run'); 
+    if (exists $test_suite_override_dirs{$dirname}) {
+        return File::Spec->catdir(@basedir, @{ $test_suite_override_dirs{$dirname} });
+    } else {
+        return;
+    }
+    
+}
+
 sub _get_env_overrides {
     my $dirmap = shift;
 
@@ -1249,6 +1344,34 @@ sub display_configuration {
     print "perl Makefile.PL\n";
     print "\nor\n\n";
     print "DB_USER=my_koha DOC_DIR=/usr/local/info perl Makefile.PL\n\n";
+    print "If installing on a Win32 platform, be sure to use:\n";
+    print "'dmake -x MAXLINELENGTH=300000'\n\n";
+}
+
+=head2 find_zebra
+
+Attempt to find Zebra - check user's PATH and
+a few other directories for zebrasrv and zebraidx.
+
+FIXME: doesn't handle Win32
+
+=cut
+
+sub find_zebra {
+    my @search_dirs = map {
+                            my $abs = File::Spec->rel2abs($_);
+                            my ($toss, $directories);
+                            ($toss, $directories, $toss) = File::Spec->splitpath($abs, 1);
+                            $directories;
+                        }  split /:/, $ENV{PATH};
+    push @search_dirs, qw(/usr/local/bin /opt/local/bin /usr/bin);
+    my @zebrasrv_dirs = grep { -x File::Spec->catpath('', $_, 'zebrasrv') } @search_dirs;
+    return unless @zebrasrv_dirs;
+    # verify that directory that contains zebrasrv also contains zebraidx
+    foreach my $dir (@zebrasrv_dirs) {
+        return $dir if -x File::Spec->catpath('', $dir, 'zebraidx');
+    }
+    return;
 }
 
 package MY;
@@ -1346,9 +1469,6 @@ install :: all install_koha warn_koha_env_vars
     $install .= "\t\$(NOECHO) \$(ECHO) export KOHA_CONF=\$(KOHA_DEST_KOHA_CONF_DIR)/koha-conf.xml\n";
     $install .= "\t\$(NOECHO) \$(ECHO) export PERL5LIB=$target_directories->{'PERL_MODULE_DIR'}\n";
     $install .= "\t\$(NOECHO) \$(ECHO)\n";
-    $install .= "\t\$(NOECHO) \$(ECHO) If installing on a Win32 platform, be sure to use:\n";
-    $install .= "\t\$(NOECHO) \$(ECHO) 'dmake -x MAXLINELENGTH=300000'\n";
-    $install .= "\t\$(NOECHO) \$(ECHO)\n";
     $install .= "\t\$(NOECHO) \$(ECHO) For other post-installation tasks, please consult the README.\n";
     $install .= "\t\$(NOECHO) \$(ECHO)\n";
 
@@ -1400,16 +1520,15 @@ upgrade :: make_upgrade_backup install
 \t\$(NOECHO) \$(NOOP)
 make_upgrade_backup ::
 \t\$(NOECHO) umask 022; \$(MOD_BACKUP) \\
-\t\t\$(KOHA_INST_KOHA_CONF_DIR) \$(KOHA_DEST_KOHA_CONF_DIR) \\
-\t\t\$(KOHA_INST_INTRANET_TMPL_DIR) \$(KOHA_DEST_INTRANET_TMPL_DIR) \\
-\t\t\$(KOHA_INST_INTRANET_WWW_DIR) \$(KOHA_DEST_INTRANET_WWW_DIR) \\
-\t\t\$(KOHA_INST_OPAC_TMPL_DIR) \$(KOHA_DEST_OPAC_TMPL_DIR) \\
-\t\t\$(KOHA_INST_OPAC_WWW_DIR) \$(KOHA_DEST_OPAC_WWW_DIR) \\
-\t\t\$(KOHA_INST_OPAC_TMPL_DIR) \$(KOHA_DEST_OPAC_TMPL_DIR) \\
-\t\t\$(KOHA_INST_OPAC_WWW_DIR) \$(KOHA_DEST_OPAC_WWW_DIR) \\
-\t\t\$(KOHA_INST_PAZPAR2_CONF_DIR) \$(KOHA_DEST_PAZPAR2_CONF_DIR) \\
-\t\t\$(KOHA_INST_ZEBRA_CONF_DIR) \$(KOHA_DEST_ZEBRA_CONF_DIR)
 /;
+    foreach my $key (qw/KOHA_CONF_DIR INTRANET_TMPL_DIR INTRANET_WWW_DIR OPAC_TMPL_DIR OPAC_WWW_DIR
+                     PAZPAR2_CONF_DIR ZEBRA_CONF_DIR/) {
+       $upgrade .= "\t\t\$(KOHA_INST_$key) \$(KOHA_DEST_$key) \\\n" 
+            unless ($config{'INSTALL_ZEBRA'} ne "yes" and $key =~ /ZEBRA/) or
+                   exists $skip_directories->{$key} or
+                   not exists $target_directories->{$key};
+    }
+    $upgrade =~ s/\\\n$/\n/;
 
     return $upgrade;
 }
@@ -1427,20 +1546,44 @@ sub postamble {
         $config{'ZEBRA_PASS'} =~ s/\$/\$\$/g;
     }
 
+    my $env;
        # Hereagain, we must alter syntax per platform...
        if ( $^O eq 'MSWin32' ) {
                # NOTE: it is imperative that there be no whitespaces in ENV=value...
-               my $env = join("\n", map { "__${_}__=$target_directories->{$_}" } keys %$target_directories); 
+               $env = join("\n", map { "__${_}__=$target_directories->{$_}" } keys %$target_directories); 
                $env .= "\n\n";
                $env .= join("\n", map { "__${_}__=$config{$_}" } keys %config);
-               return "$env\n";
        }
     else {
-               my $env = join("\n", map { "export __${_}__ := $target_directories->{$_}" } keys %$target_directories); 
+               $env = join("\n", map { "export __${_}__ := $target_directories->{$_}" } keys %$target_directories); 
                $env .= "\n\n";
                $env .= join("\n", map { "export __${_}__ := $config{$_}" } keys %config);
-               return "$env\n";
        }
+    
+    if ( $config{'RUN_DATABASE_TESTS'} eq 'yes' ) {
+        if ( open( my $confhandle, '>', 't/test-config.txt' ) ) {
+            print $confhandle "# This configuration file lets the t/Makefile prepare a test koha-conf.xml file.\n";
+            print $confhandle "# It is generated by the top-level Makefile.PL.\n";
+            print $confhandle "# It is separate from the standard koha-conf.xml so that you can edit this by hand and test with different configurations.\n";
+
+            # these directories will be relocated to the 't' directory
+            foreach my $dirname ( keys %$target_directories ) {
+                my $dir = $target_directories->{$dirname};
+                if ( exists $test_suite_override_dirs{$dirname} ) {
+                    $dir = main::get_test_dir($dirname);
+                }
+                print $confhandle "$dirname = $dir\n"
+            }
+            print $confhandle "\n";
+
+            print $confhandle join( "\n", map { "$_ = $config{$_}" } keys( %config ) ), "\n";
+            close( $confhandle );
+        } else {
+            warn 'unable to open conf file for database dependent tests: $!';
+        }
+          
+    }
+    return "$env\n";
 }