Commit 66820a05 authored by Jakob Petsovits's avatar Jakob Petsovits

Make node deletions and revisions work again.

Note that the 5.x revision bug (#263162) does *not* appear anymore. Whoo!
parent 1ab8edb4
......@@ -152,7 +152,10 @@ function field_file_delete($file, $force = FALSE) {
// file will not be deleted from Drupal, but file_delete will
// return a populated array that tests as TRUE.
if (!$force && $references = module_invoke_all('file', 'references', $file)) {
return $references;
$references = array_filter($references); // only keep positive values
if (!empty($references)) {
return $references;
}
}
// Let other modules clean up on delete.
......
......@@ -150,6 +150,34 @@ function filefield_icon_url($file) {
return _filefield_icon_url($file);
}
/**
* Implementation of hook_file().
* (Which is implemented by filefield/imagefield in Drupal 6 yet).
*/
function filefield_file($op, $file) {
switch ($op) {
// report references to prevent deletion of files associated to older revisions
// or by other fields.
case 'references':
$references = 0;
foreach(content_fields() as $field) {
if ($field['type'] != 'file') {
continue;
}
$db_info = content_database_info($field);
$references += db_result(db_query(
'SELECT count('. $db_info['columns']['fid']['column'] .')
FROM {'. $db_info['table'] .'}
WHERE '. $db_info['columns']['fid']['column'] .' = %d', $file->fid
));
if (isset($file->filefield_delete) && $field['field_name'] == $file->filefield_delete) {
--$references; // doesn't count as it's being deleted
}
}
return array('filefield' => $references);
}
}
/**
* Implementation of hook_field_info().
......@@ -329,8 +357,10 @@ function filefield_field($op, $node, $field, &$items, $teaser, $page) {
case 'delete revision':
foreach ($items as $delta => $item) {
// For hook_file($op = 'references'), remember that this is being deleted.
$item['filefield_delete'] = $field['field_name'];
if (field_file_delete($item)) {
$items[$delta] = array();
unset($items[$delta]);
}
}
$items = array_values($items); // compact deltas
......@@ -338,6 +368,8 @@ function filefield_field($op, $node, $field, &$items, $teaser, $page) {
case 'delete':
foreach ($items as $delta => $item) {
// For hook_file($op = 'references'), remember that this is being deleted.
$item['filefield_delete'] = $field['field_name'];
field_file_delete($item);
}
break;
......
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