Fragmented Thought

Magento - Error Saving Configuration - Array Encrypted.php

By

Published

Lance Gliser

Heads up! This content is more than six months old. Take some time to verify everything still works as expected.

An error occurred while saving this configuration:

Warning: preg_match() expects parameter 2 to be string, array given in app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Encrypted.php on line 62

Magento version 1.7.0.2

Found a real winner of a bug today in Magento's core configuration saving objects. We were able to save any config screen without a password on it, but nothing with a password. After a couple hours digging around in app/code/core/Mage/Adminhtml/Model/Config/Data.php, I located the issue. In the save function, around line 135ish, it attempts to get the backend model that will be used to save the data. Intense logging around showed that after the first non-standard config field, the backend model to be saved was permanently swapped to adminhtml/system_config_backend_encrypted. Why? Bad code. The issue is that they check if the backend model has been set, and uses it if it has. Which means future loops never go back to core/config because it's already set to something on the first pass!

The answer is simple, unset backend class, or fix the faulty if logic.

/** * Get field backend model */ unset( $backendClass ); // Add this line if (isset($fieldConfig->backend_model)) { $backendClass = $fieldConfig->backend_model; } if (!isset($backendClass)) { $backendClass = 'core/config_data'; }