Commit 5165b19c authored by unknown's avatar unknown

Towards deleting and recreating activities and resave repeat configuration

parent cd96b0a9
......@@ -953,6 +953,7 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task {
$activity = $this->processActivity($params);
$params['parent_entity_start_date'] = $this->_parentActivityStartDate;
$params['start_date_column_name'] = 'activity_date_time';
$params['entity_table'] = 'civicrm_activity';
//Unset activity id
unset($params['id']);
$linkedEntities = array(
......
......@@ -52,17 +52,19 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
protected $recursion = NULL;
public static $_entitiesToBeDeleted = array();
static $_recurringEntityHelper =
array(
'civicrm_event' => array(
'helper_class' => 'CRM_Event_BAO_Event',
'delete_func' => 'del',
'count_func' => ''
'helper_class' => 'CRM_Event_DAO_Event',
'delete_func' => 'CRM_Event_BAO_Event::del',
'pre_delete_func' => 'CRM_Event_Form_ManageEvent_Repeat::checkRegistrationForEvents'
),
'civicrm_activity' => array(
'helper_class' => 'CRM_Activity_BAO_Activity',
'delete_func' => 'del',
'count_func' => ''
'helper_class' => 'CRM_Activity_DAO_Activity',
'delete_func' => 'CRM_Activity_BAO_Activity::deleteActivity',
'pre_delete_func' => ''
)
);
......@@ -983,7 +985,7 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
/**
* This function gets all columns from civicrm_action_schedule on the basis of event id
*
* @param int $eventId Entity ID
* @param int $entityId Entity ID
* @param string $used_for Specifies for which entity type it's used for
*
* @access public
......@@ -991,7 +993,7 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
*
* @return object
*/
static public function getReminderDetailsByEntityId($entityId, $used_for) {
public static function getReminderDetailsByEntityId($entityId, $used_for) {
if ($entityId) {
$query = "
SELECT *
......
......@@ -298,7 +298,7 @@ class CRM_Core_Form_RecurringEntity {
*/
static function postProcess($params = array(), $type, $linkedEntities = array()) {
$params['entity_id'] = self::$_entityId;
if ($type && CRM_Utils_Array::value('entity_id', $params)) {
if (CRM_Utils_Array::value('entity_table', $params) && CRM_Utils_Array::value('entity_id', $params) && $type) {
$params['used_for'] = $type;
$params['parent_entity_id'] = self::$_parentEntityId;
$params['id'] = self::$_scheduleReminderID;
......@@ -359,18 +359,37 @@ class CRM_Core_Form_RecurringEntity {
//Delete relations if any from recurring entity tables before inserting new relations for this entity id
if ($params['entity_id']) {
$getRelatedEntities = CRM_Core_BAO_RecurringEntity::getEntitiesFor($params['entity_id'], 'civicrm_'.$type, TRUE);
if ($type == 'event') {
$participantDetails = CRM_Event_Form_ManageEvent_Repeat::getParticipantCountforEvent($getRelatedEntities);
//Check if participants exists for events
foreach ($getRelatedEntities as $key => $value) {
if (!CRM_Utils_Array::value($value['id'], $participantDetails['countByID']) && $value['id'] != $params['entity_id']) {
CRM_Event_BAO_Event::del($value['id']);
//If entity has any pre delete function, consider that first
if (CRM_Utils_Array::value('pre_delete_func', CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]) &&
CRM_Utils_Array::value('helper_class', CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']])) {
call_user_func(array(
CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['helper_class'],
call_user_func_array(CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['pre_delete_func'], array($params['entity_id'])))
);
}
//Ready to execute delete on entities if it has delete function set
if (CRM_Utils_Array::value('delete_func', CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]) &&
CRM_Utils_Array::value('helper_class', CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']])) {
//Check if pre delete function has some ids to be deleted
if (!empty(CRM_Core_BAO_RecurringEntity::$_entitiesToBeDeleted)) {
foreach (CRM_Core_BAO_RecurringEntity::$_entitiesToBeDeleted as $value) {
call_user_func(array(
CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['helper_class'],
call_user_func_array(CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['delete_func'], array($value)))
);
}
}
else {
$getRelatedEntities = CRM_Core_BAO_RecurringEntity::getEntitiesFor($params['entity_id'], $params['entity_table'], FALSE);
foreach ($getRelatedEntities as $key => $value) {
call_user_func(array(
CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['helper_class'],
call_user_func_array(CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['delete_func'], array(array('id' => $value['id']))))
);
}
}
}
}
CRM_Core_BAO_RecurringEntity::delEntityRelations($params['entity_id'], 'civicrm_'.$type);
CRM_Core_BAO_RecurringEntity::delEntityRelations($params['entity_id'], $params['entity_table']);
}
$recursion = new CRM_Core_BAO_RecurringEntity();
......@@ -397,7 +416,7 @@ class CRM_Core_Form_RecurringEntity {
}
$recursion->entity_id = $params['entity_id'];
$recursion->entity_table = 'civicrm_'.$type;
$recursion->entity_table = $params['entity_table'];
if (!empty($linkedEntities)) {
$recursion->linkedEntities = $linkedEntities;
}
......
......@@ -110,6 +110,7 @@ class CRM_Event_Form_ManageEvent_Repeat extends CRM_Event_Form_ManageEvent {
$params['parent_entity_end_date'] = $this->_parentEventEndDate;
$params['start_date_column_name'] = 'start_date';
$params['end_date_column_name'] = 'end_date';
$params['entity_table'] = 'civicrm_event';
//Unset event id
unset($params['id']);
......@@ -195,13 +196,13 @@ class CRM_Event_Form_ManageEvent_Repeat extends CRM_Event_Form_ManageEvent {
return $participantDetails;
}
/**
* Update mode column in civicrm_recurring_entity table for event related tabs
*
* @params int $entityId event id
* @params string $linkedEntityTable Linked entity table name for this event
* @return array
*/
/**
* Update mode column in civicrm_recurring_entity table for event related tabs
*
* @params int $entityId event id
* @params string $linkedEntityTable Linked entity table name for this event
* @return array
*/
public static function updateModeRecurringEntityForEvent($entityId, $linkedEntityTable) {
$result = array();
if ( $entityId && $linkedEntityTable ) {
......@@ -238,5 +239,28 @@ class CRM_Event_Form_ManageEvent_Repeat extends CRM_Event_Form_ManageEvent {
}
}
return $result;
}
}
/**
* This function checks if there was any registraion for related event ids,
* and returns array of ids with no regsitrations
* @param type $eventID Event ID
* @return type
*/
public static function checkRegistrationForEvents($eventID) {
$eventIdsWithNoRegistration = array();
if ($eventID) {
$getRelatedEntities = CRM_Core_BAO_RecurringEntity::getEntitiesFor($eventID, 'civicrm_event', TRUE);
$participantDetails = CRM_Event_Form_ManageEvent_Repeat::getParticipantCountforEvent($getRelatedEntities);
//Check if participants exists for events
foreach ($getRelatedEntities as $key => $value) {
if (!CRM_Utils_Array::value($value['id'], $participantDetails['countByID']) && $value['id'] != $eventID) {
//CRM_Event_BAO_Event::del($value['id']);
$eventIdsWithNoRegistration[] = $value['id'];
}
}
}
CRM_Core_BAO_RecurringEntity::$_entitiesToBeDeleted = $eventIdsWithNoRegistration;
return CRM_Core_BAO_RecurringEntity::$_entitiesToBeDeleted;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment