Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

1st version of sandbox system

* README.install contains informations about installation
sandbox.pl and sandbox.tt => the main script accessible with Firefox
sandbox.cron => the cronjob that update your koha installation
sandbox*.sql.gz => compressed sample databases
  • Loading branch information...
commit c40300710f3e567e42dab1578117cbef49dc485d 1 parent 2370bb7
@PaulPoulain PaulPoulain authored
View
70 sandbox/README.install
@@ -0,0 +1,70 @@
+# retrieve sandbox system from contrib repository
+git clone git://git.koha-community.org/contrib/global.git /home/koha/contrib
+
+# uncompress .sample databases
+gzip -d sandbox*.sql.gz
+
+# go to koha and update it
+cd /home/koha/src;git fetch;git checkout master;git rebase origin/master
+# copy files from contrib repo to koha:
+cp /home/koha/contrib/sandbox/* /home/koha/src
+# (the sandbox files should be in your main KOHA directory)
+
+Update your crontab.
+Your crontab should look like this:
+# who should I mail?
+MAILTO=paul.poulain@biblibre.com
+# add /home/koha/bin, where git-bz will be stored
+PATH=/home/koha/bin:/usr/local/bin:/usr/bin:/bin
+# Koha conf
+KOHA_CONF=/home/koha/etc/koha-conf.xml
+PERL5LIB=/home/koha/src
+
+##### For Rebuild Zebra
+* * * * * /home/koha/bin/zebraqueue.sh > /dev/null 2>&1
+
+# update master every night at 1:15AM
+15 1 * * * cd /home/koha/src;git fetch;git checkout master;git rebase origin/master
+
+# every minute, check if there is a sandbox to install
+* * * * * cd /home/koha/src;./sandbox.cron
+
+
+# retrieve git bz
+git clone git://gitorious.org/~slef/git-bz/slefs-git-bz.git git-bz
+# apply -3 parameters patch
+cd git-bz
+wget https://depot.biblibre.com/ppoulain/0001-Add-3-parameter-to-git-am.patch
+[ or
+wget http://webdav103-sandbox/ppoulain/0001-Add-3-parameter-to-git-am.patch
+if you're in BibLibre VPN
+]
+
+git am -3 0001-Add-3-parameter-to-git-am.patch
+
+# make git-bz on PATH
+ln -s /home/koha/git-bz/git-bz /home/koha/bin/git-bz
+
+# setup git-bz parameters
+cd ~/src
+git config bz.default-tracker bugs.koha-community.org
+git config --global bz-tracker.bugs.koha-community.org.path /bugzilla3
+git config bz.default-product Koha
+git config --global bz-tracker.bugs.koha-community.org.bz-user YOURLOGIN
+git config --global bz-tracker.bugs.koha-community.org.bz-password YOURPASSWORD
+
+# UPDATE sandbox.cron to define the database name
+# (see line 23)
+
+# you can now test the sandbox system
+http://your.koha.url/cgi-bin/koha/sandbox.pl
+
+# after submitting the form, on /tmp, you should see a /tmp/sandbox file
+# that is not null and contains the informations you've just filled
+
+# your koha user MUST be partially sudoer
+#in /etc/sudoers, add
+koha ALL=(ALL) NOPASSWD: /bin/rm /tmp/sandbox
+# if you don't have this line, the /tmp/sandbox file won't be deleted, and every minute, the cron will be restarted.
+# Expect some trouble !!!
+
View
112 sandbox/sandbox.cron
@@ -0,0 +1,112 @@
+#!/usr/bin/perl
+
+# Copyright BibLibre, 2012
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+use Mail::Sendmail;
+use C4::Context;
+
+# enter the name of your mySQL database here
+my $databasename = 'test1';
+
+open( sdbtmp, '</tmp/sandbox' );
+my $line = <sdbtmp>;
+(my $bugzilla,$database,$emailaddress,$translations) = split /\|/,$line;
+exit unless $bugzilla;
+# immediatly remove the file, to avoid cron running it twice
+`sudo rm /tmp/sandbox`;
+$emailaddress =~ s/"//g; # remove any " that have nothing to do in a mail and will break SQL insert
+my $checkout = `git checkout master;git branch -D test;git checkout -b test`;
+my $gitbz;
+unless ($bugzilla eq 'master') {
+ $gitbz = `git bz apply $bugzilla <yyyy`;
+ # test if things went well or no:
+ if ($gitbz =~ /git am --skip/) {
+ $gitbz="<h1>Something went wrong !</h1>$gitbz";
+ $gitbz=~ s/\n/<br\/>\n/g;
+ my $cancel = `git am --abort`;
+ # if something went wrong, checkout any file modified
+ my $checkout = `git status -s`;
+ foreach (split /\n/, $checkout) {
+ my $file_to_checkout = $_;
+ next if $file_to_checkout =~ /^\?\?/;
+ $file_to_checkout =~ s/^ M //;
+ `git checkout $file_to_checkout`;
+ }
+ }
+}
+
+# install translations if asked for
+chop $translations;
+if ($translations) {
+ $gitbz .="<br/>=== translation installation ===<br/>";
+ $gitbz .=`cd misc/translator;./translate install $translations`;
+}
+# do nothing to the mysqldatabase if the user requested that.
+unless ($database==-1) {
+ my $mysql = `mysql -e "drop database $databasename;create database $databasename;"`;
+}
+if ($database) {
+ if ($database==1) {
+ $mysql = `mysql $databasename <sandbox1.sql`;
+ }
+ if ($database==2) {
+ $mysql = `mysql $databasename <sandbox2.sql`;
+ }
+ # TODO = SQL UPDATE to all dates (expiry, return, holds,...) to have correct datas in the database
+ # now fill the news with some informations
+ my $dbh = C4::Context->dbh;
+ # take number 1 for the patch result.
+ $dbh->do("UPDATE opac_news SET number=number+1");
+ my $sth = $dbh->prepare("INSERT INTO opac_news (title, lang,new,timestamp,expirationdate,number) VALUES (?,'koha', ?,'2012-01-01','2099-01-01',1)");
+ $sth->execute("Sandbox setup by ".($emailaddress?$emailaddress:"unknown")." with database $database and bug $bugzilla on ".scalar(localtime),$gitbz);
+ # OK, now try to guess how "old" is our database, to update some dates.
+ # 1st we find when the last checkout has been made. We will then add this duration to many date fields in many tables
+ # thus, if you setup this database, even in 1 year, patrons won't have their subscription expired, all items checked out won't be late,...
+ $sth = $dbh->prepare("SELECT DATEDIFF(CURDATE(),max(issuedate)) FROM issues");
+ $sth->execute;
+ my ($delay) = $sth->fetchrow;
+ if ($delay) {
+ $dbh->do("UPDATE issues SET issuedate=DATE_ADD(issuedate,INTERVAL $delay DAY), date_due=DATE_ADD(date_due,INTERVAL $delay DAY)");
+ $dbh->do("UPDATE old_issues SET issuedate=DATE_ADD(issuedate,INTERVAL $delay DAY), date_due=DATE_ADD(date_due,INTERVAL $delay DAY),returndate=DATE_ADD(returndate,INTERVAL $delay DAY)");
+ $dbh->do("UPDATE aqbudgetperiods SET budget_period_startdate=DATE_ADD(budget_period_startdate,INTERVAL $delay DAY), budget_period_enddate=DATE_ADD(budget_period_enddate,INTERVAL $delay DAY)");
+ $dbh->do("UPDATE aqbasket SET creationdate=DATE_ADD(creationdate,INTERVAL $delay DAY), closedate=DATE_ADD(closedate,INTERVAL $delay DAY)");
+ $dbh->do("UPDATE aqorders SET entrydate=DATE_ADD(entrydate,INTERVAL $delay DAY), datereceived=DATE_ADD(datereceived,INTERVAL $delay DAY),datecancellationprinted=DATE_ADD(datecancellationprinted,INTERVAL $delay DAY)");
+ $dbh->do("UPDATE biblio SET datecreated=DATE_ADD(datecreated,INTERVAL $delay DAY)");
+ $dbh->do("UPDATE borrowers SET dateenrolled=DATE_ADD(dateenrolled,INTERVAL $delay DAY), dateexpiry=DATE_ADD(dateexpiry,INTERVAL $delay DAY),debarred=DATE_ADD(debarred,INTERVAL $delay DAY)");
+ $dbh->do("UPDATE items SET onloan=DATE_ADD(onloan,INTERVAL $delay DAY), datelastseen=DATE_ADD(datelastseen,INTERVAL $delay DAY),datelastborrowed=DATE_ADD(datelastborrowed,INTERVAL $delay DAY),dateaccessioned=DATE_ADD(dateaccessioned,INTERVAL $delay DAY)");
+ $dbh->do("UPDATE old_reserves SET reservedate=DATE_ADD(reservedate,INTERVAL $delay DAY), notificationdate=DATE_ADD(notificationdate,INTERVAL $delay DAY),reminderdate=DATE_ADD(reminderdate,INTERVAL $delay DAY),cancellationdate=DATE_ADD(cancellationdate,INTERVAL $delay DAY),waitingdate=DATE_ADD(waitingdate,INTERVAL $delay DAY),expirationdate=DATE_ADD(expirationdate,INTERVAL $delay DAY)");
+ $dbh->do("UPDATE reserves SET reservedate=DATE_ADD(reservedate,INTERVAL $delay DAY), notificationdate=DATE_ADD(notificationdate,INTERVAL $delay DAY),reminderdate=DATE_ADD(reminderdate,INTERVAL $delay DAY),cancellationdate=DATE_ADD(cancellationdate,INTERVAL $delay DAY),waitingdate=DATE_ADD(waitingdate,INTERVAL $delay DAY),expirationdate=DATE_ADD(expirationdate,INTERVAL $delay DAY)");
+ $dbh->do("UPDATE reviews SET datereviewed=DATE_ADD(datereviewed,INTERVAL $delay DAY)");
+ $dbh->do("UPDATE serial SET planneddate=DATE_ADD(planneddate,INTERVAL $delay DAY), publisheddate=DATE_ADD(publisheddate,INTERVAL $delay DAY),claimdate=DATE_ADD(claimdate,INTERVAL $delay DAY)");
+ $dbh->do("UPDATE statistics SET datetime=DATE_ADD(datetime,INTERVAL $delay DAY)");
+ $dbh->do("UPDATE subscription SET startdate=DATE_ADD(startdate,INTERVAL $delay DAY), firstacquidate=DATE_ADD(firstacquidate,INTERVAL $delay DAY),enddate=DATE_ADD(enddate,INTERVAL $delay DAY)");
+ $dbh->do("UPDATE suggestions SET accepteddate=DATE_ADD(accepteddate,INTERVAL $delay DAY), suggesteddate=DATE_ADD(suggesteddate,INTERVAL $delay DAY),manageddate=DATE_ADD(manageddate,INTERVAL $delay DAY),rejecteddate=DATE_ADD(rejecteddate,INTERVAL $delay DAY)");
+ }
+}
+
+# now, updating database if needed
+`installer/data/mysql/updatedatabase.pl`;
+
+unless ($database==-1) {
+ # now reindex zebra (biblio and authorities)
+ `misc/migration_tools/rebuild_zebra.pl -a -b -r`;
+}
+
+# everything is done, if we have an email, send the result
+if ( $emailaddress ) {
+ `echo "The sandbox you've requested is now ready. The patches attached to bugzilla $bugzilla have been applied, and the result is\n$gitbz\nIf you use this system for the 1st time, you may find usefull to reach the wiki page http://wiki.koha-community.org/wiki/Sandboxes to have some information about those results, to check if everything went well & if you can test the patch properly" | mail -s "sandbox ready !" $emailaddress`;
+}
View
52 sandbox/sandbox.pl
@@ -0,0 +1,52 @@
+#!/usr/bin/perl
+
+# Copyright BibLibre, 2012
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+use CGI;
+use C4::Context;
+use Template;
+use Template::Constants qw( :debug );
+
+my $query = CGI->new;
+my $bugzilla=$query->param('bugzilla');
+my $database = $query->param('database');
+my $mailaddress= $query->param('mailaddress');
+my $translations = $query->param('translations');
+
+my $template = Template->new();
+my $templatevars;
+
+my $dbh = C4::Context->dbh;
+my $sth = $dbh->prepare('select title FROM opac_news WHERE title like "Sandbox setup%" ORDER BY idnew DESC LIMIT 1');
+$sth->execute;
+my ($lastcreated) = $sth->fetchrow;
+$templatevars->{lastcreated} = $lastcreated;
+if ($bugzilla && lc($query->param('koha')) eq 'koha') {
+ # OK, we got the number, print the request on /tmp for the cronjob, after some security sanitizing
+ # parameters should/must be numbers only
+ unless ($bugzilla=~/\d*/ or $bugzilla eq 'master') { $bugzilla='' };
+ unless ($database=~/\d*/) { $database = '' };
+ open( sdbtmp, '>/tmp/sandbox');
+ print sdbtmp $bugzilla.'|'.$database.'|'.$mailaddress."|".$translations."\n";
+ close(sdbtmp);
+ chmod 0666, "/tmp/sandbox";
+ $templatevars->{done} = 1;
+}
+print $query->header();
+$template->process("sandbox.tt",$templatevars);
+
View
42 sandbox/sandbox.tt
@@ -0,0 +1,42 @@
+<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
+<head>
+
+<title>Koha sandbox setup</title>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<link rel="shortcut icon" href="/intranet-tmpl/prog/en/includes/favicon.ico" type="image/x-icon" />
+<link rel="stylesheet" type="text/css" href="/intranet-tmpl/prog/en/css/staff-global.css" />
+<style type="text/css">
+label {
+ text-align: right;
+ width: 150px;
+ display: block;
+ float: left;
+ clear: left;
+ margin-right: 3px;
+ cursor: pointer
+}
+</style>
+</head>
+<body>
+<h1>Welcome to the Koha sandbox tester</h1>
+<p>The current setup on this sandbox is = <b>[%lastcreated%]</b></p>
+<p>This tool is dedicated to testing <a href="http://koha-community.org">Koha</a> patches. See <a href="http://wiki.koha-community.org/wiki/Sandboxes">Koha wiki</a> for more informations</p>
+<form action="sandbox.pl">
+ <p><label for="bugzilla">bugzilla number</label><input type="text" name="bugzilla"/></p>
+ <p><label for="mailaddress">Your mail address</label><input type="text" name="mailaddress"/> (optional)</p>
+ <p><label for="translations">Translations</label><input type="text" name="translations" value="fr-FR" /> (optional</p>
+ <ul>
+ <p>Database:</p>
+ <ul>
+ <li><input name="database" type="radio" value="-1"/>No change (-1)</li>
+ <li><input name="database" type="radio" value=""/>No database (run webinstaller) (0)</li>
+ <li><input name="database" type="radio" value="1"/>MARC21, tiny dataset (1)</li>
+ <li><input name="database" type="radio" value="2"/>UNIMARC, public library (2) </li>
+ </ul>
+ </ul>
+ <p><label for="koha">Anti-spam</label><input type="text" name="koha"/> (Enter the name of your prefered ILS, it's the 4th word on this page, in case you hesitate ! If you don't do it, nothing will happen when you submit the form)</p>
+ <p><input type="submit" value="OK"/></p>
+ [% IF done %]<p>Request sent. It should be done in a minut or two. Check your mailbox if you've provided your email address</p>[% END %]
+</form>
+</body>
+</html>
View
BIN  sandbox/sandbox1.sql.gz
Binary file not shown
View
BIN  sandbox/sandbox2.sql.gz
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.