Commit 37b738ca2a58383a9d53d61f50ecc8366206435f
1 parent
7b40f9ce
Add an abstracted import storage system, and implement importing from
the filesystem. This can be extended to import from various archive files (such as ZIP), from other document management tools, from CVS or SVN. Includes the idea that multiple content versions exists. Does not handle importing metadata at all. git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3583 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
3 changed files
with
256 additions
and
0 deletions
lib/import/bulkimport.inc.php
0 โ 100644
| 1 | +<?php /* vim: set expandtab softtabstop=4 shiftwidth=4 foldmethod=marker: */ | |
| 2 | +/** | |
| 3 | + * $Id$ | |
| 4 | + * | |
| 5 | + * Import all documents from an import storage location | |
| 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 . '/foldermanagement/folderutil.inc.php'); | |
| 28 | +require_once(KT_LIB_DIR . '/documentmanagement/documentutil.inc.php'); | |
| 29 | +require_once(KT_LIB_DIR . '/filelike/filelikeutil.inc.php'); | |
| 30 | + | |
| 31 | +class KTBulkImportManager { | |
| 32 | + var $oStorage; | |
| 33 | + | |
| 34 | + function KTBulkImportManager($oFolder, $oStorage, $oUser, $aOptions = null) { | |
| 35 | + $this->oFolder =& $oFolder; | |
| 36 | + $this->oStorage =& $oStorage; | |
| 37 | + $this->oUser =& $oUser; | |
| 38 | + $this->aOptions =& $aOptions; | |
| 39 | + if (is_null($aOptions)) { | |
| 40 | + $aOptions = array(); | |
| 41 | + } | |
| 42 | + $this->aMetadata = KTUtil::arrayGet($aOptions, 'metadata', array()); | |
| 43 | + } | |
| 44 | + | |
| 45 | + function import() { | |
| 46 | + $res = $this->_importfolder($this->oFolder, "/"); | |
| 47 | + if (PEAR::isError($res)) { | |
| 48 | + DBUtil::rollback(); | |
| 49 | + return $res; | |
| 50 | + } | |
| 51 | + return; | |
| 52 | + } | |
| 53 | + | |
| 54 | + function _importfolder($oFolder, $sPath) { | |
| 55 | + $aDocPaths = $this->oStorage->listDocuments($sPath); | |
| 56 | + foreach ($aDocPaths as $sDocumentPath) { | |
| 57 | + $res = $this->_importdocument($oFolder, $sDocumentPath); | |
| 58 | + if (PEAR::isError($res)) { | |
| 59 | + return $res; | |
| 60 | + } | |
| 61 | + } | |
| 62 | + $aFolderPaths = $this->oStorage->listFolders($sPath); | |
| 63 | + foreach ($aFolderPaths as $sFolderPath) { | |
| 64 | + $oThisFolder = KTFolderUtil::add($oFolder, basename($sFolderPath), $this->oUser); | |
| 65 | + if (PEAR::isError($oThisFolder)) { | |
| 66 | + return $oThisFolder; | |
| 67 | + } | |
| 68 | + $res = $this->_importfolder($oThisFolder, $sFolderPath); | |
| 69 | + if (PEAR::isError($res)) { | |
| 70 | + return $res; | |
| 71 | + } | |
| 72 | + } | |
| 73 | + } | |
| 74 | + | |
| 75 | + function _importdocument($oFolder, $sPath) { | |
| 76 | + $aInfo = $this->oStorage->getDocumentInfo($sPath); | |
| 77 | + if (PEAR::isError($aInfo)) { | |
| 78 | + return $aInfo; | |
| 79 | + } | |
| 80 | + $aOptions = array( | |
| 81 | + // XXX: Multiversion Import | |
| 82 | + 'contents' => $aInfo->aVersions[0], | |
| 83 | + 'metadata' => $this->aMetadata, | |
| 84 | + ); | |
| 85 | + $oDocument =& KTDocumentUtil::add($oFolder, basename($sPath), $this->oUser, $aOptions); | |
| 86 | + return $oDocument; | |
| 87 | + } | |
| 88 | +} | |
| 89 | + | |
| 90 | +?> | ... | ... |
lib/import/fsimportstorage.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 on a filesystem. | |
| 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 . '/import/importstorage.inc.php'); | |
| 28 | +require_once(KT_LIB_DIR . '/filelike/fsfilelike.inc.php'); | |
| 29 | + | |
| 30 | +class KTFSImportStorage extends KTImportStorage { | |
| 31 | + function KTFSImportStorage($sBasePath) { | |
| 32 | + $this->sBasePath = $sBasePath; | |
| 33 | + } | |
| 34 | + | |
| 35 | + function listDocuments($sFolderPath) { | |
| 36 | + $ret = array(); | |
| 37 | + if (substr($sFolderPath, -1) === "/") { | |
| 38 | + $sFolderPath = substr($sFolderPath, 0, -1); | |
| 39 | + } | |
| 40 | + $sFullPath = sprintf("%s/%s", $this->sBasePath, $sFolderPath); | |
| 41 | + if (!is_dir($sFullPath)) { | |
| 42 | + return PEAR::raiseError('Path is not a folder'); | |
| 43 | + } | |
| 44 | + $rDir = @opendir($sFullPath); | |
| 45 | + if ($rDir === false) { | |
| 46 | + return PEAR::raiseError('Failed to open folder'); | |
| 47 | + } | |
| 48 | + while (($sFilename = readdir($rDir)) !== false) { | |
| 49 | + $sThisPath = sprintf("%s/%s", $sFullPath, $sFilename); | |
| 50 | + if (is_file($sThisPath)) { | |
| 51 | + if (empty($sFolderPath)) { | |
| 52 | + $ret[] = $sFilename; | |
| 53 | + } else { | |
| 54 | + $ret[] = sprintf("%s/%s", $sFolderPath, $sFilename); | |
| 55 | + } | |
| 56 | + } | |
| 57 | + } | |
| 58 | + closedir($rDir); | |
| 59 | + return $ret; | |
| 60 | + } | |
| 61 | + | |
| 62 | + function listFolders($sFolderPath) { | |
| 63 | + $ret = array(); | |
| 64 | + if (substr($sFolderPath, -1) === "/") { | |
| 65 | + $sFolderPath = substr($sFolderPath, 0, -1); | |
| 66 | + } | |
| 67 | + $sFullPath = sprintf("%s/%s", $this->sBasePath, $sFolderPath); | |
| 68 | + if (!is_dir($sFullPath)) { | |
| 69 | + return PEAR::raiseError('Path is not a folder'); | |
| 70 | + } | |
| 71 | + $rDir = @opendir($sFullPath); | |
| 72 | + if ($rDir === false) { | |
| 73 | + return PEAR::raiseError('Failed to open folder'); | |
| 74 | + } | |
| 75 | + while (($sFilename = readdir($rDir)) !== false) { | |
| 76 | + if (in_array($sFilename, array(".", ".."))) { | |
| 77 | + continue; | |
| 78 | + } | |
| 79 | + $sThisPath = sprintf("%s/%s", $sFullPath, $sFilename); | |
| 80 | + if (is_dir($sThisPath)) { | |
| 81 | + if (empty($sFolderPath)) { | |
| 82 | + $ret[] = $sFilename; | |
| 83 | + } else { | |
| 84 | + $ret[] = sprintf("%s/%s", $sFolderPath, $sFilename); | |
| 85 | + } | |
| 86 | + } | |
| 87 | + } | |
| 88 | + closedir($rDir); | |
| 89 | + return $ret; | |
| 90 | + } | |
| 91 | + | |
| 92 | + function getDocumentInfo($sDocumentPath) { | |
| 93 | + return new KTImportStorageInfo( | |
| 94 | + basename($sDocumentPath), | |
| 95 | + array( | |
| 96 | + new KTFSFileLike(sprintf("%s/%s", $this->sBasePath, $sDocumentPath)) | |
| 97 | + ) | |
| 98 | + ); | |
| 99 | + } | |
| 100 | +} | |
| 101 | + | |
| 102 | +?> | ... | ... |
lib/import/importstorage.inc.php
0 โ 100644
| 1 | +<?php /* vim: set expandtab softtabstop=4 shiftwidth=4 foldmethod=marker: */ | |
| 2 | +/** | |
| 3 | + * $Id$ | |
| 4 | + * | |
| 5 | + * Interface for representing a method of listing and importing | |
| 6 | + * documents from storage. | |
| 7 | + * | |
| 8 | + * Copyright (c) 2005 Jam Warehouse http://www.jamwarehouse.com | |
| 9 | + * | |
| 10 | + * This program is free software; you can redistribute it and/or modify | |
| 11 | + * it under the terms of the GNU General Public License as published by | |
| 12 | + * the Free Software Foundation; either version 2 of the License, or | |
| 13 | + * (at your option) any later version. | |
| 14 | + * | |
| 15 | + * This program is distributed in the hope that it will be useful, | |
| 16 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 17 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 18 | + * GNU General Public License for more details. | |
| 19 | + * | |
| 20 | + * You should have received a copy of the GNU General Public License | |
| 21 | + * along with this program; if not, write to the Free Software | |
| 22 | + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 23 | + * | |
| 24 | + * @version $Revision$ | |
| 25 | + * @author Neil Blakey-Milner, Jam Warehouse (Pty) Ltd, South Africa | |
| 26 | + */ | |
| 27 | + | |
| 28 | +class KTImportStorage { | |
| 29 | + function listDocuments($sFolderPath) { | |
| 30 | + return PEAR::raiseError('Not implemented'); | |
| 31 | + } | |
| 32 | + | |
| 33 | + function listFolders($sFolderPath) { | |
| 34 | + return PEAR::raiseError('Not implemented'); | |
| 35 | + } | |
| 36 | + | |
| 37 | + function getDocumentInfo($sDocumentPath) { | |
| 38 | + return PEAR::raiseError('Not implemented'); | |
| 39 | + } | |
| 40 | +} | |
| 41 | + | |
| 42 | +class KTImportStorageInfo { | |
| 43 | + /** | |
| 44 | + * File name to store in the repository. | |
| 45 | + */ | |
| 46 | + var $sFilename; | |
| 47 | + | |
| 48 | + /** | |
| 49 | + * Ordered array (oldest to newest) of KTFileLike objects that can | |
| 50 | + * get the contents for versions of the given file. | |
| 51 | + */ | |
| 52 | + var $aVersions; | |
| 53 | + | |
| 54 | + function KTImportStorageInfo ($sFilename, $aVersions) { | |
| 55 | + $this->sFilename = $sFilename; | |
| 56 | + $this->aVersions = $aVersions; | |
| 57 | + } | |
| 58 | + | |
| 59 | + function getFilename() { | |
| 60 | + return $this->sFilename; | |
| 61 | + } | |
| 62 | +} | |
| 63 | + | |
| 64 | +?> | ... | ... |