本文整理汇总了PHP中PclZip::privCloseFd方法的典型用法代码示例。如果您正苦于以下问题:PHP PclZip::privCloseFd方法的具体用法?PHP PclZip::privCloseFd怎么用?PHP PclZip::privCloseFd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PclZip
的用法示例。
在下文中一共展示了PclZip::privCloseFd方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: unZip
/**
* Uncompress zip file using pclzip library
*
* @param $zipFile string path to zip file
* @param $extractPath string path to location which will be extract to
*
* @return boolean true if success, false if failure
*/
function unZip($zipFile, $extractPath)
{
$pcl = new PclZip($zipFile);
if (empty($pcl)) {
return false;
}
$retVal = $pcl->extract(PCLZIP_OPT_PATH, $extractPath);
$pcl->privCloseFd();
return $retVal;
}
示例2: unZip
/**
* Uncompress zip file using pclzip library
*
* @param $zipFile string path to zip file
* @param $extractPath string path to location which will be extract to
*
* @return boolean true if success, false if failure
*/
public static function unZip($zipFile, $extractPath)
{
$pcl = new PclZip($zipFile);
if (empty($pcl)) {
throw new Exception("ArchiveHelper::unZip:: can not open zip file: {$zipFile}");
}
$retVal = $pcl->extract(PCLZIP_OPT_PATH, $extractPath);
$pcl->privCloseFd();
return $retVal;
}
示例3: privDeleteByRule
function privDeleteByRule(&$p_result_list, &$p_options)
{
//--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privDeleteByRule", "");
$v_result = 1;
$v_list_detail = array();
// ----- Open the zip file
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
if (($v_result = $this->privOpenFd('rb')) != 1) {
// ----- Return
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
return $v_result;
}
// ----- Read the central directory informations
$v_central_dir = array();
if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) {
$this->privCloseFd();
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
return $v_result;
}
// ----- Go to beginning of File
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'");
@rewind($this->zip_fd);
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'");
// ----- Scan all the files
// ----- Start at beginning of Central Dir
$v_pos_entry = $v_central_dir['offset'];
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position before rewind : ".ftell($this->zip_fd)."'");
@rewind($this->zip_fd);
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after rewind : ".ftell($this->zip_fd)."'");
if (@fseek($this->zip_fd, $v_pos_entry)) {
// ----- Close the zip file
$this->privCloseFd();
// ----- Error log
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
// ----- Return
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
return PclZip::errorCode();
}
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after fseek : ".ftell($this->zip_fd)."'");
// ----- Read each entry
$v_header_list = array();
$j_start = 0;
for ($i = 0, $v_nb_extracted = 0; $i < $v_central_dir['entries']; $i++) {
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Read next file header entry (index '$i')");
// ----- Read the file header
$v_header_list[$v_nb_extracted] = array();
if (($v_result = $this->privReadCentralFileHeader($v_header_list[$v_nb_extracted])) != 1) {
// ----- Close the zip file
$this->privCloseFd();
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
return $v_result;
}
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename (index '$i') : '".$v_header_list[$v_nb_extracted]['stored_filename']."'");
// ----- Store the index
$v_header_list[$v_nb_extracted]['index'] = $i;
// ----- Look for the specific extract rules
$v_found = false;
// ----- Look for extract by name rule
if (isset($p_options[PCLZIP_OPT_BY_NAME]) && $p_options[PCLZIP_OPT_BY_NAME] != 0) {
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByName'");
// ----- Look if the filename is in the list
for ($j = 0; $j < sizeof($p_options[PCLZIP_OPT_BY_NAME]) && !$v_found; $j++) {
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Compare with file '".$p_options[PCLZIP_OPT_BY_NAME][$j]."'");
// ----- Look for a directory
if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") {
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The searched item is a directory");
// ----- Look if the directory is in the filename path
if (strlen($v_header_list[$v_nb_extracted]['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j]) && substr($v_header_list[$v_nb_extracted]['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The directory is in the file path");
$v_found = true;
} elseif (($v_header_list[$v_nb_extracted]['external'] & 0x10) == 0x10 && $v_header_list[$v_nb_extracted]['stored_filename'] . '/' == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The entry is the searched directory");
$v_found = true;
}
} elseif ($v_header_list[$v_nb_extracted]['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The file is the right one.");
$v_found = true;
}
}
} else {
if (isset($p_options[PCLZIP_OPT_BY_EREG]) && $p_options[PCLZIP_OPT_BY_EREG] != "") {
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract by ereg '".$p_options[PCLZIP_OPT_BY_EREG]."'");
if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header_list[$v_nb_extracted]['stored_filename'])) {
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename match the regular expression");
$v_found = true;
}
} else {
if (isset($p_options[PCLZIP_OPT_BY_PREG]) && $p_options[PCLZIP_OPT_BY_PREG] != "") {
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByEreg'");
if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header_list[$v_nb_extracted]['stored_filename'])) {
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename match the regular expression");
$v_found = true;
}
} else {
if (isset($p_options[PCLZIP_OPT_BY_INDEX]) && $p_options[PCLZIP_OPT_BY_INDEX] != 0) {
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByIndex'");
// ----- Look if the index is in the list
for ($j = $j_start; $j < sizeof($p_options[PCLZIP_OPT_BY_INDEX]) && !$v_found; $j++) {
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Look if index '$i' is in [".$p_options[PCLZIP_OPT_BY_INDEX][$j]['start'].",".$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']."]");
if ($i >= $p_options[PCLZIP_OPT_BY_INDEX][$j]['start'] && $i <= $p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) {
//.........这里部分代码省略.........
示例4: privDeleteByRule
function privDeleteByRule(&$p_result_list, &$p_options)
{
$v_result = 1;
$v_list_detail = array();
// ----- Open the zip file
if (($v_result = $this->privOpenFd('rb')) != 1) {
// ----- Return
return $v_result;
}
// ----- Read the central directory informations
$v_central_dir = array();
if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) {
$this->privCloseFd();
return $v_result;
}
// ----- Go to beginning of File
@rewind($this->zip_fd);
// ----- Scan all the files
// ----- Start at beginning of Central Dir
$v_pos_entry = $v_central_dir['offset'];
@rewind($this->zip_fd);
if (@fseek($this->zip_fd, $v_pos_entry)) {
// ----- Close the zip file
$this->privCloseFd();
// ----- Error log
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
// ----- Return
return PclZip::errorCode();
}
// ----- Read each entry
$v_header_list = array();
$j_start = 0;
for ($i = 0, $v_nb_extracted = 0; $i < $v_central_dir['entries']; $i++) {
// ----- Read the file header
$v_header_list[$v_nb_extracted] = array();
if (($v_result = $this->privReadCentralFileHeader($v_header_list[$v_nb_extracted])) != 1) {
// ----- Close the zip file
$this->privCloseFd();
return $v_result;
}
// ----- Store the index
$v_header_list[$v_nb_extracted]['index'] = $i;
// ----- Look for the specific extract rules
$v_found = false;
// ----- Look for extract by name rule
if (isset($p_options[PCLZIP_OPT_BY_NAME]) && $p_options[PCLZIP_OPT_BY_NAME] != 0) {
// ----- Look if the filename is in the list
for ($j = 0; $j < sizeof($p_options[PCLZIP_OPT_BY_NAME]) && !$v_found; $j++) {
// ----- Look for a directory
if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") {
// ----- Look if the directory is in the filename path
if (strlen($v_header_list[$v_nb_extracted]['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j]) && substr($v_header_list[$v_nb_extracted]['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
$v_found = true;
} elseif (($v_header_list[$v_nb_extracted]['external'] & 0x10) == 0x10 && $v_header_list[$v_nb_extracted]['stored_filename'] . '/' == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
$v_found = true;
}
} elseif ($v_header_list[$v_nb_extracted]['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
$v_found = true;
}
}
} else {
if (isset($p_options[PCLZIP_OPT_BY_PREG]) && $p_options[PCLZIP_OPT_BY_PREG] != "") {
if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header_list[$v_nb_extracted]['stored_filename'])) {
$v_found = true;
}
} else {
if (isset($p_options[PCLZIP_OPT_BY_INDEX]) && $p_options[PCLZIP_OPT_BY_INDEX] != 0) {
// ----- Look if the index is in the list
for ($j = $j_start; $j < sizeof($p_options[PCLZIP_OPT_BY_INDEX]) && !$v_found; $j++) {
if ($i >= $p_options[PCLZIP_OPT_BY_INDEX][$j]['start'] && $i <= $p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) {
$v_found = true;
}
if ($i >= $p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) {
$j_start = $j + 1;
}
if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start'] > $i) {
break;
}
}
} else {
$v_found = true;
}
}
}
// ----- Look for deletion
if ($v_found) {
unset($v_header_list[$v_nb_extracted]);
} else {
$v_nb_extracted++;
}
}
// ----- Look if something need to be deleted
if ($v_nb_extracted > 0) {
// ----- Creates a temporay file
$v_zip_temp_name = PCLZIP_TEMPORARY_DIR . uniqid('pclzip-') . '.tmp';
// ----- Creates a temporary zip archive
$v_temp_zip = new PclZip($v_zip_temp_name);
// ----- Open the temporary zip file in write mode
if (($v_result = $v_temp_zip->privOpenFd('wb')) != 1) {
$this->privCloseFd();
//.........这里部分代码省略.........
示例5: privDeleteByIndex
function privDeleteByIndex($p_index, &$p_result_list)
{
PclTraceFctStart(__FILE__, __LINE__, "PclZip::privDeleteByIndex", "index='{$p_index}'");
$v_result = 1;
$v_list_detail = array();
// ----- Open the zip file
PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
if (($v_result = $this->privOpenFd('rb')) != 1) {
// ----- Return
PclTraceFctEnd(__FILE__, __LINE__, $v_result);
return $v_result;
}
// ----- Read the central directory informations
$v_central_dir = array();
if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) {
$this->privCloseFd();
PclTraceFctEnd(__FILE__, __LINE__, $v_result);
return $v_result;
}
// ----- Go to beginning of File
PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : " . ftell($this->zip_fd) . "'");
@rewind($this->zip_fd);
PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : " . ftell($this->zip_fd) . "'");
// ----- Scan all the files
// ----- Manipulate the index list
$p_index = strtr($p_index, ' ', '');
PclTraceFctMessage(__FILE__, __LINE__, 3, "Reduced index : '{$p_index}'");
$v_index_list = explode(",", $p_index);
// TBC : Here I should sort the index. However a simple sort is not enought.
// look for the use of usort()
//sort($v_index_list);
// ----- Start at beginning of Central Dir
$v_pos_entry = $v_central_dir['offset'];
PclTraceFctMessage(__FILE__, __LINE__, 3, "Position before rewind : " . ftell($this->zip_fd) . "'");
@rewind($this->zip_fd);
PclTraceFctMessage(__FILE__, __LINE__, 3, "Position after rewind : " . ftell($this->zip_fd) . "'");
if (@fseek($this->zip_fd, $v_pos_entry)) {
// ----- Close the zip file
$this->privCloseFd();
// ----- Error log
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
// ----- Return
PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
return PclZip::errorCode();
}
PclTraceFctMessage(__FILE__, __LINE__, 3, "Position after fseek : " . ftell($this->zip_fd) . "'");
// ----- Read each entry
$v_header_list = array();
for ($i = 0, $j_start = 0, $v_nb_extracted = 0; $i < $v_central_dir['entries']; $i++) {
PclTraceFctMessage(__FILE__, __LINE__, 3, "Read next file header entry : {$i}'");
// ----- Read the file header
$v_header_list[$v_nb_extracted] = array();
if (($v_result = $this->privReadCentralFileHeader($v_header_list[$v_nb_extracted])) != 1) {
// ----- Close the zip file
$this->privCloseFd();
PclTraceFctEnd(__FILE__, __LINE__, $v_result);
return $v_result;
}
// ----- Store the index
$v_header_list[$v_nb_extracted]['index'] = $i;
// ----- Look if the index is in the list
for ($j = $j_start, $v_found = false; $j < sizeof($v_index_list) && !$v_found; $j++) {
PclTraceFctMessage(__FILE__, __LINE__, 3, "Look if index '{$i}' is in '" . $v_index_list[$j] . "'");
// ----- Extract range
$v_item_list = explode("-", $v_index_list[$j]);
$v_size_item_list = sizeof($v_item_list);
if ($v_size_item_list == 1) {
if ($i == $v_item_list[0]) {
PclTraceFctMessage(__FILE__, __LINE__, 3, "Found as a single index");
$v_found = true;
}
if ($i >= $v_item_list[0]) {
$j_start = $j + 1;
}
} else {
if ($v_size_item_list == 2) {
if ($i >= $v_item_list[0] && $i <= $v_item_list[1]) {
PclTraceFctMessage(__FILE__, __LINE__, 3, "Found as part of an index range");
$v_found = true;
}
if ($i >= $v_item_list[1]) {
$j_start = $j + 1;
}
}
}
if ($v_item_list[0] > $i) {
PclTraceFctMessage(__FILE__, __LINE__, 3, "Range is greater than index, stop loop");
break;
}
}
// ----- Look for deletion
if ($v_found) {
PclTraceFctMessage(__FILE__, __LINE__, 2, "File '" . $v_header['filename'] . "', index '{$i}' need to be deleted");
unset($v_header_list[$v_nb_extracted]);
} else {
PclTraceFctMessage(__FILE__, __LINE__, 2, "File '" . $v_header['filename'] . "', index '{$i}' will not be deleted");
$v_nb_extracted++;
}
}
// ----- Creates a temporay file
//.........这里部分代码省略.........
示例6: close
/**
* Close the active archive (opened or newly created)
* @return boolean
*/
public function close()
{
return $this->pclZip->privCloseFd();
}
示例7: ajaxProcessBackupFiles
public function ajaxProcessBackupFiles()
{
if (!$this->getConfig('PS_AUTOUP_BACKUP')) {
$this->stepDone = true;
$this->next = 'backupDb';
$this->next_desc = 'File backup skipped.';
return true;
}
$this->nextParams = $this->currentParams;
$this->stepDone = false;
if (empty($this->backupFilesFilename)) {
$this->next = 'error';
$this->next_desc = $this->l('error during backupFiles');
$this->nextQuickInfo[] = '[ERROR] backupFiles filename has not been set';
$this->nextErrors[] = '[ERROR] backupFiles filename has not been set';
return false;
}
if (empty($this->nextParams['filesForBackup'])) {
// @todo : only add files and dir listed in "originalPrestashopVersion" list
$filesToBackup = $this->_listFilesInDir($this->prodRootDir, 'backup', false);
@file_put_contents($this->autoupgradePath . DIRECTORY_SEPARATOR . $this->toBackupFileList, serialize($filesToBackup));
$this->nextQuickInfo[] = sprintf($this->l('%s Files to backup.'), count($this->toBackupFileList));
$this->nextParams['filesForBackup'] = $this->toBackupFileList;
// delete old backup, create new
if (!empty($this->backupFilesFilename) && file_exists($this->backupPath . DIRECTORY_SEPARATOR . $this->backupFilesFilename)) {
unlink($this->backupPath . DIRECTORY_SEPARATOR . $this->backupFilesFilename);
}
$this->nextQuickInfo[] = sprintf($this->l('backup files initialized in %s'), $this->backupFilesFilename);
}
$filesToBackup = unserialize(file_get_contents($this->autoupgradePath . DIRECTORY_SEPARATOR . $this->toBackupFileList));
$this->next = 'backupFiles';
$this->next_desc = sprintf($this->l('Backup files in progress. %d files left'), count($filesToBackup));
if (is_array($filesToBackup)) {
if (!self::$force_pclZip && class_exists('ZipArchive', false)) {
$this->nextQuickInfo[] = $this->l('using class ZipArchive ...');
$zip_archive = true;
$zip = new ZipArchive();
$zip->open($this->backupPath . DIRECTORY_SEPARATOR . $this->backupFilesFilename, ZIPARCHIVE::CREATE);
} else {
$zip_archive = false;
$this->nextQuickInfo[] = $this->l('using class pclzip ...');
// pclzip can be already loaded (server configuration)
if (!class_exists('PclZip', false)) {
require_once dirname(__FILE__) . '/classes/pclzip.lib.php';
}
$zip = new PclZip($this->backupPath . DIRECTORY_SEPARATOR . $this->backupFilesFilename);
}
if ($zip) {
$this->next = 'backupFiles';
$this->stepDone = false;
$files_to_add = array();
for ($i = 0; $i < self::$loopBackupFiles; $i++) {
if (count($filesToBackup) <= 0) {
$this->stepDone = true;
$this->status = 'ok';
$this->next = 'backupDb';
$this->next_desc = $this->l('All files saved. Now backup Database');
$this->nextQuickInfo[] = $this->l('all files have been added to archive.', 'AdminSelfUpgrade', true);
break;
}
// filesForBackup already contains all the correct files
$file = array_shift($filesToBackup);
$archiveFilename = ltrim(str_replace($this->prodRootDir, '', $file), DIRECTORY_SEPARATOR);
if ($zip_archive) {
$added_to_zip = $zip->addFile($file, $archiveFilename);
if ($added_to_zip) {
$this->nextQuickInfo[] = sprintf($this->l('%1$s added to archive. %2$s left.', 'AdminSelfUpgrade', true), $archiveFilename, count($filesToBackup));
} else {
// if an error occur, it's more safe to delete the corrupted backup
$zip->close();
if (file_exists($this->backupPath . DIRECTORY_SEPARATOR . $this->backupFilesFilename)) {
unlink($this->backupPath . DIRECTORY_SEPARATOR . $this->backupFilesFilename);
}
$this->next = 'error';
$this->next_desc = sprintf($this->l('error when trying to add %1$s to archive %2$s.', 'AdminSelfUpgrade', true), $file, $archiveFilename);
break;
}
} else {
$files_to_add[] = $file;
$this->nextQuickInfo[] = sprintf($this->l('%1$s added to archive. %2$s left.', 'AdminSelfUpgrade', true), $archiveFilename, count($filesToBackup));
}
}
if ($zip_archive) {
$zip->close();
} else {
$added_to_zip = $zip->add($files_to_add, PCLZIP_OPT_REMOVE_PATH, $this->prodRootDir);
$zip->privCloseFd();
if (!$added_to_zip) {
$this->nextQuickInfo[] = '[ERROR] error on backup using pclzip : ' . $zip->errorInfo(true);
$this->nextErrors[] = '[ERROR] error on backup using pclzip : ' . $zip->errorInfo(true);
$this->next = 'error';
}
}
@file_put_contents($this->autoupgradePath . DIRECTORY_SEPARATOR . $this->toBackupFileList, serialize($filesToBackup));
return true;
} else {
$this->next = 'error';
$this->next_desc = $this->l('unable to open archive');
return false;
}
//.........这里部分代码省略.........
示例8: ajaxProcessBackupFiles
public function ajaxProcessBackupFiles()
{
$this->nextParams = $this->currentParams;
$this->stepDone = false;
if (empty($this->backupFilesFilename)) {
$this->next = 'error';
$this->nextDesc = $this->l('error during backupFiles');
$this->nextQuickInfo[] = '[ERROR] backupFiles filename has not been set';
return false;
}
if (empty($this->nextParams['filesForBackup'])) {
// @todo : only add files and dir listed in "originalPrestashopVersion" list
$filesToBackup = $this->_listFilesInDir($this->prodRootDir);
file_put_contents($this->autoupgradePath . DIRECTORY_SEPARATOR . $this->toBackupFileList, serialize($filesToBackup));
$this->nextQuickInfo[] = sprintf($this->l('%s Files to backup.'), sizeof($this->toBackupFileList));
$this->nextParams['filesForBackup'] = $this->toBackupFileList;
// delete old backup, create new
if (!empty($this->backupFilesFilename) && file_exists($this->autoupgradePath . DIRECTORY_SEPARATOR . $this->backupFilesFilename)) {
unlink($this->autoupgradePath . DIRECTORY_SEPARATOR . $this->backupFilesFilename);
}
$this->nextQuickInfo[] = sprintf($this->l('backup files initialized in %s'), $this->backupFilesFilename);
}
$filesToBackup = unserialize(file_get_contents($this->autoupgradePath . DIRECTORY_SEPARATOR . $this->toBackupFileList));
/////////////////////
$this->next = 'backupFiles';
// @TODO : display percent instead of this
$this->nextDesc = sprintf($this->l('Backup files in progress. %s files left'), sizeof($filesToBackup));
if (is_array($filesToBackup)) {
// @TODO later
// 1) calculate crc32 or md5 of next file
// 2) use the provided xml with crc32 calculated from previous versions ?
// or simply use the latest dir ?
//$current = crc32(file_get_contents($file));
//$file = $this->nextParams['filesForBackup'][0];
//$latestFile = str_replace(_PS_ROOT_DIR_,$this->latestRootDir,$file);
// if (file_exists($latestFile))
// $latest = crc32($latestFile);
// else
// $latest = '';
if (!self::$force_pclZip && class_exists('ZipArchive', false)) {
$zip_archive = true;
$zip = new ZipArchive();
$zip->open($this->autoupgradePath . DIRECTORY_SEPARATOR . $this->backupFilesFilename, ZIPARCHIVE::CREATE);
} else {
$zip_archive = false;
// pclzip can be already loaded (server configuration)
if (!class_exists('PclZip', false)) {
require_once dirname(__FILE__) . '/pclzip.lib.php';
}
$zip = new PclZip($this->autoupgradePath . DIRECTORY_SEPARATOR . $this->backupFilesFilename);
}
if ($zip) {
$this->next = 'backupFiles';
// @TODO all in one time will be probably too long
// 1000 ok during test, but 10 by 10 to be sure
$this->stepDone = false;
// @TODO min(self::$loopBackupFiles, sizeof())
for ($i = 0; $i < self::$loopBackupFiles; $i++) {
if (sizeof($filesToBackup) <= 0) {
$this->stepDone = true;
$this->status = 'ok';
$this->next = 'backupDb';
$this->nextDesc = $this->l('All files saved. Now backup Database');
$this->nextQuickInfo[] = $this->l('all files have been added to archive.');
break;
}
// filesForBackup already contains all the correct files
$file = array_shift($filesToBackup);
$archiveFilename = ltrim(str_replace($this->prodRootDir, '', $file), DIRECTORY_SEPARATOR);
if ($zip_archive) {
$added_to_zip = $zip->addFile($file, $archiveFilename);
if ($added_to_zip) {
$this->nextQuickInfo[] = sprintf($this->l('%1$s added to archive. %2$s left.'), $archiveFilename, sizeof($filesToBackup));
} else {
// if an error occur, it's more safe to delete the corrupted backup
$zip->close();
if (file_exists($this->autoupgradePath . DIRECTORY_SEPARATOR . $this->backupFilesFilename)) {
unlink($this->autoupgradePath . DIRECTORY_SEPARATOR . $this->backupFilesFilename);
}
$this->next = 'error';
$this->nextDesc = sprintf($this->l('error when trying to add %1$s to archive %2$s.'), $archiveFilename, $backupFilePath);
break;
}
} else {
$files_to_add[] = $file;
$this->nextQuickInfo[] = sprintf($this->l('%1$s added to archive. %2$s left.'), $archiveFilename, sizeof($filesToBackup));
}
}
if ($zip_archive) {
$zip->close();
} else {
$added_to_zip = $zip->add($files_to_add, PCLZIP_OPT_REMOVE_PATH, $this->prodRootDir);
$zip->privCloseFd();
if (!$added_to_zip) {
$this->nextQuickInfo[] = '[ERROR] error on backup using pclzip : ' . $zip->errorInfo(true);
$this->next = 'error';
}
}
file_put_contents($this->autoupgradePath . DIRECTORY_SEPARATOR . $this->toBackupFileList, serialize($filesToBackup));
return true;
//.........这里部分代码省略.........