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

Contents of /contributions/modules/filefield_paths/filefield_paths.install

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


Revision 1.7 - (show annotations) (download) (as text)
Mon Nov 2 00:37:02 2009 UTC (3 weeks, 3 days ago) by deciphered
Branch: MAIN
CVS Tags: HEAD
Changes since 1.6: +160 -95 lines
File MIME type: text/x-php
Drupal 7 port - work in progress.
1 <?php
2 // $Id: filefield_paths.install,v 1.6.2.3 2009/05/22 03:28:14 deciphered Exp $
3
4 /**
5 * @file
6 * Install, update and uninstall functions for the FileField Paths module.
7 */
8
9 /**
10 * Implements hook_schema().
11 */
12 function filefield_paths_schema() {
13 $schema['filefield_paths'] = array(
14 'fields' => array(
15 'type' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''),
16 'field' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''),
17 'filename' => array('type' => 'text', 'size' => 'medium', 'not null' => TRUE, 'serialize' => TRUE),
18 'filepath' => array('type' => 'text', 'size' => 'medium', 'not null' => TRUE, 'serialize' => TRUE),
19 ),
20 'unique keys' => array(
21 'type_field' => array('type', 'field'),
22 ),
23 );
24
25 return $schema;
26 }
27
28 /**
29 * Implements hook_schema_alter().
30 *
31 * @param $schema
32 * The system-wide schema
33 */
34 function filefield_paths_schema_alter(&$schema) {
35 $schema['file']['fields']['origname'] = array(
36 'description' => 'Original name of the file.',
37 'type' => 'varchar',
38 'length' => 255,
39 'not null' => TRUE,
40 'default' => '',
41 );
42 }
43
44 /**
45 * Implements hook_install().
46 */
47 function filefield_paths_install() {
48 db_add_field('file', 'origname', array('description' => 'Original name of the file.', 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
49
50 $result = db_query("SELECT fid, filename FROM {file}");
51 foreach ($result as $file) {
52 db_update('file')
53 ->fields(array('origname' => $file->filename))
54 ->conditions('fid', $file->fid)
55 ->execute();
56 }
57
58 variable_set('filefield_paths_schema_version', 7103);
59 }
60
61 /**
62 * Implements hook_uninstall().
63 */
64 function filefield_paths_uninstall() {
65 db_drop_field('file', 'origname');
66 variable_del('filefield_paths_schema_version');
67 }
68
69 /**
70 * Implements hook_update_N().
71 */
72 //function filefield_paths_update_6100() {
73 // $ret = array();
74 //
75 // if (db_table_exists('filefield_paths')) {
76 // return $ret;
77 // }
78 //
79 // $schema['filefield_paths'] = array(
80 // 'fields' => array(
81 // 'type' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''),
82 // 'field' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''),
83 // 'filename' => array('type' => 'text', 'size' => 'medium', 'not null' => TRUE, 'serialize' => TRUE),
84 // 'filepath' => array('type' => 'text', 'size' => 'medium', 'not null' => TRUE, 'serialize' => TRUE),
85 // ),
86 // 'unique keys' => array(
87 // 'type_field' => array('type', 'field'),
88 // ),
89 // );
90 //
91 // db_create_table($ret, 'filefield_paths', $schema['filefield_paths']);
92 //
93 // $fields = array();
94 // $content_type = content_types();
95 //
96 // foreach ($content_type as $type) {
97 // $types[] = $type['type'];
98 //
99 // foreach ($type['fields'] as $field) {
100 // if (preg_match('/\bfilefield\b|\bimage\b/', $field['type'])) {
101 //
102 // if (!in_array($field['field_name'], $fields)) {
103 // $fields[] = $field['field_name'];
104 // }
105 //
106 // }
107 // }
108 // }
109 //
110 // $types = implode('|', $types);
111 // $fields = implode('|', $fields);
112 //
113 // $result = db_query("SELECT * FROM {variable} WHERE name LIKE 'filefield_paths_%'");
114 //
115 // while ($variable = db_fetch_object($result)) {
116 // $pattern = '/filefield_paths_(' . $types . ')_(' . $fields . ')_(file_name|file_path)_?(.*)/';
117 //
118 // if (preg_match($pattern, $variable->name, $results)) {
119 // if (empty($results[4])) {
120 // $results[4] = 'value';
121 // }
122 //
123 // $data[$results[1]][$results[2]][$results[3]][$results[4]] = unserialize($variable->value);
124 // }
125 // }
126 //
127 // foreach ($data as $type => $type_data) {
128 // foreach ($type_data as $field => $field_data) {
129 // $result = db_fetch_object(
130 // db_query("SELECT widget_settings FROM {content_node_field_instance} " .
131 // "WHERE field_name = '%s' AND type_name = '%s'", $field, $type)
132 // );
133 // $widget_settings = unserialize($result->widget_settings);
134 // $field_data['file_path']['value'] = $widget_settings['file_path'];
135 //
136 // $result = db_query(
137 // "INSERT INTO {filefield_paths} (type, field, filename, filepath) VALUES ('%s', '%s', '%s', '%s')",
138 // $type, $field, serialize($field_data['file_name']), serialize($field_data['file_path']), TRUE
139 // );
140 //
141 // $ret[] = array('success' => $result !== FALSE, 'query' => check_plain("
142 // INSERT INTO {filefield_paths} (type, field, filename, filepath) VALUES ('" . $type . "', '" .
143 // $field . "', '" . serialize($field_data['file_name']) . "', '" . serialize($field_data['file_path']) . "')
144 // "));
145 // }
146 // }
147 //
148 // $ret[] = update_sql("DELETE FROM {variable} WHERE name LIKE 'filefield_paths_%'");
149 // cache_clear_all('variables', 'cache');
150 //
151 // return $ret;
152 //}
153 //
154 //function filefield_paths_update_6101() {
155 // variable_set('filefield_paths_schema_version', 6101);
156 // return array();
157 //}
158 //
159 //function filefield_paths_update_6102() {
160 // variable_set('filefield_paths_schema_version', 6102);
161 // $fields = module_invoke_all('filefield_paths_field_settings');
162 // $result = db_query("SELECT * FROM {filefield_paths}");
163 //
164 // while ($data = db_fetch_object($result)) {
165 // foreach ($fields as $field) {
166 // $cols[] = $field['sql'] . " = '%s'";
167 //
168 // $val = unserialize($data->$field['sql']);
169 // $val = str_replace('[filefield_paths-name]', '[filefield-onlyname]', $val);
170 // $val = str_replace('[filefield_paths-ext]', '[filefield-extension]', $val);
171 //
172 // $vals[] = serialize($val);
173 // }
174 //
175 // db_query(
176 // "UPDATE {filefield_paths} SET " . implode(', ', $cols) . " WHERE type = '%s' AND field = '%s'",
177 // array_merge($vals, array($data->type, $data->field))
178 // );
179 // }
180 //
181 // return array();
182 //}
183 //
184 //function filefield_paths_update_6103() {
185 // $schema_version = variable_get('filefield_paths_schema_version', '6102');
186 // variable_set('filefield_paths_schema_version', 6103);
187 //
188 // if ($schema_version < 5103 || ($schema_version > 6000 && $schema_version < 6103)) {
189 // db_add_field($ret = array(), 'file', 'origname', array('description' => 'Original name of the file.', 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
190 //
191 // $result = db_query("SELECT fid, filename FROM {file}");
192 // while ($file = db_fetch_object($result)) {
193 // db_query("UPDATE {file} SET origname = '%s' WHERE fid = %d", $file->filename, $file->fid);
194 // }
195 // }
196 //
197 // return array();
198 //}

  ViewVC Help
Powered by ViewVC 1.1.2