- Patch #1222576 by jox: file_usage_list() is defective (might return incomplete results).

8.0.x
Dries Buytaert 2011-08-01 20:50:59 -04:00
parent 233bdf5650
commit e67898ffa9
2 changed files with 8 additions and 7 deletions

View File

@ -605,7 +605,8 @@ function file_save(stdClass $file) {
*
* @return
* A nested array with usage data. The first level is keyed by module name,
* the second by object type, the third has 'id' and 'count' keys.
* the second by object type and the third by the object id. The value
* of the third level contains the usage count.
*
* @see file_usage_add()
* @see file_usage_delete()
@ -618,7 +619,7 @@ function file_usage_list(stdClass $file) {
->execute();
$references = array();
foreach ($result as $usage) {
$references[$usage->module][$usage->type] = array('id' => $usage->id, 'count' => $usage->count);
$references[$usage->module][$usage->type][$usage->id] = $usage->count;
}
return $references;
}

View File

@ -1563,7 +1563,7 @@ class FileDeleteTest extends FileHookTestCase {
file_usage_delete($file, 'testing', 'test', 1);
file_delete($file);
$usage = file_usage_list($file);
$this->assertEqual($usage['testing']['test'], array('id' => 1, 'count' => 1), t('Test file is still in use.'));
$this->assertEqual($usage['testing']['test'], array(1 => 1), t('Test file is still in use.'));
$this->assertTrue(file_exists($file->uri), t('File still exists on the disk.'));
$this->assertTrue(file_load($file->fid), t('File still exists in the database.'));
@ -2066,10 +2066,10 @@ class FileUsageTest extends FileTestCase {
$usage = file_usage_list($file);
$this->assertEqual(count($usage['testing']), 2, t('Returned the correct number of items.'));
$this->assertEqual($usage['testing']['foo']['id'], 1, t('Returned the correct id.'));
$this->assertEqual($usage['testing']['bar']['id'], 2, t('Returned the correct id.'));
$this->assertEqual($usage['testing']['foo']['count'], 1, t('Returned the correct count.'));
$this->assertEqual($usage['testing']['bar']['count'], 2, t('Returned the correct count.'));
$this->assertTrue(isset($usage['testing']['foo'][1]), t('Returned the correct id.'));
$this->assertTrue(isset($usage['testing']['bar'][2]), t('Returned the correct id.'));
$this->assertEqual($usage['testing']['foo'][1], 1, t('Returned the correct count.'));
$this->assertEqual($usage['testing']['bar'][2], 2, t('Returned the correct count.'));
}
/**