Bug 13068: (QA followup) Remove old files, use C4::Installer

* moving oai-sets.sql from atomicupdate to updatedatabase itself
 * using Installer file loader to load & execute SQL file

Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
This commit is contained in:
Paul Poulain 2015-03-06 17:06:05 +01:00 committed by Tomas Cohen Arazi
parent 7a7cca1649
commit 24ec14716f
2 changed files with 41 additions and 42 deletions

View file

@ -1,35 +0,0 @@
DROP TABLE IF EXISTS `oai_sets_descriptions`;
DROP TABLE IF EXISTS `oai_sets_mappings`;
DROP TABLE IF EXISTS `oai_sets_biblios`;
DROP TABLE IF EXISTS `oai_sets`;
CREATE TABLE `oai_sets` (
`id` int(11) NOT NULL auto_increment,
`spec` varchar(80) NOT NULL UNIQUE,
`name` varchar(80) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `oai_sets_descriptions` (
`set_id` int(11) NOT NULL,
`description` varchar(255) NOT NULL,
CONSTRAINT `oai_sets_descriptions_ibfk_1` FOREIGN KEY (`set_id`) REFERENCES `oai_sets` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `oai_sets_mappings` (
`set_id` int(11) NOT NULL,
`marcfield` char(3) NOT NULL,
`marcsubfield` char(1) NOT NULL,
`marcvalue` varchar(80) NOT NULL,
CONSTRAINT `oai_sets_mappings_ibfk_1` FOREIGN KEY (`set_id`) REFERENCES `oai_sets` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `oai_sets_biblios` (
`biblionumber` int(11) NOT NULL,
`set_id` int(11) NOT NULL,
PRIMARY KEY (`biblionumber`, `set_id`),
CONSTRAINT `oai_sets_biblios_ibfk_1` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `oai_sets_biblios_ibfk_2` FOREIGN KEY (`set_id`) REFERENCES `oai_sets` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('OAI-PMH:AutoUpdateSets','0','Automatically update OAI sets when a bibliographic record is created or updated','','YesNo');

View file

@ -4942,10 +4942,44 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
$DBversion = "3.07.00.029";
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
my $installer = C4::Installer->new();
my $full_path = C4::Context->config('intranetdir') . "/installer/data/$installer->{dbms}/atomicupdate/oai_sets.sql";
my $error = $installer->load_sql($full_path);
warn $error if $error;
$dbh->do(qq{
DROP TABLE IF EXISTS `oai_sets_descriptions`;
DROP TABLE IF EXISTS `oai_sets_mappings`;
DROP TABLE IF EXISTS `oai_sets_biblios`;
DROP TABLE IF EXISTS `oai_sets`;
CREATE TABLE `oai_sets` (
`id` int(11) NOT NULL auto_increment,
`spec` varchar(80) NOT NULL UNIQUE,
`name` varchar(80) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `oai_sets_descriptions` (
`set_id` int(11) NOT NULL,
`description` varchar(255) NOT NULL,
CONSTRAINT `oai_sets_descriptions_ibfk_1` FOREIGN KEY (`set_id`) REFERENCES `oai_sets` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `oai_sets_mappings` (
`set_id` int(11) NOT NULL,
`marcfield` char(3) NOT NULL,
`marcsubfield` char(1) NOT NULL,
`marcvalue` varchar(80) NOT NULL,
CONSTRAINT `oai_sets_mappings_ibfk_1` FOREIGN KEY (`set_id`) REFERENCES `oai_sets` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `oai_sets_biblios` (
`biblionumber` int(11) NOT NULL,
`set_id` int(11) NOT NULL,
PRIMARY KEY (`biblionumber`, `set_id`),
CONSTRAINT `oai_sets_biblios_ibfk_1` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `oai_sets_biblios_ibfk_2` FOREIGN KEY (`set_id`) REFERENCES `oai_sets` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('OAI-PMH:AutoUpdateSets','0','Automatically update OAI sets when a bibliographic record is created or updated','','YesNo');
});
print "Upgrade to $DBversion done (Atomic update for OAI-PMH sets management)\n";
SetVersion($DBversion);
}
@ -9912,9 +9946,9 @@ my $old_delimiter = $/;
$/ = ';';
while (readdir $dirh) {
next unless $_ =~ /\.sql$/; # skip non SQL files
print "DEV atomic update : $_ \n";
my $installer = C4::Installer->new();
$rv = $installer->load_sql( $atomicupd->{location}. "/$file" )? 0: 1;
#Note: load_sql already warns
my $rv = $installer->load_sql( C4::Context->config('intranetdir') . '/installer/data/mysql/atomicupdate/' . $_ )? 0: 1;
}