(bug #3819) hold policies doesn't work
authorNahuel ANGELINETTI <nahuel.angelinetti@biblibre.com>
Mon, 30 Nov 2009 14:21:17 +0000 (15:21 +0100)
committerHenri-Damien LAURENT <henridamien.laurent@biblibre.com>
Tue, 1 Dec 2009 09:08:46 +0000 (10:08 +0100)
This patch backport code from 3.2, create the database, and update kohastructure.sql

admin/smart-rules.pl
installer/data/mysql/kohastructure.sql
installer/data/mysql/updatedatabase30.pl

index 13ffa5c..2dd1878 100755 (executable)
@@ -181,6 +181,86 @@ elsif ($op eq "add-branch-cat") {
         }
     }
 }
+elsif ($op eq "add-branch-item") {
+    my $itemtype  = $input->param('itemtype');
+    my $holdallowed   = $input->param('holdallowed');
+    $holdallowed =~ s/\s//g;
+    $holdallowed = undef if $holdallowed !~ /^\d+/;
+
+    if ($branch eq "*") {
+        if ($itemtype eq "*") {
+            my $sth_search = $dbh->prepare("SELECT count(*) AS total
+                                            FROM default_circ_rules");
+            my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
+                                            (holdallowed)
+                                            VALUES (?)");
+            my $sth_update = $dbh->prepare("UPDATE default_circ_rules
+                                            SET holdallowed = ?");
+
+            $sth_search->execute();
+            my $res = $sth_search->fetchrow_hashref();
+            if ($res->{total}) {
+                $sth_update->execute($holdallowed);
+            } else {
+                $sth_insert->execute($holdallowed);
+            }
+        } else {
+            my $sth_search = $dbh->prepare("SELECT count(*) AS total
+                                            FROM default_branch_item_rules
+                                            WHERE itemtype = ?");
+            my $sth_insert = $dbh->prepare("INSERT INTO default_branch_item_rules
+                                            (itemtype, holdallowed)
+                                            VALUES (?, ?)");
+            my $sth_update = $dbh->prepare("UPDATE default_branch_item_rules
+                                            SET holdallowed = ?
+                                            WHERE itemtype = ?");
+            $sth_search->execute($itemtype);
+            my $res = $sth_search->fetchrow_hashref();
+            if ($res->{total}) {
+                $sth_update->execute($holdallowed, $itemtype);
+            } else {
+                $sth_insert->execute($itemtype, $holdallowed);
+            }
+        }
+    } elsif ($itemtype eq "*") {
+        my $sth_search = $dbh->prepare("SELECT count(*) AS total
+                                        FROM default_branch_circ_rules
+                                        WHERE branchcode = ?");
+        my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
+                                        (branchcode, holdallowed)
+                                        VALUES (?, ?)");
+        my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
+                                        SET holdallowed = ?
+                                        WHERE branchcode = ?");
+        $sth_search->execute($branch);
+        my $res = $sth_search->fetchrow_hashref();
+        if ($res->{total}) {
+            $sth_update->execute($holdallowed, $branch);
+        } else {
+            $sth_insert->execute($branch, $holdallowed);
+        }
+    } else {
+        my $sth_search = $dbh->prepare("SELECT count(*) AS total
+                                        FROM branch_item_rules
+                                        WHERE branchcode = ?
+                                        AND   itemtype = ?");
+        my $sth_insert = $dbh->prepare("INSERT INTO branch_item_rules
+                                        (branchcode, itemtype, holdallowed)
+                                        VALUES (?, ?, ?)");
+        my $sth_update = $dbh->prepare("UPDATE branch_item_rules
+                                        SET holdallowed = ?
+                                        WHERE branchcode = ?
+                                        AND itemtype = ?");
+
+        $sth_search->execute($branch, $itemtype);
+        my $res = $sth_search->fetchrow_hashref();
+        if ($res->{total}) {
+            $sth_update->execute($holdallowed, $branch, $itemtype);
+        } else {
+            $sth_insert->execute($branch, $itemtype, $holdallowed);
+        }
+    }
+}
 
 my $branches = GetBranches();
 my @branchloop;
index 11cfbc9..8e45a96 100644 (file)
@@ -677,6 +677,18 @@ CREATE TABLE `default_branch_circ_rules` (
     ON DELETE CASCADE ON UPDATE CASCADE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
+--
+-- Table structure for table `default_branch_item_rules`
+--
+
+CREATE TABLE `default_branch_item_rules` (
+  `itemtype` varchar(10) NOT NULL,
+  `holdallowed` tinyint(1) default NULL,
+  PRIMARY KEY  (`itemtype`),
+  CONSTRAINT `default_branch_item_rules_ibfk_1` FOREIGN KEY (`itemtype`) REFERENCES `itemtypes` (`itemtype`)
+    ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
 --
 -- Table structure for table `default_circ_rules`
 --
index 92a1604..83d3062 100644 (file)
@@ -632,6 +632,20 @@ OPACISBDEN
     SetVersion ($DBversion);
 }  
 
+$DBversion = "3.00.04.021";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do(<<DEFAULTBRANCHRULES);
+    CREATE TABLE `default_branch_item_rules` (
+      `itemtype` varchar(10) NOT NULL,
+      `holdallowed` tinyint(1) default NULL,
+      PRIMARY KEY  (`itemtype`),
+      CONSTRAINT `default_branch_item_rules_ibfk_1` FOREIGN KEY (`itemtype`) REFERENCES `itemtypes` (`itemtype`)
+        ON DELETE CASCADE ON UPDATE CASCADE
+    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+DEFAULTBRANCHRULES
+}
+
+
 =item DropAllForeignKeys($table)
 
   Drop all foreign keys of the table $table