Merge branch 'hotfix/0.0.11.7'
This commit is contained in:
commit
9723099e91
2 changed files with 22 additions and 9 deletions
|
@ -36,25 +36,35 @@ class DownloadWebMention implements ShouldQueue
|
||||||
*/
|
*/
|
||||||
public function handle(Client $guzzle)
|
public function handle(Client $guzzle)
|
||||||
{
|
{
|
||||||
$response = $guzzle->request('GET', $source);
|
$response = $guzzle->request('GET', $this->source);
|
||||||
//4XX and 5XX responses should get Guzzle to throw an exception,
|
//4XX and 5XX responses should get Guzzle to throw an exception,
|
||||||
//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 = new \Illuminate\FileSystem\FileSystem();
|
||||||
$filename = storage_path() . '/HTML/' . $this->createFilenameFromURL($source);
|
$filename = storage_path() . '/HTML/' . $this->createFilenameFromURL($this->source);
|
||||||
//backup file first
|
//backup file first
|
||||||
$filenameBackup = $filename . '.' . date('Y-m-d') . '.backup';
|
$filenameBackup = $filename . '.' . date('Y-m-d') . '.backup';
|
||||||
if ($filesystem->exists($filename)) {
|
if ($filesystem->exists($filename)) {
|
||||||
$filesystem->copy($filename, $filenameBackup);
|
$filesystem->copy($filename, $filenameBackup);
|
||||||
}
|
}
|
||||||
|
//check if base directory exists
|
||||||
|
if (!$filesystem->exists($filesystem->dirname($filename))) {
|
||||||
|
$filesystem->makeDirectory(
|
||||||
|
$filesystem->dirname($filename),
|
||||||
|
0755, //mode
|
||||||
|
true //recursive
|
||||||
|
);
|
||||||
|
}
|
||||||
//save new HTML
|
//save new HTML
|
||||||
$filesystem->put(
|
$filesystem->put(
|
||||||
$filename,
|
$filename,
|
||||||
(string) $response->getBody()
|
(string) $response->getBody()
|
||||||
);
|
);
|
||||||
//remove backup if the same
|
//remove backup if the same
|
||||||
if ($filesystem->get($filename) == $filesystem->get($filenameBackup)) {
|
if ($filesystem->exists($filenameBackup)) {
|
||||||
$filesystem->delete($filenameBackup);
|
if ($filesystem->get($filename) == $filesystem->get($filenameBackup)) {
|
||||||
|
$filesystem->delete($filenameBackup);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,11 +78,11 @@ class DownloadWebMention implements ShouldQueue
|
||||||
*/
|
*/
|
||||||
private function createFilenameFromURL($url)
|
private function createFilenameFromURL($url)
|
||||||
{
|
{
|
||||||
$url = str_replace(['https://', 'http://'], ['https/', 'http/'], $url);
|
$filepath = str_replace(['https://', 'http://'], ['https/', 'http/'], $url);
|
||||||
if (substr($url, -1) == '/') {
|
if (substr($filepath, -1) == '/') {
|
||||||
$url = $url . 'index.html';
|
$filepath .= 'index.html';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $url;
|
return $filepath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## Version 0.0.11.7 (2016-09-21)
|
||||||
|
- Fix: need to create necessary directories first
|
||||||
|
|
||||||
## Version 0.0.11.6 (2016-09-20)
|
## Version 0.0.11.6 (2016-09-20)
|
||||||
- Fix: save webmention HTML to correct location
|
- Fix: save webmention HTML to correct location
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue