Moodle

Suggested file API function name improvements

Details

  • Type: Sub-task Sub-task
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 2.0
  • Fix Version/s: 2.0
  • Component/s: Files API
  • Labels:
    None
  • Affected Branches:
    MOODLE_20_STABLE
  • Fixed Branches:
    MOODLE_20_STABLE

Description

I may be being overly fussy, but I think it is important to get the file API function names as clear as possible before it is too late. It will make it much easier for people trying to learn.

Fortunately, grepping the code for 'draft' only finds 13 matches, so I think we can still change it.

I suggest

get_draftarea_info -> file_get_draft_area_info
file_prepare_draftarea -> file_prepare_draft_area
file_convert_draftarea -> file_save_files_from_draft_area

Or even, since this is an important core library, we could drop the 'file_' prefix. The funciton names are sufficiently unique without it.

I also think we should rename all the other functions the run words together in function names (for example pluginfiles, draftitemid). The File API should all be nice new code. I think we should be exemplary in following the coding guidelines.

If there is agreement on this I am happy to make the changes.

Activity

Hide
Tim Hunt added a comment -

It is rather premature to make a patch for this before we have discussed it, but it was only a search and replace, and I wanted to see how the code looked afterwards, so here is a patch.

Note, in file_convert_relative_pluginfiles / rewrite_pluginfile_urls, there was some code that used to read

if ($CFG->slasharguments) { $draftbase = "$CFG->wwwroot/$file/$pluginstub"; } else { $draftbase = "$CFG->wwwroot/draftfile.php?file=/$pluginstub"; }

It looks to me like it should be

if ($CFG->slasharguments) { $draftbase = "$CFG->wwwroot/$file/$pluginstub"; } } else { $draftbase = "$CFG->wwwroot/$file?file=/$pluginstub"; }

Also, for consistency, would it be better to split up the $pluginstub parameter, so that we consistently use separate $contextid, $filearea and $itemid parameters on all these methods?

I also rewrote Dongsheng's page http://docs.moodle.org/en/Development:Convert_Draftarea_Files to use my proposed names, becuase it helped me to understand it. I will of course revert those changes if we do not agree on this soon.

Show
Tim Hunt added a comment - It is rather premature to make a patch for this before we have discussed it, but it was only a search and replace, and I wanted to see how the code looked afterwards, so here is a patch. Note, in file_convert_relative_pluginfiles / rewrite_pluginfile_urls, there was some code that used to read if ($CFG->slasharguments) { $draftbase = "$CFG->wwwroot/$file/$pluginstub"; } else { $draftbase = "$CFG->wwwroot/draftfile.php?file=/$pluginstub"; } It looks to me like it should be if ($CFG->slasharguments) { $draftbase = "$CFG->wwwroot/$file/$pluginstub"; } } else { $draftbase = "$CFG->wwwroot/$file?file=/$pluginstub"; } Also, for consistency, would it be better to split up the $pluginstub parameter, so that we consistently use separate $contextid, $filearea and $itemid parameters on all these methods? I also rewrote Dongsheng's page http://docs.moodle.org/en/Development:Convert_Draftarea_Files to use my proposed names, becuase it helped me to understand it. I will of course revert those changes if we do not agree on this soon.
Hide
Petr Škoda (skodak) added a comment -

my +1
the $draftbase looks like a bug, sure

Show
Petr Škoda (skodak) added a comment - my +1 the $draftbase looks like a bug, sure
Hide
Tim Hunt added a comment -

Just to make it clear, the patch does

file_convert_relative_pluginfiles -> rewrite_pluginfile_urls
file_prepare_draftarea -> prepare_draft_area
file_convert_draftarea -> save_files_from_draft_area
file_get_new_draftitemid -> file_get_new_draft_itemid
get_draftarea_info -> get_draft_area_info
file_get_submitted_draftitemid -> get_submitted_draft_itemid

It now occurs to me that save_files_from_draft_area could probably be further improved to save_draft_area_files

Show
Tim Hunt added a comment - Just to make it clear, the patch does file_convert_relative_pluginfiles -> rewrite_pluginfile_urls file_prepare_draftarea -> prepare_draft_area file_convert_draftarea -> save_files_from_draft_area file_get_new_draftitemid -> file_get_new_draft_itemid get_draftarea_info -> get_draft_area_info file_get_submitted_draftitemid -> get_submitted_draft_itemid It now occurs to me that save_files_from_draft_area could probably be further improved to save_draft_area_files
Hide
Petr Škoda (skodak) added a comment -

+10, thanks

Show
Petr Škoda (skodak) added a comment - +10, thanks
Hide
Martin Dougiamas added a comment -

I strongly think all those functions should start with: file_

Two reasons:

1) Helps new developers realise what subsystem the functions are part of
2) Helps autocomplete in editors

So perhaps:

file_convert_relative_pluginfiles -> file_rewrite_pluginfile_urls
file_prepare_draftarea -> file_prepare_draft_area
file_convert_draftarea -> file_save_files_from_draft_area
file_get_new_draftitemid -> file_get_new_draft_itemid
get_draftarea_info -> file_get_draft_area_info
file_get_submitted_draftitemid -> file_get_submitted_draft_itemid

Show
Martin Dougiamas added a comment - I strongly think all those functions should start with: file_ Two reasons: 1) Helps new developers realise what subsystem the functions are part of 2) Helps autocomplete in editors So perhaps: file_convert_relative_pluginfiles -> file_rewrite_pluginfile_urls file_prepare_draftarea -> file_prepare_draft_area file_convert_draftarea -> file_save_files_from_draft_area file_get_new_draftitemid -> file_get_new_draft_itemid get_draftarea_info -> file_get_draft_area_info file_get_submitted_draftitemid -> file_get_submitted_draft_itemid

People

Vote (0)
Watch (5)

Dates

  • Created:
    Updated:
    Resolved: