Fetching files with FileSet::getFilesBySetID() (bug or namespace issue?)

So this line of code

$files = FileSet::getFilesBySetID( $setID );

produces nothing, because this line:

// line 157 in concrete/src/File/Set/Set.php
if ($fileset instanceof FileSet) {

never evaluates to true on my installation. When I var_dump the $fileset variable I get

  protected 'fileSetFiles' => null
  public 'fsID' => string '2' (length=1)
  public 'fsName' => string 'Test group' (length=10)
  public 'uID' => string '1' (length=1)
  public 'fsType' => string '1' (length=1)
  public 'fsOverrideGlobalPermissions' => string '0' (length=1)

If I change the line to check for an instance of "\Concrete\Core\File\Set\Set" the check is passed, but then it trips again in Concrete\Core\File\Set\File::getFileSetFiles() which wants an instance of FileSet. If I change that too everything works ok.

Am I using namespaces wrong again or is this a bug?

EDIT: If I change "use \Concrete\Core\File\Set\Set as FileSet" to just plain "use FileSet", than getFileSetFiles() is happy. No effect on getFilesBySetID() though.

View Replies: View Best Answer
mesuva replied on at Permalink Best Answer Reply
That looks like a bug to me, I think it's worth putting this on github as an issue.

It's likely this was simply missed as the getFilesBySetID is simply not used anywhere elsewhere in the concrete5 codebase. Instead I believe the FileList approach is always used to fetch files from a fileset as that then allows filtering and pagination as well.

Something like:
$fs = FileSet::getById(123);
$fl = new FileList();
$pagination = $fl->getPagination();
$files = $pagination->getCurrentPageResults();

If you want a more complete example, my List Files From Set block probably has a lot of code you could grab -https://github.com/Mesuva/list_files_from_set...

Don't be surprised if the getFilesBySetID function ends up getting removed as legacy code. It's probably never worked for 5.7.
Juha replied on at Permalink Reply
Thanks for the info.

I actually took a quick look at the FileList class but couldn't see an easy way to get all the files without pagination, so I went with getFilesBySetID. I later found the getResults() method in the ItemList class, so if the getFilesBySetID is legacy code I may as well ditch it in favor of FileList::getResults. It's an easy thing to refactor.

I just wish these were documented somewhere, at least in the source code... *sigh*
JohntheFish replied on at Permalink Reply
pre 5.7, setting the quantity to 0 or to a very big number did the trick.