Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[BackupTools] - Human readable archive
#1
Hello

There is a problem with "Human readable archive". TAR accept only filename with 100 characters.

Then i'm modified code to create a ZIP file.
This function can be used for classic backup (not tested)

In the file "op.CreateFolderArchive.php"
Add this function
PHP Code:
function createFolderZIP($folder$zip)
{
    global 
$settings,$human_readable;

    
$documents=$folder->getDocuments();
    foreach (
$documents as $document){
        
        if (
file_exists($settings->_contentDir.$document->getDir())){

            if (
$human_readable){
            
                
// create an archive containing the files with original names and DMS path 
                // thanks to Doudoux 

                
$latestContent $document->getLatestContent();
                if (
is_object($latestContent))
                {
                    
$zip->addFile(
                      
$settings->_contentDir.$latestContent->getDir().$latestContent->getVersion().$latestContent->getFileType(),
                      
getFolderPathPlainAST($folder)."/".$document->getID()."_".mydmsDecodeString($latestContent->getOriginalFileName()));
                }
            
            }else{

                
// create a server backup archive

                
$handle opendir($settings->_contentDir.$document->getDir());
                while (
$entry readdir($handle) )
                {
                    if (!
is_dir($settings->_contentDir.$document->getDir().$entry)){

                      
$zip->addFile($settings->_contentDir.$document->getDir().$entry,$document->getDir().$entry);
                    }

                }
                
closedir($handle);
            }
        }    
    }

    
$subFolders=$folder->getSubfolders();
    foreach (
$subFolders as $folder)
        if (!
createFolderZIP($folder$zip))
            return 
false;
    
    return 
true;




Change
PHP Code:
if ($human_readable)$ark_name $settings->_contentDir.time()."_".$folderid."_HR.tar";
else 
$ark_name $settings->_contentDir.time()."_".$folderid.".tar";

$ark fopen($ark_name,"w");

if (!
createFolderTar($folder,$ark)) {
    
fclose($ark);
    
unlink($ark_name);
    
UI::exitError(getMLText("admin_tools"),getMLText("error_occured"));
}

TarAddFooter($ark);
fclose($ark);

if (
gzcompressfile($ark_name,9)) unlink($ark_name);
else 
UI::exitError(getMLText("admin_tools"),getMLText("error_occured")); 

To

PHP Code:
if ($human_readable)
{
    
$ark_name $settings->_contentDir.time()."_".$folderid."_HR.zip";
    
    
$zip = new ZipArchive;
    if (
$zip->open($ark_nameZIPARCHIVE::CREATE) === TRUE)
    {
      if (!
createFolderZIP($folder$zip))
      {
        
$zip->close();
        
unlink($ark_name);
        
UI::exitError(getMLText("admin_tools"),getMLText("error_occured"));
      }
      
      
$zip->close();
    }
}
else
{
    
$ark_name $settings->_contentDir.time()."_".$folderid.".tar";

    
$ark fopen($ark_name,"w");

    if (!
createFolderTar($folder,$ark)) {
        
fclose($ark);
        
unlink($ark_name);
        
UI::exitError(getMLText("admin_tools"),getMLText("error_occured"));
    }

    
TarAddFooter($ark);
    
fclose($ark);
    
    if (
gzcompressfile($ark_name,9)) 
        
unlink($ark_name);
    else 
        
UI::exitError(getMLText("admin_tools"),getMLText("error_occured"));    


BUG with caracters:
PHP Code:
function getFolderPathPlainAST($folder) {
    
$path="";
    
$folderPath $folder->getPath();
    for (
$i 0$i  count($folderPath); $i++) {
        
//$path .= $folderPath[$i]->getName();       
        
$path .= mydmsDecodeString($folderPath[$i]->getName());
        if (
$i+count($folderPath)) $path .= "/";
    }
    return 
$path;


In the file "out.BackupTools.php"
PHP Code:
while ($e readdir($handle)){
    if (
is_dir($settings->_contentDir.$e)) continue;
    if (
strpos($e,".tar.gz")==FALSE)
        continue;
    
$entries[] = $e;

to
PHP Code:
while ($e readdir($handle)){
    if (
is_dir($settings->_contentDir.$e)) continue;
    if ((
strpos($e,".tar.gz")==FALSE) && (strpos($e,".zip")==FALSE))
        continue;
    
$entries[] = $e;


There is a problem, accented characters in the ZIP file

Doudoux
Reply
#2
Thank you for the fix.
Do you know if zip archive creation will work on every system?
Does it depends on some version-specific library?
Reply
#3
(10-26-2010, 09:37 PM)matteo lucarelli Wrote: Do you know if zip archive creation will work on every system?
No, i use WAMP.
I would try to do a test on linux.

(10-26-2010, 09:37 PM)matteo lucarelli Wrote: Does it depends on some version-specific library?
i use php_zip module

Reply
#4
Well, what should be done to assure the wide compatibility of letoDMS with your patch?
Reply
#5
I'm testing on linux. It's OK with a simple test.

My config : ubuntu 9.10 / apache 2 / Mysql 5.1
(see attachment file)
Reply
#6
Up for the next release Wink
Reply


Forum Jump:


Users browsing this thread: