You are here

function nodeblock_update_7103 in Nodeblock 7

Add new block title column in db.

File

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

Code

function nodeblock_update_7103() {
  module_load_include('module', 'nodeblock');
  if (!db_field_exists('nodeblock', 'block_title')) {
    db_add_field('nodeblock', 'block_title', array(
      'description' => 'The block title for a block.',
      'type' => 'varchar',
      'length' => 255,
      'not null' => TRUE,
      'default' => '',
    ));
  }
  $types = node_type_get_types();
  $enabled_types = array();
  foreach ($types as $type_name => $type) {
    if (nodeblock_type_enabled($type_name)) {
      $enabled_types[] = $type_name;
    }
  }
  if (count($enabled_types)) {
    $results = db_select('node', 'n')
      ->fields('n', array(
      'nid',
      'title',
    ))
      ->condition('type', $enabled_types)
      ->execute();
    foreach ($results as $node) {
      db_update('nodeblock')
        ->fields(array(
        'block_title' => $node->title,
      ))
        ->condition('nid', $node->nid)
        ->execute();
    }
  }
}