[core] remove add_image, send_event(DataUpload) is much clearer as to what it's actually doing
This commit is contained in:
parent
c16aeca4d8
commit
4d011fa5e5
6 changed files with 28 additions and 31 deletions
|
@ -24,7 +24,11 @@ function add_dir(string $base, ?array $extra_tags = []): array
|
|||
|
||||
$tags = array_merge(path_to_tags($short_path), $extra_tags);
|
||||
try {
|
||||
$dae = add_image($full_path, $filename, $tags);
|
||||
$dae = send_event(new DataUploadEvent($full_path, [
|
||||
'filename' => pathinfo($filename, PATHINFO_BASENAME),
|
||||
'tags' => $tags,
|
||||
'source' => null,
|
||||
]));
|
||||
foreach($dae->images as $image) {
|
||||
$results[] = new UploadSuccess($filename, $image->id);
|
||||
}
|
||||
|
@ -36,18 +40,6 @@ function add_dir(string $base, ?array $extra_tags = []): array
|
|||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a DataUploadEvent for a file.
|
||||
*/
|
||||
function add_image(string $tmpname, string $filename, array $tags, ?string $source = null): DataUploadEvent
|
||||
{
|
||||
return send_event(new DataUploadEvent($tmpname, [
|
||||
'filename' => pathinfo($filename, PATHINFO_BASENAME),
|
||||
'tags' => $tags,
|
||||
'source' => $source,
|
||||
]));
|
||||
}
|
||||
|
||||
function get_file_ext(string $filename): ?string
|
||||
{
|
||||
return pathinfo($filename)['extension'] ?? null;
|
||||
|
|
|
@ -50,7 +50,12 @@ class BulkAddCSV extends Extension
|
|||
*/
|
||||
private function add_image(string $tmpname, string $filename, array $tags, string $source, string $rating, string $thumbfile)
|
||||
{
|
||||
$event = add_image($tmpname, $filename, $tags, $source);
|
||||
$event = send_event(new DataUploadEvent($tmpname, [
|
||||
'filename' => pathinfo($filename, PATHINFO_BASENAME),
|
||||
'tags' => $tags,
|
||||
'source' => $source,
|
||||
]));
|
||||
|
||||
if (count($event->images) == 0) {
|
||||
throw new UploadException("File type not recognised");
|
||||
} else {
|
||||
|
|
|
@ -52,7 +52,11 @@ class BulkImportExport extends DataHandlerExtension
|
|||
|
||||
file_put_contents($tmpfile, $stream);
|
||||
|
||||
$images = add_image($tmpfile, $item->filename, $item->new_tags)->images;
|
||||
$images = send_event(new DataUploadEvent($tmpfile, [
|
||||
'filename' => pathinfo($item->filename, PATHINFO_BASENAME),
|
||||
'tags' => $item->new_tags,
|
||||
'source' => null,
|
||||
]))->images;
|
||||
|
||||
if (count($images) == 0) {
|
||||
throw new SCoreException("Unable to import file $item->hash");
|
||||
|
|
|
@ -466,7 +466,11 @@ class CronUploader extends Extension
|
|||
*/
|
||||
private function add_image(string $tmpname, string $filename, array $tags): DataUploadEvent
|
||||
{
|
||||
$event = add_image($tmpname, $filename, $tags, null);
|
||||
$event = send_event(new DataUploadEvent($tmpname, [
|
||||
'filename' => pathinfo($filename, PATHINFO_BASENAME),
|
||||
'tags' => $tags,
|
||||
'source' => null,
|
||||
]));
|
||||
|
||||
// Generate info message
|
||||
if (count($event->images) == 0) {
|
||||
|
|
|
@ -343,10 +343,15 @@ class DanbooruApi extends Extension
|
|||
|
||||
try {
|
||||
// Fire off an event which should process the new file and add it to the db
|
||||
$nevent = add_image($file, $filename, $posttags, $source);
|
||||
$dae = send_event(new DataUploadEvent($file, [
|
||||
'filename' => pathinfo($filename, PATHINFO_BASENAME),
|
||||
'tags' => $posttags,
|
||||
'source' => $source,
|
||||
]));
|
||||
|
||||
//log_debug("danbooru_api", "send_event(".var_export($nevent,TRUE).")");
|
||||
// If it went ok, grab the id for the newly uploaded image and pass it in the header
|
||||
$newimg = Image::by_hash($hash); // FIXME: Unsupported file doesn't throw an error?
|
||||
$newimg = $dae->images[0];
|
||||
$newid = make_link("post/view/" . $newimg->id);
|
||||
if ($danboorup_kludge) {
|
||||
$newid = make_http($newid);
|
||||
|
|
|
@ -15,17 +15,4 @@ class EokmTest extends ShimmiePHPUnitTestCase
|
|||
$this->assert_no_text("Image too small");
|
||||
$this->assert_no_text("ratio");
|
||||
}
|
||||
|
||||
/*
|
||||
public function testFail()
|
||||
{
|
||||
$this->log_in_as_user();
|
||||
try {
|
||||
$this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot");
|
||||
$this->assertTrue(false, "Invalid-size image was allowed");
|
||||
} catch (UploadException $e) {
|
||||
$this->assertEquals("Image too small", $e->getMessage());
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
Reference in a new issue