You are here

protected function NodeSaveHandler::beforeSync in Services Client 7.2

Before sync event.

Overrides EventHandler::beforeSync

File

include/event.inc, line 1211

Class

NodeSaveHandler
Adds extra logic for saving remote nodes.

Code

protected function beforeSync($object) {
  if (empty($object->type) && !empty($this->config['node_type'])) {
    $object->type = $this->config['node_type'];
  }

  // Load uid from remote source
  if ($this->config['node_author'] == 'load_remote') {
    try {
      if (!empty($this
        ->getEntity()->uid)) {
        $remote_uid = $this
          ->getRemoteUserId($this
          ->getEntity()->uid);
        $object->uid = $remote_uid !== NULL ? $remote_uid : $this->config['node_author_load_remote'];
      }
    } catch (ServicesClientConnectionResponseException $e) {
      $e
        ->log();
      $object->uid = $this->config['node_author_load_remote'];
    }
  }
  elseif ($this->config['node_author'] == 'value' && !empty($this->config['node_author_value'])) {
    $object->uid = $this->config['node_author_value'];
  }
}