You are here

function cmis_sync_nodeapi in CMIS API 6

Same name and namespace in other branches
  1. 6.4 cmis_sync/cmis_sync.module \cmis_sync_nodeapi()
  2. 6.2 cmis_sync/cmis_sync.module \cmis_sync_nodeapi()
  3. 6.3 cmis_sync/cmis_sync.module \cmis_sync_nodeapi()

Implementation of hook_nodeapi

File

cmis_sync/cmis_sync.module, line 6

Code

function cmis_sync_nodeapi(&$node, $op, $teaser, $page) {
  if ($node->cmis_objectId) {
    return;
  }
  module_load_include('api.inc', 'cmis');
  switch ($op) {
    case 'insert':
      $cmis_sync_root_folder = variable_get("cmis_sync_root_folder", null);
      if (empty($cmis_sync_root_folder)) {
        watchdog(WATCHDOG_ERROR, '"cmis_sync_root_folder" not set');
        drupal_set_message(t('"cmis_sync_root_folder" not set. Synconization with CMIS repository will not work as espected.'), 'error');
        return false;
      }
      $repository = cmisapi_getRepositoryInfo();
      $folderId = cmisapi_getProperties($repository->repositoryId, drupal_urlencode($cmis_sync_root_folder));
      $objectId = cmisapi_createDocument($repository->repositoryId, 'document', array(
        'content-type' => 'text/html',
        'title' => $node->title,
      ), $folderId->id, $node->body);
      db_query('INSERT INTO {cmis_sync_node} (nid, cmis_objectId, changed_timestamp) VALUES (%d, \'%s\', %d)', $node->nid, $objectId, $_SERVER['REQUEST_TIME']);
      break;
    case 'update':
      if ($cmis_node_sync = db_fetch_object(db_query('SELECT cmis_objectId FROM {cmis_sync_node} WHERE nid = %d', $node->nid))) {
        $repository = cmisapi_getRepositoryInfo();
        cmisapi_setContentStream($repository->repositoryId, $cmis_node_sync->cmis_objectId, True, $node->body, array(
          'content-type' => 'text/html',
          'title' => $node->title,
        ));
        db_query('UPDATE {cmis_sync_node} SET changed_timestamp=%d WHERE nid = %d', $_SERVER['REQUEST_TIME'], $node->nid);
      }
      break;
  }
}