Requests
Pull Request: Client and Contact Create, Update and Delete Callbacks
Completed
Problem: Blesta only supports callbacks for when a new client is created. When a client is updated, deleted or if a contact for a client is created, updated or deleted, no callbacks exists. This makes developing plugins harder within Blesta.
Solution: Accept the Pull Request below which adds full callback support (Create, Update & Delete) for both Clients and Contacts.
Reference Link: https://www.blesta.com/forums/index.php?/topic/9348-event-handlers-client-contact-crud/
- From: Adam Brenner <adam@netops.me>
- Date: Thu, 6 Apr 2017 22:45:22 -0700
- Subject: [PATCH 1/1] CUD Callbacks on Clients and Contacts
- This is a new feature to Blesta that will allow anyone to
- get callbacks when any CUD operation occurs on a client or
- contact.
- Signed-off-by: Adam Brenner <adam@netops.me>
- ---
- app/models/clients.php | 6 +++
- app/models/contacts.php | 9 +++++
- .../events/default/events_clients_callback.php | 22 +++++++++++
- .../events/default/events_contacts_callback.php | 46 ++++++++++++++++++++++
- 4 files changed, 83 insertions(+)
- create mode 100644 components/events/default/events_contacts_callback.php
- diff --git a/app/models/clients.php b/app/models/clients.php
- index c6fdef0..1bd4468 100644
- --- a/app/models/clients.php
- +++ b/app/models/clients.php
- @@ -302,6 +302,9 @@ class Clients extends AppModel
- $fields = ['user_id', 'client_group_id', 'status'];
- $this->Record->where('id', '=', $client_id)->update('clients', $vars, $fields);
- }
- +
- + $this->Events->register('Clients.edit', ['EventsClientsCallback', 'edit']);
- + $this->Events->trigger(new EventObject('Clients.edit', ['client' => $this->get($client_id)]));
- }
- /**
- @@ -337,6 +340,9 @@ class Clients extends AppModel
- $this->Users->delete($client->user_id);
- }
- }
- +
- + $this->Events->register('Clients.delete', ['EventsClientsCallback', 'delete']);
- + $this->Events->trigger(new EventObject('Clients.delete', ['client' => $client]));
- }
- /**
- diff --git a/app/models/contacts.php b/app/models/contacts.php
- index 8776585..3e39efc 100644
- --- a/app/models/contacts.php
- +++ b/app/models/contacts.php
- @@ -93,6 +93,9 @@ class Contacts extends AppModel
- $this->setPermissions($contact_id, $vars['permissions']);
- }
- + $this->Events->register('Contacts.create', ['EventsContactsCallback', 'create']);
- + $this->Events->trigger(new EventObject('Contacts.create', ['contact' => $this->get($contact_id)]));
- +
- return $contact_id;
- }
- }
- @@ -227,6 +230,9 @@ class Contacts extends AppModel
- $this->Logs->addContact(['contact_id'=>$contact_id, 'fields'=>$fields]);
- }
- + $this->Events->register('Contacts.edit', ['EventsContactsCallback', 'edit']);
- + $this->Events->trigger(new EventObject('Contacts.edit', ['contact' => $new_contact]));
- +
- return $new_contact;
- }
- }
- @@ -270,6 +276,9 @@ class Contacts extends AppModel
- $this->Users->delete($contact->user_id);
- }
- }
- +
- + $this->Events->register('Contacts.delete', ['EventsContactsCallback', 'delete']);
- + $this->Events->trigger(new EventObject('Contacts.delete', ['contact' => $contact]));
- }
- /**
- diff --git a/components/events/default/events_clients_callback.php b/components/events/default/events_clients_callback.php
- index b9fc40c..6c81144 100644
- --- a/components/events/default/events_clients_callback.php
- +++ b/components/events/default/events_clients_callback.php
- @@ -21,4 +21,26 @@ class EventsClientsCallback extends EventCallback
- {
- return parent::triggerPluginEvent($event);
- }
- +
- + /**
- + * Handle Clients.edit events
- + *
- + * @param EventObject $event An event object for Clients.edit events
- + * @return EventObject The processed event object
- + */
- + public static function edit(EventObject $event)
- + {
- + return parent::triggerPluginEvent($event);
- + }
- +
- + /**
- + * Handle Clients.delete events
- + *
- + * @param EventObject $event An event object for Clients.delete events
- + * @return EventObject The processed event object
- + */
- + public static function delete(EventObject $event)
- + {
- + return parent::triggerPluginEvent($event);
- + }
- }
- diff --git a/components/events/default/events_contacts_callback.php b/components/events/default/events_contacts_callback.php
- new file mode 100644
- index 0000000..42b55c9
- --- /dev/null
- +++ b/components/events/default/events_contacts_callback.php
- @@ -0,0 +1,46 @@
- +<?php
- +/**
- + * Handle all default Contacts events callbacks
- + *
- + * @package blesta
- + * @subpackage blesta.components.events.default
- + * @copyright Copyright (c) 2010, Phillips Data, Inc.
- + * @license http://www.blesta.com/license/ The Blesta License Agreement
- + * @link http://www.blesta.com/ Blesta
- + */
- +class EventsContactsCallback extends EventCallback
- +{
- +
- + /**
- + * Handle Contacts.create events
- + *
- + * @param EventObject $event An event object for Contacts.create events
- + * @return EventObject The processed event object
- + */
- + public static function create(EventObject $event)
- + {
- + return parent::triggerPluginEvent($event);
- + }
- +
- + /**
- + * Handle Contacts.edit events
- + *
- + * @param EventObject $event An event object for Contacts.edit events
- + * @return EventObject The processed event object
- + */
- + public static function edit(EventObject $event)
- + {
- + return parent::triggerPluginEvent($event);
- + }
- +
- + /**
- + * Handle Contacts.delete events
- + *
- + * @param EventObject $event An event object for Contacts.delete events
- + * @return EventObject The processed event object
- + */
- + public static function delete(EventObject $event)
- + {
- + return parent::triggerPluginEvent($event);
- + }
- +}
- --
- 2.12.1
See https://dev.blesta.com/browse/CORE-2364
Comments have been locked on this page!