Beginning of a koha.upgrade script for 1.2.1. We need this if 1.2.1 is
[koha.git] / koha.upgrade
1 #!/usr/bin/perl -w
2
3 use C4::Database;
4
5 my $dbh=C4Connect();
6
7 my %configfile;
8 open (KC, "/etc/koha.conf");
9 while (<KC>) {
10  chomp;
11  (next) if (/^\s*#/);
12  if (/(.*)\s*=\s*(.*)/) {
13    my $variable=$1;
14    my $value=$2;
15    # Clean up white space at beginning and end
16    $variable=~s/^\s*//g;
17    $variable=~s/\s*$//g;
18    $value=~s/^\s*//g;
19    $value=~s/\s*$//g;
20    $configfile{$variable}=$value;
21  }
22 }
23
24 my $intranetdir=$configfile{'intranetdir'};
25 my $opacdir=$configfile{'opacdir'};
26 my $kohaversion=$configfile{'kohaversion'};
27 my $database=$configfile{'database'};
28 my $host=$configfile{'host'};
29 my $user=$configfile{'user'};
30 my $pass=$configfile{'pass'};
31
32
33 my $newversion=`cat kohaversion`;
34 chomp $newversion;
35
36 print qq|
37
38 ================
39 = Koha Upgrade =
40 ================
41
42 You are attempting to upgrade from Koha $kohaversion to $newversion.
43
44 We recommend that you do a complete backup of all your files before upgrading.
45 This upgrade script will make a backup copy of your files for you.
46
47 Would you like to proceed?  ([Y]/N):  
48 |;
49
50 my $answer = <STDIN>;
51 chomp $answer;
52
53 if ($answer eq "Y" || $answer eq "y") {
54         print "Great! continuing upgrade... \n";
55     } else {
56     print qq|
57
58 Aborting.  Please re-run koha.upgrade when you are ready to upgrade Koha.
59 |;
60     exit;
61 };
62
63
64
65 # Backup MySql database
66 #
67
68 system("mysqldump -u$user -p$pass -h$host $database > Koha.backup");
69 open (MD, "mysqldump -u$user -p$pass -h$host $database|");
70 open BF, ">Koha.backup";
71
72 my $itemcounter=0;
73 my $bibliocounter=0;
74 my $biblioitemcounter=0;
75 my $membercounter=0;
76
77 while (<MD>) {
78     (/insert into items /i) && ($itemcounter++);
79     (/insert into biblioitems /i) && ($biblioitemcounter++);
80     (/insert into biblio /i) && ($bibliocounter++);
81     (/insert into borrowers /i) && ($membercounter++);
82     print BF $_;
83 }
84
85 close BF;
86 close MD;
87
88
89 printf qq|
90
91 Backed up:
92
93 %6d biblio entries
94 %6d biblioitems entries
95 %6d items entries
96 %6d borrowers
97
98 Does this look right? ([Y]/N):
99 |, $bibliocounter, $biblioitemcounter, $itemcounter, $membercounter;
100
101 my $answer = <STDIN>;
102 chomp $answer;
103
104 if ($answer eq "Y" || $answer eq "y") {
105         print "Great! continuing upgrade... \n";
106     } else {
107     print qq|
108
109 Aborting.  The database dump is located in the Koha.backup file. 
110 |;
111     exit;
112 };
113
114
115
116