| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- <?php
- /**
- * Implements hook_schema().
- */
- function nodeblock_schema() {
- $schema['nodeblock'] = array(
- 'description' => 'The base table for nodeblock.module.',
- 'fields' => array(
- 'nid' => array(
- 'description' => 'The primary identifier for a node.',
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- ),
- 'enabled' => array(
- 'description' => 'A flag indicating whether a block should be created.',
- 'type' => 'int',
- 'size' => 'tiny',
- 'not null' => TRUE,
- 'default' => 1,
- ),
- 'machine_name' => array(
- 'description' => 'The machine name for a block.',
- 'type' => 'varchar',
- 'length' => 32,
- 'not null' => TRUE,
- ),
- 'block_title' => array(
- 'description' => 'The block title for a block.',
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- 'default' => '',
- ),
- 'view_mode' => array(
- 'description' => 'The view mode used to render the node.',
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- ),
- 'node_link' => array(
- 'description' => 'Whether the node links should be shown.',
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- 'default' => '0',
- ),
- 'comment_link' => array(
- 'description' => 'Whether the comment links should be shown.',
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- 'default' => '0',
- ),
- 'translation_fallback' => array(
- 'description' => 'A flag indicating whether the translation fallback is enabled.',
- 'type' => 'int',
- 'size' => 'tiny',
- 'not null' => TRUE,
- 'default' => 0,
- ),
- ),
- 'primary key' => array('nid'),
- 'unique keys' => array(
- 'machine_name' => array('machine_name'),
- ),
- );
- return $schema;
- }
- /**
- * Placeholder for potential Drupal 6 upgrade path
- */
- function nodeblock_update_7100() {
- }
- /**
- * Remove variable settings for nodes where blocks are not enabled.
- */
- 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;
- }
- else if(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);
- }
- }
- }
- }
- }
- }
- /**
- * Adding a new nodeblock table and create entries for all existing nodeblocks.
- */
- function nodeblock_update_7102() {
- module_load_include('module', 'nodeblock');
- if (!db_table_exists('nodeblock')) {
- $schema = nodeblock_schema();
- db_create_table('nodeblock', $schema['nodeblock']);
- $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'))
- ->condition('type', $enabled_types)
- ->execute()
- ->fetchCol();
- $defaults = array(
- 'comment_link' => 'node_block_default',
- 'node_link' => 'node_block_default',
- 'view_mode' => 'node_block_default');
- foreach ($results as $nid) {
- $settings = variable_get('nodeblock_block_' . $nid, $defaults);
- $settings = array_merge($defaults, $settings);
- if(isset($settings['teaser']) && $settings['teaser'] == 1) {
- $settings['view_mode'] == 'teaser';
- }
- if(isset($settings['links']) && $settings['links'] == 1) {
- $settings['node_link'] = 1;
- $settings['comment_link'] = 1;
- }
- db_insert('nodeblock')
- ->fields(array('nid', 'machine_name', 'view_mode', 'node_link', 'comment_link', 'translation_fallback'))
- ->values(array($nid, $nid, $settings['view_mode'], $settings['node_link'], $settings['comment_link'], variable_get('nodeblock_translation_fallback_' . $nid, 0)))
- ->execute();
- variable_del('nodeblock_translation_fallback_' . $nid);
- variable_del('nodeblock_block_' . $nid);
- }
- }
- }
- }
- /**
- * Add new block title column in db.
- */
- 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();
- }
- }
- }
- /**
- * `Show the Block title field in the Node Block fieldset` default value, change schema weight.
- */
- function nodeblock_update_7104() {
- $types = node_type_get_types();
- foreach ($types as $type_name => $type) {
- if ($var = variable_get('nodeblock_node_overrides_' . $type_name)) {
- $var[] = 'block_title_in_fieldset';
- variable_set('nodeblock_node_overrides_' . $type_name, $var);
- }
- }
- }
- /**
- * Implements hook_uninstall().
- */
- function nodeblock_uninstall() {
- $types = node_type_get_types();
- foreach ($types as $type_name => $type) {
- if (variable_get('nodeblock_' . $type_name, 0)) {
- variable_del('nodeblock_' . $type_name);
- variable_del('nodeblock_comment_link_' . $type_name);
- variable_del('nodeblock_node_link_' . $type_name);
- variable_del('nodeblock_view_mode_' . $type_name);
- variable_del('nodeblock_node_overrides_' . $type_name);
- variable_del('nodeblock_node_override_block_available_' . $type_name);
- variable_del('nodeblock_node_override_block_title_field_' . $type_name);
- }
- }
- db_delete('block')
- ->condition('module', 'nodeblock')
- ->execute();
- db_delete('block_role')
- ->condition('module', 'nodeblock')
- ->execute();
- variable_del('nodeblock_dangerous_force_block_caching');
- variable_del('nodeblock_table_exists');
- }
|