summaryrefslogtreecommitdiff
path: root/modules/system
diff options
context:
space:
mode:
Diffstat (limited to 'modules/system')
-rw-r--r--modules/system/system.install33
-rw-r--r--modules/system/system.module56
-rw-r--r--modules/system/system.schema33
3 files changed, 84 insertions, 38 deletions
diff --git a/modules/system/system.install b/modules/system/system.install
index d3bfd6ed7..96d64bfab 100644
--- a/modules/system/system.install
+++ b/modules/system/system.install
@@ -3307,6 +3307,39 @@ function system_update_6021() {
}
/**
+ * Update files tables to associate files to a uid by default instead of a nid.
+ * Rename file_revisions to upload since it should only be used by the upload
+ * module used by upload to link files to nodes.
+ */
+function system_update_6022() {
+ $ret = array();
+
+ // Rename the nid field to vid, add status and timestamp fields, and indexes.
+ db_drop_index($ret, 'files', 'nid');
+ db_change_field($ret, 'files', 'nid', 'uid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
+ db_add_field($ret, 'files', 'status', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
+ db_add_field($ret, 'files', 'timestamp', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
+ db_add_index($ret, 'files', 'uid', array('uid'));
+ db_add_index($ret, 'files', 'status', array('status'));
+ db_add_index($ret, 'files', 'timestamp', array('timestamp'));
+
+ // Rename the file_revisions table to upload then add nid column. Since we're
+ // changing the table name we need to drop and re-add the vid index so both
+ // pgsql ends up with the corect index name.
+ db_drop_index($ret, 'file_revisions', 'vid');
+ db_rename_table($ret, 'file_revisions', 'upload');
+ db_add_field($ret, 'upload', 'nid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
+ db_add_index($ret, 'upload', 'nid', array('nid'));
+ db_add_index($ret, 'upload', 'vid', array('vid'));
+
+ // The nid column was renamed to uid. Use the old nid to find the node's uid.
+ $ret[] = update_sql('UPDATE {files} f JOIN {node} n ON f.uid = n.nid SET f.uid = n.uid');
+ // Use the existing vid to find the nid.
+ $ret[] = update_sql('UPDATE {upload} u JOIN {node_revisions} r ON u.vid = r.vid SET u.nid = r.nid');
+
+ return $ret;
+}
+/**
* @} End of "defgroup updates-5.x-to-6.x"
* The next series of updates should start at 7000.
*/
diff --git a/modules/system/system.module b/modules/system/system.module
index 53b496d30..3a3e094c3 100644
--- a/modules/system/system.module
+++ b/modules/system/system.module
@@ -13,6 +13,9 @@ define('DRUPAL_MINIMUM_MYSQL', '4.1.0'); // If using MySQL
define('DRUPAL_MINIMUM_PGSQL', '7.4'); // If using PostgreSQL
define('DRUPAL_MINIMUM_APACHE', '1.3'); // If using Apache
+// Maximum age of temporary files in seconds.
+define('DRUPAL_MAXIMUM_TEMP_FILE_AGE', 1440);
+
/**
* Implementation of hook_help().
*/
@@ -83,7 +86,7 @@ function system_theme() {
* Implementation of hook_perm().
*/
function system_perm() {
- return array('administer site configuration', 'access administration pages', 'select different theme');
+ return array('administer site configuration', 'access administration pages', 'select different theme', 'administer files');
}
/**
@@ -2171,28 +2174,29 @@ function system_theme_settings($key = '') {
$form['var'] = array('#type' => 'hidden', '#value' => $var);
// Check for a new uploaded logo, and use that instead.
- if ($file = file_check_upload('logo_upload')) {
- if ($info = image_get_info($file->filepath)) {
- $parts = pathinfo($file->filename);
- $filename = ($key) ? str_replace('/', '_', $key) .'_logo.'. $parts['extension'] : 'logo.'. $parts['extension'];
-
- if ($file = file_save_upload('logo_upload', $filename, 1)) {
- $_POST['default_logo'] = 0;
- $_POST['logo_path'] = $file->filepath;
- $_POST['toggle_logo'] = 1;
- }
- }
- else {
- form_set_error('file_upload', t('Only JPEG, PNG and GIF images are allowed to be used as logos.'));
+ if ($file = file_save_upload('logo_upload', array('file_validate_is_image' => array()))) {
+ $parts = pathinfo($file->filename);
+ $filename = ($key) ? str_replace('/', '_', $key) .'_logo.'. $parts['extension'] : 'logo.'. $parts['extension'];
+
+ // The image was saved using file_save_upload() and was added to the
+ // files table as a temorary file. We'll make a copy and let the garbage
+ // collector delete the original upload.
+ if (file_copy($file, $filename, FILE_EXISTS_REPLACE)) {
+ $_POST['default_logo'] = 0;
+ $_POST['logo_path'] = $file->filepath;
+ $_POST['toggle_logo'] = 1;
}
}
// Check for a new uploaded favicon, and use that instead.
- if ($file = file_check_upload('favicon_upload')) {
+ if ($file = file_save_upload('favicon_upload')) {
$parts = pathinfo($file->filename);
$filename = ($key) ? str_replace('/', '_', $key) .'_favicon.'. $parts['extension'] : 'favicon.'. $parts['extension'];
- if ($file = file_save_upload('favicon_upload', $filename, 1)) {
+ // The image was saved using file_save_upload() and was added to the
+ // files table as a temorary file. We'll make a copy and let the garbage
+ // collector delete the original upload.
+ if (file_copy($file, $filename)) {
$_POST['default_favicon'] = 0;
$_POST['favicon_path'] = $file->filepath;
$_POST['toggle_favicon'] = 1;
@@ -2636,13 +2640,27 @@ function theme_system_admin_by_module($menu_items) {
/**
* Implementation of hook_cron().
*
- * Remove older rows from flood table
+ * Remove older rows from flood and batch table. Remove old temporary files.
*/
function system_cron() {
- // Cleanup the flood
+ // Cleanup the flood.
db_query('DELETE FROM {flood} WHERE timestamp < %d', time() - 3600);
- // Cleanup the batch table
+ // Cleanup the batch table.
db_query('DELETE FROM {batch} WHERE timestamp < %d', time() - 864000);
+
+ // Remove temporary files that are older than DRUPAL_MAXIMUM_TEMP_FILE_AGE.
+ $result = db_query('SELECT * FROM {files} WHERE status = %s and timestamp < %d', FILE_STATUS_TEMPORARY, time() - DRUPAL_MAXIMUM_TEMP_FILE_AGE);
+ while ($file = db_fetch_object($result)) {
+ if (file_exists($file->filepath)) {
+ // If files that exist cannot be deleted, continue so the database remains
+ // consistant.
+ if (!file_delete($file->filepath)) {
+ watchdog('file system', t('Could not delete temporary file "%path" during garbage collection', array('%path' => $file->filepath)), 'error');
+ continue;
+ }
+ }
+ db_query('DELETE FROM {files} WHERE fid = %d', $file->fid);
+ }
}
/**
diff --git a/modules/system/system.schema b/modules/system/system.schema
index 608d752d8..5cf4b21c7 100644
--- a/modules/system/system.schema
+++ b/modules/system/system.schema
@@ -32,26 +32,21 @@ function system_schema() {
$schema['files'] = array(
'fields' => array(
- 'fid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
- 'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
- 'filename' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
- 'filepath' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
- 'filemime' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
- 'filesize' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0)
- ),
- 'indexes' => array('nid' => array('nid')),
- 'primary key' => array('fid'),
- );
-
- $schema['file_revisions'] = array(
- 'fields' => array(
- 'fid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
- 'vid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
- 'description' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
- 'list' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'size' => 'tiny')
+ 'fid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
+ 'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
+ 'filename' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
+ 'filepath' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
+ 'filemime' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
+ 'filesize' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
+ 'status' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
+ 'timestamp' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
),
- 'primary key' => array('fid', 'vid'),
- 'indexes' => array('vid' => array('vid')),
+ 'indexes' => array(
+ 'uid' => array('uid'),
+ 'status' => array('status'),
+ 'timestamp' => array('timestamp'),
+ ),
+ 'primary key' => array('fid'),
);
$schema['flood'] = array(