You are here

function _cmis_browser_actions_content_create in CMIS API 6.2

Same name and namespace in other branches
  1. 6.4 cmis_browser/cmis_browser.content_create.inc \_cmis_browser_actions_content_create()
  2. 6.3 cmis_browser/cmis_browser.content_create.inc \_cmis_browser_actions_content_create()
  3. 7.2 cmis_browser/cmis_browser.content_create.inc \_cmis_browser_actions_content_create()
  4. 7 cmis_browser/cmis_browser.content_create.inc \_cmis_browser_actions_content_create()

Create $content_name under $parent_folder folder.

1 call to _cmis_browser_actions_content_create()
cmis_browser_actions_form_submit in cmis_browser/cmis_browser.module
Implementation of hook_form_submit().

File

cmis_browser/cmis_browser.content_create.inc, line 40

Code

function _cmis_browser_actions_content_create($folder_id, $document_name, $document_content, $document_mimetype = 'text/html') {
  module_load_include('api.inc', 'cmis');
  try {
    $repository = cmisapi_getRepositoryInfo();
  } catch (CMISException $e) {
    cmis_error_handler('_cmis_browser_actions_content_create', $e);
    return;
  }
  try {
    $folder = cmisapi_getProperties($repository->repositoryId, $folder_id);
  } catch (CMISException $e) {
    cmis_error_handler('_cmis_browser_actions_content_create', $e);
    form_set_error('path', t('Error while trying to lookup @object_id', array(
      '@object_id' => $folder_id,
    )));
    return;
  }
  if ($folder->type == 'folder') {
    try {
      $document_id = cmisapi_createDocument($repository->repositoryId, 'document', array(
        'content-type' => $document_mimetype,
        'title' => $document_name,
      ), $folder->id, $document_content);
      drupal_set_message(t('CMIS object @object_name has been created.', array(
        '@object_name' => $document_name,
      )));
    } catch (CMISException $e) {
      cmis_error_handler('_cmis_browser_actions_content_create', $e);
      form_set_error('path', t('Unable to create @object_name object.', array(
        '@object_name' => $document_name,
      )));
      return '';
    }
  }
  else {
    form_set_error('path', t('Error when locating the target space @object_id', array(
      '@object_id' => $folder_id,
    )));
    return FALSE;
  }
}