PMF Customized Config Reverting, PMF 2.6.5

Please report bugs here!

Moderator: Thorsten

Post Reply
dajoker
Posts: 59
Joined: Sat Jan 30, 2010 1:01 am

PMF Customized Config Reverting, PMF 2.6.5

Post by dajoker »

I'm having a hard time figuring out why this code is as it is:

<code language='php' file='./phpmyfaq/admin/configuration.php'>
foreach ($oldConfigValues as $key => $value) {
if (isset($newConfigValues[$key])) {
continue;
} else {
if ($oldConfigValues[$key] == 'true') {
$newConfigValues[$key] = 'false';
} else {
$newConfigValues[$key] = $oldConfigValues[$key];
}
}
}
</code>

As I've been going along adding customized values in the faqconfig table from time to time they've "mysteriously" disappeared. Today I figured out that my customized values were reverted whenever I changed something else from the Configuration Page and this code seems to be at fault. I see that $oldConfigValues (before the snippet above in the file) is set properly from the DB but then the second second 'if' section is changing all of my values which are 'true' to 'false' when I'm trying to save something completely unrelated. The configuration options I've added that do not have 'true' as their setting persist nicely so while I guess I could make all of my configuration options reversed logically (db.nofulltextsearch instead of db.fulltextsearch) and code accordingly I'd rather understand the code above or get it fixed. In my opinion, spending a whole ten seconds on it, the code seems to have an error. I'm sure there's a good reason but it escapes me.

Thanks.
Thorsten
Posts: 15561
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Re: PMF Customized Config Reverting, PMF 2.6.5

Post by Thorsten »

Hi,

the reason for this code is simple. Empty checkboxes don't send anything in POST requests and so we need to add the "old" values to restore them. But I have to check why this isn't working with your additional config values.

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
dajoker
Posts: 59
Joined: Sat Jan 30, 2010 1:01 am

Re: PMF Customized Config Reverting, PMF 2.6.5

Post by dajoker »

I think I understand, and that makes sense. Because of how a form POST sends (or doesn't) values to the server the code is finding any values that are in the table which were NOT sent via the form (presumably checkboxes) which were set to true but now are unchecked because they did not come in via the POST and then it sets them appropriately (to false). The reason this applies to custom variables is that, first, I'm using true/false (first place I could overcome this is by using 0 or 1 I suppose, though if these were ever formally adopted then that would probably not be ideal), I'm setting them to true (to enable them, with a default of false for those who do not want these features) and because there is no option on the form for them yet (the best place to fix this properly, imo). The logic applies properly to this situation and it also explains why my numeric settings (max number of pages) is not affected even though it, too, is not present on the HTML form but is inside the faqconfig table.

Documenting this somewhere may be useful (even a comment in the code, possibly pointing to this thread) for others like myself who do not have the experience leading to the decision here but in the meantime I'll assume the best fix is for me to add the config options to the HTML form so that the logic works properly in the future.

Thanks for your patience.
Thorsten
Posts: 15561
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Re: PMF Customized Config Reverting, PMF 2.6.5

Post by Thorsten »

Hi,
dajoker wrote:The logic applies properly to this situation and it also explains why my numeric settings (max number of pages) is not affected even though it, too, is not present on the HTML form but is inside the faqconfig table.
did you added a translation configuration variable into the file lang/language_en.php?

It should be look like this

Code: Select all

$LANG_CONF['main.numberSearchTerms']   = array(0 => 'input', 1 => 'Number of listed search terms');
for intput fields.

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
dajoker
Posts: 59
Joined: Sat Jan 30, 2010 1:01 am

Re: PMF Customized Config Reverting, PMF 2.6.5

Post by dajoker »

Sorry... I was unclear. This is good to know about for when I start adding these configuration options to my deployment, though.

I meant that I had not, at all, customized the configuration page for any of my configuration values. My booleans were reset because they existing in the table, but my integer-based values do not apply to this section of the code so even though they did not exist on the form (because I hadn't added them) they were unaffected by the code that you have for checkboxes that are false.

Sorry for that confusion, but thanks for the note about translation.
Thorsten
Posts: 15561
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Re: PMF Customized Config Reverting, PMF 2.6.5

Post by Thorsten »

Hi,

know I understand your problem. :-)

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
Post Reply