BUGFIX : script to fix & fill onloan field in items table.
[koha.git] / Makefile.PL
index ebb459c..bd0ea58 100644 (file)
@@ -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
 
@@ -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 }, 
@@ -404,6 +411,7 @@ my %config_defaults = (
   'PAZPAR2_HOST' => 'localhost',
   'PAZPAR2_PORT' => '11002',
   'RUN_DATABASE_TESTS' => 'no',
+  'PATH_TO_ZEBRA' => '',
 );
 
 # set some default configuratio options based on OS
@@ -482,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',
@@ -503,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),
@@ -932,6 +948,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
@@ -1050,10 +1081,24 @@ Would you like to run the database-dependent test suite?);
   if ( $config{'RUN_DATABASE_TESTS'} eq 'yes' ) {
       $config{'TEST_DB_TYPE'} = $config{'DB_TYPE'};
       $config{'TEST_DB_HOST'} = $config{'DB_HOST'};
-      $msg = q(
+      $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);
+      
+      $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
@@ -1166,6 +1211,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');
@@ -1193,7 +1239,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');
@@ -1214,6 +1261,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');
@@ -1228,6 +1276,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;
 
@@ -1280,6 +1347,32 @@ sub display_configuration {
     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;
 
 # This will have to be reworked in order to accommodate Win32...
@@ -1473,14 +1566,10 @@ sub postamble {
             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
-            my %move_to_t = map { $_ => 1 } qw( KOHA_CONF_DIR LOG_DIR SCRIPT_DIR ZEBRA_CONF_DIR ZEBRA_LOCK_DIR ZEBRA_DATA_DIR ZEBRA_RUN_DIR );
-            my $oldbasedir = substr( $target_directories->{'KOHA_CONF_DIR'}, 0, - length( '/etc' ) );
-            my $newbasedir = $target_directories->{'KOHA_CONF_DIR'};
-            $newbasedir =~ s/etc$/t/;
             foreach my $dirname ( keys %$target_directories ) {
-                my $dir = $target_directories->{ $dirname };
-                if ( $move_to_t{ $dirname } ) {
-                    $dir =~ s/$oldbasedir/$newbasedir/;
+                my $dir = $target_directories->{$dirname};
+                if ( exists $test_suite_override_dirs{$dirname} ) {
+                    $dir = main::get_test_dir($dirname);
                 }
                 print $confhandle "$dirname = $dir\n"
             }