Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cmsuser
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
Extensions
cmsuser
Commits
bcf3491e
Commit
bcf3491e
authored
2 years ago
by
mattwire
Browse files
Options
Downloads
Patches
Plain Diff
Handle the case that the CMS username already exists
parent
165a409e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
api/v3/Cmsuser/Create.php
+15
-3
15 additions, 3 deletions
api/v3/Cmsuser/Create.php
with
15 additions
and
3 deletions
api/v3/Cmsuser/Create.php
+
15
−
3
View file @
bcf3491e
...
...
@@ -37,9 +37,13 @@ function _civicrm_api3_cmsuser_create_spec(&$params) {
*/
function
civicrm_api3_cmsuser_create
(
$params
)
{
// Check for existing contact
$ufID
=
CRM_Core_BAO_UFMatch
::
getUFId
(
$params
[
'contact_id'
]);
if
(
$ufID
)
{
return
civicrm_api3_create_success
([
'uf_id'
=>
$ufID
,
'created'
=>
FALSE
],
$params
);
$ufMatchByContactID
=
\Civi\Api4\UFMatch
::
get
(
FALSE
)
->
addWhere
(
'contact_id'
,
'='
,
$params
[
'contact_id'
])
->
execute
()
->
first
();
if
(
!
empty
(
$ufMatchByContactID
))
{
return
civicrm_api3_create_success
([
'uf_id'
=>
$ufMatchByContactID
[
'id'
],
'created'
=>
FALSE
],
$params
);
}
// Get email (either from param or from contact record.
...
...
@@ -61,6 +65,14 @@ function civicrm_api3_cmsuser_create($params) {
$params
[
'cms_name'
]
=
$params
[
'email'
];
}
$ufMatchByName
=
\Civi\Api4\UFMatch
::
get
(
FALSE
)
->
addWhere
(
'uf_name'
,
'='
,
$params
[
'cms_name'
])
->
execute
()
->
first
();
if
(
!
empty
(
$ufMatchByName
))
{
throw
new
CiviCRM_API3_Exception
(
"Cannot create CMS user for contact ID:
{
$params
[
'contact_id'
]
}
. CMS Username:
{
$params
[
'cms_name'
]
}
already exists."
);
}
// If no password specified generate a random one
if
(
empty
(
$params
[
'cms_pass'
]))
{
$params
[
'cms_pass'
]
=
bin2hex
(
random_bytes
(
10
));
...
...
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