Example #1
0
 /**
  *	Save a backup of the file
  *
  */
 public function SaveBackup()
 {
     global $dataDir;
     $dir = $dataDir . '/data/_backup/pages/' . $this->gp_index;
     if ($this->draft_exists) {
         $contents = \gp\tool\Files::GetRaw($this->draft_file);
     } else {
         $contents = \gp\tool\Files::GetRaw($this->file);
     }
     //use the request time
     $time = \gp\tool\Editing::ReqTime();
     //backup file name
     $len = strlen($contents);
     $backup_file = $dir . '/' . $time . '.' . $len;
     if (isset($this->file_stats['username']) && $this->file_stats['username']) {
         $backup_file .= '.' . $this->file_stats['username'];
     }
     //compress
     if (function_exists('gzencode') && function_exists('readgzfile')) {
         $backup_file .= '.gze';
         $contents = gzencode($contents, 9);
     }
     if (file_exists($backup_file)) {
         return true;
     }
     if (!\gp\tool\Files::Save($backup_file, $contents)) {
         return false;
     }
     $this->CleanBackupFolder();
     return true;
 }