Update: Renamed to File Lock

Hi,

"File Lock" is an addon to the media-7.x-2.x-dev module.
It's a solution for this open media issue:
#1239056: Remove Media at content edit page cause the file to be completely deleted from server/database?
(short issue description: files which aren't used anymore are deleted from the database and from the file system. User has no choice to select keeping a file which isn't used anywhere)

My modules provides two ways for locking files:

  • file operations: Lock/Unlock files via file operation on Content > Files > List files
  • automatic lock for new files/updated files, configurable via Settings > Media > File Lock:
    • all files
    • filename matching a pattern
    • filename matching a regular expression
    • none (disable this feature)

Project Page:
http://drupal.org/sandbox/shuairan/1373502
Git:

git clone --branch 7.x-2.x shuairan@git.drupal.org:sandbox/shuairan/1373502.git file_lock

It is for Drupal 7 (+ media-7.x-2.x-dev)

Comments

agentrickard’s picture

Ran a coder review. No issues.

Minor (very minor points):

  • media_lock.info error, should be package = Media (uppercase).
  • description should be more clear: "Prevent deletion of untracked files from media library" or similar.
  • Very minor whitespace issues (e.g. empty indents, extra returns).
  • One badly formed docblock (line 97 of media_lock.module).
  • One-line docblock summaries are inconsistent, grammatically.

I'd like to see a Media module maintainer weigh in here. I like this module as a short-term or optional solution to the described problem. But is there a chance this will go into the main module (or main module package)?

dave reid’s picture

Yes, we will definitely have to add something like this to Media and I would really, really prefer that this support go in Media proper, but this is probably a good temporary solution in the meantime.

The only thing missing in this module is the ability for a user to manually delete a file via file/%file/delete even if the file is 'locked' but that could also probably be fixed from the File entity module side of things by using $force with file_delete().

Overall this gets my +1 as long as we can get your help improving this in media. I'd probably also suggest naming this 'File lock' since it doesn't actually have anything to do with the Media project aside from enhancing it. There's no real reason to have a dependency here as other modules might find this solution useful.

agentrickard’s picture

Good point about File Lock.

Anonymous’s picture

Title: Media Lock » File Lock

small update:
renamed the module to File Lock
package description is now 'Media'
dependency changed from media to file
better description
fixed many (all?) of the whitespace issues, docblock

feature updates earliest after christmas,
and you can count on my help to improve this in media :)

agentrickard’s picture

Status: Needs review » Reviewed & tested by the community

Sounds good to me. Developer shows great attitude, too.

klausi’s picture

Status: Reviewed & tested by the community » Needs work
StatusFileSize
new1.04 KB

Review of the 7.x-2.x branch:

This automated report was generated with PAReview.sh, your friendly project application review script. You can also use the online version to check your project. Go and review some other project applications, so we can get back to yours sooner.

manual review:

  • file_lock_admin_config(): array indentation errors, always use 2 spaces per level. Also elsewhere.
  • file_lock_admin_config_validate(): 'Empty pattern' is not a very helpful error message. 'Pattern must not be empty' or something like that?
  • file_lock_file_presave(): variable $hook is undefined. Also check the other file hook implementations.
  • file_lock_act_on(): Remove the empty "default:" and "case 'none':" cases.
  • file_lock_regex: you should mention that the input must be suitable for preg_match() in the description of this mode.
  • file_lock_pattern: you should mention that this pattern is a file system pattern suitable for fnmatch().
  • hook_file_operations_info(): I could not find that hook in Drupal core, looks like it belongs to the file_entity module (could not find it in file_entity.api.php. A function hook_file_operations_info() is lying around in file_entity.file_api.inc which should be in file_entity.api.php probably. BTW this is a name space violation, the hook should be called "hook_file_entity_operations_info"). Anyway, are you sure that you do not have to depend on the file_entity module?
klausi’s picture

StatusFileSize
new5.83 KB

Improved drupalcs to also detect array indentation errors, see attachment.

agentrickard’s picture

None of these are fatal blockers to approval, except perhaps hook_file_operations_info().

dave reid’s picture

Anonymous’s picture

Status: Needs work » Needs review
  • fixed array indentations and drupalcs warnings/errors *)
  • more meaningful descriptions and error messages (+links to php manual for fnmatch/preg_match)
  • fixed use of var $hook in the file hooks, it has to be $config_hook
  • removed unused default/none case in file_lock_act_on switch statement
  • hook_file_operations_info(): yep this hook is from the file_entity module. Because I only implement the hook and use no other file_entity function, I don't think a dependency to file_entity will be right. file_lock is usable and works fine without that hook. It's only needed for the use-case if somebody wants to lock/unlock multiple files on the file overview page

*)if I've missed any I'll fix them as soon as I got drupalcs/pareview completely integrated into my IDE (eclipse) (there are several ways to do that, I'm also working on an tutorial about that)

dave reid’s picture

Status: Needs review » Reviewed & tested by the community

I think Shuairan has done a great job in being responsive in this application and this is ready to be approved. Code looks good and ready for use.

klausi’s picture

Status: Reviewed & tested by the community » Fixed
StatusFileSize
new556 bytes

Review of the 7.x-2.x branch:

This automated report was generated with PAReview.sh, your friendly project application review script. You can also use the online version to check your project. Go and review some other project applications, so we can get back to yours sooner.

manual review:

  • "@param file $file": "file" is not a type. I think $file is just a sdtClass object, so you should write "object" here.

But that are just minor issues, so ...

Thanks for your contribution, Shuairan! Welcome to the community of project contributors on drupal.org.

I've granted you the git vetted user role which will let you promote this to a full project and also create new projects as either sandbox or "full" projects depending on which you feel is best.

Thanks, also, for your patience with the review process. Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.

As you continue to work on your module, keep in mind: Commit messages - providing history and credit and Release naming conventions.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Renamed to File Lock