You are here

function content_lock_node in Content locking (anti-concurrent editing) 6

Same name and namespace in other branches
  1. 6.2 content_lock.module \content_lock_node()
  2. 7 content_lock.module \content_lock_node()
  3. 7.2 content_lock.module \content_lock_node()

Try to lock a document for editing.

Parameters

$nid: A node id.

$uid: The user id to lock the node for.

Return value

FALSE, if a document has already been locked by someone else.

2 calls to content_lock_node()
content_lock_form_alter in ./content_lock.module
Implementation of hook_form_alter().
content_lock_nodeapi in ./content_lock.module
Implementation of hook_nodeapi().

File

./content_lock.module, line 372
Allows users to lock documents for modification.

Code

function content_lock_node($nid, $uid) {
  $lock = content_lock_fetch_lock($nid);
  if ($lock != FALSE && $lock->uid != $uid) {
    if (user_access('administer checked out documents')) {
      $message = content_lock_lock_owner($lock);
      $url = "admin/content/node/content_lock/release/{$nid}";
    }
    if (isset($url)) {
      $message .= '<br />' . t('Click <a href="!release-url">here</a> to check back in now.', array(
        '!release-url' => url($url, array(
          'query' => 'destination=' . $_GET['q'],
        )),
      ));
    }
    if (!empty($message)) {
      drupal_set_message($message, 'error');
    }
    return FALSE;
  }
  else {

    // no lock yet, create one
    if ($lock == false) {

      // Lock node.
      $data = array(
        'nid' => $nid,
        'uid' => $uid,
        'timestamp' => time(),
      );
      drupal_write_record('content_lock', $data);
    }
    if (_content_lock_verbose()) {
      drupal_set_message(t('This document is now locked against simultaneous editing. It will unlock when you navigate elsewhere.'));
    }
    module_invoke_all('content_lock_locked', $nid, $uid);
  }
  return TRUE;
}