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

Contents of /contributions/modules/taxonomy_enhancer/taxonomy_enhancer.install

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


Revision 1.2 - (show annotations) (download) (as text)
Thu Mar 27 22:55:07 2008 UTC (19 months, 4 weeks ago) by njt1982
Branch: MAIN
CVS Tags: DRUPAL-5--2-0, HEAD
Branch point for: DRUPAL-5--2
Changes since 1.1: +151 -0 lines
File MIME type: text/x-php
Adding new Taxonomy Enhancer to HEAD
1 <?php
2
3 function taxonomy_enhancer_install() {
4 switch ($GLOBALS['db_type']) {
5 case 'mysqli':
6 case 'mysql':
7 $sql = 'CREATE TABLE {taxonomy_enhancer_fields} (
8 vid int(11) unsigned NOT NULL,
9 fid varchar(255) NOT NULL default "",
10 title varchar(255) NOT NULL,
11 module varchar(255) NOT NULL,
12 type varchar(255) NOT NULL,
13 weight int(11) NOT NULL default "0",
14 settings text,
15 PRIMARY KEY (vid,fid)
16 ) /*!40100 DEFAULT CHARACTER SET utf8 */;';
17
18 db_query($sql);
19 break;
20 }
21 }
22
23
24 function taxonomy_enhancer_update_10() {
25 $ret = array();
26
27 switch ($GLOBALS['db_type']) {
28 case 'mysqli':
29 case 'mysql':
30 $ret[] = update_sql('ALTER TABLE {taxonomy_enhancer_fields} DROP PRIMARY KEY;');
31 $ret[] = update_sql('ALTER TABLE {taxonomy_enhancer_fields} CHANGE id fid VARCHAR(255);');
32 $ret[] = update_sql('ALTER TABLE {taxonomy_enhancer_fields} ADD COLUMN module VARCHAR(255) NOT NULL DEFAULT "" AFTER title;');
33 $ret[] = update_sql('ALTER TABLE {taxonomy_enhancer_fields} MODIFY type VARCHAR(255) NOT NULL;');
34 $ret[] = update_sql('ALTER TABLE {taxonomy_enhancer_fields} ADD COLUMN (weight INT(11) NOT NULL DEFAULT "0", settings TEXT);');
35 $ret[] = update_sql('ALTER TABLE {taxonomy_enhancer_fields} ADD PRIMARY KEY (vid, fid);');
36 break;
37 }
38
39 return $ret;
40 }
41
42
43 function taxonomy_enhancer_update_11() {
44 $ret = array();
45
46 switch ($GLOBALS['db_type']) {
47 case 'mysqli':
48 case 'mysql':
49 //GET LIST OF REQUIRED FIELDS...
50 $modules_to_check = array();
51
52 $result = db_query('SELECT DISTINCT type FROM {taxonomy_enhancer_fields}');
53 //Create an array with the required module as a key (to make sure its 'unique')
54 while ($row = db_fetch_array($result)) {
55 switch ($row['type']) {
56 case 'textfield' :
57 case 'textarea' :
58 $modules_to_check['taxonomy_enhancer_text'] = t('Text Field Module');
59 break;
60 }
61 }
62
63 //Loop over all found and required modules and make sure they're installed & enabled.
64 foreach ($modules_to_check as $module => $name) {
65 if (!module_exists($module)) {
66 //Not installed - display an error with a link to the modules page (anchored to the taxonomy enhancer)
67 drupal_set_message(
68 t(
69 'Taxonomy Enhancer Update Failed. The update required you to enable the !link.',
70 array('!link' => l(t($name), 'admin/build/modules', array(), NULL, 'edit-status-taxonomy-enhancer'))
71 ),
72 'error'
73 );
74
75 //Set a variable so T.E. can reset its schema version (if its not already set)
76 if (variable_get('taxonomy_enhancer_update_fail', FALSE) === FALSE) {
77 variable_set('taxonomy_enhancer_update_fail', 10);
78 }
79
80 //Set a return error
81 $ret[] = array(
82 'success' => FALSE,
83 'query' => t('Required Field Type Missing.'),
84 );
85 }
86 }
87
88 if (!empty($ret)) {
89 return $ret;
90 }
91
92
93 //Now install/update/import the old fields...
94 $result = db_query('SELECT t.* FROM {taxonomy_enhancer_fields} t WHERE t.type IN ("textarea", "textfield")');
95 while ($row = db_fetch_object($result)) {
96 //For each field, define some new settings (5 rows and formatter, or 1 row and plain)
97 //for the textarea and textfield types.
98 $settings = array();
99 if ($row->type == 'textarea') {
100 $settings = array(
101 'rows' => 5,
102 'format' => 'formatted',
103 );
104 }
105 elseif ($row->type == 'textfield') {
106 $settings = array(
107 'rows' => 1,
108 'format' => 'plain',
109 );
110 }
111
112 //Update the field entry
113 db_query('UPDATE {taxonomy_enhancer_fields} SET module = "taxonomy_enhancer_text", type = "text", settings="%s" WHERE vid = %d AND fid = "%s"', serialize($settings), $row->vid, $row->fid);
114
115
116 //Update the object for the module_api calls below
117 $row->oldtype = $row->type;
118 $row->module = 'taxonomy_enhancer_text';
119 $row->type = 'text';
120 $row->format = $settings['format'];
121
122
123 //Now for each type term which has a field of this type we need to insert an entry.
124 $sub_result = db_query('SELECT ted.* FROM {taxonomy_enhancer_data} ted LEFT JOIN {term_data} t ON t.tid = ted.tid WHERE field = "%s" AND t.vid = %d', $row->fid, $row->vid);
125 while($term = db_fetch_array($sub_result)) {
126 switch ($row->oldtype) {
127 case 'textarea' :
128 $term['fields'][$row->fid]['value'] = $term['value'];
129 $term['fields'][$row->fid]['format'] = FILTER_FORMAT_DEFAULT;
130 unset($term['value']);
131 unset($term['field']);
132 break;
133
134 default :
135 $term['fields'][$row->fid] = $term['value'];
136 unset($term['value']);
137 unset($term['field']);
138 break;
139 }
140
141
142 //Invoke the text field insert hook
143 module_invoke('taxonomy_enhancer_text', 'te_api', 'insert', 'value', $row, $term);
144 }
145 }
146
147 break;
148 }
149
150 return $ret;
151 }

  ViewVC Help
Powered by ViewVC 1.1.2