10-26-2010, 05:13 PM 
		
	
	
		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
Change
To
BUG with caracters:
In the file "out.BackupTools.php"
to
There is a problem, accented characters in the ZIP file
Doudoux
	
	
	
	
	
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_name, ZIPARCHIVE::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+1 < 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;
} 
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


