Drupal Association members fund grants that make connections all over the world.
Currently, file_delete() has both verifications that the $file->uri is valid and that there are no remaining references to it (this check can be overridden with an optional $force parameter). Both those checks and the additional argument aren't compatible with the delete() interface provided by the Entity system.
Initially, the discussion centered around simply removing those checks. However, there have been arguments raised that this makes the already complicated file API harder to use. Various solutions have been discussed and proposed, including keeping some of the checks and aborting silently, throwing exceptions or providing helper/wrapper functions that do these checks.
The current proposal from #45 changes the existing file_usage_add()/file_usage_delete() functions to automatically handle the file temporary/permament status, which makes manual status changes and file deletions in most cases unecessary. Implementing modules only need to make sure to properly add and remove their usage to/from the uploaded files. It is still possible to explicitly call flle_delete() but modules which do so are expected to understand the consequences and do the necessary checks on their own. One such example is system_cron(), which deletes temporary files.
We need an agreement on the proposed solution and finish the patch, which means identifying and implementing necessary changes to the api documentation to explain the proper usage.
It also nether to be discussed if the file_usage_*() functions should be renamed to file_managed_*() and if that should happen in this issue or a follow-up.
User interface changes
Modules relying on the file usage API do no longer need to manually change the file status or call file_delete(). Modules which use files without relying on file usage need to add the necessary checks. It is strongly recommended to rely on the file usage API.
Original report by [Dave Reid]
Spun off fromit was pointed out that we really should not have "custom" logic in file_delete() checking if the file is used or not. That should be the responsibility of the code that calls file_delete().
PASSED: [[SimpleTest]]: [MySQL] 36,657 pass(es). View
PASSED: [[SimpleTest]]: [MySQL] 36,622 pass(es). View
PASSED: [[SimpleTest]]: [MySQL] 36,625 pass(es). View
PASSED: [[SimpleTest]]: [MySQL] 36,597 pass(es). View