public function handleBackup($pass)
 {
     $year = date('Y');
     $month = date('F');
     $path = WWW_DIR . "/app/backup/{$year}/{$month}/";
     if (!file_exists($path)) {
         if (!mkdir($path, 0777, true)) {
             $this->logError('mkdir() failure -> directory was not created!');
             $this->sendMail('Automatic backup', 'Check the log file.');
         }
     }
     $file = $path . 'auto-' . date('Y-m-d') . '.sql';
     if (!file_exists($file)) {
         if ($this->backupPassword !== null) {
             if ($this->backupPassword != $pass) {
                 $this->logError('Forbidden access.');
                 $this->sendMail('Automatic database backup', 'Forbidden access');
                 return;
             }
         }
         try {
             $this->databaseBackup->save($file);
             $this->sendMail(date('Y-m-d') . ' - Automatic database backup', 'OK', $file);
         } catch (\Exception $e) {
             $this->logError($e->getMessage());
             $this->sendMail('Automatic database backup failure', $e->getMessage());
         }
     }
 }
Exemple #2
0
 public function processBackup(Form $form)
 {
     if ($this->user->isInRole('administrator')) {
         $file = WWW_DIR . '/app/backup/' . date('Y-m-d H-i-s') . '.sql';
         try {
             $this->databaseBackup->save($file);
             $this->flashMessage('Záloha databáze byla úspěšně provedena!', 'success');
         } catch (\Exception $e) {
             $this->flashMessage($e->getMessage(), 'error');
         }
         $mail = new Message();
         $mail->setFrom('Výčetkový systém <' . $this->emails['system'] . '>')->addTo($this->emails['admin'])->setSubject('Záloha databáze')->addAttachment($file);
         try {
             $this->mailer->send($mail);
             $this->flashMessage('Soubor se zálohou byl úspěšně odeslán.', 'success');
         } catch (InvalidStateException $is) {
             $this->flashMessage('Soubor se zálohou se nepodařilo odeslat.', 'warning');
         }
     } else {
         $this->flashMessage('Nemáte dostatečná oprávnění k provedení akce.', 'warning');
     }
     $this->redirect('this');
 }