diff --git a/modules/salesforce_mapping/src/Entity/MappedObject.php b/modules/salesforce_mapping/src/Entity/MappedObject.php index a50048b8d1878a9bafa11811e5ae20c5080c5ce8..87461eb7dbda6c58ddb922c04d8d8c2da6235993 100644 --- a/modules/salesforce_mapping/src/Entity/MappedObject.php +++ b/modules/salesforce_mapping/src/Entity/MappedObject.php @@ -495,7 +495,7 @@ class MappedObject extends RevisionableContentEntityBase implements MappedObject '@sffield' => $sf_field, '@sfid' => $this->sfid(), ]; - $this->eventDispatcher()->dispatch(new SalesforceNoticeEvent($e, $message, $args)); + $this->eventDispatcher()->dispatch(SalesforceEvents::NOTICE, new SalesforceNoticeEvent($e, $message, $args)); continue; } @@ -520,7 +520,7 @@ class MappedObject extends RevisionableContentEntityBase implements MappedObject '@did' => $this->entity_id->value, '@v' => $value, ]; - $this->eventDispatcher()->dispatch(new SalesforceWarningEvent($e, $message, $args)); + $this->eventDispatcher()->dispatch(SalesforceEvents::WARNING, new SalesforceWarningEvent($e, $message, $args)); continue; } } diff --git a/modules/salesforce_mapping/src/Form/MappedObjectDeleteForm.php b/modules/salesforce_mapping/src/Form/MappedObjectDeleteForm.php index cd0ef9a5df9d431a565f51495ff4fc017f4ef762..b17640e1fe97a22a11894a041182f825b3b60599 100644 --- a/modules/salesforce_mapping/src/Form/MappedObjectDeleteForm.php +++ b/modules/salesforce_mapping/src/Form/MappedObjectDeleteForm.php @@ -49,7 +49,7 @@ class MappedObjectDeleteForm extends ContentEntityConfirmFormBase { $form_state->setRedirect($mapped_object->getMappedEntity()->toUrl('salesforce')); $message = 'MappedObject @sfid deleted.'; $args = ['@sfid' => $mapped_object->salesforce_id->value]; - \Drupal::service('event_dispatcher')->dispatch(new SalesforceNoticeEvent(NULL, $message, $args)); + \Drupal::service('event_dispatcher')->dispatch(SalesforceEvents::NOTICE, new SalesforceNoticeEvent(NULL, $message, $args)); $mapped_object->delete(); } diff --git a/modules/salesforce_mapping/src/Form/MappedObjectForm.php b/modules/salesforce_mapping/src/Form/MappedObjectForm.php index 0c48eec9100748bebd014cff96dc316b7403471e..b3b08d16db807aa0dffe2382e9f257811b21a7ca 100644 --- a/modules/salesforce_mapping/src/Form/MappedObjectForm.php +++ b/modules/salesforce_mapping/src/Form/MappedObjectForm.php @@ -169,7 +169,7 @@ class MappedObjectForm extends ContentEntityForm { $mapped_object->push(); } catch (\Exception $e) { - $this->eventDispatcher->dispatch(new SalesforceErrorEvent($e)); + $this->eventDispatcher->dispatch(SalesforceEvents::ERROR, new SalesforceErrorEvent($e)); drupal_set_message(t('Push failed with an exception: %exception', array('%exception' => $e->getMessage())), 'error'); return; } diff --git a/modules/salesforce_mapping/src/Plugin/SalesforceMappingField/RelatedProperties.php b/modules/salesforce_mapping/src/Plugin/SalesforceMappingField/RelatedProperties.php index 8f2866200fd2612726889a3d29dcb9cef2f3321a..2d3343e9d67057c2ca7ddafd6014b6e85006240e 100644 --- a/modules/salesforce_mapping/src/Plugin/SalesforceMappingField/RelatedProperties.php +++ b/modules/salesforce_mapping/src/Plugin/SalesforceMappingField/RelatedProperties.php @@ -82,7 +82,7 @@ class RelatedProperties extends SalesforceMappingFieldPluginBase { } catch (\Exception $e) { // @TODO something about this exception - \Drupal::service('event_dispatcher')->dispatch(new SalesforceErrorEvent($e)); + \Drupal::service('event_dispatcher')->dispatch(SalesforceEvents::ERROR, new SalesforceErrorEvent($e)); return; } diff --git a/modules/salesforce_pull/src/DeleteHandler.php b/modules/salesforce_pull/src/DeleteHandler.php index f07ce9e875e92811b40d3944699b1d74628f73c5..dd46864296e471e2f7dea4a45781d8df48d7a03b 100644 --- a/modules/salesforce_pull/src/DeleteHandler.php +++ b/modules/salesforce_pull/src/DeleteHandler.php @@ -154,7 +154,7 @@ class DeleteHandler { '%id' => $mapped_object->entity_id->value, '%sfid' => $record['id'], ]; - $this->eventDispatcher->dispatch(new SalesforceNoticeEvent(NULL, $message, $args)); + $this->eventDispatcher->dispatch((NULL, $message, $args)); $mapped_object->delete(); return; } @@ -169,7 +169,7 @@ class DeleteHandler { '%id' => $mapped_object->id(), '%sfid' => $record['id'], ]; - $this->eventDispatcher->dispatch(new SalesforceNoticeEvent(NULL, $message, $args)); + $this->eventDispatcher->dispatch((NULL, $message, $args)); // @TODO should we delete a mapped object whose parent mapping no longer exists? Feels like someone else's job. // $mapped_object->delete(); return; @@ -190,10 +190,10 @@ class DeleteHandler { '%id' => $mapped_object->entity_id, '%sfid' => $record['id'], ]; - $this->eventDispatcher->dispatch(new SalesforceNoticeEvent(NULL, $message, $args)); + $this->eventDispatcher->dispatch((NULL, $message, $args)); } catch (\Exception $e) { - $this->eventDispatcher->dispatch(new SalesforceErrorEvent($e)); + $this->eventDispatcher->dispatch(SalesforceEvents::ERROR, new SalesforceErrorEvent($e)); // If mapped entity couldn't be deleted, do not delete the mapped object. return; } diff --git a/modules/salesforce_pull/src/Plugin/QueueWorker/PullBase.php b/modules/salesforce_pull/src/Plugin/QueueWorker/PullBase.php index da6c3afacc082c79e2b5f87d28fb406c350cab66..461515c2a796895961339ff85624f76aa00a32f2 100644 --- a/modules/salesforce_pull/src/Plugin/QueueWorker/PullBase.php +++ b/modules/salesforce_pull/src/Plugin/QueueWorker/PullBase.php @@ -138,7 +138,7 @@ abstract class PullBase extends QueueWorkerBase implements ContainerFactoryPlugi try { $entity = $this->getMappedEntity($mapped_object); if (!$entity) { - $this->eventDispatcher->dispatch(new SalesforceErrorEvent(NULL, 'Drupal entity existed at one time for Salesforce object %sfobjectid, but does not currently exist.', ['%sfobjectid' => (string) $sf_object->id()])); + $this->eventDispatcher->dispatch(SalesforceEvents::ERROR, new SalesforceErrorEvent(NULL, 'Drupal entity existed at one time for Salesforce object %sfobjectid, but does not currently exist.', ['%sfobjectid' => (string) $sf_object->id()])); return; } @@ -178,11 +178,8 @@ abstract class PullBase extends QueueWorkerBase implements ContainerFactoryPlugi } $this->eventDispatcher->dispatch( - SalesforceEvents::PULL_PREPULL, - new SalesforcePullEvent($mapped_object, MappingConstants::SALESFORCE_MAPPING_SYNC_SF_UPDATE) - ); // By default $mapped_object->forceUpdate() is FALSE. To force true, call @@ -190,12 +187,12 @@ abstract class PullBase extends QueueWorkerBase implements ContainerFactoryPlugi if ($sf_record_updated > $entity_updated || $mapped_object->forceUpdate()) { // Set fields values on the Drupal entity. $mapped_object->pull(); - $this->eventDispatcher->dispatch(new SalesforceNoticeEvent(NULL, 'Updated entity %label associated with Salesforce Object ID: %sfid', ['%label' => $entity->label(), '%sfid' => (string) $sf_object->id()])); + $this->eventDispatcher->dispatch(SalesforceEvents::NOTICE, new SalesforceNoticeEvent(NULL, 'Updated entity %label associated with Salesforce Object ID: %sfid', ['%label' => $entity->label(), '%sfid' => (string) $sf_object->id()])); return MappingConstants::SALESFORCE_MAPPING_SYNC_SF_UPDATE; } } catch (\Exception $e) { - $this->eventDispatcher->dispatch(new SalesforceErrorEvent($e, 'Failed to update entity %label from Salesforce object %sfobjectid.', ['%label' => (isset($entity)) ? $entity->label() : "Unknown", '%sfobjectid' => (string) $sf_object->id()])); + $this->eventDispatcher->dispatch(SalesforceEvents::ERROR, new SalesforceErrorEvent($e, 'Failed to update entity %label from Salesforce object %sfobjectid.', ['%label' => (isset($entity)) ? $entity->label() : "Unknown", '%sfobjectid' => (string) $sf_object->id()])); if ($e instanceof PullException) { // Throwing a new exception to keep current item in queue in Cron. @@ -273,12 +270,12 @@ abstract class PullBase extends QueueWorkerBase implements ContainerFactoryPlugi } } - $this->eventDispatcher->dispatch(new SalesforceNoticeEvent(NULL, 'Created entity %id %label associated with Salesforce Object ID: %sfid', ['%id' => $entity->id(), '%label' => $entity->label(), '%sfid' => (string) $sf_object->id()])); + $this->eventDispatcher->dispatch(SalesforceEvents::NOTICE, new SalesforceNoticeEvent(NULL, 'Created entity %id %label associated with Salesforce Object ID: %sfid', ['%id' => $entity->id(), '%label' => $entity->label(), '%sfid' => (string) $sf_object->id()])); return MappingConstants::SALESFORCE_MAPPING_SYNC_SF_CREATE; } catch (\Exception $e) { - $this->eventDispatcher->dispatch(new SalesforceNoticeEvent($e, 'Pull-create failed for Salesforce Object ID: %sfobjectid', ['%sfobjectid' => (string) $sf_object->id()])); + $this->eventDispatcher->dispatch(SalesforceEvents::NOTICE, new SalesforceNoticeEvent($e, 'Pull-create failed for Salesforce Object ID: %sfobjectid', ['%sfobjectid' => (string) $sf_object->id()])); if ($e instanceof PullException) { // Throwing a new exception to keep current item in queue in Cron. throw $e; diff --git a/modules/salesforce_pull/src/QueueHandler.php b/modules/salesforce_pull/src/QueueHandler.php index 152a18bc6b51e0dff4e491425a3cbb3a38680cc1..1644656eeeebfbb3162d2e5e18f57676e0d6e248 100644 --- a/modules/salesforce_pull/src/QueueHandler.php +++ b/modules/salesforce_pull/src/QueueHandler.php @@ -95,7 +95,7 @@ class QueueHandler { '%noi' => $this->queue->numberOfItems(), '%max' => $this->state->get('salesforce_pull_max_queue_size', 100000), ]; - $this->eventDispatcher->dispatch(new SalesforceNoticeEvent(NULL, $message, $args)); + $this->eventDispatcher->dispatch(SalesforceEvents::NOTICE, new SalesforceNoticeEvent(NULL, $message, $args)); return FALSE; } @@ -169,7 +169,7 @@ class QueueHandler { catch (\Exception $e) { $message = '%type: @message in %function (line %line of %file).'; $args = Error::decodeException($e); - $this->eventDispatcher->dispatch(new SalesforceErrorEvent($e, $message, $args)); + $this->eventDispatcher->dispatch(SalesforceEvents::ERROR, new SalesforceErrorEvent($e, $message, $args)); } } @@ -193,7 +193,7 @@ class QueueHandler { catch (\Exception $e) { $message = '%type: @message in %function (line %line of %file).'; $args = Error::decodeException($e); - $this->eventDispatcher->dispatch(new SalesforceErrorEvent($e, $message, $args)); + $this->eventDispatcher->dispatch(SalesforceEvents::ERROR, new SalesforceErrorEvent($e, $message, $args)); } } } @@ -216,7 +216,7 @@ class QueueHandler { catch (\Exception $e) { $message = '%type: @message in %function (line %line of %file).'; $args = Error::decodeException($e); - $this->eventDispatcher->dispatch(new SalesforceErrorEvent($e, $message, $args)); + $this->eventDispatcher->dispatch(SalesforceEvents::ERROR, new SalesforceErrorEvent($e, $message, $args)); } } diff --git a/modules/salesforce_push/salesforce_push.module b/modules/salesforce_push/salesforce_push.module index 0b9c827acae21210ba130b0550a50b033010af9c..7d66b394fa9b6e2e8a1f84904474c6e76a16b715 100644 --- a/modules/salesforce_push/salesforce_push.module +++ b/modules/salesforce_push/salesforce_push.module @@ -73,7 +73,7 @@ function salesforce_push_entity_crud(EntityInterface $entity, $op) { } catch (\Exception $e) { // Do not allow any exception to prevent entity CRUD. - \Drupal::service('event_dispatcher')->dispatch(new SalesforceErrorEvent($e)); + \Drupal::service('event_dispatcher')->dispatch(SalesforceEvents::ERROR, new SalesforceErrorEvent($e)); } } } @@ -130,7 +130,7 @@ function salesforce_push_entity_crud_mapping(EntityInterface $entity, $op, Sales salesforce_push_enqueue_async($entity, $mapping, $mapped_object, $op); } catch (\Exception $e) { - \Drupal::service('event_dispatcher')->dispatch(new SalesforceErrorEvent($e)); + \Drupal::service('event_dispatcher')->dispatch(SalesforceEvents::ERROR, new SalesforceErrorEvent($e)); } return; } @@ -164,12 +164,12 @@ function salesforce_push_entity_crud_mapping(EntityInterface $entity, $op, Sales new SalesforcePushOpEvent($mapped_object, $op) ); - \Drupal::service('event_dispatcher')->dispatch(new SalesforceErrorEvent($e)); + \Drupal::service('event_dispatcher')->dispatch(SalesforceEvents::ERROR, new SalesforceErrorEvent($e)); try { salesforce_push_enqueue_async($entity, $mapping, $mapped_object, $op); } catch (\Exception $e) { - \Drupal::service('event_dispatcher')->dispatch(new SalesforceErrorEvent($e)); + \Drupal::service('event_dispatcher')->dispatch(SalesforceEvents::ERROR, new SalesforceErrorEvent($e)); } $mapped_object @@ -214,6 +214,6 @@ function salesforce_push_cron() { $queue->processQueues(); } catch (\Exception $e) { - \Drupal::service('event_dispatcher')->dispatch(new SalesforceErrorEvent($e)); + \Drupal::service('event_dispatcher')->dispatch(SalesforceEvents::ERROR, new SalesforceErrorEvent($e)); } } diff --git a/modules/salesforce_push/src/PushQueue.php b/modules/salesforce_push/src/PushQueue.php index 0be50071ea9282b528a11b2051db69828bddfa67..c68212fb735375501f268c7666e3194172223d34 100644 --- a/modules/salesforce_push/src/PushQueue.php +++ b/modules/salesforce_push/src/PushQueue.php @@ -316,21 +316,21 @@ class PushQueue extends DatabaseQueue { // Getting a Requeue here is weird for a group of items, but we'll // deal with it. $this->releaseItems($items); - $this->eventDispatcher->dispatch(new SalesforceErrorEvent($e)); + $this->eventDispatcher->dispatch(SalesforceEvents::ERROR, new SalesforceErrorEvent($e)); } catch (SuspendQueueException $e) { // Getting a SuspendQueue is more likely, e.g. because of a network // or authorization error. Release items and move on to the next // mapping in this case. $this->releaseItems($items); - $this->eventDispatcher->dispatch(new SalesforceErrorEvent($e)); + $this->eventDispatcher->dispatch(SalesforceEvents::ERROR, new SalesforceErrorEvent($e)); continue 2; } catch (\Exception $e) { // In case of any other kind of exception, log it and leave the item // in the queue to be processed again later. // @TODO: this is how Cron.php queue works, but I don't really understand why it doesn't get re-queued. - $this->eventDispatcher->dispatch(new SalesforceErrorEvent($e)); + $this->eventDispatcher->dispatch(SalesforceEvents::ERROR, new SalesforceErrorEvent($e)); } finally { // If we've reached our limit, we're done. Otherwise, continue to next items. @@ -365,7 +365,7 @@ class PushQueue extends DatabaseQueue { '%id' => $item->entity_id, '%mapping' => $mapping->id(), ]; - $this->eventDispatcher->dispatch(new SalesforceNoticeEvent(NULL, $message, $args)); + $this->eventDispatcher->dispatch(SalesforceEvents::NOTICE, new SalesforceNoticeEvent(NULL, $message, $args)); $this->deleteItem($item); return; } @@ -386,7 +386,7 @@ class PushQueue extends DatabaseQueue { '%item' => $item->item_id, '%fail' => $item->failures, ]; - $this->eventDispatcher->dispatch(new SalesforceNoticeEvent(NULL, $message, $args)); + $this->eventDispatcher->dispatch(SalesforceEvents::NOTICE, new SalesforceNoticeEvent(NULL, $message, $args)); // Failed items will remain in queue, but not be released. They'll be // retried only when the current lease expires. @@ -411,7 +411,7 @@ class PushQueue extends DatabaseQueue { return $update->execute(); } catch (\Exception $e) { - $this->eventDispatcher->dispatch(new SalesforceErrorEvent($e)); + $this->eventDispatcher->dispatch(SalesforceEvents::ERROR, new SalesforceErrorEvent($e)); $this->catchException($e); // If the table doesn't exist we should consider the item released. return TRUE; diff --git a/src/Event/SalesforceEvents.php b/src/Event/SalesforceEvents.php index a4f8c07866df017053bc90372dc09d003bd4dac2..ed23bbb8d2eae5b78112575d12dccf869fef43d4 100644 --- a/src/Event/SalesforceEvents.php +++ b/src/Event/SalesforceEvents.php @@ -132,23 +132,33 @@ final class SalesforceEvents { const PULL_PRESAVE = 'salesforce.pull_presave'; /** - * Dispatched when Salesforce catches a loggable, non-fatal exception. + * Dispatched when Salesforce encounters a loggable, non-fatal error. * - * Subscribers receive a Drupal\salesforce\SalesforceExceptionEvent instance. + * Subscribers receive a Drupal\salesforce\SalesforceErrorEvent instance. * @Event * * @var string */ - const EXCEPTION = 'salesforce.exception'; + const ERROR = 'salesforce.error'; /** - * Dispatched when Salesforce encounters a loggable, non-fatal error. + * Dispatched when Salesforce encounters a concerning, but non-error event. * - * Subscribers receive a Drupal\salesforce\SalesforceErrorEvent instance. + * Subscribers receive a Drupal\salesforce\SalesforceWarningEvent instance. * @Event * * @var string */ - const ERROR = 'salesforce.error'; + const WARNING = 'salesforce.warning'; + + /** + * Dispatched when Salesforce encounters a basic loggable event. + * + * Subscribers receive a Drupal\salesforce\SalesforceNoticeEvent instance. + * @Event + * + * @var string + */ + const NOTICE = 'salesforce.error'; } diff --git a/src/Form/AuthorizeForm.php b/src/Form/AuthorizeForm.php index 199480461025ad103028fc1bcf7bb0d8e502db9f..993456136b960e40aff16e6243d4b51e5090d6a7 100644 --- a/src/Form/AuthorizeForm.php +++ b/src/Form/AuthorizeForm.php @@ -141,7 +141,7 @@ class AuthorizeForm extends ConfigFormBase { } catch (RequestException $e) { drupal_set_message($e->getMessage(), 'warning'); - $this->eventDispatcher->dispatch(new SalesforceErrorEvent($e)); + $this->eventDispatcher->dispatch(SalesforceEvents::ERROR, new SalesforceErrorEvent($e)); } } else { @@ -178,7 +178,7 @@ class AuthorizeForm extends ConfigFormBase { } catch (RequestException $e) { drupal_set_message(t("Error during authorization: %message", ['%message' => $e->getMessage()]), 'error'); - $this->eventDispatcher->dispatch(new SalesforceErrorEvent($e)); + $this->eventDispatcher->dispatch(SalesforceEvents::ERROR, new SalesforceErrorEvent($e)); } }