Commit ff9f16ddf447e406d5589e78b09aea0d450e0fd4
1 parent
b0b96508
Add KTZipImportStorage, which can be used to bulk import documents from
a zip file. git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3628 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
64 additions
and
0 deletions
lib/import/zipimportstorage.inc.php
0 → 100644
| 1 | +<?php /* vim: set expandtab softtabstop=4 shiftwidth=4 foldmethod=marker: */ | ||
| 2 | +/** | ||
| 3 | + * $Id$ | ||
| 4 | + * | ||
| 5 | + * Manages listing and contents for documents uploaded from a zip file | ||
| 6 | + * | ||
| 7 | + * Copyright (c) 2005 Jam Warehouse http://www.jamwarehouse.com | ||
| 8 | + * | ||
| 9 | + * This program is free software; you can redistribute it and/or modify | ||
| 10 | + * it under the terms of the GNU General Public License as published by | ||
| 11 | + * the Free Software Foundation; either version 2 of the License, or | ||
| 12 | + * (at your option) any later version. | ||
| 13 | + * | ||
| 14 | + * This program is distributed in the hope that it will be useful, | ||
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | + * GNU General Public License for more details. | ||
| 18 | + * | ||
| 19 | + * You should have received a copy of the GNU General Public License | ||
| 20 | + * along with this program; if not, write to the Free Software | ||
| 21 | + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 22 | + * | ||
| 23 | + * @version $Revision$ | ||
| 24 | + * @author Neil Blakey-Milner, Jam Warehouse (Pty) Ltd, South Africa | ||
| 25 | + */ | ||
| 26 | + | ||
| 27 | +require_once(KT_LIB_DIR . '/filelike/fsfilelike.inc.php'); | ||
| 28 | +require_once(KT_LIB_DIR . '/import/fsimportstorage.inc.php'); | ||
| 29 | + | ||
| 30 | +class KTZipImportStorage extends KTFSImportStorage { | ||
| 31 | + function KTZipImportStorage($sZipPath) { | ||
| 32 | + $this->sZipPath = $sZipPath; | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + function init() { | ||
| 36 | + $sTmpPath = tempnam('/tmp', 'zipimportstorage'); | ||
| 37 | + if ($sTmpPath === false) { | ||
| 38 | + return PEAR::raiseError("Could not create temporary directory for zip storage"); | ||
| 39 | + } | ||
| 40 | + unlink($sTmpPath); | ||
| 41 | + mkdir($sTmpPath, 0700); | ||
| 42 | + $this->sBasePath = $sTmpPath; | ||
| 43 | + $aArgs = array( | ||
| 44 | + "unzip", | ||
| 45 | + "-q", "-n", | ||
| 46 | + "-d", $sTmpPath, | ||
| 47 | + $this->sZipPath | ||
| 48 | + ); | ||
| 49 | + $sCommand = KTUtil::safeShellString($aArgs); | ||
| 50 | + $res = system($sCommand); | ||
| 51 | + if ($res === false) { | ||
| 52 | + return PEAR::raiseError("Could not retrieve contents from zip storage"); | ||
| 53 | + } | ||
| 54 | + } | ||
| 55 | + function cleanup() { | ||
| 56 | + if ($this->sBasePath && file_exists($this->sBasePath)) { | ||
| 57 | + // XXX: Only works on Unix-like systems for now. | ||
| 58 | + system(KTUtil::safeShellString(array('/bin/rm', '-rf', $this->sBasePath))); | ||
| 59 | + $this->sBasePath = null; | ||
| 60 | + } | ||
| 61 | + } | ||
| 62 | +} | ||
| 63 | + | ||
| 64 | +?> |