summaryrefslogtreecommitdiff
path: root/modules/upload
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2005-08-30 15:22:29 +0000
committerDries Buytaert <dries@buytaert.net>2005-08-30 15:22:29 +0000
commitd9d6a6e05c7a3c9d55e0e143e23489d7ed64be4b (patch)
tree71f531bfe2bc3663ecca9138475ae5c34fd72f82 /modules/upload
parent7e5d0c947a23c0931614b167b7107c97cdd82136 (diff)
downloadbrdo-d9d6a6e05c7a3c9d55e0e143e23489d7ed64be4b.tar.gz
brdo-d9d6a6e05c7a3c9d55e0e143e23489d7ed64be4b.tar.bz2
- Patch #7582 by Gerhard: improved node revisions!
All node revisions were stored in a serialized field in the node table and retrieved for _each_ page view although they are rarely needed. We created a separate revisions table which would be in principle identical to the node table, only that it could have several old copies of the same node. This also allows us to revision-related information, and to provide log entries to non-book pages when a new revision is being created. TODO: 1. Provide upgrade instructions for node module maintainers! 2. Upgrade modules that implement node types. 3. Provide an upgarde path for revisions. Dependency on the upgrade system.
Diffstat (limited to 'modules/upload')
-rw-r--r--modules/upload/upload.module39
1 files changed, 27 insertions, 12 deletions
diff --git a/modules/upload/upload.module b/modules/upload/upload.module
index d521a0f80..3cf56d16c 100644
--- a/modules/upload/upload.module
+++ b/modules/upload/upload.module
@@ -314,7 +314,7 @@ function upload_nodeapi(&$node, $op, $arg) {
* The ammount of disk space used by the user in bytes.
*/
function upload_space_used($uid) {
- return db_result(db_query('SELECT SUM(f.filesize) FROM {files} f INNER JOIN {node} n ON f.nid = n.nid WHERE uid = %d', $uid));
+ return db_result(db_query('SELECT SUM(f.filesize) FROM {files} f INNER JOIN {node_revisions} n ON f.vid = n.vid WHERE uid = %d', $uid));
}
/**
@@ -324,7 +324,7 @@ function upload_space_used($uid) {
* The ammount of disk space used by uploaded files in bytes.
*/
function upload_total_space_used() {
- return db_result(db_query('SELECT SUM(f.filesize) FROM {files} f INNER JOIN {node} n ON f.nid = n.nid'));
+ return db_result(db_query('SELECT SUM(f.filesize) FROM {files} f INNER JOIN {node_revisions} n ON f.vid = n.vid'));
}
function upload_save($node) {
@@ -336,18 +336,33 @@ function upload_save($node) {
// Insert new files:
if ($file = file_save_upload($file, $file->filename)) {
$fid = db_next_id('{files}_fid');
- db_query("INSERT INTO {files} (fid, nid, filename, filepath, filemime, filesize, list) VALUES (%d, %d, '%s', '%s', '%s', %d, %d)",
- $fid, $node->nid, $file->filename, $file->filepath, $file->filemime, $file->filesize, $node->list[$key]);
+ db_query("INSERT INTO {files} (fid, nid, vid, filename, filepath, filemime, filesize, list) VALUES (%d, %d, %d, '%s', '%s', '%s', %d, %d)",
+ $fid, $node->nid, $node->vid, $file->filename, $file->filepath, $file->filemime, $file->filesize, $node->list[$key]);
}
}
- else {
- // Remove or update existing files:
- if ($node->remove[$key]) {
+ }
+ // Remove or update existing files:
+ foreach ((array)$node->remove as $key => $value) {
+ if ($node->remove[$key]) {
+ db_query('DELETE FROM {files} WHERE fid = %d AND vid = %d', $key, $node->vid);
+ // We only delete a file if it isn't used anymore by any revision.
+ $count = db_result(db_query('SELECT COUNT(fid) FROM {files} WHERE fid = %d', $key));
+ if (!($count > 0)) {
file_delete($file->filepath);
- db_query("DELETE FROM {files} WHERE fid = %d", $key);
}
- if ($file->list != $node->list[$key]) {
- db_query("UPDATE {files} SET list = %d WHERE fid = %d", $node->list[$key], $key);
+ }
+ }
+ foreach ((array)$node->list as $key => $value) {
+ if (!$node->remove[$key]) {
+ db_query('UPDATE {files} SET list = %d WHERE fid = %d AND vid = %d', $node->list[$key], $key, $node->vid);
+ }
+ }
+ if ($node->old_vid) {
+ foreach ((array)$node->remove as $key => $remove) {
+ if (!$remove) {
+ $file = db_fetch_object(db_query('SELECT * FROM {files} WHERE vid = %d AND fid = %d', $node->old_vid, $key));
+ db_query("INSERT INTO {files} (fid, nid, vid, filename, filepath, filemime, filesize, list) VALUES (%d, %d, %d, '%s', '%s', '%s', %d, %d)",
+ $key, $node->nid, $node->vid, $file->filename, $file->filepath, $file->filemime, $file->filesize, $file->list);
}
}
}
@@ -392,8 +407,8 @@ function upload_form($node) {
function upload_load($node) {
$files = array();
- if ($node->nid) {
- $result = db_query("SELECT * FROM {files} WHERE nid = %d", $node->nid);
+ if ($node->vid) {
+ $result = db_query("SELECT * FROM {files} WHERE vid = %d", $node->vid);
while ($file = db_fetch_object($result)) {
$files[$file->fid] = $file;
}