/** * Unzip the file by using the ZipArchiveCto class * * @param sring $strZipPath Path to the zip * @return array A list with current path and taget path. * @throws Exception */ protected function unzipBySyncCto($strZipPath) { // New archive $objZipArchive = new ZipArchiveCto(); // Open archive if (($mixError = $objZipArchive->open($strZipPath, ZipArchiveCto::CREATE)) !== true) { throw new Exception($GLOBALS['TL_LANG']['MSC']['error'] . ": " . $objZipArchive->getErrorDescription($mixError)); } // Create tmp folder new Folder(self::TEMP_PATH . '/syncCtoAutoUpdate'); $arrMoveList = array(); // Extract all files to temp folder for ($i = 0; $i < $objZipArchive->numFiles; $i++) { $filename = $objZipArchive->getNameIndex($i); // Check if the file part of the folder "FILES" if (!preg_match("/^" . self::ZIP_FILE_PATH . "\\//i", $filename)) { continue; } // Build path $movePath = preg_replace("/^" . self::ZIP_FILE_PATH . "\\//i", "", $filename); $targetPath = self::TEMP_PATH . 'syncCtoAutoUpdate/'; $arrMoveList[$targetPath . $filename] = $movePath; // Extract file if (!$objZipArchive->extractTo($targetPath, $filename)) { throw new Exception("Error by extract file: " . $filename); } } return $arrMoveList; }
/** * Unzip files * * @param string $strRestoreFile Path to the zip file * @return mixes True - If ervething is okay, Array - If some files could not be extract to a given path. * @throws Exception if the zip file was not able to open. */ public function runRestore($strRestoreFile) { $objZipArchive = new ZipArchiveCto(); if (($mixError = $objZipArchive->open($strRestoreFile)) !== true) { $strError = sprintf("%s %s || Status (%s): %s || System (%s): %s ", $GLOBALS['TL_LANG']['ERR']['cant_extract_file'], $objZipArchive->getErrorDescription($mixError), $objZipArchive->status, $objZipArchive->getErrorDescription($objZipArchive->status), $objZipArchive->statusSys, $objZipArchive->getErrorDescription($objZipArchive->statusSys)); throw new \RuntimeException($strError); } if ($objZipArchive->numFiles == 0) { return; } $arrErrorFiles = array(); for ($i = 0; $i < $objZipArchive->numFiles; $i++) { $filename = $objZipArchive->getNameIndex($i); if (!$objZipArchive->extractTo("/", $filename)) { $arrErrorFiles[] = $filename; } } $objZipArchive->close(); if (count($arrErrorFiles) == 0) { return true; } else { return $arrErrorFiles; } }