Admin notifications cannot be disabled when using PDO

When disabling notifications in /admin.php?dispatch=notification_settings.manage&receiver_type=A, the changes are not applied and previously disabled check boxes end up being checked again. This does not happen when mysqli is used - only with pdo. The changes are reflected in the database but they don’t take effect.

I found that the issue is with the following function:
app/functions/fn.common.php:fn_get_notification_settings

/**
 * Gets all rules about notifications
 *
 * @return array Rules for notifications about all events to all receivers by all transports
 */
function fn_get_notification_settings()
{
    $table = db_get_array('SELECT * FROM ?:notification_settings');
    $result = [];
    foreach ($table as $events) {
        $result[$events['event_id']][$events['receiver']][$events['transport_id']] = ($events['is_allowed'] !== '0');
    }

    return $result;
}

It checks if $events[‘is_allowed’] !== ‘0’. is_allowed is an int field in the db and pdo returns the value as number. However this check compares it to a string ‘0’ in a typesafe way, which then always evaluates to true. Therefore notifications cannot be disabled.

Hello!

I’ve tested this with PDO and MySQLi, and both PDO and MySQLi return all fetched results as strings, so strict compare works properly here.

Have you made any changes to your installation? What version of PHP are you using?

The bug exists. I have already posted it on the RU forum? Why did you close it without fix?

I’m unable to reproduce this issue, so I cannot agree with your statement.

The topic is not closed. It is moved to the Not enough information branch. If someone will be able to provide enough information for me so I will be able to reproduce it, I will be able to confirm this issue.

This is strange, I can easily reproduce the issue. Fresh install of CS-Cart MultiVendor 4.18.1 with the mysqli PHP extension disabled → open admin console → Settings → Notifications → uncheck some boxes → click Save → boxes are checked again.

Happens with MariaDB as well as MySQL.

What version of PHP are you using?

By a fortunate coincidence, I was able to reproduce this problem. And it turned out to be directly related to the PHP version. The PDO behaviour changed in PHP 8.1.

I have notified the developers of this issue and as soon as it is fixed, someone from our team will post the news here.

1 Like

Hi @krio,
The issue has been fixed, the fix will be included in the release of CS-Cart and Multi-Vendor 4.18.3
To fix the issue yourself, you can use the patch: app-Tygh-Backend-Database-Pdo.php.diff · GitHub
You can read about how to apply the patch in our documentation: How To: Apply a DIFF File — CS-Cart 4.18.x documentation

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.