[Koha-patches] [PATCH 24/28] Provide a download link to the database dump on the tools page.

Lars Wirzenius lars at catalyst.net.nz
Tue May 25 03:44:23 CEST 2010


---
 .../modules/tools/dbdump-not-superlibrarian.tmpl   |   20 ++++++
 .../prog/en/modules/tools/tools-home.tmpl          |    4 +-
 tools/dbdump.pl                                    |   64 ++++++++++++++++++++
 3 files changed, 87 insertions(+), 1 deletions(-)
 create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/tools/dbdump-not-superlibrarian.tmpl
 create mode 100755 tools/dbdump.pl

diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/dbdump-not-superlibrarian.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/dbdump-not-superlibrarian.tmpl
new file mode 100644
index 0000000..1c4797c
--- /dev/null
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/dbdump-not-superlibrarian.tmpl
@@ -0,0 +1,20 @@
+<!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
+<title>Koha &rsaquo; Tools</title>
+<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
+</head>
+<body>
+<!-- TMPL_INCLUDE NAME="header.inc" -->
+<!-- TMPL_INCLUDE NAME="cat-search.inc" -->
+
+<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; Tools</div>
+
+<div id="doc3">
+<div id="bd">
+	<div class="yui-gb">
+
+<p>You do not have permission to download the database dump. It is
+for superlibrarians only. Sorry.</p>
+
+</div>
+</div>
+<!-- TMPL_INCLUDE NAME="intranet-bottom.inc" -->
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tmpl
index d081021..15964ce 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tmpl
@@ -86,7 +86,9 @@
     <dt><a href="/cgi-bin/koha/tools/scheduler.pl">Task scheduler</a></dt>
     <dd>Schedule tasks to run</dd>
     <!-- /TMPL_IF -->
-	
+    
+    <dt><a href="/cgi-bin/koha/tools/dbdump.pl">Database dump</a></dt>
+    <dd>Download latest database dump.</dd>
 
 </dl>
 </div>
diff --git a/tools/dbdump.pl b/tools/dbdump.pl
new file mode 100755
index 0000000..9abd12c
--- /dev/null
+++ b/tools/dbdump.pl
@@ -0,0 +1,64 @@
+#!/usr/bin/perl
+
+# This file is part of Koha.
+#
+# Copyright 2010 Catalyst IT Ltd.
+# 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., 59 Temple Place,
+# Suite 330, Boston, MA  02111-1307 USA
+
+use strict;
+use warnings;
+
+use CGI;
+use C4::Auth;
+use C4::Output;
+
+my $query = new CGI;
+my ( $user, $cookie, $sessionID, $flags ) = checkauth(
+        $query,
+        0,
+        { tools => '*' },
+        "intranet"
+   );
+if ($flags->{superlibrarian}) {
+    my $kohaname = $ENV{"KOHA_CONF"};
+    $kohaname =~ s:^/etc/koha/sites/([^/]*)/koha-conf.xml$:$1:;
+    my @basenames = glob("/var/spool/koha/$kohaname/$kohaname-*.sql.gz");
+    my $filename = $basenames[-1];
+    open(DUMP, '<', $filename) or die("Can't read $filename");
+    binmode DUMP;
+
+    my $basename = $filename;
+    $basename =~ s:.*/::;
+    print $query->header(
+        -type => 'application/x-gzip',
+        -attachment => "$basename"
+    );
+    binmode STDOUT;
+
+    while (read(DUMP, my $data, 64 * 1024)) {
+        print $data;
+    }
+} else {
+    my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
+        {
+            template_name   => "tools/dbdump-not-superlibrarian.tmpl",
+            query           => $query,
+            type            => "intranet",
+            authnotrequired => 0,
+            flagsrequired   => { tools => '*' },
+            debug           => 1,
+        }
+    );
+    output_html_with_http_headers $query, $cookie, $template->output;
+}
-- 
1.7.1




More information about the Koha-patches mailing list