- Patch #741578 by nikgregory, andypost, Berdir, noahb: 'File' is a reserved word that should not be used.
parent
e892ed5c31
commit
bdb7e56143
|
@ -509,13 +509,13 @@ function file_save(stdClass $file) {
|
|||
$file->filesize = filesize($file->uri);
|
||||
|
||||
if (empty($file->fid)) {
|
||||
drupal_write_record('file', $file);
|
||||
drupal_write_record('file_managed', $file);
|
||||
// Inform modules about the newly added file.
|
||||
module_invoke_all('file_insert', $file);
|
||||
entity_invoke('insert', 'file', $file);
|
||||
}
|
||||
else {
|
||||
drupal_write_record('file', $file, 'fid');
|
||||
drupal_write_record('file_managed', $file, 'fid');
|
||||
// Inform modules that the file has been updated.
|
||||
module_invoke_all('file_update', $file);
|
||||
entity_invoke('update', 'file', $file);
|
||||
|
@ -974,7 +974,7 @@ function file_delete(stdClass $file, $force = FALSE) {
|
|||
// Make sure the file is deleted before removing its row from the
|
||||
// database, so UIs can still find the file in the database.
|
||||
if (file_unmanaged_delete($file->uri)) {
|
||||
db_delete('file')->condition('fid', $file->fid)->execute();
|
||||
db_delete('file_managed')->condition('fid', $file->fid)->execute();
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
|
@ -1069,7 +1069,7 @@ function file_unmanaged_delete_recursive($path) {
|
|||
* An integer containing the number of bytes used.
|
||||
*/
|
||||
function file_space_used($uid = NULL, $status = FILE_STATUS_PERMANENT) {
|
||||
$query = db_select('file', 'f');
|
||||
$query = db_select('file_managed', 'f');
|
||||
// Use separate placeholders for the status to avoid a bug in some versions
|
||||
// of PHP. See http://drupal.org/node/352956.
|
||||
$query->where('f.status & :status1 = :status2', array(':status1' => $status, ':status2' => $status));
|
||||
|
@ -1083,9 +1083,9 @@ function file_space_used($uid = NULL, $status = FILE_STATUS_PERMANENT) {
|
|||
/**
|
||||
* Saves a file upload to a new location.
|
||||
*
|
||||
* The file will be added to the {file} table as a temporary file. Temporary
|
||||
* files are periodically cleaned. To make the file a permanent file, assign
|
||||
* the status and use file_save() to save the changes.
|
||||
* The file will be added to the {file_managed} table as a temporary file.
|
||||
* Temporary files are periodically cleaned. To make the file a permanent file,
|
||||
* assign the status and use file_save() to save the changes.
|
||||
*
|
||||
* @param $source
|
||||
* A string specifying the filepath or URI of the uploaded file to save.
|
||||
|
@ -1504,7 +1504,8 @@ function file_save_data($data, $destination = NULL, $replace = FILE_EXISTS_RENAM
|
|||
* Save a string to the specified destination without invoking file API.
|
||||
*
|
||||
* This function is identical to file_save_data() except the file will not be
|
||||
* saved to the {file} table and none of the file_* hooks will be called.
|
||||
* saved to the {file_managed} table and none of the file_* hooks will be
|
||||
* called.
|
||||
*
|
||||
* @param $data
|
||||
* A string containing the contents of the file.
|
||||
|
|
|
@ -197,8 +197,8 @@ function drupal_build_form($form_id, &$form_state) {
|
|||
// $menu_get_item() is not available at installation time.
|
||||
if (!isset($form_state['build_info']['file']) && !defined('MAINTENANCE_MODE')) {
|
||||
$item = menu_get_item();
|
||||
if (!empty($item['file'])) {
|
||||
$form_state['build_info']['file'] = $item['file'];
|
||||
if (!empty($item['include_file'])) {
|
||||
$form_state['build_info']['file'] = $item['include_file'];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -463,8 +463,8 @@ function menu_execute_active_handler($path = NULL, $deliver = TRUE) {
|
|||
// to make alterations just for this request.
|
||||
drupal_alter('menu_active_handler', $router_item, $path);
|
||||
if ($router_item['access']) {
|
||||
if ($router_item['file']) {
|
||||
require_once DRUPAL_ROOT . '/' . $router_item['file'];
|
||||
if ($router_item['include_file']) {
|
||||
require_once DRUPAL_ROOT . '/' . $router_item['include_file'];
|
||||
}
|
||||
$page_callback_result = call_user_func_array($router_item['page_callback'], $router_item['page_arguments']);
|
||||
}
|
||||
|
@ -3271,7 +3271,7 @@ function _menu_router_save($menu, $masks) {
|
|||
'description',
|
||||
'position',
|
||||
'weight',
|
||||
'file',
|
||||
'include_file',
|
||||
));
|
||||
|
||||
$num_records = 0;
|
||||
|
@ -3302,7 +3302,7 @@ function _menu_router_save($menu, $masks) {
|
|||
'description' => $item['description'],
|
||||
'position' => $item['position'],
|
||||
'weight' => $item['weight'],
|
||||
'file' => $item['include file'],
|
||||
'include_file' => $item['include file'],
|
||||
));
|
||||
|
||||
// Execute in batches to avoid the memory overhead of all of those records
|
||||
|
|
|
@ -194,7 +194,7 @@ class FileTestCase extends DrupalWebTestCase {
|
|||
$file->status = 0;
|
||||
// Write the record directly rather than calling file_save() so we don't
|
||||
// invoke the hooks.
|
||||
$this->assertNotIdentical(drupal_write_record('file', $file), FALSE, t('The file was added to the database.'), 'Create test file');
|
||||
$this->assertNotIdentical(drupal_write_record('file_managed', $file), FALSE, t('The file was added to the database.'), 'Create test file');
|
||||
|
||||
return $file;
|
||||
}
|
||||
|
@ -289,21 +289,21 @@ class FileSpaceUsedTest extends FileTestCase {
|
|||
|
||||
// Create records for a couple of users with different sizes.
|
||||
$file = array('uid' => 2, 'uri' => 'public://example1.txt', 'filesize' => 50, 'status' => FILE_STATUS_PERMANENT);
|
||||
drupal_write_record('file', $file);
|
||||
drupal_write_record('file_managed', $file);
|
||||
$file = array('uid' => 2, 'uri' => 'public://example2.txt', 'filesize' => 20, 'status' => FILE_STATUS_PERMANENT);
|
||||
drupal_write_record('file', $file);
|
||||
drupal_write_record('file_managed', $file);
|
||||
$file = array('uid' => 3, 'uri' => 'public://example3.txt', 'filesize' => 100, 'status' => FILE_STATUS_PERMANENT);
|
||||
drupal_write_record('file', $file);
|
||||
drupal_write_record('file_managed', $file);
|
||||
$file = array('uid' => 3, 'uri' => 'public://example4.txt', 'filesize' => 200, 'status' => FILE_STATUS_PERMANENT);
|
||||
drupal_write_record('file', $file);
|
||||
drupal_write_record('file_managed', $file);
|
||||
|
||||
// Now create some with other statuses. These values were chosen arbitrarily
|
||||
// for the sole purpose of testing that bitwise operators were used
|
||||
// correctly on the field.
|
||||
$file = array('uid' => 2, 'uri' => 'public://example5.txt', 'filesize' => 1, 'status' => 2 | 8);
|
||||
drupal_write_record('file', $file);
|
||||
drupal_write_record('file_managed', $file);
|
||||
$file = array('uid' => 3, 'uri' => 'public://example6.txt', 'filesize' => 3, 'status' => 2 | 4);
|
||||
drupal_write_record('file', $file);
|
||||
drupal_write_record('file_managed', $file);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -560,7 +560,7 @@ class FileSaveUploadTest extends FileHookTestCase {
|
|||
$this->image = current($this->drupalGetTestFiles('image'));
|
||||
$this->assertTrue(is_file($this->image->uri), t("The file we're going to upload exists."));
|
||||
|
||||
$this->maxFidBefore = db_query('SELECT MAX(fid) AS fid FROM {file}')->fetchField();
|
||||
$this->maxFidBefore = db_query('SELECT MAX(fid) AS fid FROM {file_managed}')->fetchField();
|
||||
|
||||
// Upload with replace to gurantee there's something there.
|
||||
$edit = array(
|
||||
|
@ -581,7 +581,7 @@ class FileSaveUploadTest extends FileHookTestCase {
|
|||
* Test the file_save_upload() function.
|
||||
*/
|
||||
function testNormal() {
|
||||
$max_fid_after = db_query('SELECT MAX(fid) AS fid FROM {file}')->fetchField();
|
||||
$max_fid_after = db_query('SELECT MAX(fid) AS fid FROM {file_managed}')->fetchField();
|
||||
$this->assertTrue($max_fid_after > $this->maxFidBefore, t('A new file was created.'));
|
||||
$file1 = file_load($max_fid_after);
|
||||
$this->assertTrue($file1, t('Loaded the file.'));
|
||||
|
@ -592,13 +592,13 @@ class FileSaveUploadTest extends FileHookTestCase {
|
|||
file_test_reset();
|
||||
|
||||
// Upload a second file.
|
||||
$max_fid_before = db_query('SELECT MAX(fid) AS fid FROM {file}')->fetchField();
|
||||
$max_fid_before = db_query('SELECT MAX(fid) AS fid FROM {file_managed}')->fetchField();
|
||||
$image2 = current($this->drupalGetTestFiles('image'));
|
||||
$edit = array('files[file_test_upload]' => drupal_realpath($image2->uri));
|
||||
$this->drupalPost('file-test/upload', $edit, t('Submit'));
|
||||
$this->assertResponse(200, t('Received a 200 response for posted test file.'));
|
||||
$this->assertRaw(t('You WIN!'));
|
||||
$max_fid_after = db_query('SELECT MAX(fid) AS fid FROM {file}')->fetchField();
|
||||
$max_fid_after = db_query('SELECT MAX(fid) AS fid FROM {file_managed}')->fetchField();
|
||||
|
||||
// Check that the correct hooks were called.
|
||||
$this->assertFileHooksCalled(array('validate', 'insert'));
|
||||
|
@ -1680,7 +1680,7 @@ class FileSaveTest extends FileHookTestCase {
|
|||
|
||||
$this->assertNotNull($saved_file, t("Saving the file should give us back a file object."), 'File');
|
||||
$this->assertTrue($saved_file->fid > 0, t("A new file ID is set when saving a new file to the database."), 'File');
|
||||
$loaded_file = db_query('SELECT * FROM {file} f WHERE f.fid = :fid', array(':fid' => $saved_file->fid))->fetch(PDO::FETCH_OBJ);
|
||||
$loaded_file = db_query('SELECT * FROM {file_managed} f WHERE f.fid = :fid', array(':fid' => $saved_file->fid))->fetch(PDO::FETCH_OBJ);
|
||||
$this->assertNotNull($loaded_file, t("Record exists in the database."));
|
||||
$this->assertEqual($loaded_file->status, $file->status, t("Status was saved correctly."));
|
||||
$this->assertEqual($saved_file->filesize, filesize($file->uri), t("File size was set correctly."), 'File');
|
||||
|
@ -1697,7 +1697,7 @@ class FileSaveTest extends FileHookTestCase {
|
|||
|
||||
$this->assertEqual($resaved_file->fid, $saved_file->fid, t("The file ID of an existing file is not changed when updating the database."), 'File');
|
||||
$this->assertTrue($resaved_file->timestamp >= $saved_file->timestamp, t("Timestamp didn't go backwards."), 'File');
|
||||
$loaded_file = db_query('SELECT * FROM {file} f WHERE f.fid = :fid', array(':fid' => $saved_file->fid))->fetch(PDO::FETCH_OBJ);
|
||||
$loaded_file = db_query('SELECT * FROM {file_managed} f WHERE f.fid = :fid', array(':fid' => $saved_file->fid))->fetch(PDO::FETCH_OBJ);
|
||||
$this->assertNotNull($loaded_file, t("Record still exists in the database."), 'File');
|
||||
$this->assertEqual($loaded_file->status, $saved_file->status, t("Status was saved correctly."));
|
||||
}
|
||||
|
|
|
@ -1783,7 +1783,7 @@ function hook_file_download($uri) {
|
|||
if (!file_prepare_directory($uri)) {
|
||||
$uri = FALSE;
|
||||
}
|
||||
$result = db_query("SELECT f.* FROM {file} f INNER JOIN {upload} u ON f.fid = u.fid WHERE uri = :uri", array('uri' => $uri));
|
||||
$result = db_query("SELECT f.* FROM {file_managed} f INNER JOIN {upload} u ON f.fid = u.fid WHERE uri = :uri", array('uri' => $uri));
|
||||
foreach ($result as $file) {
|
||||
if (!user_access('view uploaded files')) {
|
||||
return -1;
|
||||
|
|
|
@ -692,7 +692,7 @@ function system_schema() {
|
|||
'primary key' => array('type', 'language'),
|
||||
);
|
||||
|
||||
$schema['file'] = array(
|
||||
$schema['file_managed'] = array(
|
||||
'description' => 'Stores information for uploaded files.',
|
||||
'fields' => array(
|
||||
'fid' => array(
|
||||
|
@ -983,10 +983,10 @@ function system_schema() {
|
|||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
'file' => array(
|
||||
'include_file' => array(
|
||||
'description' => 'The file to include for this element, usually the page callback function lives in this file.',
|
||||
'type' => 'text',
|
||||
'size' => 'medium'
|
||||
'size' => 'medium',
|
||||
),
|
||||
),
|
||||
'indexes' => array(
|
||||
|
@ -2094,7 +2094,7 @@ function system_update_7033() {
|
|||
}
|
||||
|
||||
/**
|
||||
* Migrate the file_downloads setting and create the new {file} table.
|
||||
* Migrate the file_downloads setting and create the new {file_managed} table.
|
||||
*/
|
||||
function system_update_7034() {
|
||||
$files_directory = variable_get('file_directory_path', NULL);
|
||||
|
@ -2112,7 +2112,7 @@ function system_update_7034() {
|
|||
}
|
||||
variable_del('file_downloads');
|
||||
|
||||
$schema['file'] = array(
|
||||
$schema['file_managed'] = array(
|
||||
'description' => 'Stores information for uploaded files.',
|
||||
'fields' => array(
|
||||
'fid' => array(
|
||||
|
@ -2181,11 +2181,11 @@ function system_update_7034() {
|
|||
'primary key' => array('fid'),
|
||||
);
|
||||
|
||||
db_create_table('file', $schema['file']);
|
||||
db_create_table('file_managed', $schema['file_managed']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrate upload module files to the new {file} table.
|
||||
* Migrate upload module files to the new {file_managed} table.
|
||||
*/
|
||||
function system_update_7035() {
|
||||
if (!db_table_exists('upload')) {
|
||||
|
@ -2205,7 +2205,7 @@ function system_update_7035() {
|
|||
foreach ($result as $file) {
|
||||
$file['uri'] = $scheme . str_replace($basename, '', $file['uri']);
|
||||
$file['uri'] = file_stream_wrapper_uri_normalize($file['uri']);
|
||||
db_insert('file')->fields($file)->execute();
|
||||
db_insert('file_managed')->fields($file)->execute();
|
||||
$fids[] = $file['fid'];
|
||||
}
|
||||
// TODO: delete the found fids from {files}?
|
||||
|
@ -2390,6 +2390,13 @@ function system_update_7051() {
|
|||
db_change_field('blocked_ips', 'ip', 'ip', array('description' => 'IP address', 'type' => 'varchar', 'length' => 40, 'not null' => TRUE, 'default' => ''));
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename file to include_file in {menu_router} table.
|
||||
*/
|
||||
function system_update_7052() {
|
||||
db_change_field('menu_router', 'file', 'include_file', array('type' => 'text', 'size' => 'medium'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @} End of "defgroup updates-6.x-to-7.x"
|
||||
* The next series of updates should start at 8000.
|
||||
|
|
|
@ -260,7 +260,7 @@ function system_entity_info() {
|
|||
return array(
|
||||
'file' => array(
|
||||
'label' => t('File'),
|
||||
'base table' => 'file',
|
||||
'base table' => 'file_managed',
|
||||
'entity keys' => array(
|
||||
'id' => 'fid',
|
||||
),
|
||||
|
@ -2782,7 +2782,7 @@ function system_cron() {
|
|||
// Remove temporary files that are older than DRUPAL_MAXIMUM_TEMP_FILE_AGE.
|
||||
// Use separate placeholders for the status to avoid a bug in some versions
|
||||
// of PHP. See http://drupal.org/node/352956.
|
||||
$result = db_query('SELECT fid FROM {file} WHERE status & :permanent1 <> :permanent2 AND timestamp < :timestamp', array(
|
||||
$result = db_query('SELECT fid FROM {file_managed} WHERE status & :permanent1 <> :permanent2 AND timestamp < :timestamp', array(
|
||||
':permanent1' => FILE_STATUS_PERMANENT,
|
||||
':permanent2' => FILE_STATUS_PERMANENT,
|
||||
':timestamp' => REQUEST_TIME - DRUPAL_MAXIMUM_TEMP_FILE_AGE
|
||||
|
|
|
@ -469,7 +469,7 @@ class CronRunTestCase extends DrupalWebTestCase {
|
|||
function testTempFileCleanup() {
|
||||
// Temporary file that is older than DRUPAL_MAXIMUM_TEMP_FILE_AGE.
|
||||
$temp_old = file_save_data('');
|
||||
db_update('file')
|
||||
db_update('file_managed')
|
||||
->fields(array(
|
||||
'status' => 0,
|
||||
'timestamp' => 1,
|
||||
|
@ -480,7 +480,7 @@ class CronRunTestCase extends DrupalWebTestCase {
|
|||
|
||||
// Temporary file that is less than DRUPAL_MAXIMUM_TEMP_FILE_AGE.
|
||||
$temp_new = file_save_data('');
|
||||
db_update('file')
|
||||
db_update('file_managed')
|
||||
->fields(array('status' => 0))
|
||||
->condition('fid', $temp_new->fid)
|
||||
->execute();
|
||||
|
@ -488,7 +488,7 @@ class CronRunTestCase extends DrupalWebTestCase {
|
|||
|
||||
// Permanent file that is older than DRUPAL_MAXIMUM_TEMP_FILE_AGE.
|
||||
$perm_old = file_save_data('');
|
||||
db_update('file')
|
||||
db_update('file_managed')
|
||||
->fields(array('timestamp' => 1))
|
||||
->condition('fid', $temp_old->fid)
|
||||
->execute();
|
||||
|
|
|
@ -201,7 +201,7 @@ function user_schema() {
|
|||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
'description' => "Foreign key: {file}.fid of user's picture.",
|
||||
'description' => "Foreign key: {file_managed}.fid of user's picture.",
|
||||
),
|
||||
'init' => array(
|
||||
'type' => 'varchar',
|
||||
|
@ -473,7 +473,8 @@ function user_update_7003() {
|
|||
}
|
||||
|
||||
/**
|
||||
* Add the user's pictures to the {file} table and make them managed files.
|
||||
* Add the user's pictures to the {file_managed} table and make them managed
|
||||
* files.
|
||||
*/
|
||||
function user_update_7004(&$sandbox) {
|
||||
|
||||
|
@ -481,7 +482,7 @@ function user_update_7004(&$sandbox) {
|
|||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
'description' => t("Foreign key: {file}.fid of user's picture."),
|
||||
'description' => t("Foreign key: {file_managed}.fid of user's picture."),
|
||||
);
|
||||
|
||||
if (!isset($sandbox['progress'])) {
|
||||
|
@ -498,8 +499,8 @@ function user_update_7004(&$sandbox) {
|
|||
$sandbox['max'] = db_query("SELECT COUNT(*) FROM {users} WHERE picture <> ''")->fetchField();
|
||||
}
|
||||
|
||||
// As a batch operation move the photos into the {file} table and update the
|
||||
// {users} records.
|
||||
// As a batch operation move the photos into the {file_managed} table and
|
||||
// update the {users} records.
|
||||
$limit = 500;
|
||||
$result = db_query_range("SELECT uid, picture FROM {users} WHERE picture <> '' AND uid > :uid ORDER BY uid", 0, $limit, array(':uid' => $sandbox['last_user_processed']));
|
||||
foreach ($result as $user) {
|
||||
|
|
Loading…
Reference in New Issue