View | Details | Raw Unified | Return to bug 12456
Collapse All | Expand All

(-)a/C4/Maintainance.pm (-215 lines)
Lines 1-215 Link Here
1
package 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
use strict;
24
#use warnings; FIXME - Bug 2505
25
use C4::Context;
26
27
require Exporter;
28
29
use vars qw($VERSION @ISA @EXPORT);
30
31
# set the version for version checking
32
$VERSION = 3.07.00.049;
33
34
=head1 NAME
35
36
C4::Maintenance - Koha catalog maintenance functions
37
38
=head1 SYNOPSIS
39
40
  use C4::Maintenance;
41
42
=head1 DESCRIPTION
43
44
The functions in this module perform various catalog-maintenance
45
functions, including deleting and undeleting books, fixing
46
miscategorized items, etc.
47
48
=head1 FUNCTIONS
49
50
=cut
51
52
@ISA = qw(Exporter);
53
@EXPORT = qw(&listsubjects &shiftgroup &deletedbib &undeletebib
54
&updatetype &logaction);
55
56
=head2 listsubjects
57
58
  ($count, $results) = &listsubjects($subject, $n, $offset);
59
60
Finds the subjects that begin with C<$subject> in the bibliosubject
61
table of the Koha database.
62
63
C<&listsubjects> returns a two-element array. C<$results> is a
64
reference-to-array, in which each element is a reference-to-hash
65
giving information about the given subject. C<$count> is the number of
66
elements in C<@{$results}>.
67
68
Probably the only interesting field in C<$results->[$i]> is
69
C<subject>, the subject in question.
70
71
C<&listsubject> returns up to C<$n> items, starting at C<$offset>. If
72
C<$n> is 0, it will return all matching subjects.
73
74
=cut
75
76
#'
77
# FIXME - This API is bogus. The way it's currently used, it should
78
# just return a list of strings.
79
sub listsubjects {
80
  my ($sub,$num,$offset)=@_;
81
  my $dbh = C4::Context->dbh;
82
  my $query="Select * from bibliosubject where subject like ? group by subject";
83
  my @bind = ("$sub%");
84
  # FIXME - Make $num and $offset optional.
85
  # If $num was given, make sure $offset was, too.
86
  if ($num != 0){
87
    $query.=" limit ?,?";
88
    push(@bind,$offset,$num);
89
  }
90
  my $sth=$dbh->prepare($query);
91
#  print $query;
92
  $sth->execute(@bind);
93
  my @results;
94
  my $i=0;
95
  while (my $data=$sth->fetchrow_hashref){
96
    $results[$i]=$data;
97
    $i++;
98
  }
99
  $sth->finish;
100
  return($i,\@results);
101
}
102
103
=head2 shiftgroup
104
105
  &shiftgroup($biblionumber, $biblioitemnumber);
106
107
Changes the biblionumber associated with a given biblioitem.
108
C<$biblioitemnumber> is the number of the biblioitem to change.
109
C<$biblionumber> is the biblionumber to associate it with.
110
111
=cut
112
113
#'
114
sub shiftgroup{
115
  my ($biblionumber,$bi)=@_;
116
  my $dbh = C4::Context->dbh;
117
  my $sth=$dbh->prepare("update biblioitems set biblionumber=? where biblioitemnumber=?");
118
  $sth->execute($biblionumber,$bi);
119
  $sth->finish;
120
  $sth=$dbh->prepare("update items set biblionumber=? where biblioitemnumber=?");
121
  $sth->execute($biblionumber,$bi);
122
  $sth->finish;
123
}
124
125
=head2 deletedbib
126
127
  ($count, $results) = &deletedbib($title);
128
129
Looks up deleted books whose title begins with C<$title>.
130
131
C<&deletedbib> returns a two-element list. C<$results> is a
132
reference-to-array; each element is a reference-to-hash whose keys are
133
the fields of the deletedbiblio table in the Koha database. C<$count>
134
is the number of elements in C<$results>.
135
136
=cut
137
138
#'
139
sub deletedbib{
140
  my ($title)=@_;
141
  my $dbh = C4::Context->dbh;
142
  my $sth=$dbh->prepare("Select * from deletedbiblio where title like ? order by title");
143
  $sth->execute("$title%");
144
  my @results;
145
  my $i=0;
146
  while (my $data=$sth->fetchrow_hashref){
147
    $results[$i]=$data;
148
    $i++;
149
  }
150
  $sth->finish;
151
  return($i,\@results);
152
}
153
154
=head2 undeletebib
155
156
  &undeletebib($biblionumber);
157
158
Undeletes a book. C<&undeletebib> looks up the book with the given
159
biblionumber in the deletedbiblio table of the Koha database, and
160
moves its entry to the biblio table.
161
162
=cut
163
164
#'
165
sub undeletebib{
166
  my ($biblionumber)=@_;
167
  my $dbh = C4::Context->dbh;
168
  my $sth=$dbh->prepare("select * from deletedbiblio where biblionumber=?");
169
  $sth->execute($biblionumber);
170
  if (my @data=$sth->fetchrow_array){
171
    $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
    my $query="INSERT INTO biblio VALUES (";
175
   my $count = @data;
176
    $query .= ("?," x $count);
177
    $query=~ s/\,$/\)/;
178
    #   print $query;
179
    $sth=$dbh->prepare($query);
180
    $sth->execute(@data);
181
    $sth->finish;
182
  }
183
  $sth=$dbh->prepare("DELETE FROM deletedbiblio WHERE biblionumber=?");
184
  $sth->execute($biblionumber);
185
  $sth->finish;
186
}
187
188
=head2 updatetype
189
190
  &updatetype($biblioitemnumber, $itemtype);
191
192
Changes the type of the item with the given biblioitemnumber to be
193
C<$itemtype>.
194
195
=cut
196
197
#'
198
sub updatetype{
199
  my ($bi,$type)=@_;
200
  my $dbh = C4::Context->dbh;
201
  my $sth=$dbh->prepare("Update biblioitems set itemtype=? where biblioitemnumber=?");
202
  $sth->execute($type,$bi);
203
  $sth->finish;
204
}
205
206
END { }       # module clean-up code here (global destructor)
207
208
1;
209
__END__
210
211
=head1 AUTHOR
212
213
Koha Development Team <http://koha-community.org/>
214
215
=cut
(-)a/t/Maintainance.t (-15 lines)
Lines 1-14 Link Here
1
#!/usr/bin/perl
2
#
3
# This Koha test module is a stub!  
4
# Add more tests here!!!
5
6
use strict;
7
use warnings;
8
9
use Test::More tests => 1;
10
11
BEGIN {
12
        use_ok('C4::Maintainance');
13
}
14
15
- 

Return to bug 12456