Commit 78746549 authored by Dries's avatar Dries

- Patch #924554 by quicksketch, paul.lovvik: an exception is being thrown in...

- Patch #924554 by quicksketch, paul.lovvik: an exception is being thrown in the file_usage_delete() function if the corresponding file is not in the 'file_usage()' table.
parent 45bca33b
......@@ -661,7 +661,7 @@ function file_usage_delete(stdClass $file, $module, $type = NULL, $id = NULL, $c
$result = $query->execute();
// If the row has more than the specified count decrement it by that number.
if (!$result) {
if (!$result && $count > 0) {
$query = db_update('file_usage')
->condition('module', $module)
->condition('fid', $file->fid);
......@@ -670,9 +670,7 @@ function file_usage_delete(stdClass $file, $module, $type = NULL, $id = NULL, $c
->condition('type', $type)
->condition('id', $id);
}
if ($count) {
$query->expression('count', 'count - :count', array(':count' => $count));
}
$query->expression('count', 'count - :count', array(':count' => $count));
$query->execute();
}
}
......
......@@ -1971,25 +1971,36 @@ class FileUsageTest extends FileTestCase {
'module' => 'testing',
'type' => 'bar',
'id' => 2,
'count' => 2
'count' => 3,
))
->execute();
// Normal decrement.
file_usage_delete($file, 'testing', 'bar', 2);
$count = db_select('file_usage', 'f')
->fields('f', array('count'))
->condition('f.fid', $file->fid)
->execute()
->fetchField();
$this->assertEqual(1, $count, t('The count was decremented correctly.'));
$this->assertEqual(2, $count, t('The count was decremented correctly.'));
// Multiple decrement and removal.
file_usage_delete($file, 'testing', 'bar', 2, 2);
$count = db_select('file_usage', 'f')
->fields('f', array('count'))
->condition('f.fid', $file->fid)
->execute()
->fetchField();
$this->assertIdentical(FALSE, $count, t('The count was removed entirely when empty.'));
// Non-existent decrement.
file_usage_delete($file, 'testing', 'bar', 2);
$count = db_select('file_usage', 'f')
->fields('f', array('count'))
->condition('f.fid', $file->fid)
->execute()
->fetchField();
$this->assertEqual(0, $count, t('The count was decremented correctly.'));
$this->assertIdentical(FALSE, $count, t('Decrementing non-exist record complete.'));
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment