diff --git a/lib/import/bulkimport.inc.php b/lib/import/bulkimport.inc.php new file mode 100644 index 0000000..7f4bfe7 --- /dev/null +++ b/lib/import/bulkimport.inc.php @@ -0,0 +1,90 @@ +oFolder =& $oFolder; + $this->oStorage =& $oStorage; + $this->oUser =& $oUser; + $this->aOptions =& $aOptions; + if (is_null($aOptions)) { + $aOptions = array(); + } + $this->aMetadata = KTUtil::arrayGet($aOptions, 'metadata', array()); + } + + function import() { + $res = $this->_importfolder($this->oFolder, "/"); + if (PEAR::isError($res)) { + DBUtil::rollback(); + return $res; + } + return; + } + + function _importfolder($oFolder, $sPath) { + $aDocPaths = $this->oStorage->listDocuments($sPath); + foreach ($aDocPaths as $sDocumentPath) { + $res = $this->_importdocument($oFolder, $sDocumentPath); + if (PEAR::isError($res)) { + return $res; + } + } + $aFolderPaths = $this->oStorage->listFolders($sPath); + foreach ($aFolderPaths as $sFolderPath) { + $oThisFolder = KTFolderUtil::add($oFolder, basename($sFolderPath), $this->oUser); + if (PEAR::isError($oThisFolder)) { + return $oThisFolder; + } + $res = $this->_importfolder($oThisFolder, $sFolderPath); + if (PEAR::isError($res)) { + return $res; + } + } + } + + function _importdocument($oFolder, $sPath) { + $aInfo = $this->oStorage->getDocumentInfo($sPath); + if (PEAR::isError($aInfo)) { + return $aInfo; + } + $aOptions = array( + // XXX: Multiversion Import + 'contents' => $aInfo->aVersions[0], + 'metadata' => $this->aMetadata, + ); + $oDocument =& KTDocumentUtil::add($oFolder, basename($sPath), $this->oUser, $aOptions); + return $oDocument; + } +} + +?> diff --git a/lib/import/fsimportstorage.inc.php b/lib/import/fsimportstorage.inc.php new file mode 100644 index 0000000..9f8dff5 --- /dev/null +++ b/lib/import/fsimportstorage.inc.php @@ -0,0 +1,102 @@ +sBasePath = $sBasePath; + } + + function listDocuments($sFolderPath) { + $ret = array(); + if (substr($sFolderPath, -1) === "/") { + $sFolderPath = substr($sFolderPath, 0, -1); + } + $sFullPath = sprintf("%s/%s", $this->sBasePath, $sFolderPath); + if (!is_dir($sFullPath)) { + return PEAR::raiseError('Path is not a folder'); + } + $rDir = @opendir($sFullPath); + if ($rDir === false) { + return PEAR::raiseError('Failed to open folder'); + } + while (($sFilename = readdir($rDir)) !== false) { + $sThisPath = sprintf("%s/%s", $sFullPath, $sFilename); + if (is_file($sThisPath)) { + if (empty($sFolderPath)) { + $ret[] = $sFilename; + } else { + $ret[] = sprintf("%s/%s", $sFolderPath, $sFilename); + } + } + } + closedir($rDir); + return $ret; + } + + function listFolders($sFolderPath) { + $ret = array(); + if (substr($sFolderPath, -1) === "/") { + $sFolderPath = substr($sFolderPath, 0, -1); + } + $sFullPath = sprintf("%s/%s", $this->sBasePath, $sFolderPath); + if (!is_dir($sFullPath)) { + return PEAR::raiseError('Path is not a folder'); + } + $rDir = @opendir($sFullPath); + if ($rDir === false) { + return PEAR::raiseError('Failed to open folder'); + } + while (($sFilename = readdir($rDir)) !== false) { + if (in_array($sFilename, array(".", ".."))) { + continue; + } + $sThisPath = sprintf("%s/%s", $sFullPath, $sFilename); + if (is_dir($sThisPath)) { + if (empty($sFolderPath)) { + $ret[] = $sFilename; + } else { + $ret[] = sprintf("%s/%s", $sFolderPath, $sFilename); + } + } + } + closedir($rDir); + return $ret; + } + + function getDocumentInfo($sDocumentPath) { + return new KTImportStorageInfo( + basename($sDocumentPath), + array( + new KTFSFileLike(sprintf("%s/%s", $this->sBasePath, $sDocumentPath)) + ) + ); + } +} + +?> diff --git a/lib/import/importstorage.inc.php b/lib/import/importstorage.inc.php new file mode 100644 index 0000000..bb638a6 --- /dev/null +++ b/lib/import/importstorage.inc.php @@ -0,0 +1,64 @@ +sFilename = $sFilename; + $this->aVersions = $aVersions; + } + + function getFilename() { + return $this->sFilename; + } +} + +?>