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

BUG Creating Person Custom Fields in 2.4.3 #1598

Closed
saulowulhynek opened this issue Dec 30, 2016 · 7 comments · Fixed by #1634
Closed

BUG Creating Person Custom Fields in 2.4.3 #1598

saulowulhynek opened this issue Dec 30, 2016 · 7 comments · Fixed by #1634
Assignees
Labels
Milestone

Comments

@saulowulhynek
Copy link

When I add the second custom field I get the folow message:

"Can not execute query.
ALTER TABLE person_custom ADD c1 VARCHAR (30) DEFAULT NULL; "

If I press F5, the field appears correctly created. But, when I try to create third field, I get the message:

Can not execute query.
ALTER TABLE person_custom ADD c1 TINYINT (4) DEFAULT NULL;

And so on
With more tries, types and names are mixed.

@saulowulhynek
Copy link
Author

churchcrm_customfielderror_1

@saulowulhynek
Copy link
Author

churchcrm_customfielderror_2
churchcrm_customfielderror_3

@saulowulhynek
Copy link
Author

I added 3 custom fields. When I try update a person's data i get the folow error from
PersonEditor.php?PersonID=1077

Cannot execute query.
REPLACE INTO person_custom SET c1 = NULL, c1 = NULL, c1 = NULL, per_ID = 1077

@saulowulhynek
Copy link
Author

I verified that, when I imported data, the same data was imported in the 3 custom fields. Example: I created 3 custom fields as baptism date, id number and second mobile number. When i imported data, the 3 fields was filled with id number.

@chiebert
Copy link
Contributor

chiebert commented Jan 7, 2017

Same issue here, fresh install of 2.4.3. The custom fields manager query isn't incrementing the identity number 'c1' for new custom fields, so basically the ALTER query is trying to create a new field with the same primary ID as the last one.

I'm just starting to look into the problem now (brand new to this code, so it may take me a bit!), but I suspect something's wrong around line 124 and following in PersonCustomFieldsEditor.php, which starts:

if (!$bDuplicateNameError) {
          // Find the highest existing field number in the table to determine the next free one.
          // This is essentially an auto-incrementing system where deleted numbers are not re-used.

@chiebert
Copy link
Contributor

chiebert commented Jan 7, 2017

Error is in line 128 of PersonCustomFieldsEditor.php, which calls mysqli_num_fields() to calculate $last:

          $fields = mysqli_query($cnInfoCentral, "SHOW COLUMNS FROM person_custom");
          $last = mysqli_num_fields($fields) - 1;

Where it should be mysqli_num_rows() instead:

          $fields = mysqli_query($cnInfoCentral, "SHOW COLUMNS FROM person_custom");
          $last = mysqli_num_rows($fields) - 1;

I had noticed that this error not appear when adding custom family fields, so compared the code at line 168 of FamilyCustomFieldsEditor.php, and spotted the difference.

@chiebert
Copy link
Contributor

chiebert commented Jan 7, 2017

It looks like the equivalent problem with family custom fields was fixed on Nov 18 by @crossan007 with commit 58bf29f, but this problem was missed in commit 2732d5e on the same day.

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

Successfully merging a pull request may close this issue.

4 participants