Ensure that the Image object tag_array and the metadata array tags are always arrays.

This commit is contained in:
jgen 2017-05-12 00:57:50 -07:00
parent c0e87ae2ae
commit f492c6c2c3
12 changed files with 19 additions and 15 deletions

View file

@ -1210,7 +1210,7 @@ function move_upload_to_archive(DataUploadEvent $event) {
* Add a directory full of images
*
* @param $base string
* @return array
* @return array|string[]
*/
function add_dir($base) {
$results = array();
@ -1222,7 +1222,7 @@ function add_dir($base) {
$tags = path_to_tags($short_path);
$result = "$short_path (".str_replace(" ", ", ", $tags).")... ";
try {
add_image($full_path, $filename, Tag::explode($tags));
add_image($full_path, $filename, $tags);
$result .= "ok";
}
catch(UploadException $ex) {
@ -1250,7 +1250,7 @@ function add_image($tmpname, $filename, $tags) {
$metadata = array();
$metadata['filename'] = $pathinfo['basename'];
$metadata['extension'] = $pathinfo['extension'];
$metadata['tags'] = $tags;
$metadata['tags'] = Tag::explode($tags);
$metadata['source'] = null;
$event = new DataUploadEvent($tmpname, $metadata);
send_event($event);

View file

@ -73,7 +73,7 @@ class BulkAddCSV extends Extension {
$metadata = array();
$metadata['filename'] = $pathinfo['basename'];
$metadata['extension'] = $pathinfo['extension'];
$metadata['tags'] = $tags;
$metadata['tags'] = Tag::explode($tags);
$metadata['source'] = $source;
$event = new DataUploadEvent($tmpname, $metadata);
send_event($event);
@ -126,7 +126,7 @@ class BulkAddCSV extends Extension {
$list .= "<br>".html_escape("$shortpath (".str_replace(" ", ", ", $tags).")... ");
if (file_exists($csvdata[0]) && is_file($csvdata[0])) {
try{
$this->add_image($fullpath, $pathinfo["basename"], Tag::explode($tags), $source, $rating, $thumbfile);
$this->add_image($fullpath, $pathinfo["basename"], $tags, $source, $rating, $thumbfile);
$list .= "ok\n";
}
catch(Exception $ex) {

View file

@ -304,6 +304,10 @@ class CronUploader extends Extension {
/**
* Generate the necessary DataUploadEvent for a given image and tags.
*
* @param string $tmpname
* @param string $filename
* @param string $tags
*/
private function add_image($tmpname, $filename, $tags) {
assert ( file_exists ( $tmpname ) );
@ -315,7 +319,7 @@ class CronUploader extends Extension {
$metadata = array();
$metadata ['filename'] = $pathinfo ['basename'];
$metadata ['extension'] = $pathinfo ['extension'];
$metadata ['tags'] = ""; // = $tags; doesn't work when not logged in here
$metadata ['tags'] = array(""); // = $tags; doesn't work when not logged in here
$metadata ['source'] = null;
$event = new DataUploadEvent ( $tmpname, $metadata );
send_event ( $event );

View file

@ -37,7 +37,7 @@ class FlashFileHandler extends DataHandlerExtension {
$image->hash = $metadata['hash'];
$image->filename = $metadata['filename'];
$image->ext = $metadata['extension'];
$image->tag_array = $metadata['tags'];
$image->tag_array = is_array($metadata['tags']) ? $metadata['tags'] : Tag::explode($metadata['tags']);
$image->source = $metadata['source'];
$info = getimagesize($filename);

View file

@ -67,7 +67,7 @@ class IcoFileHandler extends Extension {
$image->hash = $metadata['hash'];
$image->filename = $metadata['filename'];
$image->ext = $metadata['extension'];
$image->tag_array = $metadata['tags'];
$image->tag_array = is_array($metadata['tags']) ? $metadata['tags'] : Tag::explode($metadata['tags']);
$image->source = $metadata['source'];
return $image;

View file

@ -43,7 +43,7 @@ class MP3FileHandler extends DataHandlerExtension {
$image->filename = $metadata['filename'];
$image->ext = $metadata['extension'];
$image->tag_array = $metadata['tags'];
$image->tag_array = is_array($metadata['tags']) ? $metadata['tags'] : Tag::explode($metadata['tags']);
$image->source = $metadata['source'];
return $image;

View file

@ -35,7 +35,7 @@ class PixelFileHandler extends DataHandlerExtension {
$image->hash = $metadata['hash'];
$image->filename = (($pos = strpos($metadata['filename'],'?')) !== false) ? substr($metadata['filename'],0,$pos) : $metadata['filename'];
$image->ext = (($pos = strpos($metadata['extension'],'?')) !== false) ? substr($metadata['extension'],0,$pos) : $metadata['extension'];
$image->tag_array = $metadata['tags'];
$image->tag_array = is_array($metadata['tags']) ? $metadata['tags'] : Tag::explode($metadata['tags']);
$image->source = $metadata['source'];
return $image;

View file

@ -75,7 +75,7 @@ class SVGFileHandler extends Extension {
$image->hash = $metadata['hash'];
$image->filename = $metadata['filename'];
$image->ext = $metadata['extension'];
$image->tag_array = $metadata['tags'];
$image->tag_array = is_array($metadata['tags']) ? $metadata['tags'] : Tag::explode($metadata['tags']);
$image->source = $metadata['source'];
return $image;

View file

@ -170,7 +170,7 @@ class VideoFileHandler extends DataHandlerExtension {
$image->filesize = $metadata['size'];
$image->hash = $metadata['hash'];
$image->filename = $metadata['filename'];
$image->tag_array = $metadata['tags'];
$image->tag_array = is_array($metadata['tags']) ? $metadata['tags'] : Tag::explode($metadata['tags']);
$image->source = $metadata['source'];
return $image;

View file

@ -31,7 +31,7 @@ class Oekaki extends Extension {
$metadata = array();
$metadata['filename'] = 'oekaki.png';
$metadata['extension'] = $pathinfo['extension'];
$metadata['tags'] = 'oekaki tagme';
$metadata['tags'] = Tag::explode('oekaki tagme');
$metadata['source'] = null;
$duev = new DataUploadEvent($tmpname, $metadata);
send_event($duev);

View file

@ -500,7 +500,7 @@ class OuroborosAPI extends Extension
}
}
$meta = array();
$meta['tags'] = $post->tags;
$meta['tags'] = Tag::explode($post->tags);
$meta['source'] = $post->source;
if (defined('ENABLED_EXTS')) {
if (strstr(ENABLED_EXTS, 'rating') !== false) {

View file

@ -132,7 +132,7 @@ abstract class ShimmiePHPUnitTestCase extends \PHPUnit_Framework_TestCase {
// post things
/**
* @param string $filename
* @param string|string[] $tags
* @param string $tags
* @return int
*/
protected function post_image($filename, $tags) {