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

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

Open
cyppe opened this issue Feb 2, 2024 · 1 comment

Comments

@cyppe
Copy link

cyppe commented Feb 2, 2024

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.

@cyppe
Copy link
Author

cyppe commented Feb 2, 2024

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant