Skip to content

Commit

Permalink
After @keksa CR
Browse files Browse the repository at this point in the history
  • Loading branch information
janprochazkacz committed Dec 5, 2024
1 parent f396c4d commit 1b4522a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Binary file modified plugins/backup-sync-dropbox/backup-sync-dropbox.zip
Binary file not shown.
20 changes: 16 additions & 4 deletions plugins/backup-sync-dropbox/src/src/Facade/BackupFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ public function upload(UnmsBackup $unmsBackup): void
return;
}

$temp = tmpfile();
fwrite($temp, $this->unmsApi->get(sprintf('nms/backups/%s', $unmsBackup->id)));

$this->filesystem->writeStream($unmsBackup->filename, $temp);
$temporaryFile = $this->getTemporaryFile();
$resource = fopen($temporaryFile, 'wb+');
fwrite($resource, $this->unmsApi->get(sprintf('nms/backups/%s', $unmsBackup->id)));
rewind($resource);
$this->filesystem->writeStream($unmsBackup->filename, $resource);
unlink($temporaryFile);

$this->logger->info(sprintf('Uploaded file "%s".', $unmsBackup->filename));
}
Expand All @@ -51,4 +53,14 @@ public function deleteExcept(array $filenames): void
$this->logger->info(sprintf('Deleted file "%s".', $item['path']));
}
}

private function getTemporaryFile(): string
{
$tempDir = realpath(sys_get_temp_dir());
assert(is_string($tempDir));
$tmpFile = tempnam($tempDir, 'ucrmTmpFile');
assert(is_string($tmpFile));

return $tmpFile;
}
}

0 comments on commit 1b4522a

Please sign in to comment.