Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor 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
justinfreeman (Agileware)
Core
Commits
63b69fae
Commit
63b69fae
authored
11 years ago
by
Kurund Jalmi
Browse files
Options
Downloads
Patches
Plain Diff
more fixes for delete of tags in a tagset
parent
38223007
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
CRM/Core/Form/Tag.php
+23
-21
23 additions, 21 deletions
CRM/Core/Form/Tag.php
with
23 additions
and
21 deletions
CRM/Core/Form/Tag.php
+
23
−
21
View file @
63b69fae
...
...
@@ -252,14 +252,15 @@ class CRM_Core_Form_Tag {
$existingTags
=
CRM_Core_BAO_EntityTag
::
getTag
(
$entityId
,
$entityTable
);
}
$allTagIds
=
array
();
foreach
(
$params
as
$parentId
=>
$value
)
{
if
(
!
$value
||
empty
(
$value
))
{
continue
;
}
$newTagIds
=
array
();
$realTagIds
=
array
();
$tagsIDs
=
explode
(
','
,
$value
);
$insertValues
=
array
();
$insertSQL
=
NULL
;
if
(
!
empty
(
$tagsIDs
))
{
foreach
(
$tagsIDs
as
$tagId
)
{
...
...
@@ -278,37 +279,38 @@ class CRM_Core_Form_Tag {
}
}
$a
l
lTagIds
[]
=
$tagId
;
$
re
alTagIds
[]
=
$tagId
;
if
(
$form
&&
$form
->
_action
!=
CRM_Core_Action
::
UPDATE
)
{
$
insertValue
s
[]
=
"(
{
$tagId
}
,
{
$entityId
}
, '
{
$entityTable
}
' ) "
;
$
newTagId
s
[]
=
$tagId
;
}
elseif
(
!
array_key_exists
(
$tagId
,
$existingTags
))
{
$
insertValue
s
[]
=
"(
{
$tagId
}
,
{
$entityId
}
, '
{
$entityTable
}
' ) "
;
$
newTagId
s
[]
=
$tagId
;
}
}
if
(
!
empty
(
$insertValues
))
{
// Any existing entity tags from this tagset missing from the $params should be deleted
$deleteSQL
=
"DELETE FROM civicrm_entity_tag
USING civicrm_entity_tag, civicrm_tag
WHERE civicrm_tag.id=civicrm_entity_tag.tag_id
AND civicrm_entity_tag.entity_table='
{
$entityTable
}
'
AND entity_id=
{
$entityId
}
AND parent_id=
{
$parentId
}
"
;
if
(
!
empty
(
$realTagIds
))
{
$deleteSQL
.
=
" AND tag_id NOT IN ("
.
implode
(
', '
,
$realTagIds
)
.
");"
;
}
CRM_Core_DAO
::
executeQuery
(
$deleteSQL
);
if
(
!
empty
(
$newTagIds
))
{
// New tag ids can be inserted directly into the db table.
$insertValues
=
array
();
foreach
(
$newTagIds
as
$tagId
)
{
$insertValues
[]
=
"(
{
$tagId
}
,
{
$entityId
}
, '
{
$entityTable
}
' ) "
;
}
$insertSQL
=
'INSERT INTO civicrm_entity_tag ( tag_id, entity_id, entity_table )
VALUES '
.
implode
(
', '
,
$insertValues
)
.
';'
;
CRM_Core_DAO
::
executeQuery
(
$insertSQL
);
}
}
}
// delete tags that are missing from civicrm_entity_tag table
if
(
!
$skipDelete
)
{
$inClause
=
''
;
if
(
!
empty
(
$allTagIds
))
{
$validTagIds
=
implode
(
','
,
$allTagIds
);
$inClause
=
" AND civicrm_entity_tag.tag_id NOT IN (
{
$validTagIds
}
)"
;
}
$deleteSQL
=
"
DELETE FROM civicrm_entity_tag USING civicrm_entity_tag, civicrm_tag ct1, civicrm_tag ct2
WHERE civicrm_entity_tag.tag_id = ct1.id AND ct1.parent_id IS NOT NULL AND civicrm_entity_tag.entity_id=
{
$entityId
}
AND civicrm_entity_tag.entity_table='
{
$entityTable
}
' AND ct1.parent_id = ct2.id AND ct2.is_tagset=1
{
$inClause
}
"
;
CRM_Core_DAO
::
executeQuery
(
$deleteSQL
);
}
}
}
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