/**
  * @param DatabaseBackupFile $file
  * @return ResultObject[]
  */
 public function process(DatabaseBackupFile $file)
 {
     $d = $file->getBackupDate();
     $results = [];
     foreach ($this->uploadsCredentials as $credentials) {
         $result = new ResultObject();
         // empty ResultObject means all is OK
         $backupPath = $credentials['path'] . '/' . $d->format('Y') . '/' . $d->format('F');
         $entireFilePath = $backupPath . '/' . $file->getFileName();
         try {
             $ftp = new \Ftp();
             $ftp->connect($credentials['host']);
             $ftp->login($credentials['username'], $credentials['password']);
             if (!$ftp->fileExists($backupPath)) {
                 $ftp->mkDirRecursive($backupPath);
             }
             $ftp->put($entireFilePath, $file->getFilePath(), FTP_BINARY);
             $ftp->close();
         } catch (\FtpException $e) {
             $this->logger->addCritical(sprintf('Uploading backup file\'s failed. %s', $e));
             $result->addError('Zálohu se nepodařilo nahrát na: ' . $credentials['host'], 'error');
         }
         $results[] = $result;
     }
     return $results;
 }
예제 #2
0
 /**
  * @param $path
  * @return string
  * @throws IOException
  */
 private function prepareStoragePath($path)
 {
     if (!file_exists($path) and is_dir($path)) {
         try {
             FileSystem::createDir($path);
         } catch (IOException $e) {
             $this->logger->addCritical(sprintf('DIR creation failure: %s', $e));
             throw $e;
         }
     }
     return $path;
 }
예제 #3
0
 /**
  * {@inheritdoc}
  * @return Boolean Whether the record has been processed
  */
 public function addCritical($message, array $context = [])
 {
     return $this->parentLogger->addCritical($message, ['channel' => $this->name] + $context);
 }