Make sure that synced appointments are removed from Google Calendar if the provider changes after an appointment update action
This commit is contained in:
parent
0f67dbaddc
commit
f89fdb23c0
2 changed files with 29 additions and 0 deletions
|
@ -235,6 +235,11 @@ class Calendar extends EA_Controller {
|
|||
$appointment['id_users_customer'] = $customer['id'] ?? $customer_data['id'];
|
||||
}
|
||||
|
||||
if ($manage_mode && ! empty($appointment['id']))
|
||||
{
|
||||
$this->synchronization->remove_appointment_on_provider_change($appointment['id']);
|
||||
}
|
||||
|
||||
$this->appointments_model->only($appointment, [
|
||||
'id',
|
||||
'start_datetime',
|
||||
|
|
|
@ -207,4 +207,28 @@ class Synchronization {
|
|||
log_message('error', $e->getTraceAsString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure a synced appointment is removed from Google Calendar, if its provider is changed.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function remove_appointment_on_provider_change($appointment_id)
|
||||
{
|
||||
$existing_appointment = $this->CI->appointments_model->get_row($appointment_id);
|
||||
|
||||
$existing_google_id = $existing_appointment['id_google_calendar'];
|
||||
|
||||
$existing_provider_id = $existing_appointment['id_users_provider'];
|
||||
|
||||
if ( ! empty($existing_google_id) && (int)$existing_provider_id !== (int)$existing_appointment['id_users_provider'])
|
||||
{
|
||||
$existing_provider = $this->CI->providers_model->get_row($existing_provider_id);
|
||||
|
||||
if ($existing_provider['settings']['google_sync'])
|
||||
{
|
||||
$this->sync_appointment_deleted($existing_appointment, $existing_provider);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue