You are here

function _cmis_sync_cmis_drupal_handle_updates in CMIS API 6.3

Same name and namespace in other branches
  1. 6.4 cmis_sync/cmis_sync.cmis.inc \_cmis_sync_cmis_drupal_handle_updates()
  2. 7.2 cmis_sync/cmis_sync.cmis.inc \_cmis_sync_cmis_drupal_handle_updates()
  3. 7 cmis_sync/cmis_sync.cmis.inc \_cmis_sync_cmis_drupal_handle_updates()

Creates/updates Drupal nodes with CMIS content.

Parameters

$repository:

$sync_map_type:

$node_type:

1 call to _cmis_sync_cmis_drupal_handle_updates()
_cmis_sync_cmis_drupal_update in cmis_sync/cmis_sync.cmis.inc
Handles CMIS to Drupal updates.

File

cmis_sync/cmis_sync.cmis.inc, line 67

Code

function _cmis_sync_cmis_drupal_handle_updates($repository, $sync_map_type, $node_type) {

  // get CMIS object properties
  if (isset($sync_map_type['cmis_folderId'])) {
    $cmis_folder = cmisapi_getProperties($cmis_repository->repositoryId, $sync_map_type['cmis_folderId']);
  }
  elseif (isset($sync_map_type['cmis_folderPath'])) {
    $cmis_folder = cmisapi_getObjectByPath($cmis_repository->repositoryId, $sync_map_type['cmis_folderPath']);
  }
  else {
    throw new CMISException(t("Please set `cmis_folderPath` or `cmis_folderId` properties for [@type] Drupal type.", array(
      '@type' => $node_type,
    )));
  }

  // select updated objects
  $sync_subfolders_rule = $sync_map_type['subfolders'] ? 'IN_TREE' : 'IN_FOLDER';
  $sync_full_rule = $sync_map_type['full_sync_next_cron'] ? '' : sprintf('AND cmis:lastModificationDate > \'%s\'', date_create('12 hour ago')
    ->format('Y-m-d\\TH:i:s.000-00:00'));

  // grab last updates
  $cmis_query = sprintf('SELECT * FROM %s WHERE %s(\'%s\') %s', $sync_map_type['cmis_type'], $sync_subfolders_rule, $cmis_folder->id, $sync_full_rule);
  $cmis_updates = cmisapi_query($repository->repositoryId, $cmis_query);
  foreach ($cmis_updates->objectList as $cmis_update) {

    // build/lookup Drupal node
    $drupal_node = _cmis_sync_cmis_drupal_prepare($repository, $sync_map_type, $node_type, $cmis_update);

    // unable to map current CMIS object to any Drupal content type
    if (FALSE === $drupal_node) {
      continue;
    }

    // mark the Drupal node in order to bypass nodeapi cmis_sync hook
    $drupal_node->cmis_sync_disabled = TRUE;

    // save Drupal node
    node_save($drupal_node);

    // update/insert changed timestamp
    if (db_fetch_object(db_query('SELECT nid FROM {cmis_sync_node} WHERE cmis_objectId = \'%s\'', $cmis_update->id))) {
      db_query('UPDATE {cmis_sync_node} SET changed_timestamp=%d, nid=%d WHERE cmis_objectId = \'%s\'', $_SERVER['REQUEST_TIME'], $drupal_node->nid, $cmis_update->id);
      watchdog('cmis_sync_cron', 'Updated nid @nid', array(
        '@nid' => $drupal_node->nid,
      ));
    }
    else {
      db_query('INSERT INTO {cmis_sync_node} (nid, cmis_repositoryId, cmis_objectId, changed_timestamp) VALUES (%d, \'%s\', \'%s\', %d)', $drupal_node->nid, $repository->repositoryId, $cmis_update->id, $_SERVER['REQUEST_TIME']);
      watchdog('cmis_sync_cron', 'Added nid @nid', array(
        '@nid' => $drupal_node->nid,
      ));
    }
  }
}