Skip to content

Commit

Permalink
FIX #31360 delete contact when using pgsql.
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Oct 13, 2024
1 parent 0ec6ec9 commit 21c1c02
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion htdocs/core/lib/company.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1566,7 +1566,7 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '', $showuserl

// Delete
if ($user->hasRight('societe', 'contact', 'delete')) {
print '<a class="marginleftonly right" href="'.DOL_URL_ROOT.'/societe/contact.php?action=delete&token='.newToken().'&id='.$obj->rowid.'&backtopage='.urlencode($backtopage).'">';
print '<a class="marginleftonly right" href="'.DOL_URL_ROOT.'/societe/contact.php?action=delete&token='.newToken().'&id='.$obj->rowid.'&socid='.$object->id.'&backtopage='.urlencode($backtopage).'">';
print img_delete();
print '</a>';
}
Expand Down
25 changes: 16 additions & 9 deletions htdocs/societe/contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,19 +140,26 @@
if (!empty($id) && $socid > 0) {
$db->begin();

$sql = "DELETE t, et FROM ".MAIN_DB_PREFIX."socpeople AS t";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople_extrafields AS et ON t.rowid = et.fk_object";
$sql .= " WHERE t.fk_soc = ".((int) $socid);
$sql .= " AND t.rowid = ".((int) $id);
$sql .= " AND ((t.fk_user_creat = ".((int) $user->id)." AND t.priv = 1) OR t.priv = 0)";

$result = $db->query($sql);
if (!$result) {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."socpeople_extrafields";
$sql .= " WHERE fk_object = ".((int) $socid);
$sql .= " AND fk_object IN (SELECT rowid FROM ".MAIN_DB_PREFIX."socpeople as sp WHERE sp.rowid = ".((int) $socid);
$sql .= " AND ((sp.fk_user_creat = ".((int) $user->id)." AND sp.priv = 1) OR sp.priv = 0))";

$result1 = $db->query($sql);

$sql = "DELETE FROM ".MAIN_DB_PREFIX."socpeople";
$sql .= " WHERE fk_soc = ".((int) $socid);
$sql .= " AND rowid = ".((int) $id);
$sql .= " AND ((fk_user_creat = ".((int) $user->id)." AND priv = 1) OR priv = 0)";

$result2 = $db->query($sql);

if (!$result1 || !$result2) {
setEventMessages($db->lasterror(), null, 'errors');
$db->rollback();
} else {
$db->commit();
setEventMessages('ContactDeleted', null, 'mesgs');
setEventMessages('RecordDeleted', null, 'mesgs');
header("Location: ".$_SERVER['PHP_SELF']."?id=".$socid);
exit();
}
Expand Down

0 comments on commit 21c1c02

Please sign in to comment.