Edit mass update php file to change record ownership. How

Topics related to AppGini plugins/add-ons go here.
Post Reply
sacgtdev
Veteran Member
Posts: 75
Joined: 2020-06-10 11:14

Edit mass update php file to change record ownership. How

Post by sacgtdev » 2020-12-14 09:21

I'm a newbie to php code. Should I insert the code in the mass update generated php code? Following is the snippet of code I extract from the generated php code, anyone able to explain on the bold code and comment the newly inserted code (in blue). I do not fully understand the php code and have difficulty to make it works for :idea: ownership assignment 'after update' via mass updating. Any expert can give guidance? :
/*Code extracted from mass update generated php file in hooks*/

/*Start here*/
$new_value = makeSafe($_REQUEST['newValue']);

/* prepare a safe comma-separated list of IDs to use in the query */
$cs_ids = array();
foreach($ids as $id) $cs_ids[] = "'" . makeSafe($id) . "'";
$cs_ids = implode(', ', $cs_ids);

$tn = 'Block_Yield';
$field = 'to_reviewer';
$pk = getPKFieldName($tn);

/* Declare additional variables */
$today = time();
$groupID = sqlValue("SELECT `groupID` FROM `membership_users` WHERE `memberID`='{$new_value]}' LIMIT 1");


$query = "UPDATE `{$tn}` SET `{$field}`='{$new_value}' WHERE `{$pk}` IN ({$cs_ids})";

/* Is it right to insert my second query to update the membership_userrecords */
$query2 = "UPDATE membership_userrecords SET
memberID= '{$new_value}' ,
dateUpdated='{$today}',
groupID='{$groupID}'
WHERE tableName='{$tn}' AND `{$pk}` IN ({$cs_ids})
";


/* Can you explain the if statement for the following code and the purpose of reconstructing the $query statement */
if($new_value == 'MASS_UPDATE_TOGGLE_CHECKBOX')
$query = "UPDATE `{$tn}` SET
`{$field}` = IF(ISNULL(`{$field}`), '1', IF(`{$field}`, '0', '1'))
WHERE `{$pk}` IN ({$cs_ids})";


$e = array('silentErrors' => true);
sql($query, $e);
sql($query2, $e);

/*End here*/

sacgtdev
Veteran Member
Posts: 75
Joined: 2020-06-10 11:14

Re: Edit mass update php file to change record ownership. How

Post by sacgtdev » 2020-12-28 12:59

I have solved the problem.

However, I still not able to understand the purpose of following code. It seems like the query will never be run as the if condition will be surely always return false. The $new_value will never be the 'MASS_UPDATE_TOGGLE_CHECKBOX'

Code: Select all

/* Can you explain the if statement for the following code and the purpose of reconstructing the $query statement */
if($new_value == 'MASS_UPDATE_TOGGLE_CHECKBOX')
$query = "UPDATE `{$tn}` SET
`{$field}` = IF(ISNULL(`{$field}`), '1', IF(`{$field}`, '0', '1'))
WHERE `{$pk}` IN ({$cs_ids})";

Post Reply