Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
CiviCRM Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Development
CiviCRM Core
Commits
fedefd6c
Commit
fedefd6c
authored
1 month ago
by
ayduns
Browse files
Options
Downloads
Patches
Plain Diff
Allow `hook_civicrm_pre()` delete on a contact to delete a CMS user
parent
214f30ea
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
CRM/Contact/BAO/Contact.php
+29
-10
29 additions, 10 deletions
CRM/Contact/BAO/Contact.php
with
29 additions
and
10 deletions
CRM/Contact/BAO/Contact.php
+
29
−
10
View file @
fedefd6c
...
...
@@ -837,6 +837,20 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer');
return
$displayName
;
}
/**
* Get the CMS user id
*
* @param int $contactId
* @return int
*/
private
static
function
getUFId
(
int
$contactId
):
int
{
// Note: we're not using CRM_Core_BAO_UFMatch::getUFId() because that's cached.
$ufmatch
=
new
CRM_Core_DAO_UFMatch
();
$ufmatch
->
contact_id
=
$contactId
;
$ufmatch
->
domain_id
=
CRM_Core_Config
::
domainID
();
return
$ufmatch
->
find
(
TRUE
)
?
$ufmatch
->
uf_id
:
0
;
}
/**
* Delete a contact and all its associated records.
*
...
...
@@ -890,15 +904,6 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer');
return
FALSE
;
}
// Note: we're not using CRM_Core_BAO_UFMatch::getUFId() because that's cached.
$ufmatch
=
new
CRM_Core_DAO_UFMatch
();
$ufmatch
->
contact_id
=
$id
;
$ufmatch
->
domain_id
=
CRM_Core_Config
::
domainID
();
if
(
$ufmatch
->
find
(
TRUE
))
{
// Do not permit a contact to be deleted if it is linked to a site user.
return
FALSE
;
}
$contactType
=
$contact
->
contact_type
;
if
(
$restore
)
{
// @todo deprecate calling contactDelete with the intention to restore.
...
...
@@ -914,9 +919,20 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer');
$transaction
=
new
CRM_Core_Transaction
();
if
(
$skipUndelete
)
{
$hookParams
=
[
'check_permissions'
=>
$checkPermissions
];
$hookParams
=
[
'check_permissions'
=>
$checkPermissions
,
'uf_id'
=>
self
::
getUFId
(
$id
),
];
// Hook might delete the CMS user
CRM_Utils_Hook
::
pre
(
'delete'
,
$contactType
,
$id
,
$hookParams
);
// Do not permit a contact to be deleted if it is (still) linked to a site user.
if
(
$hookParams
[
'uf_id'
]
&&
self
::
getUFId
(
$id
))
{
$transaction
->
rollback
();
return
FALSE
;
}
//delete billing address if exists.
CRM_Contribute_BAO_Contribution
::
deleteAddress
(
NULL
,
$id
);
...
...
@@ -953,6 +969,9 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer');
$contact
->
delete
();
}
else
{
if
(
self
::
getUFId
(
$id
))
{
return
FALSE
;
}
self
::
contactTrash
(
$contact
);
}
// currently we only clear employer cache.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment