Archive_Tar::addModify PHP Method

addModify() public method

The $p_filelist parameter can be an array of string, each string representing a filename or a directory name with their path if needed. It can also be a single string with names separated by a single blank. The path indicated in $p_remove_dir will be removed from the memorized path of each file / directory listed when this path exists. By default nothing is removed (empty path '') The path indicated in $p_add_dir will be added at the beginning of the memorized path of each file / directory listed. However it can be set to empty ''. The adding of a path is done after the removing of path. The path add/remove ability enables the user to prepare an archive for extraction in a different path than the origin files are. If a file/dir is already in the archive it will only be added at the end of the archive. There is no update of the existing archived file/dir. However while extracting the archive, the last file will replace the first one. This results in a none optimization of the archive size. If a file/dir does not exist the file/dir is ignored. However an error text is send to PEAR error. If a file/dir is not readable the file/dir is ignored. However an error text is send to PEAR error.
public addModify ( array $p_filelist, string $p_add_dir, string $p_remove_dir = '' ) : true
$p_filelist array An array of filenames and directory names, or a single string with names separated by a single blank space.
$p_add_dir string A string which contains a path to be added to the memorized path of each element in the list.
$p_remove_dir string A string which contains a path to be removed from the memorized path of each element in the list, when relevant.
return true on success, false on error.
    function addModify($p_filelist, $p_add_dir, $p_remove_dir = '')
    {
        $v_result = true;
        if (!$this->_isArchive()) {
            $v_result = $this->createModify($p_filelist, $p_add_dir, $p_remove_dir);
        } else {
            if (is_array($p_filelist)) {
                $v_list = $p_filelist;
            } elseif (is_string($p_filelist)) {
                $v_list = explode($this->_separator, $p_filelist);
            } else {
                $this->_error('Invalid file list');
                return false;
            }
            $v_result = $this->_append($v_list, $p_add_dir, $p_remove_dir);
        }
        return $v_result;
    }

Usage Example

示例#1
0
 public static function archive($name = false, $listFilesAndFolders, $export_files_dir, $export_files_dir_name, $backupName, $move = false, $identifier, $type)
 {
     if (empty($export_files_dir)) {
         return;
     }
     $dir_separator = DIRECTORY_SEPARATOR;
     $backupName = 'backup' . $dir_separator . $backupName;
     $installFilePath = 'system' . $dir_separator . 'admin-scripts' . $dir_separator . 'miscellaneous' . $dir_separator;
     $dbSQLFilePath = 'backup' . $dir_separator;
     $old_path = getcwd();
     chdir($export_files_dir);
     $tar = new Archive_Tar($backupName, 'gz');
     if (SJB_System::getIfTrialModeIsOn()) {
         $tar->setIgnoreList(array('system/plugins/mobile', 'system/plugins/facebook_app', 'templates/mobile', 'templates/Facebook'));
     }
     SessionStorage::write('backup_' . $identifier, serialize(array('last_time' => time())));
     switch ($type) {
         case 'full':
             $tar->addModify("{$installFilePath}install.php", '', $installFilePath);
             $tar->addModify($dbSQLFilePath . $name, '', $dbSQLFilePath);
             $tar->addModify($listFilesAndFolders, '');
             SJB_Filesystem::delete($export_files_dir . $dbSQLFilePath . $name);
             break;
         case 'files':
             $tar->addModify("{$installFilePath}install.php", '', $installFilePath);
             $tar->addModify($listFilesAndFolders, '');
             break;
         case 'database':
             $tar->addModify($dbSQLFilePath . $listFilesAndFolders, '', $dbSQLFilePath);
             SJB_Filesystem::delete($export_files_dir . $dbSQLFilePath . $listFilesAndFolders);
             break;
     }
     chdir($old_path);
     return true;
 }
All Usage Examples Of Archive_Tar::addModify