summaryrefslogtreecommitdiffstats
path: root/link.install
blob: 2ca4a1bc8750b410b5e3e17c57893177f0cf2abe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
// $Id$

/**
 * Implementation of hook_install().
 */
function link_install() {
  content_notify('install', 'link');
}

/**
* Implementation of hook_uninstall().
*/
function link_uninstall() {
  content_notify('uninstall', 'link');
}

/**
* Implementation of hook_enable().
*/
function link_enable() {
  content_notify('enable', 'link');
}

/**
* Implementation of hook_disable().
*/
function link_disable() {
  content_notify('disable', 'link');
}

/**
 * Removed link.module created tables, move data to content.module tables
 */
function link_update_1() {
  $ret = array();

  include_once(drupal_get_path('module', 'content') .'/content.module');
  include_once(drupal_get_path('module', 'content') .'/content_admin.inc');

  $fields = content_fields();

  foreach ($fields as $field) {
    switch ($field['type']) {
      case 'link':
        $columns = array(
          'url' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => "''"),
          'title' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => "''"),
          'attributes' => array('type' => 'mediumtext', 'not null' => FALSE),
        );
        content_alter_db_field(array(), array(), $field, $columns);
        $db_info = content_database_info($field);
        if ($field['multiple']) {
          $ret[] = update_sql('INSERT INTO {'. $db_info['table'] .'} (vid, delta, nid, '. $field['field_name'] .'_url, '. $field['field_name'] .'_title, '. $field['field_name'] ."_attributes) SELECT vid, delta, nid, field_url, field_title, attributes FROM {node_field_link_data} WHERE field_name = '". $field['field_name'] ."'");
        }
        else {
          $ret[] = update_sql('UPDATE {'. $db_info['table'] .'} c, {node_field_link_data} l SET c.'. $field['field_name'] .'_url = l.field_url, c.'. $field['field_name'] .'_title = l.field_title, c.'. $field['field_name'] ."_attributes = l.attributes WHERE l.field_name = '". $field['field_name'] ."' AND c.vid = l.vid AND c.nid = l.nid");
        }
    }
  }

  $ret[] = update_sql('DROP TABLE {node_field_link_data}');

  db_query('DELETE FROM {cache}');
  return $ret;
}