add admin script for mass importing files from file system

This commit is contained in:
Uwe Steinmann 2016-03-08 18:35:39 +01:00
parent 60edc144e4
commit 7280668f91
3 changed files with 197 additions and 0 deletions

82
op/op.ImportFS.php Normal file
View File

@ -0,0 +1,82 @@
<?php
include("../inc/inc.Settings.php");
include("../inc/inc.Utils.php");
include("../inc/inc.DBInit.php");
include("../inc/inc.Language.php");
include("../inc/inc.ClassUI.php");
include("../inc/inc.ClassAccessOperation.php");
include("../inc/inc.Authentication.php");
if (!isset($_GET["targetid"]) || !is_numeric($_GET["targetid"]) || $_GET["targetid"]<1) {
UI::exitError(getMLText("admin_tools"),getMLText("invalid_target_folder"));
}
$targetid = $_GET["targetid"];
$folder = $dms->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);

37
out/out.ImportFS.php Normal file
View File

@ -0,0 +1,37 @@
<?php
// MyDMS. Document Management System
// Copyright (C) 2010 Matteo Lucarelli
//
// This program 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.
//
// This program 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 this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
include("../inc/inc.Settings.php");
include("../inc/inc.DBInit.php");
include("../inc/inc.Utils.php");
include("../inc/inc.Language.php");
include("../inc/inc.ClassUI.php");
include("../inc/inc.Authentication.php");
if (!$user->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;
}

View File

@ -0,0 +1,78 @@
<?php
/**
* Implementation of ImportFS view
*
* @category DMS
* @package SeedDMS
* @license GPL 2
* @version @version@
* @author Uwe Steinmann <uwe@steinmann.cx>
* @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 <uwe@steinmann.cx>
* @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 "<form class=\"form-horizontal\" action=\"../op/op.ImportFS.php\" name=\"form1\">";
print "<div class=\"control-group\"><label class=\"control-label\"></label><div class=\"controls\">";
$this->printFolderChooserHtml("form1",M_READWRITE);
print "</div></div>";
if($dropfolderdir) {
print "<div class=\"control-group\"><label class=\"control-label\">";
printMLText("dropfolder_file");
echo ": ";
print "</label><div class=\"controls\">";
/* Setting drop folder dir to "" will force to take the default from settings.xml */
$this->printDropFolderChooserHtml("form1", "", 1);
print "</div></div>";
}
print "<div class=\"control-group\"><label class=\"control-label\">";
print "</label><div class=\"controls\">";
print "<input type='submit' class='btn' name='' value='".getMLText("import")."'/><br />";
print "</div></div>";
print "</form>\n";
$this->contentContainerEnd();
$this->htmlEndPage();
} /* }}} */
}