Ejemplo n.º 1
0
 public function process(Vtiger_Request $request)
 {
     $log = vglobal('log');
     $newBackup = Settings_BackUp_Module_Model::clearBackupFilesTable();
     $log->info('Settings_BackUp_CreateFileBackUp_Action::process - Start files backup');
     $dirsFromConfig = Settings_BackUp_Module_Model::getConfig('folder');
     $dirsDiffConfig = '';
     $dirs = array_filter(array_merge(glob('*'), glob('.htaccess')));
     $dirs = array_diff($dirs, array('cache'));
     if ('true' != $dirsFromConfig['storage_folder']) {
         $dirs = array_diff($dirs, ['storage']);
     }
     if ('true' != $dirsFromConfig['backup_folder']) {
         $dirs = array_diff($dirs, [Settings_BackUp_Module_Model::$destDir]);
     }
     $dbDirs = Settings_BackUp_Module_Model::getDirs();
     $newDirs = array();
     $count = 0;
     $backUpInfo = Settings_BackUp_Module_Model::getBackUpInfo();
     $sqlFileName = $backUpInfo['file_name'];
     $this->fileName = $sqlFileName . '.files';
     if ($request->get('backUpAction') == 'cron') {
         $cron = TRUE;
     } else {
         $cron = FALSE;
     }
     if ($newBackup) {
         $log->info('New files backup');
         foreach ($dirs as $dir) {
             $dir = str_replace('\\', '/', $dir);
             if (!isset($dbDirs[$dir])) {
                 $newDirs[] = $dir;
             }
             if (!isset($dbDirs[$dir]) || $dbDirs[$dir] == 0) {
                 Settings_BackUp_CreateFileBackUp_Action::zipData($dir, Settings_BackUp_Module_Model::$tempDir . '/' . $this->fileName . '.zip', 0, $cron, array(), $this->fileName);
             }
         }
         Settings_BackUp_Module_Model::addBackupDirs($newDirs);
     }
     $dbAccuallyDirs = Settings_BackUp_Module_Model::getDirs();
     foreach ($dirs as $dir) {
         Settings_BackUp_CreateFileBackUp_Action::zipData($dir, Settings_BackUp_Module_Model::$tempDir . '/' . $this->fileName . '.zip', 1, $cron, $dbAccuallyDirs, $this->fileName);
     }
     $zip = new ZipArchive();
     $zip->open(Settings_BackUp_Module_Model::$destDir . '/' . $sqlFileName . '.zip', ZipArchive::CREATE);
     $zip->addFile(Settings_BackUp_Module_Model::$tempDir . '/' . $sqlFileName . '.db.zip', "db.zip");
     $zip->addFile(Settings_BackUp_Module_Model::$tempDir . '/' . $this->fileName . '.zip', "files.zip");
     $zip->close();
     Settings_BackUp_Module_Model::sendBackupToFTP(Settings_BackUp_Module_Model::$destDir . '/', $sqlFileName . '.zip');
     Settings_BackUp_Module_Model::sendNotificationEmail();
     Settings_BackUp_Module_Model::setBackUp();
     Settings_BackUp_Module_Model::deleteTmpBackUpContent();
     Settings_BackUp_Module_Model::deleteFile($sqlFileName . '.db.zip');
     Settings_BackUp_Module_Model::deleteFile($this->fileName . '.zip');
     echo json_encode(array('percentage' => 100));
 }