Merge branch 'feature/backup-before-wmredownload' into develop
This commit is contained in:
commit
a65ed7d141
2 changed files with 21 additions and 8 deletions
|
@ -41,6 +41,7 @@ class ParseCachedWebMentions extends Command
|
||||||
{
|
{
|
||||||
$HTMLfiles = $filesystem->allFiles(storage_path() . '/HTML');
|
$HTMLfiles = $filesystem->allFiles(storage_path() . '/HTML');
|
||||||
foreach ($HTMLfiles as $file) {
|
foreach ($HTMLfiles as $file) {
|
||||||
|
if ($file->getExtension() != 'backup') { //we don’t want to parse.backup files
|
||||||
$filepath = $file->getPathname();
|
$filepath = $file->getPathname();
|
||||||
$html = $filesystem->get($filepath);
|
$html = $filesystem->get($filepath);
|
||||||
$url = $this->URLFromFilename($filepath);
|
$url = $this->URLFromFilename($filepath);
|
||||||
|
@ -50,6 +51,7 @@ class ParseCachedWebMentions extends Command
|
||||||
$webmention->save();
|
$webmention->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine the source URL from a filename.
|
* Determine the source URL from a filename.
|
||||||
|
|
|
@ -41,10 +41,21 @@ class DownloadWebMention implements ShouldQueue
|
||||||
//Laravel should catch and retry these automatically.
|
//Laravel should catch and retry these automatically.
|
||||||
if ($response->getStatusCode() == '200') {
|
if ($response->getStatusCode() == '200') {
|
||||||
$filesystem = \Illuminate\FileSystem\FileSystem();
|
$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(
|
$filesystem->put(
|
||||||
$this->createFilenameFromURL($source),
|
$filename,
|
||||||
(string) $response->getBody()
|
(string) $response->getBody()
|
||||||
);
|
);
|
||||||
|
//remove backup if the same
|
||||||
|
if ($filesystem->get($filename) == $filesystem->get($filenameBackup)) {
|
||||||
|
$filesystem->delete($filenameBackup);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue