Merge branch 'feature/backup-before-wmredownload' into develop

This commit is contained in:
Jonny Barnes 2016-09-19 17:25:29 +01:00
commit a65ed7d141
2 changed files with 21 additions and 8 deletions

View file

@ -41,13 +41,15 @@ class ParseCachedWebMentions extends Command
{
$HTMLfiles = $filesystem->allFiles(storage_path() . '/HTML');
foreach ($HTMLfiles as $file) {
$filepath = $file->getPathname();
$html = $filesystem->get($filepath);
$url = $this->URLFromFilename($filepath);
$microformats = \Mf2\parse($html, $url);
$webmention = WebMention::where('source', $url)->firstOrFail();
$webmention->mf2 = json_encode($microformats);
$webmention->save();
if ($file->getExtension() != 'backup') { //we dont want to parse.backup files
$filepath = $file->getPathname();
$html = $filesystem->get($filepath);
$url = $this->URLFromFilename($filepath);
$microformats = \Mf2\parse($html, $url);
$webmention = WebMention::where('source', $url)->firstOrFail();
$webmention->mf2 = json_encode($microformats);
$webmention->save();
}
}
}

View file

@ -41,10 +41,21 @@ 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
$filenameBackup = $filename . '.' . date('Y-m-d') . '.backup';
if ($filesystem->exists($filename)) {
$filesystem->copy($filename, $filenameBackup);
}
//save new HTML
$filesystem->put(
$this->createFilenameFromURL($source),
$filename,
(string) $response->getBody()
);
//remove backup if the same
if ($filesystem->get($filename) == $filesystem->get($filenameBackup)) {
$filesystem->delete($filenameBackup);
}
}
}