Exemplo n.º 1
0
 public function zipData($source, $destination, $backup, $cron, $backupedDirs = array(), $fileName)
 {
     $log = vglobal('log');
     $log->info('Create zip');
     $newSubDirs[] = (string) $source;
     if (extension_loaded('zip')) {
         if (file_exists($source)) {
             $zip = new ZipArchive();
             if ($zip->open($destination, ZIPARCHIVE::CREATE)) {
                 if (is_dir($source)) {
                     $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
                     foreach ($files as $file) {
                         if ($count == 80) {
                             if ($cron == FALSE) {
                                 $percentage = Settings_BackUp_Module_Model::getPercentage();
                                 exit(json_encode(array('percentage' => $percentage)));
                             }
                         }
                         if (is_dir($file)) {
                             $newSubDirs[] = $file;
                             if ($backup) {
                                 $fileName = str_replace('\\', '/', (string) $file);
                                 if (isset($backupedDirs[$fileName]) && $backupedDirs[$fileName] == 0) {
                                     Settings_BackUp_Module_Model::setDirBackuped($fileName);
                                     $zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
                                     $count++;
                                 }
                             }
                         } else {
                             if (is_file($file)) {
                                 if ($backup && strpos((string) $file, $fileName) === FALSE) {
                                     $zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
                                 }
                             }
                         }
                     }
                     if (!$backup) {
                         Settings_BackUp_Module_Model::addBackupDirs($newSubDirs);
                     }
                 } else {
                     if (is_file($source)) {
                         if ($backup) {
                             $zip->addFromString(basename($source), file_get_contents($source));
                         }
                     }
                 }
             }
             Settings_BackUp_Module_Model::setDirBackuped($source);
             return $zip->close();
         }
     }
     return false;
 }