bug 1546 - replacing REPLACE statements
replaced REPLACE statements with a pair of INSERT and UPDATE statements. Hopefully, these are the last ones. Signed-off-by: Galen Charlton <galen.charlton@liblime.com>
This commit is contained in:
parent
bfec1aa5ae
commit
286c3c3a9e
2 changed files with 129 additions and 46 deletions
|
@ -24,7 +24,7 @@ use CGI;
|
||||||
use C4::Context;
|
use C4::Context;
|
||||||
|
|
||||||
|
|
||||||
sub StringSearch {
|
sub string_search {
|
||||||
my ($searchstring,$authtypecode)=@_;
|
my ($searchstring,$authtypecode)=@_;
|
||||||
my $dbh = C4::Context->dbh;
|
my $dbh = C4::Context->dbh;
|
||||||
$searchstring=~ s/\'/\\\'/g;
|
$searchstring=~ s/\'/\\\'/g;
|
||||||
|
@ -44,6 +44,14 @@ sub StringSearch {
|
||||||
return ($cnt,\@results);
|
return ($cnt,\@results);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub auth_subfield_structure_exists {
|
||||||
|
my ($authtypecode, $tagfield, $tagsubfield) = @_;
|
||||||
|
my $dbh = C4::Context->dbh;
|
||||||
|
my $sql = "select tagfield from auth_subfield_structure where authtypecode = ? and tagfield = ? and tagsubfield = ?";
|
||||||
|
my $rows = $dbh->selectall_arrayref($sql, {}, $authtypecode, $tagfield, $tagsubfield);
|
||||||
|
return @$rows > 0;
|
||||||
|
}
|
||||||
|
|
||||||
my $input = new CGI;
|
my $input = new CGI;
|
||||||
my $tagfield=$input->param('tagfield');
|
my $tagfield=$input->param('tagfield');
|
||||||
my $tagsubfield=$input->param('tagsubfield');
|
my $tagsubfield=$input->param('tagsubfield');
|
||||||
|
@ -384,8 +392,12 @@ if ($op eq 'add_form') {
|
||||||
} elsif ($op eq 'add_validate') {
|
} elsif ($op eq 'add_validate') {
|
||||||
my $dbh = C4::Context->dbh;
|
my $dbh = C4::Context->dbh;
|
||||||
$template->param(tagfield => "$input->param('tagfield')");
|
$template->param(tagfield => "$input->param('tagfield')");
|
||||||
my $sth=$dbh->prepare("replace auth_subfield_structure (authtypecode,tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,frameworkcode,value_builder,hidden,isurl)
|
# my $sth=$dbh->prepare("replace auth_subfield_structure (authtypecode,tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,frameworkcode,value_builder,hidden,isurl)
|
||||||
|
# values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
|
||||||
|
my $sth_insert = $dbh->prepare("insert into auth_subfield_structure (authtypecode,tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,frameworkcode,value_builder,hidden,isurl)
|
||||||
values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
|
values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
|
||||||
|
my $sth_update = $dbh->prepare("update auth_subfield_structure set authtypecode=?, tagfield=?, tagsubfield=?, liblibrarian=?, libopac=?, repeatable=?, mandatory=?, kohafield=?, tab=?, seealso=?, authorised_value=?, frameworkcode=?, value_builder=?, hidden=?, isurl=?
|
||||||
|
where authtypecode=? and tagfield=? and tagsubfield=?");
|
||||||
my @tagsubfield = $input->param('tagsubfield');
|
my @tagsubfield = $input->param('tagsubfield');
|
||||||
my @liblibrarian = $input->param('liblibrarian');
|
my @liblibrarian = $input->param('liblibrarian');
|
||||||
my @libopac = $input->param('libopac');
|
my @libopac = $input->param('libopac');
|
||||||
|
@ -418,26 +430,53 @@ if ($op eq 'add_form') {
|
||||||
my $isurl = $input->param("isurl$i")?1:0;
|
my $isurl = $input->param("isurl$i")?1:0;
|
||||||
if ($liblibrarian) {
|
if ($liblibrarian) {
|
||||||
unless (C4::Context->config('demo') eq 1) {
|
unless (C4::Context->config('demo') eq 1) {
|
||||||
$sth->execute($authtypecode,
|
if (auth_subfield_structure_exists($authtypecode, $tagfield, $tagsubfield)) {
|
||||||
$tagfield,
|
$sth_update->execute(
|
||||||
$tagsubfield,
|
$authtypecode,
|
||||||
$liblibrarian,
|
$tagfield,
|
||||||
$libopac,
|
$tagsubfield,
|
||||||
$repeatable,
|
$liblibrarian,
|
||||||
$mandatory,
|
$libopac,
|
||||||
$kohafield,
|
$repeatable,
|
||||||
$tab,
|
$mandatory,
|
||||||
$seealso,
|
$kohafield,
|
||||||
$authorised_value,
|
$tab,
|
||||||
$frameworkcode,
|
$seealso,
|
||||||
$value_builder,
|
$authorised_value,
|
||||||
$hidden,
|
$frameworkcode,
|
||||||
$isurl,
|
$value_builder,
|
||||||
);
|
$hidden,
|
||||||
|
$isurl,
|
||||||
|
(
|
||||||
|
$authtypecode,
|
||||||
|
$tagfield,
|
||||||
|
$tagsubfield
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$sth_insert->execute(
|
||||||
|
$authtypecode,
|
||||||
|
$tagfield,
|
||||||
|
$tagsubfield,
|
||||||
|
$liblibrarian,
|
||||||
|
$libopac,
|
||||||
|
$repeatable,
|
||||||
|
$mandatory,
|
||||||
|
$kohafield,
|
||||||
|
$tab,
|
||||||
|
$seealso,
|
||||||
|
$authorised_value,
|
||||||
|
$frameworkcode,
|
||||||
|
$value_builder,
|
||||||
|
$hidden,
|
||||||
|
$isurl,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$sth->finish;
|
$sth_insert->finish;
|
||||||
|
$sth_update->finish;
|
||||||
print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode\"></html>";
|
print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode\"></html>";
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
|
@ -473,7 +512,7 @@ if ($op eq 'add_form') {
|
||||||
# END $OP eq DELETE_CONFIRMED
|
# END $OP eq DELETE_CONFIRMED
|
||||||
################## DEFAULT ##################################
|
################## DEFAULT ##################################
|
||||||
} else { # DEFAULT
|
} else { # DEFAULT
|
||||||
my ($count,$results)=StringSearch($tagfield,$authtypecode);
|
my ($count,$results)=string_search($tagfield,$authtypecode);
|
||||||
my $toggle=1;
|
my $toggle=1;
|
||||||
my @loop_data = ();
|
my @loop_data = ();
|
||||||
for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
|
for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
|
||||||
|
|
|
@ -24,7 +24,7 @@ use CGI;
|
||||||
use C4::Context;
|
use C4::Context;
|
||||||
|
|
||||||
|
|
||||||
sub StringSearch {
|
sub string_search {
|
||||||
my ( $searchstring, $frameworkcode ) = @_;
|
my ( $searchstring, $frameworkcode ) = @_;
|
||||||
my $dbh = C4::Context->dbh;
|
my $dbh = C4::Context->dbh;
|
||||||
$searchstring =~ s/\'/\\\'/g;
|
$searchstring =~ s/\'/\\\'/g;
|
||||||
|
@ -49,6 +49,14 @@ sub StringSearch {
|
||||||
return ( $cnt, \@results );
|
return ( $cnt, \@results );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub marc_subfield_structure_exists {
|
||||||
|
my ($tagfield, $tagsubfield, $frameworkcode) = @_;
|
||||||
|
my $dbh = C4::Context->dbh;
|
||||||
|
my $sql = "select tagfield from marc_subfield_structure where tagfield = ? and tagsubfield = ? and frameworkcode = ?";
|
||||||
|
my $rows = $dbh->selectall_arrayref($sql, {}, $tagfield, $tagsubfield, $frameworkcode);
|
||||||
|
return @$rows > 0;
|
||||||
|
}
|
||||||
|
|
||||||
my $input = new CGI;
|
my $input = new CGI;
|
||||||
my $tagfield = $input->param('tagfield');
|
my $tagfield = $input->param('tagfield');
|
||||||
my $tagsubfield = $input->param('tagsubfield');
|
my $tagsubfield = $input->param('tagsubfield');
|
||||||
|
@ -382,10 +390,18 @@ if ( $op eq 'add_form' ) {
|
||||||
elsif ( $op eq 'add_validate' ) {
|
elsif ( $op eq 'add_validate' ) {
|
||||||
my $dbh = C4::Context->dbh;
|
my $dbh = C4::Context->dbh;
|
||||||
$template->param( tagfield => "$input->param('tagfield')" );
|
$template->param( tagfield => "$input->param('tagfield')" );
|
||||||
my $sth = $dbh->prepare(
|
# my $sth = $dbh->prepare(
|
||||||
"replace marc_subfield_structure (tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,authtypecode,value_builder,hidden,isurl,frameworkcode, link,defaultvalue)
|
# "replace marc_subfield_structure (tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,authtypecode,value_builder,hidden,isurl,frameworkcode, link,defaultvalue)
|
||||||
values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
|
# values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
|
||||||
);
|
# );
|
||||||
|
my $sth_insert = $dbh->prepare(qq{
|
||||||
|
insert into marc_subfield_structure (tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,authtypecode,value_builder,hidden,isurl,frameworkcode, link,defaultvalue)
|
||||||
|
values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
|
||||||
|
});
|
||||||
|
my $sth_update = $dbh->prepare(qq{
|
||||||
|
update marc_subfield_structure set tagfield=?, tagsubfield=?, liblibrarian=?, libopac=?, repeatable=?, mandatory=?, kohafield=?, tab=?, seealso=?, authorised_value=?, authtypecode=?, value_builder=?, hidden=?, isurl=?, frameworkcode=?, link=?, defaultvalue=?
|
||||||
|
where tagfield=? and tagsubfield=? and frameworkcode=?
|
||||||
|
});
|
||||||
my @tagsubfield = $input->param('tagsubfield');
|
my @tagsubfield = $input->param('tagsubfield');
|
||||||
my @liblibrarian = $input->param('liblibrarian');
|
my @liblibrarian = $input->param('liblibrarian');
|
||||||
my @libopac = $input->param('libopac');
|
my @libopac = $input->param('libopac');
|
||||||
|
@ -421,29 +437,57 @@ elsif ( $op eq 'add_validate' ) {
|
||||||
|
|
||||||
if ($liblibrarian) {
|
if ($liblibrarian) {
|
||||||
unless ( C4::Context->config('demo') eq 1 ) {
|
unless ( C4::Context->config('demo') eq 1 ) {
|
||||||
$sth->execute(
|
if (marc_subfield_structure_exists($tagfield, $tagsubfield, $frameworkcode)) {
|
||||||
$tagfield,
|
$sth_update->execute(
|
||||||
$tagsubfield,
|
$tagfield,
|
||||||
$liblibrarian,
|
$tagsubfield,
|
||||||
$libopac,
|
$liblibrarian,
|
||||||
$repeatable,
|
$libopac,
|
||||||
$mandatory,
|
$repeatable,
|
||||||
$kohafield,
|
$mandatory,
|
||||||
$tab,
|
$kohafield,
|
||||||
$seealso,
|
$tab,
|
||||||
$authorised_value,
|
$seealso,
|
||||||
$authtypecode,
|
$authorised_value,
|
||||||
$value_builder,
|
$authtypecode,
|
||||||
$hidden,
|
$value_builder,
|
||||||
$isurl,
|
$hidden,
|
||||||
$frameworkcode,
|
$isurl,
|
||||||
$link,
|
$frameworkcode,
|
||||||
$defaultvalue,
|
$link,
|
||||||
);
|
$defaultvalue,
|
||||||
|
(
|
||||||
|
$tagfield,
|
||||||
|
$tagsubfield,
|
||||||
|
$frameworkcode,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$sth_insert->execute(
|
||||||
|
$tagfield,
|
||||||
|
$tagsubfield,
|
||||||
|
$liblibrarian,
|
||||||
|
$libopac,
|
||||||
|
$repeatable,
|
||||||
|
$mandatory,
|
||||||
|
$kohafield,
|
||||||
|
$tab,
|
||||||
|
$seealso,
|
||||||
|
$authorised_value,
|
||||||
|
$authtypecode,
|
||||||
|
$value_builder,
|
||||||
|
$hidden,
|
||||||
|
$isurl,
|
||||||
|
$frameworkcode,
|
||||||
|
$link,
|
||||||
|
$defaultvalue,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$sth->finish;
|
$sth_insert->finish;
|
||||||
|
$sth_update->finish;
|
||||||
print
|
print
|
||||||
"Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=marc_subfields_structure.pl?tagfield=$tagfield&frameworkcode=$frameworkcode\"></html>";
|
"Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=marc_subfields_structure.pl?tagfield=$tagfield&frameworkcode=$frameworkcode\"></html>";
|
||||||
exit;
|
exit;
|
||||||
|
@ -494,7 +538,7 @@ elsif ( $op eq 'delete_confirmed' ) {
|
||||||
################## DEFAULT ##################################
|
################## DEFAULT ##################################
|
||||||
}
|
}
|
||||||
else { # DEFAULT
|
else { # DEFAULT
|
||||||
my ( $count, $results ) = StringSearch( $tagfield, $frameworkcode );
|
my ( $count, $results ) = string_search( $tagfield, $frameworkcode );
|
||||||
my $toggle = 1;
|
my $toggle = 1;
|
||||||
my @loop_data = ();
|
my @loop_data = ();
|
||||||
for (
|
for (
|
||||||
|
|
Loading…
Reference in a new issue