-
Notifications
You must be signed in to change notification settings - Fork 451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pkp/pkp-lib#10668 Announcement image handling fixed #10787
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, missed that when refactoring Announcements!
My main concern is why settings aren't removed together with the main Model (announcements). Is this some sort of edge case? Or maybe this was the case before this issue was resolved #10562?
@@ -119,7 +119,7 @@ public function save(array $options = []) | |||
|
|||
Hook::call('Announcement::add', [$this]); | |||
|
|||
$hasNewImage = $this?->image?->temporaryFileId; | |||
$hasNewImage = isset($this?->image?->temporaryFileId) ? $this->image->temporaryFileId : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hoped PHP null safe operator does this automatically :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
me too . But for simple stdClass
object , PHP register waring also which is better to avoid .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about $hasNewImage = $this?->image?->temporaryFileId ?? null;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about
$hasNewImage = $this?->image?->temporaryFileId ?? null;
That should work .
@@ -376,6 +376,11 @@ public function coerce($value, $type, $schema) | |||
return $newArray; | |||
case 'object': | |||
$newObject = []; // we handle JSON objects as assoc arrays in PHP | |||
|
|||
if (isValidJson($value)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, in which situation we need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In our case. we are getting the data as JSON but here we try to access each inner prop of JSON data as array, it handle that case we for announcement files data are not converted to JSON to array .
// need to delete the image for this announcement model instance | ||
if (!$hasNewImage && !$this?->image && $this->fresh()->image) { | ||
$this->deleteImage(); | ||
DB::table($this->getSettingsTable()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect that settings are removed together with the main model, isn't this happening?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This handle a case when at updating an announcement image is deleted and that is the only update .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's the only case, I'm ok with it)
Thanks, for explaining. Looks good for merging then! |
3bdca93
to
69319c0
Compare
for #10668