CRM icon indicating copy to clipboard operation
CRM copied to clipboard

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

Open kdwinton opened this issue 2 years ago • 19 comments

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);
}`

kdwinton avatar May 25 '22 01:05 kdwinton

Hi Any update on a fix for this?

djoh2 avatar Oct 23 '22 10:10 djoh2

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);

}`

hafizaqibshafique avatar Jun 13 '23 13:06 hafizaqibshafique

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

DawoudIO avatar Jun 14 '23 18:06 DawoudIO

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[bot] avatar Oct 30 '23 02:10 github-actions[bot]

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[bot] avatar Dec 02 '23 02:12 github-actions[bot]

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

github-actions[bot] avatar Dec 17 '23 02:12 github-actions[bot]

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?

djoh2 avatar Jan 04 '24 17:01 djoh2

Ok Let me check it

On Thu, Jan 4, 2024 at 10:50 PM djoh2 @.***> wrote:

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?

— Reply to this email directly, view it on GitHub https://github.com/ChurchCRM/CRM/issues/6011#issuecomment-1877521263, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMXIBYZT7IDNTLU5V5LHAWDYM3TWNAVCNFSM5W3NH7M2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBXG42TEMJSGYZQ . You are receiving this because you commented.Message ID: @.***>

-- H.A.S

hafizaqibshafique avatar Jan 07 '24 09:01 hafizaqibshafique

I have fixed the issue Let me know on which branch do I need to commit my code

On Sun, Jan 7, 2024 at 2:43 PM Aqib Shafique @.***> wrote:

Ok Let me check it

On Thu, Jan 4, 2024 at 10:50 PM djoh2 @.***> wrote:

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?

— Reply to this email directly, view it on GitHub https://github.com/ChurchCRM/CRM/issues/6011#issuecomment-1877521263, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMXIBYZT7IDNTLU5V5LHAWDYM3TWNAVCNFSM5W3NH7M2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBXG42TEMJSGYZQ . You are receiving this because you commented.Message ID: @.***>

-- H.A.S

-- H.A.S

hafizaqibshafique avatar Jan 10 '24 11:01 hafizaqibshafique

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

DAcodedBEAT avatar Jan 10 '24 16:01 DAcodedBEAT

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[bot] avatar Feb 11 '24 02:02 github-actions[bot]

@hafizaqibshafique are you still planning on contributing this fix?

DAcodedBEAT avatar Feb 11 '24 04:02 DAcodedBEAT

Yeah sure Sorry I didn't commit the code as I was busy. I will upload the code tonight

On Sun, 11 Feb 2024, 9:28 am Arun Philip, @.***> wrote:

@hafizaqibshafique https://github.com/hafizaqibshafique are you still planning on contributing this fix?

— Reply to this email directly, view it on GitHub https://github.com/ChurchCRM/CRM/issues/6011#issuecomment-1937420719, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMXIBY3NMH5K4MNKG342UUDYTBCF7AVCNFSM5W3NH7M2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOJTG42DEMBXGE4Q . You are receiving this because you were mentioned.Message ID: @.***>

hafizaqibshafique avatar Feb 11 '24 04:02 hafizaqibshafique

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[bot] avatar Mar 13 '24 02:03 github-actions[bot]

@hafizaqibshafique any update?

DAcodedBEAT avatar Mar 13 '24 16:03 DAcodedBEAT

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[bot] avatar Apr 14 '24 03:04 github-actions[bot]