Remove attribute for all associated customers if customer number exists; prevent re-adding exception in invoice collection logic.
This commit is contained in:
@@ -220,6 +220,22 @@ class users_o extends db
|
||||
$user_id = $this->id;
|
||||
}
|
||||
$attribute = $db->escape_string($attribute);
|
||||
// If the user has a customer number, we will delete the attribute from all associated customers
|
||||
$customer_number = $this->customer_number->value();
|
||||
if (!empty($customer_number)) {
|
||||
$sql = "SELECT * FROM users WHERE customer_number = $customer_number";
|
||||
$result = $db->query($sql);
|
||||
$user_ids = [];
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$user_ids[] = (int)$row['id'];
|
||||
}
|
||||
// Delete the attribute from all users
|
||||
foreach ($user_ids as $user_id) {
|
||||
$sql = "DELETE FROM customer_attributes WHERE user_id = $user_id AND attribute = '$attribute' LIMIT 1";
|
||||
$db->query($sql);
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Make sure the attribute exists
|
||||
if (!$this->doesUserHaveAttribute((string)$attribute, (int)$user_id)) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user