You are here

function _cmis_sync_cmis_to_drupal_handle_updates in CMIS API 6.2

Creates/updates Drupal nodes with CMIS content.

Parameters

$repository:

$sync_map_type:

$node_type:

1 call to _cmis_sync_cmis_to_drupal_handle_updates()
cmis_sync_cron in cmis_sync/cmis_sync.module
Implementation of hook_cron

File

cmis_sync/cmis_sync.module, line 316

Code

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

  // Get CMIS object properties
  $cmis_folder = cmisapi_getProperties($repository->repositoryId, drupal_urlencode($sync_map_type['cmis_root']));

  // 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 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->respositoryId, $cmis_query);
  foreach ($cmis_updates as $cmis_update) {

    // Build/lookup Drupal node
    $drupal_node = _cmis_sync_cmis_to_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_objectId, changed_timestamp) VALUES (%d, \'%s\', %d)', $drupal_node->nid, $cmis_update->id, $_SERVER['REQUEST_TIME']);
      watchdog('cmis_sync_cron', 'Added nid @nid', array(
        '@nid' => $drupal_node->nid,
      ));
    }
  }
}