You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Ive been using Guest Entries with success but I may have found a possible edge-case that could use some thought. Hear me out please.
Many thanks in advance for the excellent addon and for any insights!
Steps to reproduce
I have a listener set-up, listening for EntryCreated, so that when a File is attached to this field, it gets renamed and converted to JPG.
(...)
if ($event->entry->presentation_file) {
$name = 'presentation-' . $event->entry->title;
$filename = 'abstracts/' . $name . '.' . $event->entry->presentation_file->extension();
if ($event->entry->presentation_file->path() !== $filename) {
Log::info($event->entry->presentation_file->path());
Log::info($filename);
if (Storage::disk('assets')->exists($filename)) Storage::disk('assets')->delete($filename);
$new = $event->entry->presentation_file->rename($name); $filename
if (strtolower($new->extension()) === "pdf") {
$pdf = new Pdf($new->resolvedPath());
$pdf->saveImage($new->resolvedPath() . '.jpg');
}
}
}
(...)
It works fine on the CP.
Now, if i set up a Guest Entries, using file and save my attachment, the field becomes empty on the CP, despite the file was uploaded, renamed and even the JPG was processed. So the listener works, but in the end, the field is blank.
Heres what i found out:
The "culprit" was this: vendor/doublethreedigital/guest-entries/src/Http/Controllers/GuestEntryController.php@164
We have:
(...)
// $entry->save();
$entry->touch();
(...)
If I comment save(), everything works as expected. Hmmm.
(...)
public function touch($user = null)
{
$this->updateLastModified($user)->save();
}
(...)
So I'm guessing having save() followed by touch() its either redundant and/or causes some bad behaviour on my listener by "double-triggering". But the funny thing is that if I actually log the actions on the Event Listener, they only happen ONCE even if I leave save() followed by touch().
beatwiz
changed the title
Edge case: Maybe touch() not needed after save()
Maybe touch() not needed after save() (possible edge-case)
Oct 16, 2022
beatwiz
changed the title
Maybe touch() not needed after save() (possible edge-case)
Maybe touch() and save() together are redundant (possible edge-case)
Oct 16, 2022
Bug Description
Hey!
Ive been using Guest Entries with success but I may have found a possible edge-case that could use some thought. Hear me out please.
Many thanks in advance for the excellent addon and for any insights!
Steps to reproduce
I have a listener set-up, listening for EntryCreated, so that when a File is attached to this field, it gets renamed and converted to JPG.
It works fine on the CP.
Now, if i set up a Guest Entries, using file and save my attachment, the field becomes empty on the CP, despite the file was uploaded, renamed and even the JPG was processed. So the listener works, but in the end, the field is blank.
Heres what i found out:
The "culprit" was this:
vendor/doublethreedigital/guest-entries/src/Http/Controllers/GuestEntryController.php
@164We have:
If I comment save(), everything works as expected. Hmmm.
While trying to dive in further....
Looking at:
vendor/statamic/cms/src/Data/TracksLastModified.php
@39It seems that touch() also actually saves():
So I'm guessing having save() followed by touch() its either redundant and/or causes some bad behaviour on my listener by "double-triggering". But the funny thing is that if I actually log the actions on the Event Listener, they only happen ONCE even if I leave save() followed by touch().
What do you think? I hope that made any sense :)
Environment
Statamic 3.3.45 Pro
Laravel 8.83.25
PHP 8.0.24
anakadote/statamic-recaptcha 1.0.7
aryehraber/statamic-uuid 2.1.0
cnj/seotamic 2.1.0
doublethreedigital/guest-entries 1.2.2
optimoapps/statamic-bard-text-align 1.0.2
rias/statamic-data-import 1.2.2
The text was updated successfully, but these errors were encountered: