Skip to content

fluent_crm/list_updated hook returns update result (int) instead of List model instance #44

@RaviT-RSW

Description

@RaviT-RSW

Bug Description
The action hook fluent_crm/list_updated does not return the expected List model instance. Instead, it returns an integer (affected rows count) from the update query.

File: fluent-crm/app/Http/Controllers/ListsController.php

Problematic Code

$list = Lists::where('id', $id)->update([
    'title'       => sanitize_text_field($allData['title']),
    'slug'        => $allData['slug'],
    'description' => sanitize_textarea_field(Arr::get($allData, 'description')),
]);

do_action('fluent_crm/list_updated', $list);

Expected Behavior
According to documentation, the hook should pass the List model instance:

add_action('fluent_crm/list_updated', function($listModel) {
   // Expecting $listModel to be a model object
});

Actual Behavior
The $list variable contains the result of the update() method (integer), not the updated List model. As a result, the hook receives 1 instead of a model instance.

Impact
This breaks expected extensibility for developers relying on this hook, as they cannot access updated list properties.

Suggested Fix
Instead of using update() directly, retrieve and update the model instance:

$list = Lists::findOrFail($id);
$list->update([
    'title'       => sanitize_text_field($allData['title']),
    'slug'        => $allData['slug'],
    'description' => sanitize_textarea_field(Arr::get($allData, 'description')),
]);

do_action('fluent_crm/list_updated', $list);

Alternatively, fetch the model after update:

Lists::where('id', $id)->update([...]);
$list = Lists::find($id);

do_action('fluent_crm/list_updated', $list);

Also found same issue in fluent-crm/app/Http/Controllers/TagsController.php store() method

Problematic Code

$tag = Tag::where('id', $id)->update([
    'title'       => sanitize_text_field($allData['title']),
    'slug'        => $allData['slug'],
    'description' => sanitize_textarea_field(Arr::get($allData, 'description')),
]);

do_action('fluentcrm_tag_updated', $id);

do_action('fluent_crm/tag_updated', $tag);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions