Bugzilla – Attachment 8672 Details for
Bug 7178
Improve order item creation
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Follow-up Improve order item creation
0001-Bug-7178-Follow-up-Improve-order-item-creation.patch (text/plain), 3.03 KB, created by
Julian Maurice
on 2012-03-28 15:05:01 UTC
(
hide
)
Description:
Follow-up Improve order item creation
Filename:
MIME Type:
Creator:
Julian Maurice
Created:
2012-03-28 15:05:01 UTC
Size:
3.03 KB
patch
obsolete
>From 1c24a6c3d22fb00ea98d8fa00d04aed3f5e96c27 Mon Sep 17 00:00:00 2001 >From: Julian Maurice <julian.maurice@biblibre.com> >Date: Wed, 28 Mar 2012 17:01:07 +0200 >Subject: [PATCH] Bug 7178: Follow-up Improve order item creation > >Move SQL code from Perl script to Perl module >Replace SHOW COLUMNS by $dbh->column_info() >--- > C4/Items.pm | 38 ++++++++++++++++++++++++++++++++++++++ > acqui/check_uniqueness.pl | 27 ++++++--------------------- > 2 files changed, 44 insertions(+), 21 deletions(-) > >diff --git a/C4/Items.pm b/C4/Items.pm >index facd91f..e9fdcd7 100644 >--- a/C4/Items.pm >+++ b/C4/Items.pm >@@ -80,6 +80,7 @@ BEGIN { > GetAnalyticsCount > GetItemHolds > >+ SearchItems > > PrepareItemrecordDisplay > >@@ -2493,6 +2494,43 @@ sub GetItemHolds { > $holds = $sth->fetchrow; > return $holds; > } >+ >+# Return the list of the column names of items table >+sub _get_items_columns { >+ my $dbh = C4::Context->dbh; >+ my $sth = $dbh->column_info(undef, undef, 'items', '%'); >+ $sth->execute; >+ my $results = $sth->fetchall_hashref('COLUMN_NAME'); >+ return keys %$results; >+} >+ >+=head2 SearchItems >+ >+ my $items = SearchItems($field, $value); >+ >+SearchItems will search for items on a specific given field. >+For instance you can search all items with a specific stocknumber like this: >+ >+ my $items = SearchItems('stocknumber', $stocknumber); >+ >+=cut >+ >+sub SearchItems { >+ my ($field, $value) = @_; >+ >+ my $dbh = C4::Context->dbh; >+ my @columns = _get_items_columns; >+ my $results = []; >+ if(0 < grep /^$field$/, @columns) { >+ my $query = "SELECT $field FROM items WHERE $field = ?"; >+ my $sth = $dbh->prepare( $query ); >+ $sth->execute( $value ); >+ $results = $sth->fetchall_arrayref({}); >+ } >+ return $results; >+} >+ >+ > =head1 OTHER FUNCTIONS > > =head2 _find_value >diff --git a/acqui/check_uniqueness.pl b/acqui/check_uniqueness.pl >index 95b1992..6260048 100755 >--- a/acqui/check_uniqueness.pl >+++ b/acqui/check_uniqueness.pl >@@ -33,36 +33,21 @@ use Modern::Perl; > > use CGI; > use JSON; >-use C4::Context; > use C4::Output; >-use C4::Auth; >+use C4::Items; > > my $input = new CGI; > my @field = $input->param('field'); > my @value = $input->param('value'); > >-my $dbh = C4::Context->dbh; >- >-my $query = "SHOW COLUMNS FROM items"; >-my $sth = $dbh->prepare($query); >-$sth->execute; >-my $results = $sth->fetchall_hashref('Field'); >-my @columns = keys %$results; >- > my $r = {}; >-my $index = 0; >-for my $f ( @field ) { >- if(0 < grep /^$f$/, @columns) { >- $query = "SELECT $f FROM items WHERE $f = ?"; >- $sth = $dbh->prepare( $query ); >- $sth->execute( $value[$index] ); >- my @values = $sth->fetchrow_array; >+my $i = 0; >+for ( my $i=0; $i<@field; $i++ ) { >+ my $items = C4::Items::SearchItems($field[$i], $value[$i]); > >- if ( @values ) { >- push @{ $r->{$f} }, $values[0]; >- } >+ if ( @$items ) { >+ push @{ $r->{$field[$i]} }, $value[$i]; > } >- $index++; > } > > output_with_http_headers $input, undef, to_json($r), 'json'; >-- >1.7.9.1 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 7178
:
6233
|
7249
|
7279
|
7450
|
7806
|
7807
|
7892
|
7963
|
8558
|
8672
|
8715
|
8857
|
8886
|
9511
|
9518
|
9690