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

Contents of /contributions/modules/comment_upload/comment_upload.install

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


Revision 1.4 - (show annotations) (download) (as text)
Thu Aug 7 07:41:30 2008 UTC (15 months, 2 weeks ago) by heine
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--1
Changes since 1.3: +188 -23 lines
File MIME type: text/x-php
#197015 - Initial rewrite of comment_upload for Drupal 6.x.
1 <?php
2 // $Id$
3
4
5 /**
6 * @file
7 * The install file that defines the tables in use by comment_upload.
8 *
9 * Written by Heine Deelstra. Copyright (c) 2008 by Ustima (http://ustima.com). All rights reserved.
10 *
11 * This module is licensed under GPL v2. See LICENSE.txt for more information.
12 */
13
14 /**
15 * Implementation of hook_install().
16 */
17 function comment_upload_install() {
18 drupal_install_schema('comment_upload');
19 }
20
21 /**
22 * Implementation of hook_uninstall().
23 */
24 function comment_upload_uninstall() {
25 drupal_uninstall_schema('comment_upload');
26 db_query("DELETE FROM {variables} WHERE name LIKE 'comment_upload_%'");
27 }
28
29 /**
30 * Implementation of hook_schema().
31 */
32 function comment_upload_schema() {
33 $schema['comment_upload'] = array(
34 'description' => t('Stores uploaded file information and table associations.'),
35 'fields' => array(
36 'fid' => array(
37 'type' => 'int',
38 'unsigned' => TRUE,
39 'not null' => TRUE,
40 'default' => 0,
41 'description' => t('Primary Key: The {files}.fid.'),
42 ),
43 'nid' => array(
44 'type' => 'int',
45 'unsigned' => TRUE,
46 'not null' => TRUE,
47 'default' => 0,
48 'description' => t('The {node}.nid of the comment the uploaded files is associated with.'),
49 ),
50 'cid' => array(
51 'type' => 'int',
52 'unsigned' => TRUE,
53 'not null' => TRUE,
54 'default' => 0,
55 'description' => t('The {comment}.cid associated with the uploaded file.'),
56 ),
57 'description' => array(
58 'type' => 'varchar',
59 'length' => 255,
60 'not null' => TRUE,
61 'default' => '',
62 'description' => t('Description of the uploaded file.'),
63 ),
64 'list' => array(
65 'type' => 'int',
66 'unsigned' => TRUE,
67 'not null' => TRUE,
68 'default' => 0,
69 'size' => 'tiny',
70 'description' => t('Whether the file should be visibly listed on the comment: yes(1) or no(0).'),
71 ),
72 'weight' => array(
73 'type' => 'int',
74 'not null' => TRUE,
75 'default' => 0,
76 'size' => 'tiny',
77 'description' => t('Weight of this upload in relation to other uploads - determines the order.'),
78 ),
79 ),
80 'primary key' => array('fid'),
81 'indexes' => array(
82 'cid_fid' => array('cid', 'fid'),
83 'nid' => array('nid'),
84 ),
85 );
86
87 return $schema;
88 }
89
90 // FIXME: Update from comment_upload 5.x
91 function comment_upload_update_1() {
92 $ret = array();
93 $ret[] = update_sql("ALTER TABLE {comment_files} ADD nid int NOT NULL default '0'");
94
95 // loop through all the comment upload records and populate the nid column
96 $results = db_query("SELECT c.cid, c.nid FROM {comments} c WHERE c.cid IN (SELECT DISTINCT cf.cid FROM {comment_files} cf)");
97 while ($c = db_fetch_object($results)) {
98 $ret[] = update_sql("UPDATE {comment_files} SET nid = $c->nid WHERE cid = $c->cid");
99 }
100 return $ret;
101 }
102
103 /**
104 * Move previously saved data from {files}, {file_revisions} and {comment_files}
105 * into {comment_upload_files}.
106 *
107 * Implementation of hook_update_N().
108 */
109 function comment_upload_update_2() {
110 $ret = array();
111 $ret[] = update_sql("CREATE TABLE {comment_upload_files} (
112 `fid` int(10) unsigned NOT NULL default '0',
113 `nid` int(10) unsigned NOT NULL default '0',
114 `cid` int NOT NULL default '0',
115 `filename` varchar(255) NOT NULL default '',
116 `filepath` varchar(255) NOT NULL default '',
117 `filemime` varchar(255) NOT NULL default '',
118 `filesize` int(10) unsigned NOT NULL default '0',
119 description varchar(255) NOT NULL default '',
120 list tinyint(1) unsigned NOT NULL default 0,
121 PRIMARY KEY (`fid`)
122 ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
123
124 $max_fid = db_result(db_query("SELECT MAX(fid) FROM {comment_files}"));
125 $results = db_query("SELECT f.fid, cf.nid, cf.cid, cf.cid, f.filename, f.filepath, f.filemime, f.filesize, r.list, r.description FROM {files} f INNER JOIN {file_revisions} r ON f.fid = r.fid INNER JOIN {comment_files} cf ON f.fid = cf.fid WHERE f.nid = 0");
126
127 while ($c = db_fetch_object($results)) {
128 db_query("INSERT INTO {comment_upload_files} (fid, nid, cid, filename, filepath, filemime, filesize, description, list) VALUES(%d, %d, %d, '%s', '%s', '%s', %d, '%s', %d)", $c->fid, $c->nid, $c->cid, $c->filename, $c->filepath, $c->filemime, $c->filesize, $c->description, $c->list);
129 db_query("DELETE FROM {files} WHERE fid = %d", $c->fid);
130 db_query("DELETE FROM {file_revisions} WHERE fid = %d", $c->fid);
131 }
132 if ($max_fid) {
133 $ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES('". db_prefix_tables('{comment_upload_files}') ."_fid', $max_fid)");
134 }
135 $ret[] = update_sql("DROP TABLE {comment_files}");
136 return $ret;
137 }
138
139 /**
140 * Update column cid to be an unsigned int (MySQL only).
141 * Add index on nid.
142 *
143 * Implementation of hook_update_N().
144 */
145 function comment_upload_update_3() {
146 $ret = array();
147 switch ($GLOBALS['db_type']) {
148 case 'mysql':
149 case 'mysqli':
150 $ret[] = update_sql("ALTER TABLE {comment_upload_files} CHANGE COLUMN cid cid int unsigned NOT NULL default '0'");
151 $ret[] = update_sql("ALTER TABLE {comment_upload_files} ADD INDEX(nid)");
152 break;
153 }
154 return $ret;
155 }
156
157 /**
158 * Move all data in {comment_upload_files} to {files} and {comment_upload}.
159 *
160 * Implementation of hook_update_N().
161 */
162 function comment_upload_update_6000() {
163 $schema['comment_upload'] = array(
164 'description' => t('Stores uploaded file information and table associations.'),
165 'fields' => array(
166 'fid' => array(
167 'type' => 'int',
168 'unsigned' => TRUE,
169 'not null' => TRUE,
170 'default' => 0,
171 'description' => t('Primary Key: The {files}.fid.'),
172 ),
173 'nid' => array(
174 'type' => 'int',
175 'unsigned' => TRUE,
176 'not null' => TRUE,
177 'default' => 0,
178 'description' => t('The {node}.nid of the comment the uploaded files is associated with.'),
179 ),
180 'cid' => array(
181 'type' => 'int',
182 'unsigned' => TRUE,
183 'not null' => TRUE,
184 'default' => 0,
185 'description' => t('The {comment}.cid associated with the uploaded file.'),
186 ),
187 'description' => array(
188 'type' => 'varchar',
189 'length' => 255,
190 'not null' => TRUE,
191 'default' => '',
192 'description' => t('Description of the uploaded file.'),
193 ),
194 'list' => array(
195 'type' => 'int',
196 'unsigned' => TRUE,
197 'not null' => TRUE,
198 'default' => 0,
199 'size' => 'tiny',
200 'description' => t('Whether the file should be visibly listed on the comment: yes(1) or no(0).'),
201 ),
202 'weight' => array(
203 'type' => 'int',
204 'not null' => TRUE,
205 'default' => 0,
206 'size' => 'tiny',
207 'description' => t('Weight of this upload in relation to other uploads - determines the order.'),
208 ),
209 ),
210 'primary key' => array('fid'),
211 'indexes' => array(
212 'cid_fid' => array('cid', 'fid'),
213 'nid' => array('nid'),
214 ),
215 );
216
217
218 $ret = array();
219
220 db_create_table($ret, 'comment_upload', $schema['comment_upload']);
221
222 $result = db_query("SELECT cuf.*, c.uid FROM {comment_upload_files} cuf INNER JOIN {comments} c ON cuf.cid = c.cid");
223 while ($file = db_fetch_object($result)) {
224 unset($file->fid);
225 drupal_write_record('files', $file);
226 drupal_write_record('comment_upload', $file);
227 }
228 db_drop_table($ret, 'comment_upload_files');
229 return $ret;
230 }
231

  ViewVC Help
Powered by ViewVC 1.1.2