[core] image_id should never be null, only uninitialised
This commit is contained in:
parent
bc933bbbca
commit
f0457b4f94
2 changed files with 6 additions and 4 deletions
|
@ -32,7 +32,9 @@ class Image implements \ArrayAccess
|
|||
public const IMAGE_DIR = "images";
|
||||
public const THUMBNAIL_DIR = "thumbs";
|
||||
|
||||
public ?int $id = null;
|
||||
private bool $in_db = false;
|
||||
|
||||
public int $id;
|
||||
#[Field]
|
||||
public int $height = 0;
|
||||
#[Field]
|
||||
|
@ -116,6 +118,7 @@ class Image implements \ArrayAccess
|
|||
}
|
||||
}
|
||||
}
|
||||
$this->in_db = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -146,7 +149,6 @@ class Image implements \ArrayAccess
|
|||
#[Field(name: "post_id")]
|
||||
public function graphql_oid(): int
|
||||
{
|
||||
assert(!is_null($this->id));
|
||||
return $this->id;
|
||||
}
|
||||
#[Field(name: "id")]
|
||||
|
@ -288,7 +290,7 @@ class Image implements \ArrayAccess
|
|||
"audio" => $this->audio,
|
||||
"length" => $this->length
|
||||
];
|
||||
if (is_null($this->id)) {
|
||||
if (!$this->in_db) {
|
||||
$props_to_save["owner_id"] = $user->id;
|
||||
$props_to_save["owner_ip"] = get_real_ip();
|
||||
$props_to_save["posted"] = date('Y-m-d H:i:s', time());
|
||||
|
@ -301,6 +303,7 @@ class Image implements \ArrayAccess
|
|||
$props_to_save,
|
||||
);
|
||||
$this->id = $database->get_last_insert_id('images_id_seq');
|
||||
$this->in_db = true;
|
||||
} else {
|
||||
$props_sql = implode(", ", array_map(fn ($prop) => "$prop = :$prop", array_keys($props_to_save)));
|
||||
$database->execute(
|
||||
|
|
|
@ -34,7 +34,6 @@ function add_dir(string $base, array $extra_tags = []): array
|
|||
]));
|
||||
$results = [];
|
||||
foreach($dae->images as $image) {
|
||||
assert(!is_null($image->id));
|
||||
$results[] = new UploadSuccess($filename, $image->id);
|
||||
}
|
||||
return $results;
|
||||
|
|
Reference in a new issue