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

Contents of /contributions/modules/filebrowser/filebrowser.install

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


Revision 1.10 - (show annotations) (download) (as text)
Thu Oct 22 07:20:52 2009 UTC (5 weeks, 2 days ago) by ulhume
Branch: MAIN
CVS Tags: HEAD
Changes since 1.9: +15 -2 lines
File MIME type: text/x-php
- copmpanion module api
- Image thumbnailing first support
- Package peroperty changed
1 <?php
2
3
4 /* This file is part of "filebrowser".
5 * Copyright 2009, arNuméral
6 * Author : Yoran Brault
7 * eMail : yoran.brault@bad_arnumeral.fr (remove bad_ before sending an email)
8 * Site : http://www.arnumeral.fr/node/5
9 *
10 * Original credit for susurrus (http://drupal.org/user/118433).
11 *
12 * "filebrowser" is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2.1 of
15 * the License, or (at your option) any later version.
16 *
17 * "filebrowser" is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public
23 * License along with "Broken Anchor for Node comments Module"; if not, write to the Free
24 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
26 */
27
28 function filebrowser_schema() {
29 $schema['node_dir_listing'] = array (
30 'fields' => array (
31 'nid' => array (
32 'type' => 'int',
33 'unsigned' => TRUE,
34 'not null' => TRUE
35 ),
36 'folder_path' => array (
37 'type' => 'varchar',
38 'length' => '255',
39 'not null' => TRUE
40 ),
41
42 'properties' => array (
43 'type' => 'text',
44 'not null' => TRUE,
45 'size' => 'big'
46 )
47 ),
48 'primary key' => array (
49 'nid'
50 )
51 );
52
53 return $schema;
54 }
55
56 function filebrowser_install() {
57 drupal_install_schema('filebrowser');
58 }
59
60 function filebrowser_uninstall() {
61 drupal_uninstall_schema('filebrowser');
62 }
63
64 // Update from 5.x-1.x to 6.x-1.x
65 function filebrowser_update_6100() {
66
67 $ret = array ();
68
69 // Add the old directory listing into the new database structure given that
70 // this old data exists and users haven't already upgraded manually.
71 global $conf;
72 if (isset ($conf['filebrowser_root']) && !db_table_exists('filebrowser')) {
73 db_create_table($ret, 'filebrowser', array (
74 'fields' => array (
75 'path' => array (
76 'type' => 'varchar',
77 'length' => '255',
78 'not null' => TRUE
79 ),
80 'location' => array (
81 'type' => 'varchar',
82 'length' => '255',
83 'not null' => TRUE
84 ),
85 'can_explore' => array (
86 'type' => 'int',
87 'size' => 'tiny',
88 'not null' => TRUE,
89 'disp-width' => '1'
90 )
91 ),
92 'primary key' => array (
93 'path'
94 )
95 ));
96
97 $ret[] = update_sql("INSERT INTO {filebrowser} (path, location, can_explore) VALUES ('filebrowser', '{$conf['filebrowser_root']}', 1)");
98 }
99
100 // Clean up variables from 5.x branch
101 variable_del('filebrowser_icons');
102 variable_del('filebrowser_root');
103 variable_del('filebrowser_hide_description_files');
104
105 return $ret;
106 }
107
108 // Update from 6.x-1.x to 6.x-2.x
109 function filebrowser_update_6200() {
110
111 $ret = array ();
112
113 // Add new fields
114 db_add_field($ret, 'filebrowser', 'nid', array (
115 'type' => 'int',
116 'unsigned' => TRUE,
117 'not null' => TRUE
118 ));
119 db_add_field($ret, 'filebrowser', 'file_blacklist', array (
120 'type' => 'varchar',
121 'length' => '255',
122 'not null' => TRUE
123 ));
124
125 // Change existing fields
126 db_change_field($ret, 'filebrowser', 'location', 'file_path', array (
127 'type' => 'varchar',
128 'length' => '255',
129 'not null' => TRUE
130 ));
131 db_drop_primary_key($ret, 'filebrowser');
132 db_change_field($ret, 'filebrowser', 'can_explore', 'explore_subdirs', array (
133 'type' => 'int',
134 'size' => 'tiny',
135 'not null' => TRUE,
136 'disp-width' => '1'
137 ));
138
139 // Grab all existing filebrowser data
140 $qry = db_query('SELECT file_path, path, explore_subdirs FROM {filebrowser}');
141 $new_nodes = array ();
142 while ($node = db_fetch_object($qry)) {
143 $new_nodes[] = $node;
144 }
145
146 // Clear out the filebrowser data
147 // This is necessary so that we can use node_save() which will automatically
148 // call filebrowser_save() for us.
149 $ret[] = update_sql('TRUNCATE TABLE {filebrowser}');
150
151 // We need to add the primary key after we've truncated the table, otherwise
152 // it'll fail on duplicate keys if multiple directory listings have been
153 // created.
154 db_add_primary_key($ret, 'filebrowser', array (
155 'nid'
156 ));
157
158 // Attach these nodes to the default administrator account
159 $user = user_load(array (
160 'uid' => 1
161 ));
162
163 // Reinsert our directory listing nodes
164 foreach ($new_nodes as $node) {
165 $node->type = 'dir_listing';
166 $node->uid = 1;
167 $node->name = $user->name;
168 $node->file_blacklist = '';
169 node_save($node);
170 }
171
172 // Drop unneeded fields
173 db_drop_field($ret, 'filebrowser', 'path');
174
175 return $ret;
176 }
177
178 // Update enabling private downloads
179 function filebrowser_update_6201() {
180 $ret = array ();
181 db_add_field($ret, 'filebrowser', 'private_downloads', array (
182 'type' => 'int',
183 'size' => 'tiny',
184 'unsigned' => TRUE,
185 'not null' => TRUE,
186 'default' => 0
187 ));
188 return $ret;
189 }
190
191 function filebrowser_update_6202() {
192
193 $ret = array ();
194
195 // Add new fields
196 db_add_field($ret, 'filebrowser', 'hidden_files', array (
197 'type' => 'varchar',
198 'length' => '255',
199 'not null' => TRUE,
200 'default' => ''
201 ));
202 db_add_field($ret, 'filebrowser', 'filtered_files', array (
203 'type' => 'varchar',
204 'length' => '255',
205 'not null' => TRUE,
206 'default' => ''
207 ));
208
209 // Grab all existing filebrowser data
210 $cursor = db_query('SELECT nid, file_blacklist FROM {filebrowser}');
211 while ($node = db_fetch_object($cursor)) {
212 $hidden = preg_replace("/\s*,\s*/", "\r\n", $node->file_blacklist);
213 $ret[] = update_sql("update {filebrowser} set hidden_files='" . $hidden . "' where nid=" . $node->nid);
214 }
215
216 // Change existing fields
217 $ret[] = db_drop_field($ret, 'filebrowser', 'file_blacklist');
218
219 return $ret;
220 }
221
222 function filebrowser_update_6203() {
223
224 $ret = array ();
225
226 // Add new fields
227 db_add_field($ret, 'filebrowser', 'allowed_uploaded_files', array (
228 'type' => 'varchar',
229 'length' => '255',
230 'not null' => TRUE,
231 'default' => ''
232 ));
233
234 return $ret;
235 }
236
237 function filebrowser_update_6204() {
238
239 $ret = array ();
240
241 // Add new fields
242 db_add_field($ret, 'filebrowser', 'hide_extension', array (
243 'type' => 'int',
244 'size' => 'tiny',
245 'not null' => TRUE,
246 'disp-width' => '1',
247 'default' => '0'
248 ));
249
250 return $ret;
251 }
252
253 function filebrowser_update_6205() {
254 $ret = array ();
255 // Add new fields
256 db_add_field($ret, 'filebrowser', 'visible_columns', array (
257 'type' => 'varchar',
258 'length' => '255',
259 'not null' => TRUE,
260 'default' => ''
261 ));
262
263 return $ret;
264 }
265
266 function filebrowser_update_6210() {
267 $ret = array ();
268 // Add new fields
269 db_add_field($ret, 'filebrowser', 'allow_files_upload', array (
270 'type' => 'int',
271 'size' => 'tiny',
272 'not null' => FALSE,
273 'disp-width' => '1'
274 ));
275
276 return $ret;
277 }
278
279 function filebrowser_update_6211() {
280 $ret = array ();
281 if (db_table_exists("node_dir_listing")) {
282 db_drop_table($ret, "node_dir_listing");
283 }
284 $schema = filebrowser_schema();
285 db_create_table($ret, 'node_dir_listing', $schema['node_dir_listing']);
286 $cursor = db_query("select * from {filebrowser}");
287 while ($node = db_fetch_object($cursor)) {
288 $properties = (object)array (
289 'folder_rights' => (object)array (
290 'explore_subdirs' => $node->explore_subdirs ? true : false,
291 'private_downloads' => $node->private_downloads ? true : false,
292 'forbidden_files' => $node->hidden_files?$node->hidden_files:'',
293 'filtered_files' => $node->filtered_files?$node->filtered_files:''
294 ),
295 'folder_uploads' => (object)array(
296 'enabled' => $node->allow_files_upload?true:false,
297 'accepted_uploaded_files' => $node->allowed_uploaded_files?$node->allowed_uploaded_files:''
298 ),
299 'folder_presentation' => (object)array(
300 'hide_extension' => $node->hide_extension ? true : false,
301 'visible_columns' => $node->visible_columns?unserialize($node->visible_columns):array('icon'=>true, 'display_name'=>true)
302 )
303 );
304 $serialised = serialize($properties);
305 $ret[]=filebrowser_update_sql("
306 insert into {node_dir_listing}
307 (nid,folder_path,properties)
308 values(%d,'%s','%s')",
309 $node->nid, $node->file_path, $serialised);
310 }
311
312 return $ret;
313 }
314
315 function filebrowser_update_sql($query) {
316 $args = func_get_args();
317 $result = call_user_func_array("db_query", $args);
318 return array('success' => $result !== FALSE, 'query' => check_plain($query));
319 }
320
321 function filebrowser_update_6212() {
322 $ret = array();
323 if (db_column_exists('node_dir_listing', 'path')) {
324 db_change_field($ret, 'node_dir_listing', 'path', 'folder_path',
325 array (
326 'type' => 'varchar',
327 'length' => '255',
328 'not null' => TRUE
329 ));
330 }
331 return $ret;
332 }

  ViewVC Help
Powered by ViewVC 1.1.2