You are here

protected function EntityPublisher::haveToSave in Content Synchronizer 8.2

Same name and namespace in other branches
  1. 8 src/Service/EntityPublisher.php \Drupal\content_synchronizer\Service\EntityPublisher::haveToSave()
  2. 3.x src/Service/EntityPublisher.php \Drupal\content_synchronizer\Service\EntityPublisher::haveToSave()

Return TRUE if the entity has to be updated.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The imported entity.

\Drupal\Core\Entity\EntityInterface $existingEntity: The entity before update.

Return value

bool The state of update.

2 calls to EntityPublisher::haveToSave()
EntityPublisher::defaultSave in src/Service/EntityPublisher.php
Save without publish status care.
EntityPublisher::saveEntityWithRevision in src/Service/EntityPublisher.php
Try to create a revision of the entity.

File

src/Service/EntityPublisher.php, line 144

Class

EntityPublisher
THe entity publsher service.

Namespace

Drupal\content_synchronizer\Service

Code

protected function haveToSave(EntityInterface $entity, EntityInterface $existingEntity = NULL) {
  $haveToSave = TRUE;

  // Update :
  if ($entity
    ->id()) {
    switch (ImportProcessor::getCurrentImportProcessor()
      ->getUpdateType()) {
      case ImportProcessor::UPDATE_IF_RECENT:
        if ($existingEntity) {
          if (method_exists($entity, 'getChangedTime')) {
            $haveToSave = $entity
              ->getChangedTime() > $existingEntity
              ->getChangedTime();
          }
          else {
            $haveToSave = TRUE;
          }
        }
        else {
          $haveToSave = TRUE;
        }
        break;
      case ImportProcessor::UPDATE_NO_UPDATE:
        $haveToSave = FALSE;
        break;
      case ImportProcessor::UPDATE_SYSTEMATIC:
      default:
        $haveToSave = TRUE;
    }
  }
  return $haveToSave;
}