File Coverage

File:C4/Maintainance.pm
Coverage:17.7%

linestmtbrancondsubtimecode
1package C4::Maintainance; #assumes C4/Maintainance
2
3#package to deal with marking up output
4
5
6# Copyright 2000-2002 Katipo Communications
7#
8# This file is part of Koha.
9#
10# Koha is free software; you can redistribute it and/or modify it under the
11# terms of the GNU General Public License as published by the Free Software
12# Foundation; either version 2 of the License, or (at your option) any later
13# version.
14#
15# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License along
20# with Koha; if not, write to the Free Software Foundation, Inc.,
21# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22
23
3
3
3
25214
20
113
use strict;
24#use warnings; FIXME - Bug 2505
25
3
3
3
263
6
27
use C4::Context;
26
27require Exporter;
28
29
3
3
3
13
4
2162
use vars qw($VERSION @ISA @EXPORT);
30
31# set the version for version checking
32$VERSION = 0.01;
33
34 - 50
=head1 NAME

C4::Maintenance - Koha catalog maintenance functions

=head1 SYNOPSIS

  use C4::Maintenance;

=head1 DESCRIPTION

The functions in this module perform various catalog-maintenance
functions, including deleting and undeleting books, fixing
miscategorized items, etc.

=head1 FUNCTIONS

=cut
51
52@ISA = qw(Exporter);
53@EXPORT = qw(&listsubjects &shiftgroup &deletedbib &undeletebib
54&updatetype &logaction);
55
56 - 74
=head2 listsubjects

  ($count, $results) = &listsubjects($subject, $n, $offset);

Finds the subjects that begin with C<$subject> in the bibliosubject
table of the Koha database.

C<&listsubjects> returns a two-element array. C<$results> is a
reference-to-array, in which each element is a reference-to-hash
giving information about the given subject. C<$count> is the number of
elements in C<@{$results}>.

Probably the only interesting field in C<$results->[$i]> is
C<subject>, the subject in question.

C<&listsubject> returns up to C<$n> items, starting at C<$offset>. If
C<$n> is 0, it will return all matching subjects.

=cut
75
76#'
77# FIXME - This API is bogus. The way it's currently used, it should
78# just return a list of strings.
79sub listsubjects {
80
0
  my ($sub,$num,$offset)=@_;
81
0
  my $dbh = C4::Context->dbh;
82
0
  my $query="Select * from bibliosubject where subject like ? group by subject";
83
0
  my @bind = ("$sub%");
84  # FIXME - Make $num and $offset optional.
85  # If $num was given, make sure $offset was, too.
86
0
  if ($num != 0){
87
0
    $query.=" limit ?,?";
88
0
    push(@bind,$offset,$num);
89  }
90
0
  my $sth=$dbh->prepare($query);
91# print $query;
92
0
  $sth->execute(@bind);
93
0
  my @results;
94
0
  my $i=0;
95
0
  while (my $data=$sth->fetchrow_hashref){
96
0
    $results[$i]=$data;
97
0
    $i++;
98  }
99
0
  $sth->finish;
100
0
  return($i,\@results);
101}
102
103 - 111
=head2 shiftgroup

  &shiftgroup($biblionumber, $biblioitemnumber);

Changes the biblionumber associated with a given biblioitem.
C<$biblioitemnumber> is the number of the biblioitem to change.
C<$biblionumber> is the biblionumber to associate it with.

=cut
112
113#'
114sub shiftgroup{
115
0
  my ($biblionumber,$bi)=@_;
116
0
  my $dbh = C4::Context->dbh;
117
0
  my $sth=$dbh->prepare("update biblioitems set biblionumber=? where biblioitemnumber=?");
118
0
  $sth->execute($biblionumber,$bi);
119
0
  $sth->finish;
120
0
  $sth=$dbh->prepare("update items set biblionumber=? where biblioitemnumber=?");
121
0
  $sth->execute($biblionumber,$bi);
122
0
  $sth->finish;
123}
124
125 - 136
=head2 deletedbib

  ($count, $results) = &deletedbib($title);

Looks up deleted books whose title begins with C<$title>.

C<&deletedbib> returns a two-element list. C<$results> is a
reference-to-array; each element is a reference-to-hash whose keys are
the fields of the deletedbiblio table in the Koha database. C<$count>
is the number of elements in C<$results>.

=cut
137
138#'
139sub deletedbib{
140
0
  my ($title)=@_;
141
0
  my $dbh = C4::Context->dbh;
142
0
  my $sth=$dbh->prepare("Select * from deletedbiblio where title like ? order by title");
143
0
  $sth->execute("$title%");
144
0
  my @results;
145
0
  my $i=0;
146
0
  while (my $data=$sth->fetchrow_hashref){
147
0
    $results[$i]=$data;
148
0
    $i++;
149  }
150
0
  $sth->finish;
151
0
  return($i,\@results);
152}
153
154 - 162
=head2 undeletebib

  &undeletebib($biblionumber);

Undeletes a book. C<&undeletebib> looks up the book with the given
biblionumber in the deletedbiblio table of the Koha database, and
moves its entry to the biblio table.

=cut
163
164#'
165sub undeletebib{
166
0
  my ($biblionumber)=@_;
167
0
  my $dbh = C4::Context->dbh;
168
0
  my $sth=$dbh->prepare("select * from deletedbiblio where biblionumber=?");
169
0
  $sth->execute($biblionumber);
170
0
  if (my @data=$sth->fetchrow_array){
171
0
    $sth->finish;
172    # FIXME - Doesn't this keep the same biblionumber? Isn't this
173    # forbidden by the definition of 'biblio'? Or doesn't it matter?
174
0
    my $query="INSERT INTO biblio VALUES (";
175
0
   my $count = @data;
176
0
    $query .= ("?," x $count);
177
0
    $query=~ s/\,$/\)/;
178    # print $query;
179
0
    $sth=$dbh->prepare($query);
180
0
    $sth->execute(@data);
181
0
    $sth->finish;
182  }
183
0
  $sth=$dbh->prepare("DELETE FROM deletedbiblio WHERE biblionumber=?");
184
0
  $sth->execute($biblionumber);
185
0
  $sth->finish;
186}
187
188 - 195
=head2 updatetype

  &updatetype($biblioitemnumber, $itemtype);

Changes the type of the item with the given biblioitemnumber to be
C<$itemtype>.

=cut
196
197#'
198sub updatetype{
199
0
  my ($bi,$type)=@_;
200
0
  my $dbh = C4::Context->dbh;
201
0
  my $sth=$dbh->prepare("Update biblioitems set itemtype=? where biblioitemnumber=?");
202
0
  $sth->execute($type,$bi);
203
0
  $sth->finish;
204}
205
206
3
320518
END { } # module clean-up code here (global destructor)
207
2081;