/[drupal]/drupal/modules/upload/upload.install
ViewVC logotype

Contents of /drupal/modules/upload/upload.install

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


Revision 1.16 - (show annotations) (download) (as text)
Fri Oct 16 19:06:25 2009 UTC (6 weeks ago) by dries
Branch: MAIN
CVS Tags: DRUPAL-7-0-UNSTABLE-10, HEAD
Changes since 1.15: +2 -1 lines
File MIME type: text/x-php
- Patch #593746 by #593746 by sun, andypost: prepare Drupal core for dynamic data translation.
1 <?php
2 // $Id: upload.install,v 1.15 2009/09/29 15:13:57 dries Exp $
3
4 /**
5 * @file
6 * Install, update and uninstall functions for the upload module.
7 */
8
9 /**
10 * @file
11 * This is the install file for the upload module.
12 */
13
14 /**
15 * Implement hook_schema().
16 */
17 function upload_schema() {
18 $schema['upload'] = array(
19 'description' => 'Stores uploaded file information and table associations.',
20 'fields' => array(
21 'fid' => array(
22 'type' => 'int',
23 'unsigned' => TRUE,
24 'not null' => TRUE,
25 'default' => 0,
26 'description' => 'Primary Key: The {file}.fid.',
27 ),
28 'nid' => array(
29 'type' => 'int',
30 'unsigned' => TRUE,
31 'not null' => TRUE,
32 'default' => 0,
33 'description' => 'The {node}.nid associated with the uploaded file.',
34 ),
35 'vid' => array(
36 'type' => 'int',
37 'unsigned' => TRUE,
38 'not null' => TRUE,
39 'default' => 0,
40 'description' => 'Primary Key: The {node}.vid associated with the uploaded file.',
41 ),
42 'description' => array(
43 'type' => 'varchar',
44 'length' => 255,
45 'not null' => TRUE,
46 'default' => '',
47 'description' => 'Description of the uploaded file.',
48 'translatable' => TRUE,
49 ),
50 'list' => array(
51 'type' => 'int',
52 'unsigned' => TRUE,
53 'not null' => TRUE,
54 'default' => 0,
55 'size' => 'tiny',
56 'description' => 'Whether the file should be visibly listed on the node: yes(1) or no(0).',
57 ),
58 'weight' => array(
59 'type' => 'int',
60 'not null' => TRUE,
61 'default' => 0,
62 'size' => 'tiny',
63 'description' => 'Weight of this upload in relation to other uploads in this node.',
64 ),
65 ),
66 'primary key' => array('vid', 'fid'),
67 'foreign keys' => array(
68 'fid' => array('files' => 'fid'),
69 'nid' => array('node' => 'nid'),
70 'vid' => array('node' => 'vid'),
71 ),
72 'indexes' => array(
73 'fid' => array('fid'),
74 'nid' => array('nid'),
75 ),
76 );
77
78 return $schema;
79 }
80
81
82 /**
83 * Migrate upload module files from {files} to {file}.
84 */
85 function upload_update_7000(&$sandbox) {
86
87 /*
88 TODO: Fix the updates. This is broken. See http://drupal.org/node/329301#comment-1404336
89 Also note new DB structure http://drupal.org/node/227232#comment-1683976
90 */
91
92 if (!isset($sandbox['progress'])) {
93 // Initialize batch update information.
94 $sandbox['progress'] = 0;
95 $sandbox['last_fid_processed'] = -1;
96 $sandbox['max'] = db_query("SELECT COUNT(DISTINCT u.fid) FROM {upload} u")->fetchField();
97 }
98
99 // As a batch operation move records from {files} into the {file} table.
100 $limit = 500;
101 $result = db_query_range("SELECT DISTINCT u.fid FROM {upload} u ORDER BY u.vid", array(), 0, $limit);
102 foreach ($result as $record) {
103 $old_file = db_query('SELECT f.* FROM {files} f WHERE f.fid = :fid', array(':fid' => $record->fid))->fetch(PDO::FETCH_OBJ);
104 if (!$old_file) {
105 continue;
106 }
107
108 $new_file = db_query('SELECT f.* FROM {files} f WHERE f.filepath = :filepath', array(':filepath' => $old_file->uri))->fetch(PDO::FETCH_OBJ);
109 if (!$new_file) {
110 // Re-save the file into the new {file} table.
111 $new_file = clone $old_file;
112 drupal_write_record('file', $new_file);
113 }
114
115 // If the fid has changed we need to update the {upload} record to use the
116 // new id.
117 if (!empty($new_file->fid) && ($new_file->fid != $old_file->fid)) {
118 db_update('upload')
119 ->fields(array('fid' => $new_file->fid))
120 ->condition('fid', $old_file->fid)
121 ->execute();
122 }
123
124 // Update our progress information for the batch update.
125 $sandbox['progress']++;
126 $sandbox['last_fid_processed'] = $old_file->fid;
127 }
128
129 // Indicate our current progress to the batch update system. If there's no
130 // max value then there's nothing to update and we're finished.
131 $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
132 }
133

  ViewVC Help
Powered by ViewVC 1.1.2