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

Contents of /contributions/modules/deadwood/deadwood.install

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


Revision 1.12 - (show annotations) (download) (as text)
Thu Aug 6 20:57:58 2009 UTC (3 months, 2 weeks ago) by solotandem
Branch: MAIN
CVS Tags: DRUPAL-6--1-6, HEAD
Changes since 1.11: +4 -4 lines
File MIME type: text/x-php
Replace messages to screen with writes to a log file; Add .test as a file extension to convert and sort all extensions; Rename 'files' key to to 'deadwood_files' in hook_requirements(); Removing trailing spaces in all files.
1 <?php
2 // $Id: deadwood.install,v 1.11 2008/12/24 20:34:20 solotandem Exp $
3
4 /**
5 * @file
6 * Generate version upgrade code from 5.x to 6.x.
7 *
8 * Copyright 2008 by Jim Berry ("solotandem", http://drupal.org/user/240748)
9 */
10
11 module_load_include('module', 'deadwood', 'deadwood');
12 module_load_include('inc', 'deadwood', 'deadwood');
13
14 /**
15 * Implementation of hook_schema().
16 */
17 function deadwood_schema() {
18 $schema['dw_category'] = array(
19 'description' => t('Stores categories for deadwood conversion items.'),
20 'fields' => array(
21 'nid' => array(
22 'description' => t('The primary identifier for a node.'),
23 'type' => 'int',
24 'unsigned' => TRUE,
25 'not null' => TRUE,
26 ),
27 'vid' => array(
28 'description' => t('The current {node_revisions}.vid version identifier.'),
29 'type' => 'int',
30 'unsigned' => TRUE,
31 'not null' => TRUE,
32 'default' => 0,
33 ),
34 'weight' => array(
35 'description' => t('The weight of a category used for ordering.'),
36 'type' => 'int',
37 'not null' => TRUE,
38 'default' => 0,
39 ),
40 'include' => array(
41 'description' => t('Include this category by default when doing conversions.'),
42 'type' => 'int',
43 'not null' => TRUE,
44 'default' => 1,
45 ),
46 'code_status' => array(
47 'description' => t('The availability status of conversion code for a category.'),
48 'type' => 'int',
49 'not null' => TRUE,
50 'default' => 0,
51 ),
52 'hook' => array(
53 'description' => t('Name of the category conversion hook.'),
54 'type' => 'varchar',
55 'length' => 255,
56 'not null' => TRUE,
57 'default' => '',
58 ),
59 ),
60 'indexes' => array(
61 'vid' => array('vid')
62 ),
63 'primary key' => array('nid')
64 );
65
66 $schema['dw_item'] = array(
67 'description' => t('Stores items for deadwood conversion categories.'),
68 'fields' => array(
69 'nid' => array(
70 'description' => t('The primary identifier for a node.'),
71 'type' => 'int',
72 'unsigned' => TRUE,
73 'not null' => TRUE,
74 ),
75 'vid' => array(
76 'description' => t('The current {node_revisions}.vid version identifier.'),
77 'type' => 'int',
78 'unsigned' => TRUE,
79 'not null' => TRUE,
80 'default' => 0,
81 ),
82 'cid' => array(
83 'description' => t('The {deadwood_category}.vid to which the conversion item is being assigned.'),
84 'type' => 'int',
85 'not null' => TRUE,
86 'default' => 0,
87 ),
88 'weight' => array(
89 'description' => t('The weight of an item used for ordering.'),
90 'type' => 'int',
91 'not null' => TRUE,
92 'default' => 0,
93 ),
94 'include' => array(
95 'description' => t('Include this item by default when doing conversions.'),
96 'type' => 'int',
97 'not null' => TRUE,
98 'default' => 1,
99 ),
100 'code_status' => array(
101 'description' => t('The availability status of conversion code for an item.'),
102 'type' => 'int',
103 'not null' => TRUE,
104 'default' => 0,
105 ),
106 ),
107 'indexes' => array(
108 'nid' => array('nid'),
109 'vid' => array('vid')
110 ),
111 'primary key' => array('cid', 'vid'),
112 );
113
114 return $schema;
115 }
116
117 /**
118 * Implementation of hook_install().
119 */
120 function deadwood_install() {
121 // Create tables.
122 drupal_install_schema('deadwood');
123
124 // Create the module input and output directories.
125 $dir = file_directory_path() . '/' . DEADWOOD_IN;
126 if (file_check_directory($dir, TRUE)) {
127 // variable_set('deadwood_dir', DEADWOOD_IN);
128 }
129 $dir = file_directory_path() . '/' . DEADWOOD_OUT;
130 if (file_check_directory($dir, TRUE)) {
131 // variable_set('goodwood_dir', DEADWOOD_OUT);
132 }
133
134 deadwood_load_categories();
135 }
136
137 /**
138 * Implementation of hook_uninstall().
139 */
140 function deadwood_uninstall() {
141 // Delete records.
142 deadwood_unload_categories();
143 // Remove tables.
144 drupal_uninstall_schema('deadwood');
145
146 // Remove the module input and output directories.
147 $dir = file_directory_path() . '/' . variable_get('deadwood_dir', DEADWOOD_IN);
148 deadwood_clean_directory($dir, TRUE);
149 $dir = file_directory_path() . '/' . variable_get('goodwood_dir', DEADWOOD_OUT);
150 deadwood_clean_directory($dir, TRUE);
151
152 // Remove items from {variables} table.
153 // TODO The other modules that add items here should also remove them.
154 // These strings end in 'deadwood_category' and 'deadwood_item' (eventually).
155 variable_del('deadwood_dir');
156 variable_del('goodwood_dir');
157 }
158
159 /**
160 * Load conversion categories from file into database table.
161 */
162 function deadwood_load_categories($install = TRUE) {
163 global $user;
164
165 // Delete any existing records.
166 deadwood_unload_categories();
167
168 // Open and read parameter file.
169 $handle = fopen(drupal_get_path('module', 'deadwood') . '/api_changes.csv', 'r');
170 while (($data = fgetcsv($handle, 250, ',', '"')) !== FALSE) {
171 $node = new stdClass();
172 // Standard node fields.
173 $node->type = 'deadwood_category';
174 $node->language = '';
175 $node->title = $data[3];
176 $node->uid = $user->uid;
177 $node->body = $data[3];
178 // Deadwood node fields.
179 $node->weight = $data[0];
180 $node->include = $data[1] > DEADWOOD_CONVERSION_CODE_NOT_AVAILABLE && $data[1] < DEADWOOD_CONVERSION_CODE_NOT_NEEDED ? 1 : 0;
181 $node->code_status = $data[1];
182 $node->hook = $data[2];
183 // Save the node.
184 node_save($node);
185 /*
186 * The dw_category records are not inserted by node_save during install.
187 *
188 * Once installed and the system information is updated, node_save calls
189 * node_invoke which calls node_hook to determine whether a node hook exists.
190 * It eventually calls _node_types_build which retrieves from the node_type
191 * table. This table must not be updated when the install hooks are running.
192 * Normally, node_invoke would call deadwood_insert. So we will do it
193 * manually.
194 */
195 if ($install) {
196 deadwood_insert($node);
197 }
198 }
199 fclose($handle);
200 }
201
202 /**
203 * Unload conversion categories from the database tables.
204 */
205 function deadwood_unload_categories() {
206 // TODO Should we instead query the node table for the nids of records with
207 // type = 'deadwood_category' and call node_delete?
208
209 // Delete any existing records.
210 db_query("DELETE FROM {dw_item}");
211 db_query("DELETE FROM {dw_category}");
212 db_query("DELETE FROM {node_revisions} WHERE nid IN (SELECT nid FROM {node} WHERE type = 'deadwood_category')");
213 db_query("DELETE FROM {node_comment_statistics} WHERE nid IN (SELECT nid FROM {node} WHERE type = 'deadwood_category')");
214 db_query("DELETE FROM {node} WHERE type = 'deadwood_category'");
215 }
216
217 /**
218 * Implementation of hook_requirements().
219 */
220 function deadwood_requirements($phase) {
221 $requirements = array();
222
223 // Test writeability to files directory.
224 if ($phase == 'install') {
225 $dir = file_directory_path();
226 if (!file_check_directory($dir, TRUE)) {
227 $requirements['deadwood_files'] = array(
228 'title' => t('Files directory'),
229 'description' => t('Your files directory at %directory can not be written to. Deadwood places converted module code in subdirectories of this directory.', array('%directory' => $dir)),
230 'severity' => REQUIREMENT_ERROR
231 );
232 }
233 }
234 else {
235 $dir = file_directory_path() . '/' . variable_get('goodwood_dir', DEADWOOD_OUT);
236 if (!file_check_directory($dir, TRUE)) {
237 $requirements['deadwood_files'] = array(
238 'title' => t('Deadwood directory'),
239 'description' => t('Your files directory at %directory can not be written to. Deadwood places converted module code in subdirectories of this directory.', array('%directory' => $dir)),
240 'severity' => REQUIREMENT_ERROR,
241 'value' => t('Not writeable (%dir)', array('%dir' => $dir))
242 );
243 }
244 else {
245 $requirements['deadwood_files'] = array(
246 'title' => t('Deadwood directory'),
247 'value' => t('Writeable (%dir)', array('%dir' => $dir))
248 );
249 }
250 }
251
252 return $requirements;
253 }

  ViewVC Help
Powered by ViewVC 1.1.2