Example #1
0
 /**
  *  CREATE
  *  Creates the zip file and adds the SQL file to the archive
  */
 public static function Create(DUP_Archive $archive)
 {
     try {
         $timerAllStart = DUP_Util::GetMicrotime();
         $package_zip_flush = DUP_Settings::Get('package_zip_flush');
         self::$compressDir = rtrim(DUP_Util::SafePath($archive->PackDir), '/');
         self::$filterDirsArray = array_map('DUP_Util::SafePath', explode(";", $archive->FilterDirs, -1));
         self::$filterDirsList = $archive->FilterDirs;
         self::$filterExtsArray = explode(";", $archive->FilterExts, -1);
         self::$filterExtsList = $archive->FilterExts;
         self::$filterOn = $archive->FilterOn;
         self::$sqlPath = DUP_Util::SafePath("{$archive->Package->StorePath}/{$archive->Package->Database->File}");
         self::$zipPath = DUP_Util::SafePath("{$archive->Package->StorePath}/{$archive->File}");
         self::$zipArchive = new ZipArchive();
         self::$filterDirsOn = count(self::$filterDirsArray);
         self::$filterExtsOn = count(self::$filterExtsArray);
         self::$networkFlush = empty($package_zip_flush) ? false : $package_zip_flush;
         DUP_Log::Info("\n********************************************************************************");
         DUP_Log::Info("ARCHIVE (ZIP):");
         DUP_Log::Info("********************************************************************************");
         DUP_Log::Info("ARCHIVE DIR:  " . self::$compressDir);
         DUP_Log::Info("ARCHIVE FILE: " . basename(self::$zipPath));
         DUP_Log::Info("FILTER DIRS:  " . self::$filterDirsList);
         DUP_Log::Info("FILTER EXTS:  " . self::$filterExtsList);
         //--------------------------------
         //OPEN ZIP
         $isZipOpen = self::$zipArchive->open(self::$zipPath, ZIPARCHIVE::CREATE) === TRUE;
         if (!$isZipOpen) {
             DUP_Log::Error("Cannot open zip file with PHP ZipArchive.", "Path location [" . self::$zipPath . "]");
         }
         //--------------------------------
         //ADD FILES
         DUP_Log::Info("----------------------------------------");
         DUP_Log::Info("SCANNING");
         $timerFilesStart = DUP_Util::GetMicrotime();
         if (self::$filterOn && (self::$filterDirsOn || self::$filterExtsOn)) {
             DUP_Log::Info("FILTERS *ON*");
             !in_array(self::$compressDir, self::$filterDirsArray) ? self::recurseDirsWithFilters(self::$compressDir) : DUP_Log::Info("-filter@[" . self::$compressDir . "]");
         } else {
             DUP_Log::Info("FILTERS *OFF*");
             self::recurseDirs(self::$compressDir);
         }
         $timerFilesEnd = DUP_Util::GetMicrotime();
         $timerFilesSum = DUP_Util::ElapsedTime($timerFilesEnd, $timerFilesStart);
         DUP_Log::Info("STATS:\tDirs " . self::$countDirs . " | Files " . self::$countFiles . " | Links " . self::$countLinks);
         DUP_Log::Info("SIZE:\t" . DUP_Util::ByteSize(self::$size));
         DUP_Log::Info("TIME:\t{$timerFilesSum}");
         DUP_Log::Info("----------------------------------------");
         DUP_Log::Info("COMPRESSING");
         //--------------------------------
         //ADD SQL
         $isSQLInZip = self::$zipArchive->addFile(self::$sqlPath, "database.sql");
         if ($isSQLInZip) {
             DUP_Log::Info("SQL ADDED: " . basename(self::$sqlPath));
         } else {
             DUP_Log::Error("Unable to add database.sql file to archive.", "SQL File Path [" . self::$sqlath . "]");
         }
         self::$zipArchive->close();
         self::$zipArchive->open(self::$zipPath, ZipArchive::CREATE);
         DUP_Log::Info(print_r(self::$zipArchive, true));
         //--------------------------------
         //LOG FINAL RESULTS
         DUP_Util::FcgiFlush();
         $zipCloseResult = self::$zipArchive->close();
         $zipCloseResult ? DUP_Log::Info("COMPRESSION RESULT: '{$zipCloseResult}'") : DUP_Log::Error("ZipArchive close failure.", "This hosted server may have a disk quota limit.\nCheck to make sure this archive file can be stored.");
         $timerAllEnd = DUP_Util::GetMicrotime();
         $timerAllSum = DUP_Util::ElapsedTime($timerAllEnd, $timerAllStart);
         self::$zipFileSize = @filesize(self::$zipPath);
         DUP_Log::Info("COMPRESSED SIZE: " . DUP_Util::ByteSize(self::$zipFileSize));
         DUP_Log::Info("ARCHIVE RUNTIME: {$timerAllSum}");
     } catch (Exception $e) {
         DUP_Log::Error("Runtime error in package.archive.zip.php constructor.", "Exception: {$e}");
     }
 }