From e67898ffa96b716f052ae1ebda9fa0c3f64db7da Mon Sep 17 00:00:00 2001 From: Dries Buytaert <dries@buytaert.net> Date: Mon, 1 Aug 2011 20:50:59 -0400 Subject: [PATCH] - Patch #1222576 by jox: file_usage_list() is defective (might return incomplete results). --- includes/file.inc | 5 +++-- modules/simpletest/tests/file.test | 10 +++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/includes/file.inc b/includes/file.inc index 1278d39d4799..bc8ae79d325d 100644 --- a/includes/file.inc +++ b/includes/file.inc @@ -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; } diff --git a/modules/simpletest/tests/file.test b/modules/simpletest/tests/file.test index 9dbe5464fc1e..db4097c44a0b 100644 --- a/modules/simpletest/tests/file.test +++ b/modules/simpletest/tests/file.test @@ -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.')); } /** -- GitLab