You are here

function nodeblock_update_7101 in Nodeblock 7

Remove variable settings for nodes where blocks are not enabled.

File

./nodeblock.install, line 88
Define module install logic.

Code

function nodeblock_update_7101() {
  $variables = variable_initialize();
  foreach ($variables as $name => $value) {
    if (strpos($name, 'nodeblock') !== FALSE) {
      if (strpos($name, 'nodeblock_block_') !== FALSE) {
        $blocks[str_replace('nodeblock_block_', '', $name)] = $name;
      }
      elseif (strpos($name, 'nodeblock_comment_link_') === FALSE && strpos($name, 'nodeblock_node_link_') === FALSE && strpos($name, 'nodeblock_view_mode_') === FALSE) {
        if ((bool) $value) {
          $content_types[] = str_replace('nodeblock_', '', $name);
        }
      }
    }
  }
  if (!empty($content_types) && !empty($blocks)) {
    $query = db_select('node', 'n')
      ->fields('n', array(
      'nid',
    ))
      ->condition('n.type', $content_types);
    $result = $query
      ->execute()
      ->fetchAll();
    if (!empty($result)) {
      foreach ($result as $value) {
        $nids[$value->nid] = $value->nid;
      }
      if (!empty($nids)) {
        $blocks = array_diff_key($blocks, $nids);
        if (!empty($blocks)) {
          foreach ($blocks as $name) {
            variable_del($name);
          }
        }
      }
    }
  }
}