/[drupal]/contributions/modules/cck_fullname/cck_fullname.install
ViewVC logotype

Contents of /contributions/modules/cck_fullname/cck_fullname.install

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download) (as text)
Sat Dec 15 00:59:45 2007 UTC (23 months, 1 week ago) by rconstantine
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +1 -1 lines
File MIME type: text/x-php
#201108 forgot to comment out ID line
1 <?php
2 //$Id: cck_fullname.install,v 1.2 2007/12/14 20:26:41 rconstantine Exp $;
3 /**
4 * Not needed unless upgrading from an older version;
5 * see the updates below.
6 */
7 function cck_fullname_install() {
8
9 }
10
11 /**
12 * Implementation of hook_update_N().
13 */
14 function cck_fullname_update_1() {
15 $ret = array();
16
17 //first, handle existing table issues
18 include_once('./'. drupal_get_path('module', 'content') .'/content.module');
19 include_once('./'. drupal_get_path('module', 'content') .'/content_admin.inc');
20
21 content_clear_type_cache();
22 $fields = content_fields();
23
24 foreach ($fields as $field) {
25 switch ($field['type']) {
26 case 'cck_fullname':
27 $db_info = content_database_info($field);
28 $table = $db_info['table'];
29 $fieldname = $field['field_name'] .'_';
30 $sql = "SHOW COLUMNS FROM {%s}";
31 $results = db_query($sql, $table);
32 while ($result = db_fetch_object($results)) {
33 if ($result->Field == $fieldname .'last') {
34 $last_type = $result->Type;
35 if ($result->Null == 'Yes') {
36 $last_null = 'NULL';
37 }
38 else {
39 $last_null = 'NOT NULL';
40 }
41 if (isset($result->Default)) {
42 $last_default = $result->Default;
43 }
44 else {
45 $last_default = '';
46 }
47 }
48 elseif ($result->Field == $fieldname .'first') {
49 $first_type = $result->Type;
50 if ($result->Null == 'Yes') {
51 $first_null = 'NULL';
52 }
53 else {
54 $first_null = 'NOT NULL';
55 }
56 if (isset($result->Default)) {
57 $first_default = $result->Default;
58 }
59 else {
60 $first_default = '';
61 }
62 }
63 elseif ($result->Field == $fieldname .'middle') {
64 $middle_type = $result->Type;
65 if ($result->Null == 'Yes') {
66 $middle_null = 'NULL';
67 }
68 else {
69 $middle_null = 'NOT NULL';
70 }
71 if (isset($result->Default)) {
72 $middle_default = $result->Default;
73 }
74 else {
75 $middle_default = '';
76 }
77 }
78 }
79 $ret[] = update_sql("ALTER TABLE {". $table ."} ADD COLUMN ". $fieldname ."prefix varchar(6) NOT NULL");
80 $ret[] = update_sql("ALTER TABLE {". $table ."} ADD COLUMN ". $fieldname ."suffix varchar(6) NOT NULL");
81 $ret[] = update_sql("ALTER TABLE {". $table ."} ADD COLUMN ". $fieldname ."last_preferred $last_type $last_null $last_default");
82 $ret[] = update_sql("ALTER TABLE {". $table ."} ADD COLUMN ". $fieldname ."first_preferred $first_type $first_null $first_default");
83 $ret[] = update_sql("ALTER TABLE {". $table ."} ADD COLUMN ". $fieldname ."middle_preferred $middle_type $middle_null $middle_default");
84 $ret[] = update_sql("ALTER TABLE {". $table ."} ADD COLUMN ". $fieldname ."prefix_preferred varchar(6) NOT NULL");
85 $ret[] = update_sql("ALTER TABLE {". $table ."} ADD COLUMN ". $fieldname ."suffix_preferred varchar(6) NOT NULL");
86
87 $ret[] = array(
88 'query' => strtr('The field %field_name has been updated in several respects.', array('%field_name' => $field['field_name'])),
89 'success' => TRUE
90 );
91 break;
92 }
93 }
94 return $ret;
95 }

  ViewVC Help
Powered by ViewVC 1.1.2