Skip to content
Snippets Groups Projects
Commit 76d2d11c authored by Aaron Bauman's avatar Aaron Bauman
Browse files

/**************** REQUIRES ENTITY UPDATE *****************/

RUN `drush entup` AFTER PULLING THIS COMMIT

- Add MappedObject->force_pull field to mark mapped objects for forcible pull, ignoring entity and salesforce record timestamps
- Fix pull queue handler refusing to pull when max_pull_size is null
- Fix invalid delete query due to 30-day query window limit
parent 2857b4d9
No related branches found
No related tags found
No related merge requests found
......@@ -74,13 +74,6 @@ class MappedObject extends RevisionableContentEntityBase implements MappedObject
*/
protected $drupal_entity = NULL;
/**
* Force update of mapped entity Flag.
*
* @var bool
*/
protected $force_update = FALSE;
/**
* Overrides ContentEntityBase::__construct().
*/
......@@ -229,6 +222,11 @@ class MappedObject extends RevisionableContentEntityBase implements MappedObject
->setSetting('max_length', MappingConstants::SALESFORCE_MAPPING_TRIGGER_MAX_LENGTH)
->setRevisionable(TRUE);
$fields['force_pull'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Force Pull'))
->setDescription(t('Whether to ignore entity timestamps and force an update on the next pull for this record.'))
->setRevisionable(FALSE);
// @see ContentEntityBase::baseFieldDefinitions
// and RevisionLogEntityTrait::revisionLogBaseFieldDefinitions
$fields += parent::baseFieldDefinitions($entity_type);
......@@ -544,7 +542,7 @@ class MappedObject extends RevisionableContentEntityBase implements MappedObject
->set('entity_updated', $this->getRequestTime())
->set('last_sync_action', 'pull')
->set('last_sync_status', TRUE)
// ->set('last_sync_message', '')
->set('force_pull', 0)
->save();
return $this;
......@@ -560,24 +558,4 @@ class MappedObject extends RevisionableContentEntityBase implements MappedObject
return \Drupal::time()->getRequestTime();
}
/**
* Set the force entity update flag to desired state.
*
* @param bool $state
* TRUE or FALSE.
*/
public function setForceUpdate(bool $state) {
$this->force_update = $state;
}
/**
* Return the state of the force update flag.
*
* @return bool
* TRUE or FALSE.
*/
public function forceUpdate() {
return $this->force_update;
}
}
......@@ -388,6 +388,9 @@ abstract class SalesforceMappingFormCrudBase extends SalesforceMappingFormBase {
*/
public function lastPullReset(array $form, FormStateInterface $form_state) {
$mapping = $this->entity->setLastPullTime(NULL);
$this->entityTypeManager
->getStorage('salesforce_mapped_object')
->setForcePull($mapping);
}
/**
......
......@@ -8,6 +8,7 @@ use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\salesforce\SFID;
use Drupal\salesforce_mapping\Entity\SalesforceMappingInterface;
use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Entity\EntityTypeInterface;
......@@ -94,4 +95,20 @@ class MappedObjectStorage extends SqlContentEntityStorage {
]);
}
/**
* Set the "force_pull" column to TRUE for all mapped objects of the given
* mapping
*
* @param SalesforceMappingInterface $mapping
*
* @return $this
*/
public function setForcePull(SalesforceMappingInterface $mapping) {
$query = $this->database->update($this->baseTable)
->condition('salesforce_mapping', $mapping->id())
->fields(array('force_pull' => 1))
->execute();
return $this;
}
}
......@@ -99,9 +99,13 @@ class DeleteHandler {
? $pull_info[$type]['last_delete_timestamp']
: strtotime('-29 days');
$now = time();
// getDeleted() restraint: startDate must be at least one minute
// getDeleted() constraint: startDate must be at least one minute
// greater than endDate.
$now = $now > $last_delete_sync + 60 ? $now : $now + 60;
// getDeleted() constraint: startDate cannot be more than 30 days ago.
if ($last_delete_sync < strtotime('-29 days')) {
$last_delete_sync = strtotime('-29 days');
}
$last_delete_sync_sf = gmdate('Y-m-d\TH:i:s\Z', $last_delete_sync);
$now_sf = gmdate('Y-m-d\TH:i:s\Z', $now);
$deleted = $this->sfapi->getDeleted($type, $last_delete_sync_sf, $now_sf);
......
......@@ -187,9 +187,7 @@ abstract class PullBase extends QueueWorkerBase implements ContainerFactoryPlugi
new SalesforcePullEvent($mapped_object, MappingConstants::SALESFORCE_MAPPING_SYNC_SF_UPDATE)
);
// By default $mapped_object->forceUpdate() is FALSE. To force true, call
// $mapped_object->setForceUpdate() in the prepull event hook above.
if ($sf_record_updated > $entity_updated || $mapped_object->forceUpdate()) {
if ($sf_record_updated > $entity_updated || $mapped_object->force_pull) {
// Set fields values on the Drupal entity.
$mapped_object->pull();
$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()]));
......
......@@ -87,11 +87,12 @@ class QueueHandler {
public function getUpdatedRecords() {
// Avoid overloading the processing queue and pass this time around if it's
// over a configurable limit.
if ($this->queue->numberOfItems() > $this->config->get('pull_max_queue_size', self::PULL_MAX_QUEUE_SIZE)) {
$max_size = $this->config->get('pull_max_queue_size', static::PULL_MAX_QUEUE_SIZE);
if ($max_size && $this->queue->numberOfItems() > $max_size) {
$message = 'Pull Queue contains %noi items, exceeding the max size of %max items. Pull processing will be blocked until the number of items in the queue is reduced to below the max size.';
$args = [
'%noi' => $this->queue->numberOfItems(),
'%max' => $this->config->get('pull_max_queue_size', self::PULL_MAX_QUEUE_SIZE),
'%max' => $max_size,
];
$this->eventDispatcher->dispatch(SalesforceEvents::NOTICE, new SalesforceNoticeEvent(NULL, $message, $args));
return FALSE;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment