You are here

function _node_expire_node_update_insert in Node expire 8

Same name and namespace in other branches
  1. 7 node_expire.nodeapi.inc \_node_expire_node_update_insert()

Implements hook_node_update() and hook_node_insert().

2 calls to _node_expire_node_update_insert()
node_expire_node_insert in ./node_expire.module
Implements hook_nodeapi_insert().
node_expire_node_update in ./node_expire.module
Implements hook_nodeapi_update().

File

./node_expire.nodeapi.inc, line 103
Node API integration.

Code

function _node_expire_node_update_insert(&$ntype, \Drupal\node\NodeInterface $node) {
  $handle_content_expiry = \Drupal::config('node_expire.settings')
    ->get('node_expire_handle_content_expiry');
  if ($handle_content_expiry == 0) {

    // Old (legacy) style of processing.
    // Has the expiration been removed, or does it exist?
    if (isset($node->expire)) {
      db_delete('node_expire')
        ->condition('nid', $node
        ->id())
        ->execute();

      // Should we create a new record?
      if ($node->expire) {
        if (strtotime($node->expire)) {
          $node->expire = strtotime($node->expire);
        }
        $node->expired = FALSE;
        \Drupal::database()
          ->insert('node_expire')
          ->fields($node)
          ->execute();
      }
    }
  }
  else {
    if (!isset($ntype['enabled']) || !$ntype['enabled']) {
      return;
    }

    // Create a proper $node_expire stdClass.
    $node_expire = new stdClass();
    $node_expire->nid = $node
      ->id();

    // For compatibility with Node Clone module.
    // Set default $node->expire value if it is not set.
    if (!isset($node->expire)) {
      _node_expire_node_prepare($ntype, $node);
    }

    // Expire.
    $date_expire = _node_expire_date_str_to_db($node->expire, $ntype);
    $node_expire->expire = $date_expire;

    // Lastnotify.
    if (isset($node->lastnotify)) {
      $node_expire->lastnotify = $node->lastnotify;
    }
    else {

      // Default value.
      $node_expire->lastnotify = 0;
    }

    // Expired.
    if (isset($node->expired)) {
      $node_expire->new_record = 0;
      $node_expire->expired = $node->expired;
      if ($node_expire->expire >= NODE_EXPIRE_NO_EXPIRE) {

        // No expiry for this node.
        $node_expire->expired = 0;
      }
    }
    elseif (isset($node->original->expired)) {

      // For VBO (Views Bulk Operations) compatibility.
      // With VBO it is necessary to get all Node expire information
      // from $node->original instead of $node.
      $node_expire->new_record = 0;
      $node_expire->expired = $node->original->expired;

      // Also get other Node expire values.
      // Expire.
      $date_expire = _node_expire_date_str_to_db($node->original->expire, $ntype);
      $node_expire->expire = $date_expire;

      // Lastnotify.
      if (isset($node->original->lastnotify)) {
        $node_expire->lastnotify = $node->original->lastnotify;
      }
      else {

        // Default value.
        $node_expire->lastnotify = 0;
      }
      if ($node_expire->expire >= NODE_EXPIRE_NO_EXPIRE) {

        // No expiry for this node.
        $node_expire->expired = 0;
      }
    }
    else {

      // No record in the database yet.
      $node_expire->new_record = 1;

      // Default value.
      $node_expire->expired = 0;
    }

    // Write the record.
    _node_expire_write_record($node_expire, $node
      ->id());
  }
}