/**
* @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;
}