From 6804cc3776beb73dc02583736c9a80b1501415e4 Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Mon, 19 Sep 2016 17:18:24 +0100 Subject: [PATCH] Backup a file before saving the new HTML contents --- app/Jobs/DownloadWebMention.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/Jobs/DownloadWebMention.php b/app/Jobs/DownloadWebMention.php index 592b41d3..71894270 100644 --- a/app/Jobs/DownloadWebMention.php +++ b/app/Jobs/DownloadWebMention.php @@ -41,8 +41,13 @@ class DownloadWebMention implements ShouldQueue //Laravel should catch and retry these automatically. if ($response->getStatusCode() == '200') { $filesystem = \Illuminate\FileSystem\FileSystem(); + $filename = $this->createFilenameFromURL($source); + //backup file first + if ($filesystem->exists($filename)) { + $filesystem->copy($filename, $filename . '.' . date('Y-m-d') . '.backup'); + } $filesystem->put( - $this->createFilenameFromURL($source), + $filename, (string) $response->getBody() ); }