[StoreRemoteMedia] Implement the first version of it in v3
This commit is contained in:
@@ -22,6 +22,7 @@ namespace App\Entity;
|
||||
use App\Core\DB\DB;
|
||||
use App\Core\Entity;
|
||||
use App\Core\Event;
|
||||
use App\Core\GSFile;
|
||||
use App\Core\HTTPClient;
|
||||
use App\Util\Common;
|
||||
use App\Util\Exception\DuplicateFoundException;
|
||||
@@ -137,7 +138,7 @@ class RemoteURL extends Entity
|
||||
$head = HTTPClient::head($url);
|
||||
// This must come before getInfo given that Symfony HTTPClient is lazy (thus forcing curl exec)
|
||||
$headers = $head->getHeaders();
|
||||
$url = $head->getInfo('url'); // The last effective url (after getHeaders so it follows redirects)
|
||||
$url = $head->getInfo('url'); // The last effective url (after getHeaders, so it follows redirects)
|
||||
$url_hash = hash(self::URLHASH_ALGO, $url);
|
||||
try {
|
||||
return DB::findOneBy('remoteurl', ['remote_url_hash' => $url_hash]);
|
||||
@@ -149,7 +150,7 @@ class RemoteURL extends Entity
|
||||
'mimetype' => $headers['content-type'][0],
|
||||
]);
|
||||
DB::persist($remoteurl);
|
||||
Event::handle('RemoteURLStoreNew', [&$remoteurl]);
|
||||
Event::handle('RemoteURLStoredNew', [&$remoteurl]);
|
||||
return $remoteurl;
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -19,7 +19,9 @@
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Core\DB\DB;
|
||||
use App\Core\Entity;
|
||||
use App\Core\Event;
|
||||
use DateTimeInterface;
|
||||
|
||||
/**
|
||||
@@ -73,6 +75,22 @@ class RemoteURLToNote extends Entity
|
||||
return $this->modified;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of RemoteURLToNote or fill in the
|
||||
* properties of $obj with the associative array $args. Doesn't
|
||||
* persist the result
|
||||
*
|
||||
* @param null|mixed $obj
|
||||
*/
|
||||
public static function create(array $args, $obj = null)
|
||||
{
|
||||
$remoteURL = DB::find('remoteurl', ['id' => $args['remoteurl_id']]);
|
||||
$note = DB::find('note', ['id' => $args['note_id']]);
|
||||
Event::handle('NewRemoteURLFromNote', [$remoteURL, $note]);
|
||||
$obj = new self();
|
||||
return parent::create($args, $obj);
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreEnd
|
||||
// }}} Autocode
|
||||
|
||||
|
||||
Reference in New Issue
Block a user