function _cmis_sync_drupal_cmis_update in CMIS API 6.3
Same name and namespace in other branches
- 6.4 cmis_sync/cmis_sync.drupal.inc \_cmis_sync_drupal_cmis_update()
- 7.2 cmis_sync/cmis_sync.drupal.inc \_cmis_sync_drupal_cmis_update()
- 7 cmis_sync/cmis_sync.drupal.inc \_cmis_sync_drupal_cmis_update()
Handles Drupal to CMIS updates.
1 call to _cmis_sync_drupal_cmis_update()
- cmis_sync_nodeapi in cmis_sync/
cmis_sync.module - Implementation of hook_nodeapi() for CMIS sync module.
File
- cmis_sync/
cmis_sync.drupal.inc, line 6
Code
function _cmis_sync_drupal_cmis_update($context = array()) {
if (isset($context['node']) && isset($context['op'])) {
$node = $context['node'];
$op = $context['op'];
if (in_array($op, array(
'insert',
'update',
'delete',
))) {
module_load_include('api.inc', 'cmis');
$cmis_object = _cmis_sync_drupal_cmis_prepare($node);
if ($cmis_object && !isset($node->cmis_sync_disabled)) {
switch ($op) {
// node created
case 'insert':
try {
$new_cmis_object = cmisapi_createDocument($cmis_object->repositoryId, $cmis_object->folderId, $cmis_object->name, $cmis_object->properties, $cmis_object->content, $cmis_object->contentStreamMimeType);
} catch (CMISException $e) {
cmis_error_handler('cmis_sync_nodeapi', $e);
return;
}
// saving CMIS reference id in {cmis_sync_node} table
db_query('INSERT INTO {cmis_sync_node} (nid, cmis_repositoryId, cmis_objectId, changed_timestamp) VALUES (%d, \'%s\', \'%s\', %d)', $node->nid, $cmis_object->repositoryId, $new_cmis_object->id, $_SERVER['REQUEST_TIME']);
break;
// node updated
case 'update':
// send updates only if the current node has a CMIS reference id.
if ($cmis_objectId = db_result(db_query('SELECT cmis_objectId FROM {cmis_sync_node} WHERE nid = %d', $node->nid))) {
try {
// updating CMIS reference object content stream
if ($cmis_object->content) {
cmisapi_setContentStream($cmis_object->repositoryId, $cmis_objectId, $cmis_object->content, $cmis_object->contentStreamMimeType);
}
// updating CMIS properties
cmisapi_updateProperties($cmis_object->repositoryId, $cmis_objectId, $cmis_object->properties);
// update changed timestamp
db_query('UPDATE {cmis_sync_node} SET changed_timestamp=%d WHERE nid = %d', $_SERVER['REQUEST_TIME'], $node->nid);
} catch (CMISException $e) {
cmis_error_handler('cmis_sync_nodeapi', $e);
return;
}
}
break;
// node delete
case 'delete':
if ($cmis_object->sync_deletes && ($cmis_objectId = db_result(db_query('SELECT cmis_objectId FROM {cmis_sync_node} WHERE nid = %d', $node->nid)))) {
try {
// delete CMIS reference object content
$cmis_object_properties = cmisapi_getProperties($cmis_object->repositoryId, $cmis_objectId);
cmisapi_deleteObject($cmis_object->repositoryId, $cmis_object_properties->id);
// delete sync refs
db_query('DELETE FROM {cmis_sync_node} WHERE nid = %d', $node->nid);
} catch (CMISException $e) {
cmis_error_handler('cmis_sync_nodeapi', $e);
return;
}
}
break;
}
}
}
}
}