You are here

function _cmis_sync_cmis_drupal_update in CMIS API 7

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

Handles CMIS to Drupal updates.

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

File

cmis_sync/cmis_sync.cmis.inc, line 7

Code

function _cmis_sync_cmis_drupal_update($context = array()) {
  module_load_include('api.inc', 'cmis');
  module_load_include('inc', 'node', 'node.pages');
  $sync_map = variable_get('cmis_sync_map', array());
  $sync_map_changed = FALSE;
  foreach ($sync_map as $node_type => $sync_map_type) {

    // check if sync is enabled for this Drupal content type
    if (!array_key_exists('enabled', $sync_map_type) || !$sync_map_type['enabled']) {
      continue;
    }

    // merge in defaults
    $sync_map_type += array(
      'fields' => array(),
      'content_field' => 'body',
      'cmis_type' => 'cmis:document',
      'cmis_repositoryId' => 'default',
      'subfolders' => FALSE,
      'deletes' => FALSE,
      'full_sync_next_cron' => FALSE,
    );
    try {

      // lookup CMIS repository
      $repository = cmis_get_repository($sync_map_type['cmis_repositoryId']);

      // handle CMIS updates
      _cmis_sync_cmis_drupal_handle_updates($repository, $sync_map_type, $node_type);

      // handle CMIS deletes
      if ($sync_map_type['deletes']) {
        _cmis_sync_cmis_drupal_handle_deletes($repository, $sync_map_type, $node_type);
      }

      // update CMIS sync setting
      if ($sync_map_type['full_sync_next_cron']) {
        $sync_map[$node_type]['full_sync_next_cron'] = 0;
        $sync_map_changed = TRUE;
      }
    } catch (CMISException $e) {
      cmis_error_handler('cmis_sync_cron', $e);
    }
  }

  // save CMIS sync settings
  if ($sync_map_changed) {
    variable_set('cmis_sync_map', $sync_map);
  }
}