mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-06-08 14:19:19 +00:00
- use $dms->contentDir instead of $settings->_contentDir where ever possible
This commit is contained in:
parent
cfb360e45d
commit
4481185dab
|
@ -1,51 +1,51 @@
|
||||||
<?php
|
<?php
|
||||||
// MyDMS. Document Management System
|
// MyDMS. Document Management System
|
||||||
// Copyright (C) 2010 Matteo Lucarelli
|
// Copyright (C) 2010 Matteo Lucarelli
|
||||||
//
|
//
|
||||||
// This program is free software; you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU General Public License as published by
|
||||||
// the Free Software Foundation; either version 2 of the License, or
|
// the Free Software Foundation; either version 2 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// This program is distributed in the hope that it will be useful,
|
// This program is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU General Public License for more details.
|
// GNU General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with this program; if not, write to the Free Software
|
// along with this program; if not, write to the Free Software
|
||||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
include("../inc/inc.Settings.php");
|
include("../inc/inc.Settings.php");
|
||||||
include("../inc/inc.ClassEmail.php");
|
include("../inc/inc.ClassEmail.php");
|
||||||
include("../inc/inc.DBInit.php");
|
include("../inc/inc.DBInit.php");
|
||||||
include("../inc/inc.Language.php");
|
include("../inc/inc.Language.php");
|
||||||
include("../inc/inc.ClassUI.php");
|
include("../inc/inc.ClassUI.php");
|
||||||
include("../inc/inc.Authentication.php");
|
include("../inc/inc.Authentication.php");
|
||||||
|
|
||||||
if (!$user->isAdmin()) {
|
if (!$user->isAdmin()) {
|
||||||
UI::exitError(getMLText("admin_tools"),getMLText("access_denied"));
|
UI::exitError(getMLText("admin_tools"),getMLText("access_denied"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adds file header to the tar file, it is used before adding file content.
|
/**
|
||||||
// f: file resource (provided by eg. fopen)
|
* Adds file header to the tar file, it is used before adding file content.
|
||||||
// phisfn: path to file
|
* code by calmarius at nospam dot atw dot hu
|
||||||
// archfn: path to file in archive, directory names must be followed by '/'
|
*
|
||||||
// code by calmarius at nospam dot atw dot hu
|
* @param resource $f file resource (provided by eg. fopen)
|
||||||
function TarAddHeader($f,$phisfn,$archfn)
|
* $param string $phisfn path to file
|
||||||
{
|
* $param string $archfn path to file in archive, directory names must
|
||||||
|
* be followed by '/'
|
||||||
|
*/
|
||||||
|
function TarAddHeader($f,$phisfn,$archfn) { /* {{{ */
|
||||||
$info=stat($phisfn);
|
$info=stat($phisfn);
|
||||||
$ouid=sprintf("%6s ", decoct($info[4]));
|
$ouid=sprintf("%6s ", decoct($info[4]));
|
||||||
$ogid=sprintf("%6s ", decoct($info[5]));
|
$ogid=sprintf("%6s ", decoct($info[5]));
|
||||||
$omode=sprintf("%6s ", decoct(fileperms($phisfn)));
|
$omode=sprintf("%6s ", decoct(fileperms($phisfn)));
|
||||||
$omtime=sprintf("%11s", decoct(filemtime($phisfn)));
|
$omtime=sprintf("%11s", decoct(filemtime($phisfn)));
|
||||||
if (@is_dir($phisfn))
|
if (@is_dir($phisfn)) {
|
||||||
{
|
|
||||||
$type="5";
|
$type="5";
|
||||||
$osize=sprintf("%11s ", decoct(0));
|
$osize=sprintf("%11s ", decoct(0));
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$type='';
|
$type='';
|
||||||
$osize=sprintf("%11s ", decoct(filesize($phisfn)));
|
$osize=sprintf("%11s ", decoct(filesize($phisfn)));
|
||||||
clearstatcache();
|
clearstatcache();
|
||||||
|
@ -72,20 +72,16 @@ function TarAddHeader($f,$phisfn,$archfn)
|
||||||
fwrite($f,$bdchecksum,8);
|
fwrite($f,$bdchecksum,8);
|
||||||
fwrite($f,$chunkafterCS,356);
|
fwrite($f,$chunkafterCS,356);
|
||||||
return true;
|
return true;
|
||||||
}
|
} /* }}} */
|
||||||
|
|
||||||
// Writes file content to the tar file must be called after a TarAddHeader
|
// Writes file content to the tar file must be called after a TarAddHeader
|
||||||
// f:file resource provided by fopen
|
// f:file resource provided by fopen
|
||||||
// phisfn: path to file
|
// phisfn: path to file
|
||||||
// code by calmarius at nospam dot atw dot hu
|
// code by calmarius at nospam dot atw dot hu
|
||||||
function TarWriteContents($f,$phisfn)
|
function TarWriteContents($f,$phisfn) { /* {{{ */
|
||||||
{
|
if (@is_dir($phisfn)) {
|
||||||
if (@is_dir($phisfn))
|
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$size=filesize($phisfn);
|
$size=filesize($phisfn);
|
||||||
$padding=$size % 512 ? 512-$size%512 : 0;
|
$padding=$size % 512 ? 512-$size%512 : 0;
|
||||||
$f2=fopen($phisfn,"rb");
|
$f2=fopen($phisfn,"rb");
|
||||||
|
@ -93,18 +89,17 @@ function TarWriteContents($f,$phisfn)
|
||||||
$pstr=sprintf("a%d",$padding);
|
$pstr=sprintf("a%d",$padding);
|
||||||
fwrite($f,pack($pstr,''));
|
fwrite($f,pack($pstr,''));
|
||||||
}
|
}
|
||||||
}
|
} /* }}} */
|
||||||
|
|
||||||
// Adds 1024 byte footer at the end of the tar file
|
// Adds 1024 byte footer at the end of the tar file
|
||||||
// f: file resource
|
// f: file resource
|
||||||
// code by calmarius at nospam dot atw dot hu
|
// code by calmarius at nospam dot atw dot hu
|
||||||
function TarAddFooter($f)
|
function TarAddFooter($f) { /* {{{ */
|
||||||
{
|
|
||||||
fwrite($f,pack('a1024',''));
|
fwrite($f,pack('a1024',''));
|
||||||
}
|
} /* }}} */
|
||||||
|
|
||||||
// thanks to Doudoux
|
// thanks to Doudoux
|
||||||
function getFolderPathPlainAST($folder) {
|
function getFolderPathPlainAST($folder) { /* {{{ */
|
||||||
$path="";
|
$path="";
|
||||||
$folderPath = $folder->getPath();
|
$folderPath = $folder->getPath();
|
||||||
for ($i = 0; $i < count($folderPath); $i++) {
|
for ($i = 0; $i < count($folderPath); $i++) {
|
||||||
|
@ -112,77 +107,73 @@ function getFolderPathPlainAST($folder) {
|
||||||
if ($i+1 < count($folderPath)) $path .= "/";
|
if ($i+1 < count($folderPath)) $path .= "/";
|
||||||
}
|
}
|
||||||
return $path;
|
return $path;
|
||||||
}
|
} /* }}} */
|
||||||
|
|
||||||
function createFolderTar($folder,$ark)
|
function createFolderTar($folder,$ark) { /* {{{ */
|
||||||
{
|
global $human_readable,$dms;
|
||||||
global $settings,$human_readable;
|
|
||||||
|
|
||||||
$documents=$folder->getDocuments();
|
$documents=$folder->getDocuments();
|
||||||
foreach ($documents as $document){
|
foreach ($documents as $document){
|
||||||
|
|
||||||
if (file_exists($settings->_contentDir.$document->getDir())){
|
if (file_exists($dms->contentDir.$document->getDir())){
|
||||||
|
|
||||||
if ($human_readable){
|
if ($human_readable){
|
||||||
|
// create an archive containing the files with original names and DMS path
|
||||||
// create an archive containing the files with original names and DMS path
|
// thanks to Doudoux
|
||||||
// thanks to Doudoux
|
|
||||||
$latestContent = $document->getLatestContent();
|
$latestContent = $document->getLatestContent();
|
||||||
if (is_object($latestContent))
|
if (is_object($latestContent)) {
|
||||||
{
|
|
||||||
TarAddHeader(
|
TarAddHeader(
|
||||||
$ark,
|
$ark,
|
||||||
$settings->_contentDir.$latestContent->getDir().$latestContent->getVersion().$latestContent->getFileType(),
|
$dms->contentDir.$latestContent->getDir().$latestContent->getVersion().$latestContent->getFileType(),
|
||||||
getFolderPathPlainAST($folder)."/".$document->getID()."_".mydmsDecodeString($latestContent->getOriginalFileName()));
|
getFolderPathPlainAST($folder)."/".$document->getID()."_".mydmsDecodeString($latestContent->getOriginalFileName()));
|
||||||
|
|
||||||
TarWriteContents($ark, $settings->_contentDir.$latestContent->getDir().$latestContent->getVersion().$latestContent->getFileType());
|
TarWriteContents($ark, $dms->contentDir.$latestContent->getDir().$latestContent->getVersion().$latestContent->getFileType());
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
|
|
||||||
// create a server backup archive
|
// create a server backup archive
|
||||||
$handle = opendir($settings->_contentDir.$document->getDir());
|
$handle = opendir($dms->contentDir.$document->getDir());
|
||||||
while ($entry = readdir($handle) )
|
while ($entry = readdir($handle) ) {
|
||||||
{
|
if (!is_dir($dms->contentDir.$document->getDir().$entry)){
|
||||||
if (!is_dir($settings->_contentDir.$document->getDir().$entry)){
|
|
||||||
|
TarAddHeader($ark,$dms->contentDir.$document->getDir().$entry,$document->getDir().$entry);
|
||||||
TarAddHeader($ark,$settings->_contentDir.$document->getDir().$entry,$document->getDir().$entry);
|
TarWriteContents($ark,$dms->contentDir.$document->getDir().$entry);
|
||||||
TarWriteContents($ark,$settings->_contentDir.$document->getDir().$entry);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
closedir($handle);
|
closedir($handle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$subFolders=$folder->getSubfolders();
|
$subFolders=$folder->getSubfolders();
|
||||||
foreach ($subFolders as $folder)
|
foreach ($subFolders as $folder)
|
||||||
if (!createFolderTar($folder,$ark))
|
if (!createFolderTar($folder,$ark))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isset($_GET["targetidform2"]) || !is_numeric($_GET["targetidform2"]) || intval($_GET["targetidform2"])<1) {
|
return true;
|
||||||
UI::exitError(getMLText("admin_tools"),getMLText("invalid_folder_id"));
|
} /* }}} */
|
||||||
}
|
|
||||||
$folderid = $_GET["targetidform2"];
|
if (!isset($_GET["targetidform2"]) || !is_numeric($_GET["targetidform2"]) || intval($_GET["targetidform2"])<1) {
|
||||||
|
UI::exitError(getMLText("admin_tools"),getMLText("invalid_folder_id"));
|
||||||
|
}
|
||||||
|
$folderid = $_GET["targetidform2"];
|
||||||
$folder = $dms->getFolder($folderid);
|
$folder = $dms->getFolder($folderid);
|
||||||
|
|
||||||
if (!is_object($folder)) {
|
if (!is_object($folder)) {
|
||||||
UI::exitError(getMLText("admin_tools"),getMLText("invalid_folder_id"));
|
UI::exitError(getMLText("admin_tools"),getMLText("invalid_folder_id"));
|
||||||
}
|
}
|
||||||
|
|
||||||
$human_readable = (isset($_GET["human_readable"]) && $_GET["human_readable"]==1 ? true : false);
|
$human_readable = (isset($_GET["human_readable"]) && $_GET["human_readable"]==1 ? true : false);
|
||||||
|
|
||||||
if ($human_readable)$ark_name = $settings->_contentDir.time()."_".$folderid."_HR.tar";
|
if ($human_readable)$ark_name = $settings->_contentDir.time()."_".$folderid."_HR.tar";
|
||||||
else $ark_name = $settings->_contentDir.time()."_".$folderid.".tar";
|
else $ark_name = $settings->_contentDir.time()."_".$folderid.".tar";
|
||||||
|
|
||||||
$ark = fopen($ark_name,"w");
|
$ark = fopen($ark_name,"w");
|
||||||
|
|
||||||
if (!createFolderTar($folder,$ark)) {
|
if (!createFolderTar($folder,$ark)) {
|
||||||
fclose($ark);
|
fclose($ark);
|
||||||
unlink($ark_name);
|
unlink($ark_name);
|
||||||
UI::exitError(getMLText("admin_tools"),getMLText("error_occured"));
|
UI::exitError(getMLText("admin_tools"),getMLText("error_occured"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TarAddFooter($ark);
|
TarAddFooter($ark);
|
||||||
|
@ -193,6 +184,6 @@ else UI::exitError(getMLText("admin_tools"),getMLText("error_occured"));
|
||||||
|
|
||||||
add_log_line();
|
add_log_line();
|
||||||
|
|
||||||
header("Location:../out/out.BackupTools.php");
|
header("Location:../out/out.BackupTools.php");
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user