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

Regression: Fail to save preferences #279

Closed
jlmoya opened this issue Sep 18, 2014 · 13 comments
Closed

Regression: Fail to save preferences #279

jlmoya opened this issue Sep 18, 2014 · 13 comments
Labels
Milestone

Comments

@jlmoya
Copy link

jlmoya commented Sep 18, 2014

There is an error preventing to save user preferences. I noticed this bug had been resolved but I downloaded the master as of now, RC-3 and can't save any changes in user configuration.
playsmserror

@antonraharja
Copy link
Member

I can're produce this bug report. I tried in my laptop and http://playsms.org/trial and they're fine.

What were you doing to get that bug ? What I tested was to renew the database by re-inserting db/playsms.sql and then login as admin and change the country to Costa Rica. In my tests both installation shown Preferences has been saved.

@jlmoya
Copy link
Author

jlmoya commented Sep 19, 2014

I pull last version from GIT and proceeded to make a clean install using the installation script. Login to playSMS and try to save changes in preferences and get the error. In my test I just changed the country but doesn’t matter which I change always get the error.

@antonraharja
Copy link
Member

Ok, lets go back to forum and post your question there so we can discuss this. In the mean time I will put the label "Require feedback" as I can't reproduce it, yet.

@antonraharja antonraharja added this to the 1.0 milestone Sep 19, 2014
@jlmoya
Copy link
Author

jlmoya commented Sep 19, 2014

I installed version 0.9.9.2 and did exactly as was doing and can save without any issues. Therefore, I have discarded that I have any problems with the DB. After having success with this test I cleaned everything and installed the latest from repository again. After installing I dropped the schema and ran the playsms.sql script from the db folder. Tested again and again got the "Fail to save preferences" error. I should mention that I can save other forms without any problem, the only form that is giving me errors is the aforementioned.

@antonraharja
Copy link
Member

Edit plugin/core/user/user_pref.php:
https://github.com/antonraharja/playSMS/blob/master/web/plugin/core/user/user_pref.php

Insert this line between line 273-274:

print_r($up); die();

Then submit, copy paste what shown on browser.

@jlmoya
Copy link
Author

jlmoya commented Sep 19, 2014

Just in case, this is the code as it is with the change.

                            if ($continue) {
                                    print_r($up); die();
                                    if (dba_update(_DB_PREF_ . '_tblUser', $up, array(

This is the answer:

Array ( [name] => Administrator [email] => noreply@playsms.org [mobile] => +62000000000 [address] => [city] => [state] => [country] => 44 [zipcode] => [parent_uid] => [username] => admin [lastupdate_datetime] => 2014-09-18 13:50:35 )

@jlmoya
Copy link
Author

jlmoya commented Sep 20, 2014

I have discovered the error, the SQL Statement that is being sent for execution is the following:

"UPDATE playsms_tblUser SET name='Administrator',email='noreply@playsms.org',mobile='+62000000000',address='',city='',state='',country='44',zipcode='',parent_uid='',username='admin',lastupdate_datetime='2014-09-19 23:01:56' WHERE 1=1 AND username='admin'"

When I execute the statement in the mysql-workbench, the error is:

Error Code: 1366. Incorrect integer value: '' for column 'parent_uid' at row 1

Looking closely at the parent_uid is being sent with a null value instead of a zero. That is the root cause of the error. Now, as to how to solve the error, I'm really hoping you can enlighten me :)

@antonraharja
Copy link
Member

yes that could be it, had this type of error sometime ago.

try this fix:
8d8306d

or simply pull and install latest master release (beyond 1.0-rc3).

@jlmoya
Copy link
Author

jlmoya commented Sep 20, 2014

I propose the following correction:

In the file, web/plugin/core/user/user_pref.php, after line 253, that is the else, include the conditional as shown:

    // subuser's parent uid, by default its uid=1
    if ($_POST['up_parent_uid']) {
        $up['parent_uid'] = ($user_edited['status'] == 4 ? $_POST['up_parent_uid'] : 1);
    } else {
                if ($allow_edit_parent) {
                    $up['parent_uid'] = user_getparentbyuid(user_username2uid($c_username));
                }
    }

admin has no parent_uid or is 0 and the $up array includes the value but $allow_edit_parent is false in line 241, not incrementing the $fields array.

What puzzles me the most is that you could not reproduce the error. I know you are extremely busy, but could you at least tell me if the proposed solution is sound and what could be secondary effects, if any, by it.

@antonraharja
Copy link
Member

Forcing $parent_uid to 0 should be alright, I mean its the default (db table tblUser) for field parent_uid.

I couldn't reproduce probably because my MySQL settings or whatever (didn't bother to check for now) :D Put it simple somehow my system allowed NULL value for parent_uid.

@jlmoya
Copy link
Author

jlmoya commented Sep 20, 2014

I will look at your solution. Had not refreshed the page and did not see it until after I posted.

@jlmoya
Copy link
Author

jlmoya commented Sep 20, 2014

I tried to force it to 0 but the $parent_uid gets always a boolean value which is not parsed well when creating the SQL statement probably because $_POST doesn't even contain the field in the first place.

@antonraharja
Copy link
Member

There are 4 locations where you need to cast to int, take a look again:
8d8306d

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

No branches or pull requests

2 participants