Skip to content

Temporary loaded meta not correct if event observer returns false #17

Description

@mjdigital

Hi, firstly to say thank you for this package, it is great.

I have been working on adding an approval workflow to an application that uses this package and I can listen to creating/updating events correctly and can intercept/block the create/update of metadata if conditions are not met, however it appears the package utilises temporary cached data against the model that updates with newly passed data even though the database record is not updated.

For example, if I create an observer and listen for the ::updating event on the Zoha\Meta\Models\Meta model and get it to return false, if I already have a meta value for key "updated_time" as (for example) "1641464807" then call something like the below:

$user = \Auth::user();
$user->setMeta('updated_time',time());
ddd($user->getMeta('updated_time'));

it will dump the latest time even though the meta database record does now get updated.

It appears that in SetMetaHelper.php you save the meta (in both executeUpdateMeta() and executeCreateMeta()) but do not check to see whether the data was actually saved or not before setting the value of the temporary loaded meta items.

Would it be possible to tweak the code to check to see if the save was completed successfully or not and update the temporary meta items cache accordingly? It may also be useful to then return false from UpdateMetaHelper::updateMeta and CreateMetaHelper::createMeta if the executions do not get saved due to events blocking them?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions