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
50182f0e
Commit
50182f0e
authored
5 years ago
by
eileen
Browse files
Options
Downloads
Patches
Plain Diff
[ref] Move copyCustomFields function from Event to Core_DAO for re-usablibilty
parent
0908f97c
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/Core/DAO.php
+55
-0
55 additions, 0 deletions
CRM/Core/DAO.php
CRM/Event/BAO/Event.php
+1
-52
1 addition, 52 deletions
CRM/Event/BAO/Event.php
with
56 additions
and
52 deletions
CRM/Core/DAO.php
+
55
−
0
View file @
50182f0e
...
...
@@ -1679,6 +1679,61 @@ FROM civicrm_domain
return
$newObject
;
}
/**
* Method that copies custom fields values from an old event to a new one. Fixes bug CRM-19302,
* where if a custom field of File type was present, left both events using the same file,
* breaking download URL's for the old event.
*
* @todo the goal here is to clean this up so that it works for any entity. Copy Generic already DOES some custom field stuff
* so it's not clear why this is needed - best guess is the custom fields are not handled - this is ALSO the
* situation with the dedupe.
*
* @param int $oldEventID
* @param int $newCopyID
*/
public
function
copyCustomFields
(
$oldEventID
,
$newCopyID
)
{
// Obtain custom values for old event
$customParams
=
$htmlType
=
[];
$customValues
=
CRM_Core_BAO_CustomValueTable
::
getEntityValues
(
$oldEventID
,
'Event'
);
// If custom values present, we copy them
if
(
!
empty
(
$customValues
))
{
// Get Field ID's and identify File type attributes, to handle file copying.
$fieldIds
=
implode
(
', '
,
array_keys
(
$customValues
));
$sql
=
"SELECT id FROM civicrm_custom_field WHERE html_type = 'File' AND id IN (
{
$fieldIds
}
)"
;
$result
=
CRM_Core_DAO
::
executeQuery
(
$sql
);
// Build array of File type fields
while
(
$result
->
fetch
())
{
$htmlType
[]
=
$result
->
id
;
}
// Build params array of custom values
foreach
(
$customValues
as
$field
=>
$value
)
{
if
(
$value
!==
NULL
)
{
// Handle File type attributes
if
(
in_array
(
$field
,
$htmlType
))
{
$fileValues
=
CRM_Core_BAO_File
::
path
(
$value
,
$oldEventID
);
$customParams
[
"custom_
{
$field
}
_-1"
]
=
[
'name'
=>
CRM_Utils_File
::
duplicate
(
$fileValues
[
0
]),
'type'
=>
$fileValues
[
1
],
];
}
// Handle other types
else
{
$customParams
[
"custom_
{
$field
}
_-1"
]
=
$value
;
}
}
}
// Save Custom Fields for new Event
CRM_Core_BAO_CustomValueTable
::
postProcess
(
$customParams
,
'civicrm_event'
,
$newCopyID
,
'Event'
);
}
// copy activity attachments ( if any )
CRM_Core_BAO_File
::
copyEntityFile
(
'civicrm_event'
,
$oldEventID
,
'civicrm_event'
,
$newCopyID
);
}
/**
* Cascade update through related entities.
*
...
...
This diff is collapsed.
Click to expand it.
CRM/Event/BAO/Event.php
+
1
−
52
View file @
50182f0e
...
...
@@ -986,7 +986,7 @@ WHERE civicrm_event.is_active = 1
[
'entity_value'
=>
$id
,
'mapping_id'
=>
$oldMapping
->
getId
()],
[
'entity_value'
=>
$copyEvent
->
id
,
'mapping_id'
=>
$copyMapping
->
getId
()]
);
self
::
copyCustomFields
(
$id
,
$copyEvent
->
id
);
$copyEvent
->
copyCustomFields
(
$id
,
$copyEvent
->
id
);
$copyEvent
->
save
();
...
...
@@ -996,57 +996,6 @@ WHERE civicrm_event.is_active = 1
return
$copyEvent
;
}
/**
* Method that copies custom fields values from an old event to a new one. Fixes bug CRM-19302,
* where if a custom field of File type was present, left both events using the same file,
* breaking download URL's for the old event.
*
* @param int $oldEventID
* @param int $newCopyID
*/
public
static
function
copyCustomFields
(
$oldEventID
,
$newCopyID
)
{
// Obtain custom values for old event
$customParams
=
$htmlType
=
[];
$customValues
=
CRM_Core_BAO_CustomValueTable
::
getEntityValues
(
$oldEventID
,
'Event'
);
// If custom values present, we copy them
if
(
!
empty
(
$customValues
))
{
// Get Field ID's and identify File type attributes, to handle file copying.
$fieldIds
=
implode
(
', '
,
array_keys
(
$customValues
));
$sql
=
"SELECT id FROM civicrm_custom_field WHERE html_type = 'File' AND id IN (
{
$fieldIds
}
)"
;
$result
=
CRM_Core_DAO
::
executeQuery
(
$sql
);
// Build array of File type fields
while
(
$result
->
fetch
())
{
$htmlType
[]
=
$result
->
id
;
}
// Build params array of custom values
foreach
(
$customValues
as
$field
=>
$value
)
{
if
(
$value
!==
NULL
)
{
// Handle File type attributes
if
(
in_array
(
$field
,
$htmlType
))
{
$fileValues
=
CRM_Core_BAO_File
::
path
(
$value
,
$oldEventID
);
$customParams
[
"custom_
{
$field
}
_-1"
]
=
[
'name'
=>
CRM_Utils_File
::
duplicate
(
$fileValues
[
0
]),
'type'
=>
$fileValues
[
1
],
];
}
// Handle other types
else
{
$customParams
[
"custom_
{
$field
}
_-1"
]
=
$value
;
}
}
}
// Save Custom Fields for new Event
CRM_Core_BAO_CustomValueTable
::
postProcess
(
$customParams
,
'civicrm_event'
,
$newCopyID
,
'Event'
);
}
// copy activity attachments ( if any )
CRM_Core_BAO_File
::
copyEntityFile
(
'civicrm_event'
,
$oldEventID
,
'civicrm_event'
,
$newCopyID
);
}
/**
* This is sometimes called in a loop (during event search).
*
...
...
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