Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trigger post hook on Event Copy #12990

Merged
merged 1 commit into from
Nov 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CRM/Core/DAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -1670,7 +1670,9 @@ public static function &copyGeneric($daoName, $criteria, $newData = NULL, $field
}
}
$newObject->save();
CRM_Utils_Hook::post('create', CRM_Core_DAO_AllCoreTables::getBriefName($daoName), $newObject->id, $newObject);
}

return $newObject;
}

Expand Down
50 changes: 16 additions & 34 deletions CRM/Event/BAO/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -920,13 +920,11 @@ public static function &getCompleteInfo(
* @param int $id
* The event id to copy.
* boolean $afterCreate call to copy after the create function
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also remove this line?

* @param null $newEvent
* @param bool $afterCreate
*
* @return CRM_Event_DAO_Event
* @throws \CRM_Core_Exception
*/
public static function copy($id, $newEvent = NULL, $afterCreate = FALSE) {

public static function copy($id) {
$eventValues = array();

//get the require event values.
Expand All @@ -941,46 +939,35 @@ public static function copy($id, $newEvent = NULL, $afterCreate = FALSE) {

CRM_Core_DAO::commonRetrieve('CRM_Event_DAO_Event', $eventParams, $eventValues, $returnProperties);

// since the location is sharable, lets use the same loc_block_id.
$locBlockId = CRM_Utils_Array::value('loc_block_id', $eventValues);

$fieldsFix = ($afterCreate) ? array() : array('prefix' => array('title' => ts('Copy of') . ' '));
$fieldsFix = array('prefix' => array('title' => ts('Copy of') . ' '));
if (empty($eventValues['is_show_location'])) {
$fieldsFix['prefix']['is_show_location'] = 0;
}

if ($newEvent && is_a($newEvent, 'CRM_Event_DAO_Event')) {
$copyEvent = $newEvent;
}

if (!isset($copyEvent)) {
$copyEvent = &CRM_Core_DAO::copyGeneric('CRM_Event_DAO_Event',
array('id' => $id),
array(
'loc_block_id' =>
($locBlockId) ? $locBlockId : NULL,
),
$fieldsFix
);
}
$copyEvent = CRM_Core_DAO::copyGeneric('CRM_Event_DAO_Event',
array('id' => $id),
// since the location is sharable, lets use the same loc_block_id.
array('loc_block_id' => CRM_Utils_Array::value('loc_block_id', $eventValues)),
$fieldsFix
);
CRM_Price_BAO_PriceSet::copyPriceSet('civicrm_event', $id, $copyEvent->id);
$copyUF = &CRM_Core_DAO::copyGeneric('CRM_Core_DAO_UFJoin',
CRM_Core_DAO::copyGeneric('CRM_Core_DAO_UFJoin',
array(
'entity_id' => $id,
'entity_table' => 'civicrm_event',
),
array('entity_id' => $copyEvent->id)
);

$copyTellFriend = &CRM_Core_DAO::copyGeneric('CRM_Friend_DAO_Friend',
CRM_Core_DAO::copyGeneric('CRM_Friend_DAO_Friend',
array(
'entity_id' => $id,
'entity_table' => 'civicrm_event',
),
array('entity_id' => $copyEvent->id)
);

$copyPCP = &CRM_Core_DAO::copyGeneric('CRM_PCP_DAO_PCPBlock',
CRM_Core_DAO::copyGeneric('CRM_PCP_DAO_PCPBlock',
array(
'entity_id' => $id,
'entity_table' => 'civicrm_event',
Expand All @@ -995,22 +982,17 @@ public static function copy($id, $newEvent = NULL, $afterCreate = FALSE) {
$copyMapping = CRM_Utils_Array::first(CRM_Core_BAO_ActionSchedule::getMappings(array(
'id' => ($copyEvent->is_template == 1 ? CRM_Event_ActionMapping::EVENT_TPL_MAPPING_ID : CRM_Event_ActionMapping::EVENT_NAME_MAPPING_ID),
)));
$copyReminder = &CRM_Core_DAO::copyGeneric('CRM_Core_DAO_ActionSchedule',
CRM_Core_DAO::copyGeneric('CRM_Core_DAO_ActionSchedule',
array('entity_value' => $id, 'mapping_id' => $oldMapping->getId()),
array('entity_value' => $copyEvent->id, 'mapping_id' => $copyMapping->getId())
);

if (!$afterCreate) {
// CRM-19302
self::copyCustomFields($id, $copyEvent->id);
}
self::copyCustomFields($id, $copyEvent->id);

$copyEvent->save();

CRM_Utils_System::flushCache();
if (!$afterCreate) {
CRM_Utils_Hook::copy('Event', $copyEvent);
}
CRM_Utils_Hook::copy('Event', $copyEvent);

return $copyEvent;
}

Expand Down
7 changes: 4 additions & 3 deletions CRM/Event/Form/ManageEvent/EventInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,12 @@ public function postProcess() {
$params = array_merge(CRM_Event_BAO_Event::getTemplateDefaultValues($params['template_id']), $params);
}

$event = CRM_Event_BAO_Event::create($params);

// now that we have the event’s id, do some more template-based stuff
if (!empty($params['template_id'])) {
CRM_Event_BAO_Event::copy($params['template_id'], $event, TRUE);
$event = CRM_Event_BAO_Event::copy($params['template_id']);
}
else {
$event = CRM_Event_BAO_Event::create($params);
}

$this->set('id', $event->id);
Expand Down
1 change: 1 addition & 0 deletions CRM/Event/Page/ManageEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ public function browse() {
* all the fields in the event wizard
*
* @return void
* @throws \CRM_Core_Exception
*/
public function copy() {
$id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE, 0, 'GET');
Expand Down
1 change: 1 addition & 0 deletions CRM/Export/Form/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public function preProcess() {
$components = array('Contact', 'Contribute', 'Member', 'Event', 'Pledge', 'Case', 'Grant', 'Activity');

// FIXME: This should use a modified version of CRM_Contact_Form_Search::getModeValue but it doesn't have all the contexts
// FIXME: Or better still, use CRM_Core_DAO_AllCoreTables::getBriefName($daoName) to get the $entityShortName
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, this is comment is unrelated to this PR... but I was looking for a function to get the Entity shortname and I found it!

switch ($this->getQueryMode()) {
case CRM_Contact_BAO_Query::MODE_CONTRIBUTE:
$entityShortname = 'Contribute';
Expand Down