Skip to content
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

Merged
merged 2 commits into from
Jan 23, 2025

Conversation

touhidurabir
Copy link
Member

for #10668

Copy link
Collaborator

@Vitaliy-1 Vitaliy-1 left a 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;
Copy link
Collaborator

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 :(

Copy link
Member Author

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 .

Copy link
Contributor

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;

Copy link
Member Author

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)) {
Copy link
Collaborator

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?

Copy link
Member Author

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())
Copy link
Collaborator

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?

Copy link
Member Author

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 .

Copy link
Collaborator

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)

@Vitaliy-1
Copy link
Collaborator

Thanks, for explaining. Looks good for merging then!

@touhidurabir touhidurabir merged commit fdd66d9 into pkp:main Jan 23, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants