- Patch #380064 by c960657: make file_scan_directory() use save property names as file_load().

merge-requests/26/head
Dries Buytaert 2009-02-22 17:55:30 +00:00
parent b3e36d655c
commit 5d658d0848
16 changed files with 109 additions and 107 deletions

View File

@ -1395,9 +1395,9 @@ function file_download() {
* the provided directory. Defaults to TRUE. * the provided directory. Defaults to TRUE.
* - 'key' * - 'key'
* The key to be used for the returned array of files. Possible values are * The key to be used for the returned array of files. Possible values are
* "filename", for the path starting with $dir, "basename", for the * 'filepath', for the path starting with $dir, 'filename', for the
* basename of the file, and "name" for the name of the file without an * basename of the file, and 'name' for the name of the file without an
* extension. Defaults to 'filename'. * extension. Defaults to 'filepath'.
* - 'min_depth' * - 'min_depth'
* Minimum depth of directories to return files from. Defaults to 0. * Minimum depth of directories to return files from. Defaults to 0.
* @param $depth * @param $depth
@ -1405,7 +1405,7 @@ function file_download() {
* should not be passed. * should not be passed.
* @return * @return
* An associative array (keyed on the provided key) of objects with * An associative array (keyed on the provided key) of objects with
* "filename", "basename", and "name" members corresponding to the * 'filepath', 'filename', and 'name' members corresponding to the
* matching files. * matching files.
*/ */
function file_scan_directory($dir, $mask, $options = array(), $depth = 0) { function file_scan_directory($dir, $mask, $options = array(), $depth = 0) {
@ -1414,33 +1414,32 @@ function file_scan_directory($dir, $mask, $options = array(), $depth = 0) {
'nomask' => '/(\.\.?|CVS)$/', 'nomask' => '/(\.\.?|CVS)$/',
'callback' => 0, 'callback' => 0,
'recurse' => TRUE, 'recurse' => TRUE,
'key' => 'filename', 'key' => 'filepath',
'min_depth' => 0, 'min_depth' => 0,
); );
$options['key'] = (in_array($options['key'], array('filename', 'basename', 'name')) ? $options['key'] : 'filename'); $options['key'] = in_array($options['key'], array('filepath', 'filename', 'name')) ? $options['key'] : 'filepath';
$files = array(); $files = array();
if (is_dir($dir) && $handle = opendir($dir)) { if (is_dir($dir) && $handle = opendir($dir)) {
while (FALSE !== ($file = readdir($handle))) { while (FALSE !== ($filename = readdir($handle))) {
if (!preg_match($options['nomask'], $file) && $file[0] != '.') { if (!preg_match($options['nomask'], $filename) && $filename[0] != '.') {
if (is_dir("$dir/$file") && $options['recurse']) { $filepath = "$dir/$filename";
if (is_dir($filepath) && $options['recurse']) {
// Give priority to files in this folder by merging them in after any subdirectory files. // Give priority to files in this folder by merging them in after any subdirectory files.
$files = array_merge(file_scan_directory("$dir/$file", $mask, $options, $depth + 1), $files); $files = array_merge(file_scan_directory($filepath, $mask, $options, $depth + 1), $files);
} }
elseif ($depth >= $options['min_depth'] && preg_match($mask, $file)) { elseif ($depth >= $options['min_depth'] && preg_match($mask, $filename)) {
// Always use this match over anything already set in $files with the // Always use this match over anything already set in $files with the
// same $$options['key']. // same $$options['key'].
$filename = "$dir/$file"; $file = (object) array(
$basename = basename($file); 'filepath' => $filepath,
$name = substr($basename, 0, strrpos($basename, '.'));
$files[${$options['key']}] = (object) array(
'filename' => $filename, 'filename' => $filename,
'basename' => $basename, 'name' => pathinfo($filename, PATHINFO_FILENAME),
'name' => $name,
); );
$key = $options['key'];
$files[$file->$key] = $file;
if ($options['callback']) { if ($options['callback']) {
$options['callback']($filename); $options['callback']($filepath);
} }
} }
} }

View File

@ -216,9 +216,9 @@ function drupal_detect_database_types() {
// file for the driver explicitly. // file for the driver explicitly.
foreach (file_scan_directory(DRUPAL_ROOT . '/includes/database', '/^[a-z]*$/i', array('recurse' => FALSE)) as $file) { foreach (file_scan_directory(DRUPAL_ROOT . '/includes/database', '/^[a-z]*$/i', array('recurse' => FALSE)) as $file) {
include_once "{$file->filename}/install.inc"; include_once "{$file->filepath}/install.inc";
include_once "{$file->filename}/database.inc"; include_once "{$file->filepath}/database.inc";
$drivers[$file->basename] = $file->filename; $drivers[$file->filename] = $file->filepath;
} }
foreach ($drivers as $driver => $file) { foreach ($drivers as $driver => $file) {
@ -934,7 +934,7 @@ function drupal_check_profile($profile) {
// Collect requirement testing results // Collect requirement testing results
$requirements = array(); $requirements = array();
foreach ($installs as $install) { foreach ($installs as $install) {
require_once DRUPAL_ROOT . '/' . $install->filename; require_once DRUPAL_ROOT . '/' . $install->filepath;
$function = $install->name. '_requirements'; $function = $install->name. '_requirements';
if (function_exists($function)) { if (function_exists($function)) {
$requirements = array_merge($requirements, $function('install')); $requirements = array_merge($requirements, $function('install'));
@ -974,7 +974,7 @@ function drupal_check_module($module) {
// Include install file // Include install file
$install = drupal_get_install_files(array($module)); $install = drupal_get_install_files(array($module));
if (isset($install[$module])) { if (isset($install[$module])) {
require_once DRUPAL_ROOT . '/' . $install[$module]->filename; require_once DRUPAL_ROOT . '/' . $install[$module]->filepath;
// Check requirements // Check requirements
$requirements = module_invoke($module, 'requirements', 'install'); $requirements = module_invoke($module, 'requirements', 'install');

View File

@ -2675,20 +2675,21 @@ function _locale_batch_build($files, $finished = NULL, $components = array()) {
$operations = array(); $operations = array();
foreach ($files as $file) { foreach ($files as $file) {
// We call _locale_batch_import for every batch operation. // We call _locale_batch_import for every batch operation.
$operations[] = array('_locale_batch_import', array($file->filename)); } $operations[] = array('_locale_batch_import', array($file->filepath));
$batch = array( }
'operations' => $operations, $batch = array(
'title' => $t('Importing interface translations'), 'operations' => $operations,
'init_message' => $t('Starting import'), 'title' => $t('Importing interface translations'),
'error_message' => $t('Error importing interface translations'), 'init_message' => $t('Starting import'),
'file' => 'includes/locale.inc', 'error_message' => $t('Error importing interface translations'),
// This is not a batch API construct, but data passed along to the 'file' => 'includes/locale.inc',
// installer, so we know what did we import already. // This is not a batch API construct, but data passed along to the
'#components' => $components, // installer, so we know what did we import already.
); '#components' => $components,
if (isset($finished)) { );
$batch['finished'] = $finished; if (isset($finished)) {
} $batch['finished'] = $finished;
}
return $batch; return $batch;
} }
return FALSE; return FALSE;

View File

@ -101,41 +101,41 @@ function module_rebuild_cache() {
'files' => array(), 'files' => array(),
); );
foreach ($files as $filename => $file) { foreach ($files as $filepath => $file) {
// Look for the info file. // Look for the info file.
$file->info = drupal_parse_info_file(dirname($file->filename) . '/' . $file->name . '.info'); $file->info = drupal_parse_info_file(dirname($file->filepath) . '/' . $file->name . '.info');
// Skip modules that don't provide info. // Skip modules that don't provide info.
if (empty($file->info)) { if (empty($file->info)) {
unset($files[$filename]); unset($files[$filepath]);
continue; continue;
} }
// Merge in defaults and save. // Merge in defaults and save.
$files[$filename]->info = $file->info + $defaults; $files[$filepath]->info = $file->info + $defaults;
// Invoke hook_system_info_alter() to give installed modules a chance to // Invoke hook_system_info_alter() to give installed modules a chance to
// modify the data in the .info files if necessary. // modify the data in the .info files if necessary.
drupal_alter('system_info', $files[$filename]->info, $files[$filename]); drupal_alter('system_info', $files[$filepath]->info, $files[$filepath]);
// Update the contents of the system table: // Update the contents of the system table:
if (isset($file->status) || (isset($file->old_filename) && $file->old_filename != $file->filename)) { if (isset($file->status) || (isset($file->old_filepath) && $file->old_filepath != $file->filepath)) {
db_update('system') db_update('system')
->fields(array( ->fields(array(
'info' => serialize($files[$filename]->info), 'info' => serialize($files[$filepath]->info),
'name' => $file->name, 'name' => $file->name,
'filename' => $file->filename)) 'filename' => $file->filepath))
->condition('filename', $file->old_filename) ->condition('filename', $file->old_filepath)
->execute(); ->execute();
} }
else { else {
// This is a new module. // This is a new module.
$files[$filename]->status = 0; $files[$filepath]->status = 0;
db_insert('system') db_insert('system')
->fields(array( ->fields(array(
'name' => $file->name, 'name' => $file->name,
'info' => serialize($files[$filename]->info), 'info' => serialize($files[$filepath]->info),
'type' => 'module', 'type' => 'module',
'filename' => $file->filename, 'filename' => $file->filepath,
'status' => 0)) 'status' => 0))
->execute(); ->execute();
} }
@ -535,7 +535,7 @@ function drupal_required_modules() {
$files = drupal_system_listing('/\.info$/', 'modules', 'name', 0); $files = drupal_system_listing('/\.info$/', 'modules', 'name', 0);
$required = array(); $required = array();
foreach ($files as $name => $file) { foreach ($files as $name => $file) {
$info = drupal_parse_info_file($file->filename); $info = drupal_parse_info_file($file->filepath);
if (!empty($info) && !empty($info['required']) && $info['required']) { if (!empty($info) && !empty($info['required']) && $info['required']) {
$required[] = $name; $required[] = $name;
} }

View File

@ -43,7 +43,7 @@ function _registry_rebuild() {
$files = array(); $files = array();
foreach (module_rebuild_cache() as $module) { foreach (module_rebuild_cache() as $module) {
if ($module->status) { if ($module->status) {
$dir = dirname($module->filename); $dir = dirname($module->filepath);
foreach ($module->info['files'] as $file) { foreach ($module->info['files'] as $file) {
$files["$dir/$file"] = array('module' => $module->name, 'weight' => $module->weight); $files["$dir/$file"] = array('module' => $module->name, 'weight' => $module->weight);
} }

View File

@ -831,7 +831,7 @@ function drupal_find_theme_templates($cache, $extension, $path) {
$files = drupal_system_listing($regex, $path, 'name', 0); $files = drupal_system_listing($regex, $path, 'name', 0);
foreach ($files as $template => $file) { foreach ($files as $template => $file) {
// Ignore sub-theme templates for the current theme. // Ignore sub-theme templates for the current theme.
if (strpos($file->filename, str_replace($subtheme_paths, '', $file->filename)) !== 0) { if (strpos($file->filepath, str_replace($subtheme_paths, '', $file->filepath)) !== 0) {
continue; continue;
} }
// Chop off the remaining extensions if there are any. $template already // Chop off the remaining extensions if there are any. $template already
@ -846,7 +846,7 @@ function drupal_find_theme_templates($cache, $extension, $path) {
if (isset($cache[$hook])) { if (isset($cache[$hook])) {
$templates[$hook] = array( $templates[$hook] = array(
'template' => $template, 'template' => $template,
'path' => dirname($file->filename), 'path' => dirname($file->filepath),
); );
} }
// Ensure that the pattern is maintained from base themes to its sub-themes. // Ensure that the pattern is maintained from base themes to its sub-themes.
@ -872,7 +872,7 @@ function drupal_find_theme_templates($cache, $extension, $path) {
// Put the underscores back in for the hook name and register this pattern. // Put the underscores back in for the hook name and register this pattern.
$templates[strtr($file, '-', '_')] = array( $templates[strtr($file, '-', '_')] = array(
'template' => $file, 'template' => $file,
'path' => dirname($files[$match]->filename), 'path' => dirname($files[$match]->filepath),
'arguments' => $info['arguments'], 'arguments' => $info['arguments'],
); );
} }

View File

@ -420,7 +420,7 @@ function install_select_profile() {
// Don't need to choose profile if only one available. // Don't need to choose profile if only one available.
if (sizeof($profiles) == 1) { if (sizeof($profiles) == 1) {
$profile = array_pop($profiles); $profile = array_pop($profiles);
require_once $profile->filename; require_once $profile->filepath;
return $profile->name; return $profile->name;
} }
elseif (sizeof($profiles) > 1) { elseif (sizeof($profiles) > 1) {
@ -451,7 +451,7 @@ function install_select_profile_form(&$form_state, $profile_files) {
$names = array(); $names = array();
foreach ($profile_files as $profile) { foreach ($profile_files as $profile) {
include_once DRUPAL_ROOT . '/' . $profile->filename; include_once DRUPAL_ROOT . '/' . $profile->filepath;
// Load profile details and store them for later retrieval. // Load profile details and store them for later retrieval.
$function = $profile->name . '_profile_details'; $function = $profile->name . '_profile_details';

View File

@ -68,7 +68,7 @@ class BlogAPITestCase extends DrupalWebTestCase {
// Upload file. // Upload file.
$file = current($this->drupalGetTestFiles('text')); $file = current($this->drupalGetTestFiles('text'));
$file_contents = file_get_contents($file->filename); $file_contents = file_get_contents($file->filepath);
$file = array(); $file = array();
$file['name'] = $this->randomName() . '.txt'; $file['name'] = $this->randomName() . '.txt';
$file['type'] = 'text'; $file['type'] = 'text';

View File

@ -593,9 +593,9 @@ class DrupalWebTestCase {
// If size is set then remove any files that are not of that size. // If size is set then remove any files that are not of that size.
if ($size !== NULL) { if ($size !== NULL) {
foreach ($files as $file) { foreach ($files as $file) {
$stats = stat($file->filename); $stats = stat($file->filepath);
if ($stats['size'] != $size) { if ($stats['size'] != $size) {
unset($files[$file->filename]); unset($files[$file->filepath]);
} }
} }
} }
@ -609,7 +609,7 @@ class DrupalWebTestCase {
*/ */
protected function drupalCompareFiles($file1, $file2) { protected function drupalCompareFiles($file1, $file2) {
// Determine which file is larger. // Determine which file is larger.
$compare_size = (filesize($file1->filename) > filesize($file2->filename)); $compare_size = (filesize($file1->filepath) > filesize($file2->filepath));
if (!$compare_size) { if (!$compare_size) {
// Both files were the same size, so return whichever one is alphabetically greater. // Both files were the same size, so return whichever one is alphabetically greater.
return strnatcmp($file1->name, $file2->name); return strnatcmp($file1->name, $file2->name);

View File

@ -33,7 +33,7 @@ function simpletest_install() {
$original = drupal_get_path('module', 'simpletest') . '/files'; $original = drupal_get_path('module', 'simpletest') . '/files';
$files = file_scan_directory($original, '/(html|image|javascript|php|sql)-.*/'); $files = file_scan_directory($original, '/(html|image|javascript|php|sql)-.*/');
foreach ($files as $file) { foreach ($files as $file) {
file_unmanaged_copy($file->filename, $path . '/' . $file->basename); file_unmanaged_copy($file->filepath, $path);
} }
$generated = TRUE; $generated = TRUE;
} }

View File

@ -465,7 +465,7 @@ function simpletest_get_all_tests() {
$tests_directory = $module_path . '/tests'; $tests_directory = $module_path . '/tests';
if (is_dir($tests_directory)) { if (is_dir($tests_directory)) {
foreach (file_scan_directory($tests_directory, '/\.test$/') as $file) { foreach (file_scan_directory($tests_directory, '/\.test$/') as $file) {
$files[] = $file->filename; $files[] = $file->filepath;
} }
} }
} }

View File

@ -21,14 +21,14 @@ function file_test_validator($file, $errors) {
* When the function is called with $reset parameter TRUE the cache is cleared * When the function is called with $reset parameter TRUE the cache is cleared
* and the results returned. * and the results returned.
* *
* @param $file * @param $filepath
* File object * File path
* @param $reset * @param $reset
* Boolean indicating that the stored files should be removed and returned. * Boolean indicating that the stored files should be removed and returned.
* @return * @return
* An array of all previous $file parameters since $reset was last called. * An array of all previous $file parameters since $reset was last called.
*/ */
function file_test_file_scan_callback($file, $reset = FALSE) { function file_test_file_scan_callback($filepath, $reset = FALSE) {
static $files = array(); static $files = array();
if ($reset) { if ($reset) {
@ -37,7 +37,7 @@ function file_test_file_scan_callback($file, $reset = FALSE) {
return $ret; return $ret;
} }
$files[] = $file; $files[] = $filepath;
} }
/** /**
@ -525,14 +525,14 @@ class FileSaveUploadTest extends FileHookTestCase {
$this->drupalLogin($account); $this->drupalLogin($account);
$this->image = current($this->drupalGetTestFiles('image')); $this->image = current($this->drupalGetTestFiles('image'));
$this->assertTrue(is_file($this->image->filename), t("The file we're going to upload exists.")); $this->assertTrue(is_file($this->image->filepath), t("The file we're going to upload exists."));
$this->maxFidBefore = db_query('SELECT MAX(fid) AS fid FROM {files}')->fetchField(); $this->maxFidBefore = db_query('SELECT MAX(fid) AS fid FROM {files}')->fetchField();
// Upload with replace to gurantee there's something there. // Upload with replace to gurantee there's something there.
$edit = array( $edit = array(
'file_test_replace' => FILE_EXISTS_REPLACE, 'file_test_replace' => FILE_EXISTS_REPLACE,
'files[file_test_upload]' => realpath($this->image->filename) 'files[file_test_upload]' => realpath($this->image->filepath)
); );
$this->drupalPost('file-test/upload', $edit, t('Submit')); $this->drupalPost('file-test/upload', $edit, t('Submit'));
$this->assertResponse(200, t('Received a 200 response for posted test file.')); $this->assertResponse(200, t('Received a 200 response for posted test file.'));
@ -559,7 +559,7 @@ class FileSaveUploadTest extends FileHookTestCase {
// Upload a second file. // Upload a second file.
$max_fid_before = db_query('SELECT MAX(fid) AS fid FROM {files}')->fetchField(); $max_fid_before = db_query('SELECT MAX(fid) AS fid FROM {files}')->fetchField();
$image2 = current($this->drupalGetTestFiles('image')); $image2 = current($this->drupalGetTestFiles('image'));
$edit = array('files[file_test_upload]' => realpath($image2->filename)); $edit = array('files[file_test_upload]' => realpath($image2->filepath));
$this->drupalPost('file-test/upload', $edit, t('Submit')); $this->drupalPost('file-test/upload', $edit, t('Submit'));
$this->assertResponse(200, t('Received a 200 response for posted test file.')); $this->assertResponse(200, t('Received a 200 response for posted test file.'));
$this->assertRaw(t('You WIN!')); $this->assertRaw(t('You WIN!'));
@ -584,7 +584,7 @@ class FileSaveUploadTest extends FileHookTestCase {
function testExistingRename() { function testExistingRename() {
$edit = array( $edit = array(
'file_test_replace' => FILE_EXISTS_RENAME, 'file_test_replace' => FILE_EXISTS_RENAME,
'files[file_test_upload]' => realpath($this->image->filename) 'files[file_test_upload]' => realpath($this->image->filepath)
); );
$this->drupalPost('file-test/upload', $edit, t('Submit')); $this->drupalPost('file-test/upload', $edit, t('Submit'));
$this->assertResponse(200, t('Received a 200 response for posted test file.')); $this->assertResponse(200, t('Received a 200 response for posted test file.'));
@ -600,7 +600,7 @@ class FileSaveUploadTest extends FileHookTestCase {
function testExistingReplace() { function testExistingReplace() {
$edit = array( $edit = array(
'file_test_replace' => FILE_EXISTS_REPLACE, 'file_test_replace' => FILE_EXISTS_REPLACE,
'files[file_test_upload]' => realpath($this->image->filename) 'files[file_test_upload]' => realpath($this->image->filepath)
); );
$this->drupalPost('file-test/upload', $edit, t('Submit')); $this->drupalPost('file-test/upload', $edit, t('Submit'));
$this->assertResponse(200, t('Received a 200 response for posted test file.')); $this->assertResponse(200, t('Received a 200 response for posted test file.'));
@ -616,7 +616,7 @@ class FileSaveUploadTest extends FileHookTestCase {
function testExistingError() { function testExistingError() {
$edit = array( $edit = array(
'file_test_replace' => FILE_EXISTS_ERROR, 'file_test_replace' => FILE_EXISTS_ERROR,
'files[file_test_upload]' => realpath($this->image->filename) 'files[file_test_upload]' => realpath($this->image->filepath)
); );
$this->drupalPost('file-test/upload', $edit, t('Submit')); $this->drupalPost('file-test/upload', $edit, t('Submit'));
$this->assertResponse(200, t('Received a 200 response for posted test file.')); $this->assertResponse(200, t('Received a 200 response for posted test file.'));
@ -829,16 +829,16 @@ class FileScanDirectoryTest extends FileTestCase {
// Check the first file. // Check the first file.
$file = reset($all_files); $file = reset($all_files);
$this->assertEqual(key($all_files), $file->filename, t('Correct array key was used for the first returned file.')); $this->assertEqual(key($all_files), $file->filepath, t('Correct array key was used for the first returned file.'));
$this->assertEqual($file->filename, $this->path . '/javascript-1.txt', t('First file name was set correctly.')); $this->assertEqual($file->filepath, $this->path . '/javascript-1.txt', t('First file name was set correctly.'));
$this->assertEqual($file->basename, 'javascript-1.txt', t('First basename was set correctly')); $this->assertEqual($file->filename, 'javascript-1.txt', t('First basename was set correctly'));
$this->assertEqual($file->name, 'javascript-1', t('First name was set correctly.')); $this->assertEqual($file->name, 'javascript-1', t('First name was set correctly.'));
// Check the second file. // Check the second file.
$file = next($all_files); $file = next($all_files);
$this->assertEqual(key($all_files), $file->filename, t('Correct array key was used for the second returned file.')); $this->assertEqual(key($all_files), $file->filepath, t('Correct array key was used for the second returned file.'));
$this->assertEqual($file->filename, $this->path . '/javascript-2.script', t('Second file name was set correctly.')); $this->assertEqual($file->filepath, $this->path . '/javascript-2.script', t('Second file name was set correctly.'));
$this->assertEqual($file->basename, 'javascript-2.script', t('Second basename was set correctly')); $this->assertEqual($file->filename, 'javascript-2.script', t('Second basename was set correctly'));
$this->assertEqual($file->name, 'javascript-2', t('Second name was set correctly.')); $this->assertEqual($file->name, 'javascript-2', t('Second name was set correctly.'));
} }
@ -879,13 +879,13 @@ class FileScanDirectoryTest extends FileTestCase {
function testOptionKey() { function testOptionKey() {
// "filename", for the path starting with $dir. // "filename", for the path starting with $dir.
$expected = array($this->path . '/javascript-1.txt', $this->path . '/javascript-2.script'); $expected = array($this->path . '/javascript-1.txt', $this->path . '/javascript-2.script');
$actual = array_keys(file_scan_directory($this->path, '/^javascript-/', array('key' => 'filename'))); $actual = array_keys(file_scan_directory($this->path, '/^javascript-/', array('key' => 'filepath')));
sort($actual); sort($actual);
$this->assertEqual($expected, $actual, t('Returned the correct values for the filename key.')); $this->assertEqual($expected, $actual, t('Returned the correct values for the filename key.'));
// "basename", for the basename of the file. // "basename", for the basename of the file.
$expected = array('javascript-1.txt', 'javascript-2.script'); $expected = array('javascript-1.txt', 'javascript-2.script');
$actual = array_keys(file_scan_directory($this->path, '/^javascript-/', array('key' => 'basename'))); $actual = array_keys(file_scan_directory($this->path, '/^javascript-/', array('key' => 'filename')));
sort($actual); sort($actual);
$this->assertEqual($expected, $actual, t('Returned the correct values for the basename key.')); $this->assertEqual($expected, $actual, t('Returned the correct values for the basename key.'));

View File

@ -1062,7 +1062,8 @@ function system_get_files_database(&$files, $type) {
$result = db_query("SELECT filename, name, type, status, schema_version, weight FROM {system} WHERE type = '%s'", $type); $result = db_query("SELECT filename, name, type, status, schema_version, weight FROM {system} WHERE type = '%s'", $type);
while ($file = db_fetch_object($result)) { while ($file = db_fetch_object($result)) {
if (isset($files[$file->name]) && is_object($files[$file->name])) { if (isset($files[$file->name]) && is_object($files[$file->name])) {
$file->old_filename = $file->filename; $file->filepath = $file->filename;
$file->old_filepath = $file->filepath;
foreach ($file as $key => $value) { foreach ($file as $key => $value) {
if (!isset($files[$file->name]) || !isset($files[$file->name]->$key)) { if (!isset($files[$file->name]) || !isset($files[$file->name]->$key)) {
$files[$file->name]->$key = $value; $files[$file->name]->$key = $value;
@ -1155,7 +1156,8 @@ function _system_theme_data() {
$sub_themes = array(); $sub_themes = array();
// Read info files for each theme // Read info files for each theme
foreach ($themes as $key => $theme) { foreach ($themes as $key => $theme) {
$themes[$key]->info = drupal_parse_info_file($theme->filename) + $defaults; $themes[$key]->filename = $theme->filepath;
$themes[$key]->info = drupal_parse_info_file($theme->filepath) + $defaults;
// Invoke hook_system_info_alter() to give installed modules a chance to // Invoke hook_system_info_alter() to give installed modules a chance to
// modify the data in the .info files if necessary. // modify the data in the .info files if necessary.
@ -1165,7 +1167,7 @@ function _system_theme_data() {
$sub_themes[] = $key; $sub_themes[] = $key;
} }
if (empty($themes[$key]->info['engine'])) { if (empty($themes[$key]->info['engine'])) {
$filename = dirname($themes[$key]->filename) . '/' . $themes[$key]->name . '.theme'; $filename = dirname($themes[$key]->filepath) . '/' . $themes[$key]->name . '.theme';
if (file_exists($filename)) { if (file_exists($filename)) {
$themes[$key]->owner = $filename; $themes[$key]->owner = $filename;
$themes[$key]->prefix = $key; $themes[$key]->prefix = $key;
@ -1174,7 +1176,7 @@ function _system_theme_data() {
else { else {
$engine = $themes[$key]->info['engine']; $engine = $themes[$key]->info['engine'];
if (isset($engines[$engine])) { if (isset($engines[$engine])) {
$themes[$key]->owner = $engines[$engine]->filename; $themes[$key]->owner = $engines[$engine]->filepath;
$themes[$key]->prefix = $engines[$engine]->name; $themes[$key]->prefix = $engines[$engine]->name;
$themes[$key]->template = TRUE; $themes[$key]->template = TRUE;
} }
@ -1184,7 +1186,7 @@ function _system_theme_data() {
$pathed_stylesheets = array(); $pathed_stylesheets = array();
foreach ($themes[$key]->info['stylesheets'] as $media => $stylesheets) { foreach ($themes[$key]->info['stylesheets'] as $media => $stylesheets) {
foreach ($stylesheets as $stylesheet) { foreach ($stylesheets as $stylesheet) {
$pathed_stylesheets[$media][$stylesheet] = dirname($themes[$key]->filename) . '/' . $stylesheet; $pathed_stylesheets[$media][$stylesheet] = dirname($themes[$key]->filepath) . '/' . $stylesheet;
} }
} }
$themes[$key]->info['stylesheets'] = $pathed_stylesheets; $themes[$key]->info['stylesheets'] = $pathed_stylesheets;
@ -1192,12 +1194,12 @@ function _system_theme_data() {
// Give the scripts proper path information. // Give the scripts proper path information.
$scripts = array(); $scripts = array();
foreach ($themes[$key]->info['scripts'] as $script) { foreach ($themes[$key]->info['scripts'] as $script) {
$scripts[$script] = dirname($themes[$key]->filename) . '/' . $script; $scripts[$script] = dirname($themes[$key]->filepath) . '/' . $script;
} }
$themes[$key]->info['scripts'] = $scripts; $themes[$key]->info['scripts'] = $scripts;
// Give the screenshot proper path information. // Give the screenshot proper path information.
if (!empty($themes[$key]->info['screenshot'])) { if (!empty($themes[$key]->info['screenshot'])) {
$themes[$key]->info['screenshot'] = dirname($themes[$key]->filename) . '/' . $themes[$key]->info['screenshot']; $themes[$key]->info['screenshot'] = dirname($themes[$key]->filepath) . '/' . $themes[$key]->info['screenshot'];
} }
} }

View File

@ -69,7 +69,7 @@ function _update_process_info_list(&$projects, $list, $project_type) {
// which is left alone by tar and correctly set to the time the .info file // which is left alone by tar and correctly set to the time the .info file
// was unpacked. // was unpacked.
if (!isset($file->info['_info_file_ctime'])) { if (!isset($file->info['_info_file_ctime'])) {
$info_filename = dirname($file->filename) . '/' . $file->name . '.info'; $info_filename = dirname($file->filepath) . '/' . $file->name . '.info';
$file->info['_info_file_ctime'] = filectime($info_filename); $file->info['_info_file_ctime'] = filectime($info_filename);
} }

View File

@ -39,7 +39,7 @@ class UploadTestCase extends DrupalWebTestCase {
// Create a node and attempt to attach files. // Create a node and attempt to attach files.
$node = $this->drupalCreateNode(); $node = $this->drupalCreateNode();
$text_files = $this->drupalGetTestFiles('text'); $text_files = $this->drupalGetTestFiles('text');
$files = array(current($text_files)->filename, next($text_files)->filename); $files = array(current($text_files)->filepath, next($text_files)->filepath);
$this->uploadFile($node, $files[0]); $this->uploadFile($node, $files[0]);
$this->uploadFile($node, $files[1]); $this->uploadFile($node, $files[1]);
@ -108,17 +108,17 @@ class UploadTestCase extends DrupalWebTestCase {
$text_file = current($this->drupalGetTestFiles('text')); $text_file = current($this->drupalGetTestFiles('text'));
// Select a file that's less than the 1MB upload limit so we only test one // Select a file that's less than the 1MB upload limit so we only test one
// limit at a time. // limit at a time.
$this->uploadFile($node, $text_file->filename, FALSE); $this->uploadFile($node, $text_file->filepath, FALSE);
// Test the error message in two steps in case there are additional errors // Test the error message in two steps in case there are additional errors
// that change the error message's format. // that change the error message's format.
$this->assertRaw(t('The specified file %name could not be uploaded.', array('%name' => $text_file->basename)), t('File %filename was not allowed to be uploaded', array('%filename' => $text_file->filename))); $this->assertRaw(t('The specified file %name could not be uploaded.', array('%name' => $text_file->filename)), t('File %filepath was not allowed to be uploaded', array('%filepath' => $text_file->filepath)));
$this->assertRaw(t('Only files with the following extensions are allowed: %files-allowed.', array('%files-allowed' => $settings['upload_extensions'])), t('File extension cited as reason for failure')); $this->assertRaw(t('Only files with the following extensions are allowed: %files-allowed.', array('%files-allowed' => $settings['upload_extensions'])), t('File extension cited as reason for failure'));
// Attempt to upload .html file when .html is only extension allowed. // Attempt to upload .html file when .html is only extension allowed.
$html_files = array_values($this->drupalGetTestFiles('html')); $html_files = array_values($this->drupalGetTestFiles('html'));
// Use the HTML file with the .html extension, $html_files[0] has a .txt // Use the HTML file with the .html extension, $html_files[0] has a .txt
// extension. // extension.
$html_file = $html_files[1]->filename; $html_file = $html_files[1]->filepath;
$this->uploadFile($node, $html_file); $this->uploadFile($node, $html_file);
$this->assertNoRaw(t('The specified file %name could not be uploaded.', array('%name' => basename($html_file))), t('File '. $html_file . ' was allowed to be uploaded')); $this->assertNoRaw(t('The specified file %name could not be uploaded.', array('%name' => basename($html_file))), t('File '. $html_file . ' was allowed to be uploaded'));
} }
@ -128,7 +128,7 @@ class UploadTestCase extends DrupalWebTestCase {
*/ */
function testLimit() { function testLimit() {
$files = $this->drupalGetTestFiles('text', 1310720); // 1 MB. $files = $this->drupalGetTestFiles('text', 1310720); // 1 MB.
$file = current($files)->filename; $file = current($files)->filepath;
$admin_user = $this->drupalCreateUser(array('administer site configuration')); $admin_user = $this->drupalCreateUser(array('administer site configuration'));
$web_user = $this->drupalCreateUser(array('access content', 'edit any page content', 'upload files', 'view uploaded files')); $web_user = $this->drupalCreateUser(array('access content', 'edit any page content', 'upload files', 'view uploaded files'));

View File

@ -535,7 +535,7 @@ class UserPictureTestCase extends DrupalWebTestCase {
$this->drupalLogin($this->user); $this->drupalLogin($this->user);
$image = current($this->drupalGetTestFiles('image')); $image = current($this->drupalGetTestFiles('image'));
$info = image_get_info($image->filename); $info = image_get_info($image->filepath);
// Set new variables: invalid dimensions, valid filesize (0 = no limit). // Set new variables: invalid dimensions, valid filesize (0 = no limit).
$test_dim = ($info['width'] - 10) . 'x' . ($info['height'] - 10); $test_dim = ($info['width'] - 10) . 'x' . ($info['height'] - 10);
@ -569,7 +569,7 @@ class UserPictureTestCase extends DrupalWebTestCase {
$this->drupalLogin($this->user); $this->drupalLogin($this->user);
$image = current($this->drupalGetTestFiles('image')); $image = current($this->drupalGetTestFiles('image'));
$info = image_get_info($image->filename); $info = image_get_info($image->filepath);
// Set new variables: valid dimensions, invalid filesize. // Set new variables: valid dimensions, invalid filesize.
$test_dim = ($info['width'] + 10) . 'x' . ($info['height'] + 10); $test_dim = ($info['width'] + 10) . 'x' . ($info['height'] + 10);
@ -580,9 +580,9 @@ class UserPictureTestCase extends DrupalWebTestCase {
$pic_path = $this->saveUserPicture($image); $pic_path = $this->saveUserPicture($image);
// Test that the upload failed and that the correct reason was cited. // Test that the upload failed and that the correct reason was cited.
$text = t('The specified file %filename could not be uploaded.', array('%filename' => $image->basename)); $text = t('The specified file %filename could not be uploaded.', array('%filename' => $image->filename));
$this->assertRaw($text, t('Upload failed.')); $this->assertRaw($text, t('Upload failed.'));
$text = t('The file is %filesize exceeding the maximum file size of %maxsize.', array('%filesize' => format_size(filesize($image->filename)), '%maxsize' => format_size($test_size * 1024))); $text = t('The file is %filesize exceeding the maximum file size of %maxsize.', array('%filesize' => format_size(filesize($image->filepath)), '%maxsize' => format_size($test_size * 1024)));
$this->assertRaw($text, t('File size cited as reason for failure.')); $this->assertRaw($text, t('File size cited as reason for failure.'));
// Check if file is not uploaded. // Check if file is not uploaded.
@ -604,7 +604,7 @@ class UserPictureTestCase extends DrupalWebTestCase {
$this->drupalLogin($this->user); $this->drupalLogin($this->user);
$image = current($this->drupalGetTestFiles('image')); $image = current($this->drupalGetTestFiles('image'));
$info = image_get_info($image->filename); $info = image_get_info($image->filepath);
// Set new variables: invalid dimensions, valid filesize (0 = no limit). // Set new variables: invalid dimensions, valid filesize (0 = no limit).
$test_dim = ($info['width'] - 10) . 'x' . ($info['height'] - 10); $test_dim = ($info['width'] - 10) . 'x' . ($info['height'] - 10);
@ -614,7 +614,7 @@ class UserPictureTestCase extends DrupalWebTestCase {
$pic_path = $this->saveUserPicture($image); $pic_path = $this->saveUserPicture($image);
// Test that the upload failed and that the correct reason was cited. // Test that the upload failed and that the correct reason was cited.
$text = t('The specified file %filename could not be uploaded.', array('%filename' => $image->basename)); $text = t('The specified file %filename could not be uploaded.', array('%filename' => $image->filename));
$this->assertRaw($text, t('Upload failed.')); $this->assertRaw($text, t('Upload failed.'));
$text = t('The image is too large; the maximum dimensions are %dimensions pixels.', array('%dimensions' => $test_dim)); $text = t('The image is too large; the maximum dimensions are %dimensions pixels.', array('%dimensions' => $test_dim));
$this->assertRaw($text, t('Checking response on invalid image (dimensions).')); $this->assertRaw($text, t('Checking response on invalid image (dimensions).'));
@ -637,7 +637,7 @@ class UserPictureTestCase extends DrupalWebTestCase {
$this->drupalLogin($this->user); $this->drupalLogin($this->user);
$image = current($this->drupalGetTestFiles('image')); $image = current($this->drupalGetTestFiles('image'));
$info = image_get_info($image->filename); $info = image_get_info($image->filepath);
// Set new variables: valid dimensions, invalid filesize. // Set new variables: valid dimensions, invalid filesize.
$test_dim = ($info['width'] + 10) . 'x' . ($info['height'] + 10); $test_dim = ($info['width'] + 10) . 'x' . ($info['height'] + 10);
@ -648,9 +648,9 @@ class UserPictureTestCase extends DrupalWebTestCase {
$pic_path = $this->saveUserPicture($image); $pic_path = $this->saveUserPicture($image);
// Test that the upload failed and that the correct reason was cited. // Test that the upload failed and that the correct reason was cited.
$text = t('The specified file %filename could not be uploaded.', array('%filename' => $image->basename)); $text = t('The specified file %filename could not be uploaded.', array('%filename' => $image->filename));
$this->assertRaw($text, t('Upload failed.')); $this->assertRaw($text, t('Upload failed.'));
$text = t('The file is %filesize exceeding the maximum file size of %maxsize.', array('%filesize' => format_size(filesize($image->filename)), '%maxsize' => format_size($test_size * 1024))); $text = t('The file is %filesize exceeding the maximum file size of %maxsize.', array('%filesize' => format_size(filesize($image->filepath)), '%maxsize' => format_size($test_size * 1024)));
$this->assertRaw($text, t('File size cited as reason for failure.')); $this->assertRaw($text, t('File size cited as reason for failure.'));
// Check if file is not uploaded. // Check if file is not uploaded.
@ -669,7 +669,7 @@ class UserPictureTestCase extends DrupalWebTestCase {
$this->drupalLogin($this->user); $this->drupalLogin($this->user);
$image = current($this->drupalGetTestFiles('image')); $image = current($this->drupalGetTestFiles('image'));
$info = image_get_info($image->filename); $info = image_get_info($image->filepath);
// Set new variables: valid dimensions, valid filesize (0 = no limit). // Set new variables: valid dimensions, valid filesize (0 = no limit).
$test_dim = ($info['width'] + 10) . 'x' . ($info['height'] + 10); $test_dim = ($info['width'] + 10) . 'x' . ($info['height'] + 10);
@ -688,10 +688,10 @@ class UserPictureTestCase extends DrupalWebTestCase {
} }
function saveUserPicture($image) { function saveUserPicture($image) {
$edit = array('files[picture_upload]' => realpath($image->filename)); $edit = array('files[picture_upload]' => realpath($image->filepath));
$this->drupalPost('user/' . $this->user->uid.'/edit', $edit, t('Save')); $this->drupalPost('user/' . $this->user->uid.'/edit', $edit, t('Save'));
$img_info = image_get_info($image->filename); $img_info = image_get_info($image->filepath);
$picture_dir = variable_get('user_picture_path', 'pictures'); $picture_dir = variable_get('user_picture_path', 'pictures');
$pic_path = file_directory_path() . '/' . $picture_dir . '/picture-' . $this->user->uid . '.' . $img_info['extension']; $pic_path = file_directory_path() . '/' . $picture_dir . '/picture-' . $this->user->uid . '.' . $img_info['extension'];