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

Group-specific properties does not add a new record to groupprop_xx table #6011

Open
kdwinton opened this issue May 25, 2022 · 21 comments
Open

Comments

@kdwinton
Copy link

ChurchCRM 4.4.5.
Browser doesn't matter.
mysql Ver 15.1 Distrib 10.5.10-MariaDB, for Linux (x86_64).
AWS t2.micro instance with Amazon Linux amzn2-ami-kernel-5.10-hvm-2.0.20220406.1-x86_64-gp2
Apache/2.4.53
PHP 7.4.28

Workflow:

  1. add people, create a group, put people into the group
  2. edit group to enable group-specific properties, define at least one property and enable it to be visible on the person view
  3. attempt to add a value for that new property on one of the group's members
  4. there is no error, but no record is created in groupprop_xx

Explanation:
The code in GroupPropsEditor.php only does a DB UPDATE. If you added the group property definition after the person was already in the group, there is no record "automatically" added at that time. Subsequently, if you try to edit (really, add) one, it UI functions as expected for that task, but no data is written to the db because it's only doing an UPDATE. If you manually add an appropriate record to the DB and go try again, the update works fine.

I have done a temporary fix on my installation by adding in the TEMPORARY FIX lines below. This simply checks and if no row has been retrieved, it adds a row, so that the existing logic later on will always find a row to update.

`// First Pass
// we are always editing, because the record for a group member was created when they were added to the group
// Get the existing data for this group member
$sSQL = 'SELECT * FROM groupprop_'.$iGroupID.' WHERE per_ID = '.$iPersonID;
$rsPersonProps = RunQuery($sSQL);

// TEMPORARY FIX I added this "if statement, and put the existing line inside its "else" clause
if (mysqli_num_rows($rsPersonProps) == 0) {
$sSQL = 'INSERT into groupprop_'.$iGroupID.' (per_ID) values ('.$iPersonID .')';
RunQuery($sSQL);
}
else {
$aPersonProps = mysqli_fetch_array($rsPersonProps, MYSQLI_BOTH);
}`

@djoh2
Copy link

djoh2 commented Oct 23, 2022

Hi Any update on a fix for this?

@hafizaqibshafique
Copy link

Hello,
I fixed this issue and now it's storing the properties details without any issues. go to this file GroupPropsEditor.php

Replace this piece of code
` if (!$bErrorFlag) {
mysqli_data_seek($rsPropList, 0);

    $sSQL = 'UPDATE groupprop_'.$iGroupID.' SET ';

    while ($rowPropList = mysqli_fetch_array($rsPropList, MYSQLI_BOTH)) {
        extract($rowPropList);
        echo $currentFieldData = trim($aPersonProps[$prop_Field]);

        sqlCustomField($sSQL, $type_ID, $currentFieldData, $prop_Field, $sPhoneCountry);
    }

    // chop off the last 2 characters (comma and space) added in the last while loop iteration.
    $sSQL = mb_substr($sSQL, 0, -2);

    $sSQL .= ' WHERE per_ID = '.$iPersonID;
    
    echo $sSQL;

    //Execute the SQL
    RunQuery($sSQL);

    // Return to the Person View
    RedirectUtils::Redirect('PersonView.php?PersonID='.$iPersonID);
}`

with this updated code

`if (!$bErrorFlag) {
mysqli_data_seek($rsPropList, 0);

$sSQL = "SELECT * FROM groupprop_".$iGroupID." WHERE per_ID = ".$iPersonID;
$result = mysqli_query($connection, $sSQL);

if (mysqli_num_rows($result) > 0) {
    // Data found, perform an update
	$sSQL = "UPDATE groupprop_".$iGroupID." SET ";

	while ($rowPropList = mysqli_fetch_array($rsPropList, MYSQLI_BOTH)) {
		extract($rowPropList);
		$currentFieldData = trim($aPersonProps[$prop_Field]);

        // Add dynamic column to the update query
		if (!empty($currentFieldData) &&  $currentFieldData !== null ) {
                  // Add dynamic column to the update query
			$sSQL .= $prop_Field . " = '" . InputUtils::LegacyFilterInput($currentFieldData) . "', ";
		}

	}

    // Chop off the last 2 characters (comma and space) added in the last while loop iteration.
	$sSQL = mb_substr($sSQL, 0, -2);

	$sSQL .= " WHERE per_ID = ".$iPersonID;



    // Execute the SQL
	RunQuery($sSQL);
} else {
    // No data found, perform an insert
	$columns = '';
	$values = '';

	mysqli_data_seek($rsPropList, 0);
	while ($rowPropList = mysqli_fetch_array($rsPropList, MYSQLI_BOTH)) {
		extract($rowPropList);
		$currentFieldData = trim($aPersonProps[$prop_Field]);


        // Add dynamic column to the insert query
		$columns .= $prop_Field.", ";
		$values .= "'".InputUtils::LegacyFilterInput($currentFieldData)."', ";

	}

    // Chop off the last 2 characters (comma and space) added in the last while loop iteration.
	$columns = mb_substr($columns, 0, -2);
	$values = mb_substr($values, 0, -2);


	$sSQL = "INSERT INTO groupprop_".$iGroupID." (per_ID, ".$columns.") VALUES (".$iPersonID.", ".$values.")";



    // Execute the SQL
	RunQuery($sSQL);
}

// Return to the Person View
RedirectUtils::Redirect('PersonView.php?PersonID='.$iPersonID);

}`

@DawoudIO
Copy link
Contributor

Another great find can you please create a pull request with the changes so that I can test and release

@github-actions
Copy link
Contributor

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Oct 30, 2023
@DawoudIO DawoudIO added this to the 5.0.5 milestone Oct 30, 2023
@DawoudIO DawoudIO removed the Stale label Oct 30, 2023
@DawoudIO DawoudIO modified the milestones: 5.0.5, Backlog Oct 31, 2023
Copy link
Contributor

github-actions bot commented Dec 2, 2023

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Dec 2, 2023
Copy link
Contributor

This issue was closed because it has been stalled for 15 days with no activity.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 17, 2023
@djoh2
Copy link

djoh2 commented Jan 4, 2024

Hi -- in version 5.3.0 this bug seems to have reappeared, but adding the fix above to the GroupPropsEditor.php file no longer works -- it results in the error:
This page isn't working at the moment xxx.xxx can't currently handle this request. HTTP ERROR 500
Can you advise?

@hafizaqibshafique
Copy link

hafizaqibshafique commented Jan 7, 2024 via email

@hafizaqibshafique
Copy link

hafizaqibshafique commented Jan 10, 2024 via email

@DAcodedBEAT
Copy link
Contributor

@hafizaqibshafique please submit a pull request against the master branch :)

@DAcodedBEAT DAcodedBEAT reopened this Jan 10, 2024
@github-actions github-actions bot removed the Stale label Jan 11, 2024
Copy link
Contributor

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Feb 11, 2024
@DAcodedBEAT
Copy link
Contributor

@hafizaqibshafique are you still planning on contributing this fix?

@hafizaqibshafique
Copy link

hafizaqibshafique commented Feb 11, 2024 via email

@github-actions github-actions bot removed the Stale label Feb 12, 2024
Copy link
Contributor

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Mar 13, 2024
@DAcodedBEAT
Copy link
Contributor

@hafizaqibshafique any update?

@github-actions github-actions bot removed the Stale label Mar 14, 2024
Copy link
Contributor

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

Copy link
Contributor

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

Copy link
Contributor

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

Copy link
Contributor

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

Copy link
Contributor

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

Copy link
Contributor

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Dec 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants