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
69a7d71a
Commit
69a7d71a
authored
11 years ago
by
Kurund Jalmi
Browse files
Options
Downloads
Plain Diff
Merge pull request #2320 from kurund/CRM-14052
delete tags that belongs to tagset, CRM-14052
parents
e645d68f
e450bc79
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CRM/Case/Page/AJAX.php
+1
-3
1 addition, 3 deletions
CRM/Case/Page/AJAX.php
CRM/Core/Form/Tag.php
+43
-30
43 additions, 30 deletions
CRM/Core/Form/Tag.php
with
44 additions
and
33 deletions
CRM/Case/Page/AJAX.php
+
1
−
3
View file @
69a7d71a
...
...
@@ -84,9 +84,7 @@ class CRM_Case_Page_AJAX {
$tagIds
=
explode
(
','
,
$tags
);
}
$skipEntityDelete
=
FALSE
;
if
(
!
empty
(
$tagIds
))
{
$skipEntityDelete
=
TRUE
;
$params
=
array
(
'entity_id'
=>
$caseId
,
'entity_table'
=>
'civicrm_case'
,
...
...
@@ -103,7 +101,7 @@ class CRM_Case_Page_AJAX {
}
if
(
!
empty
(
$tagList
))
{
CRM_Core_Form_Tag
::
postProcess
(
$tagList
,
$caseId
,
'civicrm_case'
,
CRM_Core_DAO
::
$_nullObject
,
$skipEntityDelete
);
CRM_Core_Form_Tag
::
postProcess
(
$tagList
,
$caseId
,
'civicrm_case'
,
CRM_Core_DAO
::
$_nullObject
);
}
$session
=
CRM_Core_Session
::
singleton
();
...
...
This diff is collapsed.
Click to expand it.
CRM/Core/Form/Tag.php
+
43
−
30
View file @
69a7d71a
...
...
@@ -226,6 +226,8 @@ class CRM_Core_Form_Tag {
}
if
(
!
empty
(
$tagset
))
{
// assign current tagsets which is used in postProcess
$form
->
_tagsetInfo
=
$tagset
;
$form
->
assign
(
"tagsetInfo_
$mode
"
,
$tagset
);
$form
->
assign
(
"isTagset"
,
TRUE
);
}
...
...
@@ -238,13 +240,12 @@ class CRM_Core_Form_Tag {
* @param int $entityId entity id, eg: contact id, activity id, case id, file id
* @param string $entityTable entity table
* @param object $form form object
* @param boolean $skipDelete TRUE if you need to skip delete action in tag entity table
*
* @return void
* @access public
* @static
*/
static
function
postProcess
(
&
$params
,
$entityId
,
$entityTable
=
'civicrm_contact'
,
&
$form
,
$skipDelete
=
FALSE
)
{
static
function
postProcess
(
&
$params
,
$entityId
,
$entityTable
=
'civicrm_contact'
,
&
$form
)
{
if
(
$form
&&
!
empty
(
$form
->
_entityTagValues
))
{
$existingTags
=
$form
->
_entityTagValues
;
}
...
...
@@ -252,16 +253,26 @@ 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
;
if
(
$form
)
{
// if the key is missing from the form response then all the tags were deleted / cleared
// in that case we create empty tagset params so that below logic works and tagset are
// deleted correctly
foreach
(
$form
->
_tagsetInfo
as
$tagsetName
=>
$tagsetInfo
)
{
$tagsetId
=
substr
(
$tagsetName
,
strlen
(
'parentId_'
));
if
(
empty
(
$params
[
$tagsetId
]))
{
$params
[
$tagsetId
]
=
''
;
}
}
}
$tagsIDs
=
explode
(
','
,
$value
);
$insertValues
=
array
();
$insertSQL
=
NULL
;
if
(
!
empty
(
$tagsIDs
))
{
// when form is submitted with tagset values below logic will work and in the case when all tags in a tagset
// are deleted we will have to set $params[tagset id] = '' which is done by above logic
foreach
(
$params
as
$parentId
=>
$value
)
{
$newTagIds
=
array
();
$realTagIds
=
array
();
if
(
$value
)
{
$tagsIDs
=
explode
(
','
,
$value
);
foreach
(
$tagsIDs
as
$tagId
)
{
if
(
!
is_numeric
(
$tagId
))
{
// check if user has selected existing tag or is creating new tag
...
...
@@ -278,36 +289,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
))
{
$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
}
)"
;
// 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
)
.
");"
;
}
$deleteSQL
=
"
DELETE FROM civicrm_entity_tag USING civicrm_entity_tag, civicrm_tag
WHERE civicrm_entity_tag.tag_id = civicrm_tag.id AND civicrm_tag.parent_id IS NOT NULL
AND civicrm_entity_tag.entity_id=
{
$entityId
}
AND civicrm_entity_tag.entity_table='
{
$entityTable
}
'
{
$inClause
}
"
;
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
);
}
}
}
}
...
...
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