You are here

function boost_expire_node in Boost 6

Expires a node from the cache; including related pages.

Expires front page if promoted, taxonomy terms,

Parameters

$node: node object

$nid: node id

$debug: TRUE to return values without expiring anything.

Return value

TRUE if no debug, array($data, $paths) if debug turned on.

5 calls to boost_expire_node()
boost_block in ./boost.module
Implementation of hook_block().
boost_comment in ./boost.module
Implementation of hook_comment(). Acts on comment modification.
boost_nodeapi in ./boost.module
Implementation of hook_nodeapi(). Acts on nodes defined by other modules.
boost_votingapi_delete in ./boost.module
Implementation of hook_votingapi_delete().
boost_votingapi_insert in ./boost.module
Implementation of hook_votingapi_insert().
1 string reference to 'boost_expire_node'
boost.module in ./boost.module
Provides static file caching for Drupal text output. Pages, Feeds, ect...

File

./boost.module, line 1706
Provides static file caching for Drupal text output. Pages, Feeds, ect...

Code

function boost_expire_node($node, $nid = 0, $debug = FALSE) {
  global $_boost;
  $data = array();
  $paths = array();

  // Check node object
  if (empty($node->nid)) {
    if (is_numeric($nid)) {
      $node->nid = $nid;
    }
    else {
      return FALSE;
    }
  }

  // Expire this node
  if (BOOST_NO_DATABASE) {
    $paths['node'] = 'node/' . $node->nid;
  }
  else {
    $data['node'] = array(
      'page_callback' => 'node',
      'page_id' => $node->nid,
    );
  }

  // If promoted to front page, expire front page
  if (BOOST_FLUSH_FRONT && $node->promote == 1) {
    $paths['front'] = '<front>';
  }

  // Get taxonomy terms and flush
  if (module_exists('taxonomy') && BOOST_FLUSH_NODE_TERMS) {

    // Get old terms from DB
    $tids = boost_taxonomy_node_get_tids($node->nid);

    // Get new terms from node object
    if (!empty($node->taxonomy)) {
      foreach ($node->taxonomy as $vocab) {
        if (is_array($vocab)) {
          foreach ($vocab as $term) {
            $tids[$term] = $term;
          }
        }
      }
    }

    // See if the taxonony/term/% path is a view containing domain access restrictions
    if (module_exists('domain') && module_exists('views')) {
      $list = boost_views_get_valid_list();
      foreach ($list as $hash => $enabled) {
        $info = explode(' - ', $hash);
        if ($info[2] == '/taxonomy/term/%') {

          // Load View
          $view = views_get_view($info[0], TRUE);
          if (!is_object($view)) {
            continue;
          }

          // Check for domain access filter "Available on current domain"
          $filters = $view
            ->get_items('filter', $info[1]);

          // Free memory
          $view
            ->destroy();
          unset($view);
          if (isset($filters['current_all']) || isset($filters['gid']) || isset($filters['domain_id'])) {
            $fake_node = $node;
          }
          else {
            foreach (domain_domains() as $key => $value) {
              $domains[$key] = $key;
            }
            $fake_node = new stdClass();
            $fake_node->domains = $domains;
          }
          break;
        }
      }
    }
    if (!isset($fake_node)) {
      $fake_node = $node;
    }

    // Get list of base urls for this node
    $base_dirs = array();
    foreach (boost_get_base_urls($fake_node) as $domain_id) {
      foreach ($domain_id as $base) {
        $parts = parse_url($base);
        $base_dirs[] = boost_cache_directory($parts['host'], FALSE);
      }
    }
    unset($fake_node);

    // Set each tid in the data array
    foreach ($tids as $tid) {
      if (is_numeric($tid)) {
        if (BOOST_NO_DATABASE) {
          $term = taxonomy_get_term($tid);
          $paths['term' . $tid] = taxonomy_term_path($term);
        }
        else {
          foreach ($base_dirs as $base_dir) {
            $data['term:' . $tid . ' base:' . $base_dir] = array(
              'page_callback' => 'taxonomy',
              'page_id' => $tid,
              'base_dir' => $base_dir,
            );
          }
        }
      }
    }

    // Save all term IDs into the global scope
    $_boost['nid-' . $node->nid]['tids'] = $tids;
  }

  // Get menu and flush related items in the menu.
  if (BOOST_FLUSH_MENU_ITEMS != 0) {
    if (!isset($node->menu['menu_name'])) {
      menu_nodeapi($node, 'prepare');
    }
    $menu = menu_tree_all_data($node->menu['menu_name']);
    $tempa = NULL;
    $tempb = NULL;
    if (BOOST_FLUSH_MENU_ITEMS == 1) {
      $links = boost_get_menu_structure($menu, FALSE, 'node/' . $node->nid, NULL, $tempa, $tempb);
    }
    elseif (BOOST_FLUSH_MENU_ITEMS == 2) {
      $links = boost_get_menu_structure($menu, NULL, NULL, NULL, $tempa, $tempb);
    }
    unset($tempa);
    unset($tempb);
    $paths = array_merge($links, $paths);
  }

  // Get CCK References and flush.
  if (BOOST_FLUSH_CCK_REFERENCES && module_exists('nodereference')) {
    $nids = array();
    $type = content_types($node->type);
    if ($type) {
      foreach ($type['fields'] as $field) {

        // Add referenced nodes to nids. This will clean up nodereferrer fields
        // when the referencing node is updated.
        if ($field['type'] == 'nodereference') {
          $node_field = isset($node->{$field}['field_name']) ? $node->{$field}['field_name'] : array();
          foreach ($node_field as $delta => $item) {
            $nids[$item['nid']] = $item['nid'];
          }
        }
      }
      foreach ($nids as $nid) {
        if (is_numeric($nid)) {
          if (BOOST_NO_DATABASE) {
            $paths['reference' . $nid] = 'node/' . $nid;
          }
          else {
            $data['reference' . $nid] = array(
              'page_callback' => 'node',
              'page_id' => $nid,
            );
          }
        }
      }
    }

    // Get CCK references pointing to this node and flush.
    if (module_exists('nodereferrer')) {
      $nids = nodereferrer_referrers($node->nid);
      foreach ($nids as $nid) {
        if (is_numeric($nid['nid'])) {
          if (BOOST_NO_DATABASE) {
            $paths['referrer' . $nid['nid']] = 'node/' . $nid['nid'];
          }
          else {
            $data['referrer' . $nid['nid']] = array(
              'page_callback' => 'node',
              'page_id' => $nid['nid'],
            );
          }
        }
      }
    }
  }

  // Get views containing this node and flush.
  if (BOOST_FLUSH_VIEWS && module_exists('views')) {
    $router_item = _boost_get_menu_router();
    $relationship = array();
    $relationship[] = array(
      'page_callback' => 'node',
      'page_type' => $node->type,
      'page_id' => $node->nid,
    );
    $relationships = boost_cache_get_node_relationships($relationship);
    $data = array_merge($data, $relationships);
  }

  // Flush the cache
  $flushed = 0;
  if (!$debug) {
    if (!empty($data)) {
      $flushed += boost_cache_expire_router($data);
    }
    if (!empty($paths)) {
      $flushed += boost_cache_expire_derivative($paths, TRUE);
    }
    if (BOOST_VERBOSE >= 7 && isset($_boost['verbose_option_selected']['boost_expire_node'])) {
      watchdog('boost', 'Debug: boost_expire_node() <br />Node !nid was flushed resulting in !flushed pages being expired from the cache <br />data: !data <br />paths: !paths', array(
        '!nid' => $node->nid,
        '!flushed' => $flushed,
        '!data' => boost_print_r($data, TRUE, TRUE),
        '!paths' => boost_print_r($paths, TRUE, TRUE),
      ));
    }
    return $flushed;
  }
  else {
    return array(
      'router-in' => $data,
      'router-results' => boost_cache_expire_router($data, FALSE, FALSE, TRUE),
      'paths-in' => $paths,
      'path-results' => boost_cache_expire_derivative($paths, FALSE, FALSE, TRUE),
    );
  }
}