Skip to content

Regexp support checkTablesOnly gives unexpected results as it's not strict per default #17

Open

Description

@cyppe

Hello!

Not sure if it's just me. But I am using laravel-trigger library that is using your package. And I noticed I got events on tables not listed in my config for tablesOnly.

So i tried to just modify the code to output logs and realized it's due to the regexp not being strict as default.

So the modified version below with log output, gives this result:

Log: Table: af_products matches af_products_bike_cache

Code:

 private static function matchNames(string $subject, array $names): bool
    {
        foreach ($names as $name) {
            if (preg_match("/$name/", $subject)) {
                Log::info("Table: ". $name . " matches " . $subject);  // ADDED FOR DEBUGGING
                return true;
            }
        }

        return false;
    }

I have worked around the issue by defining strict regexp in my config for the laravel-trigger package.

From:

TRIGGER_TABLES=af_static,af_static_translate,af_brands,af_brands_images,ma_campaigns,ma_campaigns_products,af_categories,af_products_to_manufacturers_models_years,af_manufacturers_models,af_manufacturers_models_years,af_images,af_manufacturers,language,af_product_package,af_products,af_properties,af_properties_option,trustpilot_product_review_reviews_log,trustpilot_product_review_reviews_summary,af_storage,af_storage_templates,af_translation_new,af_products_images_to_products

To:
TRIGGER_TABLES=^af_static$,^af_static_translate$,^af_brands$,^af_brands_images$,^ma_campaigns$,^ma_campaigns_products$,^af_categories$,^af_products_to_manufacturers_models_years$,^af_manufacturers_models$,^af_manufacturers_models_years$,^af_images$,^af_manufacturers$,^language$,^af_product_package$,^af_products$,^af_properties$,^af_properties_option$,^trustpilot_product_review_reviews_log$,^trustpilot_product_review_reviews_summary$,^af_storage$,^af_storage_templates$,^af_translation_new$,^af_products_images_to_products$

But maybe it should be strict per default if there is no regexp pattern in the string?

Again - my issue is resolved but it was a bit surprise so maybe you can consider doing something.

Activity

  1. cyppe commented on Feb 2, 2024

    @cyppe
    Author

    Worth noting is that also database name is passing through the same method, so if you have for example two databases with names :

    • company
    • company_backup

    per default it will also listen on company_backup if you define "company" as databasesOnly and forget to set it as ^company$

    Probably it's a bit more rare case, but just fyi. At least good to document it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions