Bug 21617: DBRev 18.06.00.042
[koha_ffzg] / installer / data / mysql / updatedatabase.pl
index 49b6f33..692604d 100755 (executable)
@@ -16453,6 +16453,231 @@ if( CheckVersion( $DBversion ) ) {
     print "Upgrade to $DBversion done (Bug 5458: length of items.ccode disagrees with authorised_values.authorised_value)\n";
 }
 
+$DBversion = '18.06.00.033';
+if( CheckVersion( $DBversion ) ) {
+    $dbh->do(q|
+        INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES ('AdditionalFieldsInZ3950ResultSearch', '', 'NULL', 'Determines which MARC field/subfields are displayed in -Additional field- column in the result of a search Z3950', 'Free')
+    |);
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 12747 - Add AdditionalFieldsInZ3950ResultSearch system preference)\n";
+}
+
+$DBversion = '18.06.00.034';
+if( CheckVersion( $DBversion ) ) {
+    $dbh->do(q|
+        INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type)
+        VALUES ('RecordedBooksClientSecret','','30','Client key for RecordedBooks integration','YesNo'),
+               ('RecordedBooksLibraryID','','','Library ID for RecordedBooks integration','Integer'),
+               ('RecordedBooksDomain','','','RecordedBooks domain','Free');
+    |);
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 17602 - Integrate support for OneClickdigital/Recorded Books API)\n";
+}
+
+$DBversion = '18.06.00.035';
+if( CheckVersion( $DBversion ) ) {
+    $dbh->do(q{
+        UPDATE `systempreferences` SET options = 'US|CA|DE|FR|IN|JP|UK' WHERE variable = 'AmazonLocale' AND options='US|CA|DE|FR|JP|UK';
+    });
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 21403 - Add Indian Amazon Affiliate option to AmazonLocale setting)\n";
+}
+
+
+$DBversion = '18.06.00.036';
+if( CheckVersion( $DBversion ) ) {
+    unless (TableExists('circulation_rules')){
+        $dbh->do(q{
+            CREATE TABLE `circulation_rules` (
+              `id` int(11) NOT NULL auto_increment,
+              `branchcode` varchar(10) NULL default NULL,
+              `categorycode` varchar(10) NULL default NULL,
+              `itemtype` varchar(10) NULL default NULL,
+              `rule_name` varchar(32) NOT NULL,
+              `rule_value` varchar(32) NOT NULL,
+              PRIMARY KEY (`id`),
+              CONSTRAINT `circ_rules_ibfk_1` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE,
+              CONSTRAINT `circ_rules_ibfk_2` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`) ON DELETE CASCADE ON UPDATE CASCADE,
+              CONSTRAINT `circ_rules_ibfk_3` FOREIGN KEY (`itemtype`) REFERENCES `itemtypes` (`itemtype`) ON DELETE CASCADE ON UPDATE CASCADE,
+              KEY `rule_name` (`rule_name`),
+              UNIQUE (`branchcode`,`categorycode`,`itemtype`,`rule_name`)
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+        });
+    }
+    if (column_exists('branch_borrower_circ_rules', 'max_holds') ){
+        $dbh->do(q{
+            INSERT IGNORE INTO circulation_rules ( branchcode, categorycode, itemtype, rule_name, rule_value )
+            SELECT branchcode, categorycode, NULL, 'max_holds', COALESCE( max_holds, '' ) FROM branch_borrower_circ_rules
+        });
+        $dbh->do(q{
+            ALTER TABLE branch_borrower_circ_rules DROP COLUMN max_holds
+        });
+    }
+    if (column_exists('default_borrower_circ_rules', 'max_holds') ){
+        $dbh->do(q{
+            INSERT IGNORE INTO circulation_rules ( branchcode, categorycode, itemtype, rule_name, rule_value )
+            SELECT NULL, categorycode, NULL, 'max_holds', COALESCE( max_holds, '' ) FROM default_borrower_circ_rules
+        });
+        $dbh->do(q{
+            ALTER TABLE default_borrower_circ_rules DROP COLUMN max_holds
+        });
+    }
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 18887 - Introduce new table 'circulation_rules', use for 'max_holds' rules)\n";
+}
+
+$DBversion = '18.06.00.037';
+if( CheckVersion( $DBversion ) ) {
+    unless (TableExists('branches_overdrive')){
+        $dbh->do( q|
+            CREATE TABLE IF NOT EXISTS branches_overdrive (
+                `branchcode` VARCHAR( 10 ) NOT NULL ,
+                `authname` VARCHAR( 255 ) NOT NULL ,
+                PRIMARY KEY (`branchcode`) ,
+                CONSTRAINT `branches_overdrive_ibfk_1` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE
+            ) ENGINE = INNODB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci |
+        );
+    }
+    $dbh->do("INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES ('OverDriveAuthname', '', 'Authname for OverDrive Patron Authentication, will be used as fallback if individual branch authname not set', NULL, 'Free');");
+    $dbh->do("INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES ('OverDriveWebsiteID','', 'WebsiteID provided by OverDrive', NULL, 'Free');");
+    $dbh->do("INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES ('OverDrivePasswordRequired','', 'Does the library require passwords for OverDrive SIP authentication', NULL, 'YesNo');");
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 21082 - Add overdrive patron auth method)\n";
+}
+
+$DBversion = '18.06.00.038';
+if( CheckVersion( $DBversion ) ) {
+    $dbh->do( "ALTER TABLE edifact_ean MODIFY branchcode VARCHAR(10) NULL DEFAULT NULL" );
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 21417 - EDI ordering fails when basket and EAN libraries do not match)\n";
+}
+
+$DBversion = '18.06.00.039';
+if( CheckVersion( $DBversion ) ) {
+    $dbh->do(q{
+        INSERT IGNORE INTO `permissions` (module_bit, code, description) VALUES(3, 'manage_circ_rules_from_any_libraries', 'Manage circ rules for any libraries');
+    });
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 15520 - Add more granular permission for only editing own library's circ rules)\n";
+}
+
+$DBversion = '18.06.00.040';
+if( CheckVersion( $DBversion ) ) {
+    # Stock Rotation Rotas
+    unless (TableExists('stockrotationrotas')){
+        $dbh->do(q{
+          CREATE TABLE `stockrotationrotas` (
+            `rota_id` int(11) auto_increment,         -- Stockrotation rota ID
+            `title` varchar(100) NOT NULL,            -- Title for this rota
+            `description` text NOT NULL default '',   -- Description for this rota
+            `cyclical` tinyint(1) NOT NULL default 0, -- Should items on this rota keep cycling?
+            `active` tinyint(1) NOT NULL default 0,   -- Is this rota currently active?
+            PRIMARY KEY (`rota_id`),
+            CONSTRAINT `stockrotationrotas_title`
+            UNIQUE (`title`)
+          ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+        });
+    }
+    # Stock Rotation Stages
+    unless (TableExists('stockrotationstages')){
+        $dbh->do(q{
+          CREATE TABLE `stockrotationstages` (
+              `stage_id` int(11) auto_increment,     -- Unique stage ID
+              `position` int(11) NOT NULL,           -- The position of this stage within its rota
+              `rota_id` int(11) NOT NULL,            -- The rota this stage belongs to
+              `branchcode_id` varchar(10) NOT NULL,  -- Branch this stage relates to
+              `duration` int(11) NOT NULL default 4, -- The number of days items shoud occupy this stage
+              PRIMARY KEY (`stage_id`),
+              CONSTRAINT `stockrotationstages_rifk`
+                FOREIGN KEY (`rota_id`)
+                REFERENCES `stockrotationrotas` (`rota_id`)
+                ON UPDATE CASCADE ON DELETE CASCADE,
+              CONSTRAINT `stockrotationstages_bifk`
+                FOREIGN KEY (`branchcode_id`)
+                REFERENCES `branches` (`branchcode`)
+                ON UPDATE CASCADE ON DELETE CASCADE
+          ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+        });
+    }
+    # Stock Rotation Items
+    unless (TableExists('stockrotationitems')){
+        $dbh->do(q{
+          CREATE TABLE `stockrotationitems` (
+              `itemnumber_id` int(11) NOT NULL,         -- Itemnumber to link to a stage & rota
+              `stage_id` int(11) NOT NULL,              -- stage ID to link the item to
+              `indemand` tinyint(1) NOT NULL default 0, -- Should this item be skipped for rotation?
+              `fresh` tinyint(1) NOT NULL default 0,    -- Flag showing item is only just added to rota
+              PRIMARY KEY (itemnumber_id),
+              CONSTRAINT `stockrotationitems_iifk`
+                FOREIGN KEY (`itemnumber_id`)
+                REFERENCES `items` (`itemnumber`)
+                ON UPDATE CASCADE ON DELETE CASCADE,
+              CONSTRAINT `stockrotationitems_sifk`
+                FOREIGN KEY (`stage_id`)
+                REFERENCES `stockrotationstages` (`stage_id`)
+                ON UPDATE CASCADE ON DELETE CASCADE
+          ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+        });
+    }
+    # System preferences
+    $dbh->do(q{
+        INSERT IGNORE INTO `systempreferences` (`variable`,`value`,`explanation`,`options`,`type`)
+        VALUES ('StockRotation','0','If ON, enables the stock rotation module','','YesNo'),
+               ('RotationPreventTransfers','0','If ON, prevent any transfers for items on stock rotation rotas, except for stock rotation transfers','','YesNo');
+    });
+    # Permissions
+    $dbh->do(q{
+        INSERT IGNORE INTO `userflags` (`bit`, `flag`, `flagdesc`, `defaulton`)
+        VALUES (24, 'stockrotation', 'Manage stockrotation operations', 0);
+    });
+    $dbh->do(q{
+        INSERT IGNORE INTO `permissions` (`module_bit`, `code`, `description`)
+        VALUES (24, 'manage_rotas', 'Create, edit and delete rotas'),
+               (24, 'manage_rota_items', 'Add and remove items from rotas');
+    });
+    # Notices
+    $dbh->do(q{
+        INSERT IGNORE INTO `letter` (`module`, `code`, `branchcode`, `name`, `is_html`, `title`, `content`, `message_transport_type`)
+        VALUES ('circulation', 'SR_SLIP', '', 'Stock Rotation Slip', 0, 'Stockrotation Report', 'Stockrotation report for [% branch.name %]:\r\n\r\n[% IF branch.items.size %][% branch.items.size %] items to be processed for this branch.\r\n[% ELSE %]No items to be processed for this branch\r\n[% END %][% FOREACH item IN branch.items %][% IF item.reason ne \'in-demand\' %]Title: [% item.title %]\r\nAuthor: [% item.author %]\r\nCallnumber: [% item.callnumber %]\r\nLocation: [% item.location %]\r\nBarcode: [% item.barcode %]\r\nOn loan?: [% item.onloan %]\r\nStatus: [% item.reason %]\r\nCurrent Library: [% item.branch.branchname %] [% item.branch.branchcode %]\r\n\r\n[% END %][% END %]', 'email');
+    });
+    print "Upgrade to $DBversion done (Bug 11897 - Add Stock Rotation Feature)\n";
+    SetVersion( $DBversion );
+}
+
+$DBversion = '18.06.00.041';
+if( CheckVersion( $DBversion ) ) {
+
+     if( !column_exists( 'illrequests', 'price_paid' ) ) {
+        $dbh->do(q{
+            ALTER TABLE illrequests
+                ADD COLUMN price_paid varchar(20) DEFAULT NULL
+                AFTER cost
+        });
+     }
+
+     if( !column_exists( 'illrequestattributes', 'readonly' ) ) {
+        $dbh->do(q{
+            ALTER TABLE illrequestattributes
+                ADD COLUMN readonly tinyint(1) NOT NULL DEFAULT 1
+                AFTER value
+        });
+        $dbh->do(q{
+            UPDATE illrequestattributes SET readonly = 1
+        });
+     }
+
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 20772 - Add illrequestattributes.readonly and illrequest.price_paid columns)\n";
+}
+
+$DBversion = '18.06.00.042';
+if( CheckVersion( $DBversion ) ) {
+    $dbh->do( "alter table statistics change column ccode ccode varchar(80) default NULL" );
+
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 21617: Make statistics.ccode longer)\n";
+}
+
 # SEE bug 13068
 # if there is anything in the atomicupdate, read and execute it.