Skip to content
Open
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
4 changes: 2 additions & 2 deletions config/schema/salesforce.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ salesforce.settings:
description: 'Set the maximum number of items which can be enqueued for pull at any given time. Note this setting is not exactly analogous to the push queue limit, since Drupal Cron API does not offer such granularity. Use 0 for no limit.'
standalone:
type: boolean
label: 'Provide standalone push queue processing endpoint'
description: 'Enable standalone push processing, and do not process push mappings during cron. Note: when enabled, you must set up your own service to query this endpoint.'
label: 'Provide standalone queue processing endpoint and disable cron processing.'
description: 'Enable standalone queue processing, and do not process push mappings during cron. Pull queue will be populated and processed via standalone endpoint, and may also be processed during cron. Note: when enabled, you must set up your own service to query this endpoint.'
show_all_objects:
type: boolean
label: 'Show all Salesforce objects in mapping UI, including system and non-writeable tables'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ salesforce_mapping.salesforce_mapping.*:
push_standalone:
type: boolean
label: 'Standalone push queue processing'
pull_standalone:
type: boolean
label: 'Standalone pull queue processing'
pull_trigger_date:
type: string
label: 'Pull Trigger Date Field'
Expand Down
15 changes: 15 additions & 0 deletions modules/salesforce_mapping/src/Entity/SalesforceMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
* "key",
* "async",
* "push_standalone",
* "pull_standalone",
* "pull_trigger_date",
* "pull_where_clause",
* "sync_triggers",
Expand Down Expand Up @@ -127,6 +128,13 @@ class SalesforceMapping extends ConfigEntityBase implements SalesforceMappingInt
*/
protected $push_standalone = FALSE;

/**
* Whether a standalone push endpoint is enabled for this mapping.
*
* @var bool
*/
protected $pull_standalone = FALSE;

/**
* The Salesforce field to use for determining whether or not to pull.
*
Expand Down Expand Up @@ -440,6 +448,13 @@ public function doesPushStandalone() {
return $this->push_standalone;
}

/**
* {@inheritdoc}
*/
public function doesPullStandalone() {
return $this->pull_standalone;
}

/**
* {@inheritdoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ public function getPullTriggerDate();
*/
public function doesPushStandalone();

/**
* Getter for push_standalone property.
*
* @return bool
* TRUE if this mapping is set to process push queue via a standalone
* endpoint instead of during cron.
*/
public function doesPullStandalone();

/**
* Checks mappings for any push operation.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,34 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#default_value' => $mapping->pull_frequency,
'#description' => t('Enter a frequency, in seconds, for how often this mapping should be used to pull data to Drupal. Enter 0 to pull as often as possible. FYI: 1 hour = 3600; 1 day = 86400. <em>NOTE: pull frequency is shared per-Salesforce Object. The setting is exposed here for convenience.</em>'),
];

$description = t('Check this box to disable cron pull processing for this mapping, and allow standalone processing only. A URL will be generated after saving the mapping.');
if ($mapping->id()) {
$standalone_url = Url::fromRoute(
'salesforce_pull.endpoint.salesforce_mapping',
[
'salesforce_mapping' => $mapping->id(),
'key' => \Drupal::state()->get('system.cron_key'),
],
['absolute' => TRUE])
->toString();
$description = t('Check this box to disable cron pull processing for this mapping, and allow standalone processing via this URL: <a href=":url">:url</a>', [':url' => $standalone_url]);
}
$form['pull']['pull_standalone'] = [
'#title' => t('Enable standalone pull queue processing'),
'#type' => 'checkbox',
'#description' => $description,
'#default_value' => $mapping->pull_standalone,
];

// If global standalone is enabled, then we force this mapping's
// standalone property to true.
if ($this->config('salesforce.settings')->get('standalone')) {
$settings_url = Url::fromRoute('salesforce.global_settings')->toString();
$form['pull']['pull_standalone']['#default_value'] = TRUE;
$form['pull']['pull_standalone']['#disabled'] = TRUE;
$form['pull']['pull_standalone']['#description'] .= ' ' . t('See also <a href="@url">global standalone processing settings</a>.', ['@url' => $settings_url]);
}
}

if ($this->moduleHandler->moduleExists('salesforce_push')) {
Expand Down Expand Up @@ -316,7 +344,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
// If global standalone is enabled, then we force this mapping's
// standalone property to true.
if ($this->config('salesforce.settings')->get('standalone')) {
$settings_url = Url::fromRoute('salesforce.global_settings');
$settings_url = Url::fromRoute('salesforce.global_settings')->toString();
$form['push']['push_standalone']['#default_value'] = TRUE;
$form['push']['push_standalone']['#disabled'] = TRUE;
$form['push']['push_standalone']['#description'] .= ' ' . t('See also <a href="@url">global standalone processing settings</a>.', ['@url' => $settings_url]);
Expand Down
45 changes: 43 additions & 2 deletions modules/salesforce_mapping/src/SalesforceMappingStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,32 @@ public function loadPushMappings($entity_type_id = NULL) {
}

/**
* Get Mapping entities who are standalone push-enabled.
* Get push Mappings to be processed during cron.
*
* @return \Drupal\salesforce_mapping\Entity\SalesforceMappingInterface[]
* The push-standalong mappings Mappings.
* The Mappings to process.
*/
public function loadCronPushMappings() {
if ($this->configFactory->get('salesforce.settings')->get('standalone')) {
return [];
}
$properties["push_standalone"] = FALSE;
return $this->loadPushMappingsByProperties($properties);
}

/**
* Get pull Mappings to be processed during cron.
*
* @return \Drupal\salesforce_mapping\Entity\SalesforceMappingInterface[]
* The pull Mappings.
*/
public function loadCronPullMappings() {
if ($this->configFactory->get('salesforce.settings')->get('standalone')) {
return [];
}
return $this->loadPullMappingsByProperties(["pull_standalone" => FALSE]);
}

/**
* Return an array push-enabled mappings by properties.
*
Expand All @@ -138,6 +154,31 @@ public function loadPushMappingsByProperties(array $properties) {
return $push_mappings;
}

/**
* Return an array push-enabled mappings by properties.
*
* @param array $properties
* Properties array for storage handler.
*
* @return \Drupal\salesforce_mapping\Entity\SalesforceMappingInterface[]
* The pull mappings.
*
* @see ::loadByProperties()
*/
public function loadPullMappingsByProperties(array $properties) {
$mappings = $this->loadByProperties($properties);
foreach ($mappings as $key => $mapping) {
if (!$mapping->doesPull()) {
continue;
}
$push_mappings[$key] = $mapping;
}
if (empty($push_mappings)) {
return [];
}
return $push_mappings;
}

/**
* Return an array of SalesforceMapping entities who are pull-enabled.
*
Expand Down
14 changes: 14 additions & 0 deletions modules/salesforce_pull/salesforce_pull.install
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,17 @@ function salesforce_pull_update_8004() {
\Drupal::state()->set('salesforce.mapping_pull_info', $mapping_pull_info);
\Drupal::state()->delete('salesforce.sobject_pull_info');
}

/**
* Update mappings with "pull standalone" property.
*/
function salesforce_pull_update_8005() {
$mappings = \Drupal::entityTypeManager()->getStorage('salesforce_mapping')->loadPullMappings();
foreach ($mappings as $mapping) {
if (empty($mapping->get('pull_standalone'))) {
$mapping
->set('pull_standalone', FALSE)
->save();
}
}
}
4 changes: 4 additions & 0 deletions modules/salesforce_pull/salesforce_pull.module
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
* Implements hook_cron().
*/
function salesforce_pull_cron() {
if (\Drupal::config('salesforce.settings')->get('standalone')) {
// If global standalone processing is enabled, stop here.
return;
}
$sfapi = \Drupal::service('salesforce.client');
if ($sfapi->isAuthorized()) {
\Drupal::service('salesforce_pull.queue_handler')->getUpdatedRecords();
Expand Down
26 changes: 26 additions & 0 deletions modules/salesforce_pull/salesforce_pull.routing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
salesforce_pull.endpoint:
path: '/salesforce_pull/endpoint/{key}'
defaults:
_controller: '\Drupal\salesforce_pull\Controller\PullController::endpoint'
options:
no_cache: TRUE
requirements:
_access_system_cron: 'TRUE'

salesforce_pull.endpoint.salesforce_mapping:
path: '/salesforce_pull/{salesforce_mapping}/endpoint/{key}'
defaults:
_controller: '\Drupal\salesforce_pull\Controller\PullController::endpoint'
options:
no_cache: TRUE
requirements:
_access_system_cron: 'TRUE'

salesforce_pull.endpoint.single_record:
path: '/salesforce_pull/{salesforce_mapping}/endpoint/{key}/record/{id}'
defaults:
_controller: '\Drupal\salesforce_pull\Controller\PullController::endpoint'
options:
no_cache: TRUE
requirements:
_access_system_cron: 'TRUE'
Loading