Contact update status fix

This commit is contained in:
Pinga 2025-05-02 22:18:54 +03:00
parent 8633a580b4
commit b2ba26d8b8

View file

@ -439,24 +439,36 @@ function processContactUpdate($conn, $db, $xml, $clid, $database_type, $trans) {
} }
} }
if ($contactRem && $xml->xpath("./*[name()='$contactRem']")) { if (!empty($contactRem)) {
$status_list = $xml->xpath("contact:status/@s"); $status_list = $xml->xpath('//contact:rem/contact:status/@s');
foreach ($status_list as $node) { foreach ($status_list as $node) {
$status = (string)$node[0]; $status = (string)$node;
$sth = $db->prepare("DELETE FROM contact_status WHERE contact_id = ? AND status = ?"); $sth = $db->prepare("DELETE FROM contact_status WHERE contact_id = ? AND status = ?");
$sth->execute([$contact_id, $status]); $sth->execute([$contact_id, $status]);
} }
$sth = $db->prepare("SELECT COUNT(*) FROM contact_status WHERE contact_id = ?");
$sth->execute([$contact_id]);
$remaining = $sth->fetchColumn();
if ((int)$remaining === 0) {
$sth = $db->prepare("INSERT INTO contact_status (contact_id, status) VALUES (?, 'ok')");
$sth->execute([$contact_id]);
}
} }
if ($contactAdd && $xml->xpath("./*[name()='$contactAdd']")) { if (!empty($contactAdd)) {
$status_list = $xml->xpath("contact:status/@s"); $status_list = $xml->xpath('//contact:add/contact:status/@s');
foreach ($status_list as $node) { foreach ($status_list as $node) {
$status = (string)$node[0]; $status = (string)$node;
$sth = $db->prepare("INSERT INTO contact_status (contact_id, status) VALUES (?, ?)"); $sth = $db->prepare("INSERT INTO contact_status (contact_id, status) VALUES (?, ?)");
$sth->execute([$contact_id, $status]); $sth->execute([$contact_id, $status]);
} }
$sth = $db->prepare("DELETE FROM contact_status WHERE contact_id = ? AND status = 'ok'");
$sth->execute([$contact_id]);
} }
if ($contactChg) { if ($contactChg) {