From 7280668f91ec230f2a85cdb862409b537d233872 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Tue, 8 Mar 2016 18:35:39 +0100 Subject: [PATCH] add admin script for mass importing files from file system --- op/op.ImportFS.php | 82 ++++++++++++++++++++++++++++++ out/out.ImportFS.php | 37 ++++++++++++++ views/bootstrap/class.ImportFS.php | 78 ++++++++++++++++++++++++++++ 3 files changed, 197 insertions(+) create mode 100644 op/op.ImportFS.php create mode 100644 out/out.ImportFS.php create mode 100644 views/bootstrap/class.ImportFS.php diff --git a/op/op.ImportFS.php b/op/op.ImportFS.php new file mode 100644 index 000000000..162633fc3 --- /dev/null +++ b/op/op.ImportFS.php @@ -0,0 +1,82 @@ +getFolder($targetid); +if (!is_object($folder)) { + echo "Could not find specified folder\n"; + exit(1); +} + +if ($folder->getAccessMode($user) < M_READWRITE) { + UI::exitError(getMLText("admin_tools"),getMLText("access_denied")); +} + +if (empty($_GET["dropfolderfileform1"])) { + UI::exitError(getMLText("admin_tools"),getMLText("invalid_target_folder")); +} +$dirname = $settings->_dropFolderDir.'/'.$user->getLogin()."/".$_GET["dropfolderfileform1"]; +if(!is_dir($dirname)) { + UI::exitError(getMLText("admin_tools"),getMLText("invalid_target_folder")); +} + +function import_folder($dirname, $folder) { /* {{{ */ + global $user; + + $d = dir($dirname); + $sequence = 1; + while(false !== ($entry = $d->read())) { + $path = $dirname.'/'.$entry; + if($entry != '.' && $entry != '..' && $entry != '.svn') { + if(is_file($path)) { + $name = basename($path); + $filetmp = $path; + + $reviewers = array(); + $approvers = array(); + $comment = ''; + $version_comment = ''; + $reqversion = 1; + $expires = false; + $keywords = ''; + $categories = array(); + + $finfo = finfo_open(FILEINFO_MIME_TYPE); + $mimetype = finfo_file($finfo, $path); + $lastDotIndex = strrpos($path, "."); + if (is_bool($lastDotIndex) && !$lastDotIndex) $filetype = "."; + else $filetype = substr($path, $lastDotIndex); + + echo $mimetype." - ".$filetype." - ".$path."\n"; + $res = $folder->addDocument($name, $comment, $expires, $user, $keywords, + $categories, $filetmp, $name, + $filetype, $mimetype, $sequence, $reviewers, + $approvers, $reqversion, $version_comment); + + if (is_bool($res) && !$res) { + echo "Could not add document to folder\n"; + exit(1); + } + set_time_limit(1200); + } elseif(is_dir($path)) { + $name = basename($path); + $newfolder = $folder->addSubFolder($name, '', $user, $sequence); + import_folder($path, $newfolder); + } + $sequence++; + } + } +} /* }}} */ + +header("Content-Type: text/plain"); +import_folder($dirname, $folder); + diff --git a/out/out.ImportFS.php b/out/out.ImportFS.php new file mode 100644 index 000000000..ff9a44ded --- /dev/null +++ b/out/out.ImportFS.php @@ -0,0 +1,37 @@ +isAdmin()) { + UI::exitError(getMLText("admin_tools"),getMLText("access_denied")); +} + +$tmp = explode('.', basename($_SERVER['SCRIPT_FILENAME'])); +$view = UI::factory($theme, $tmp[1], array('dms'=>$dms, 'user'=>$user, 'dropfolderdir'=>$settings->_dropFolderDir)); +if($view) { + $view($_GET); + exit; +} + + diff --git a/views/bootstrap/class.ImportFS.php b/views/bootstrap/class.ImportFS.php new file mode 100644 index 000000000..b14062b47 --- /dev/null +++ b/views/bootstrap/class.ImportFS.php @@ -0,0 +1,78 @@ + + * @copyright Copyright (C) 2002-2005 Markus Westphal, + * 2006-2008 Malcolm Cowe, 2010 Matteo Lucarelli, + * 2010-2012 Uwe Steinmann + * @version Release: @package_version@ + */ + +/** + * Include parent class + */ +require_once("class.Bootstrap.php"); + +/** + * Class which outputs the html page for ImportFS view + * + * @category DMS + * @package SeedDMS + * @author Markus Westphal, Malcolm Cowe, Uwe Steinmann + * @copyright Copyright (C) 2002-2005 Markus Westphal, + * 2006-2008 Malcolm Cowe, 2010 Matteo Lucarelli, + * 2010-2012 Uwe Steinmann + * @version Release: @package_version@ + */ +class SeedDMS_View_ImportFS extends SeedDMS_Bootstrap_Style { + + function js() { /* {{{ */ + header('Content-Type: application/javascript'); + + $this->printFolderChooserJs("form1"); + $this->printDropFolderChooserJs("form1", 1); + } /* }}} */ + + function show() { /* {{{ */ + $dms = $this->params['dms']; + $user = $this->params['user']; + $dropfolderdir = $this->params['dropfolderdir']; + + $this->htmlStartPage(getMLText("import_fs")); + $this->globalNavigation(); + $this->contentStart(); + $this->pageNavigation(getMLText("admin_tools"), "admin_tools"); + + $this->contentHeading(getMLText("import_fs")); + $this->contentContainerStart(); + + print "
"; + print "
"; + $this->printFolderChooserHtml("form1",M_READWRITE); + print "
"; + if($dropfolderdir) { + print "
"; + /* Setting drop folder dir to "" will force to take the default from settings.xml */ + $this->printDropFolderChooserHtml("form1", "", 1); + print "
"; + } + print "
"; + print "
"; + print "
"; + print "
\n"; + + $this->contentContainerEnd(); + + $this->htmlEndPage(); + } /* }}} */ +} +