File set listing broken after upgrade to 5.6

Permalink 1 user found helpful
Hi all

I have a single page with a file set listing which lists all the files in a site, which I use to manually tell Google to index PDFs. This was working will until I upgraded the site from 5.5 to 5.6 -- the page no longer does anything.

Here's my controller code:

<?php
Class FileArchiveController extends Controller {
    public function view() {
                Loader::model('file_set');
          Loader::model('file_list');
          $fs = FileSet::getGlobal();
          $files = array();        
                $this->fileSetName = $fs->getFileSetName(); 
                $fl = new FileList();
                $fl->filterBySet($fs);
                $files = $fl->get((int)$this->numberFiles, 0);
                $this->set('files', $files);
    }
}


and my view (file-archive.php):

defined('C5_EXECUTE') or die("Access Denied."); 
header('X-Robots-Tag: noindex');
$plth = Loader::helper('page_list_teasers', 'page_list_teasers');
$nh = Loader::helper('navigation');
// Variables
$c = Page::getCurrentPage();
echo count($files);
foreach($files as $f) {
      $fp = new Permissions($f);
      if ($fp->canRead()) {  
         $fv = $f->getApprovedVersion();
         // although the 'title' for a file is used for display,
         // the filename is retreived here so we can always get a file extension
         $filename = $fv->getFileName();
         $ext =  pathinfo($filename, PATHINFO_EXTENSION);


All I see is 0, and no file listing (in other words, the $files array is empty). I presume this is something to do with
$fs = FileSet::getGlobal()


not working any more, but I'm not sure why. Could it be a permissions thing (because the user accessing the file-archive single page is a guest)?

Any help would be much appreciated! :)

melat0nin
 
mesuva replied on at Permalink Reply
mesuva
Try changing the line:
if ($fp->canRead())
to
if ($fp->canViewFile())

It looks like you are using code from my block List Files From Set - I had to update this block for 5.6.x in this way.
melat0nin replied on at Permalink Reply
melat0nin
Hi mesuva

Indeed, I did use your block as a basis for the code!

Unfortunately that hasn't worked... I still see 0 and no file listing :(

I'm not sure if it's in any way related but I also noticed that my theme paths have broken following the upgrade to 5.6 -- custom 404s etc are now being wrapped in the view.php where they weren't before.
melat0nin replied on at Permalink Reply
melat0nin
The problem seems to be with

$fs = FileSet::getGlobal();


If I specify the file set like this

$fs = FileSet::getById(12);


then it works. Must be an API change, I'll try and find it in the docs
melat0nin replied on at Permalink Reply
melat0nin
I'm wondering if it's something to do with advanced permissions and the global FilePermissions object?
mesuva replied on at Permalink Reply
mesuva
I had someone ask me about a similar problem with my block in 5.6. We eventually worked out that there was some bug in the upgrade process from 5.5 to 5.6 in the way it updated the permissions for file sets.

One solution was to simply remove the offending file set and re-create it (leaving the files as is, just re-adding them back to the newly created set).

However you're talking about using getGlobal() and not getting a particular file set, so this suggestion isn't going to work for you, but I'm wondering if it's sort of related as getGlobal is really just the same as using getById(0).. (not saying I know what this is actually doing though, I've never used getGlobal before)
melat0nin replied on at Permalink Reply
melat0nin
Thanks for your reply :)

Yes it looks like getGlobal is just returning the FileSet with an ID of 0, so it's just the same as FileSet::getByID(0).

I did a print_r on it and I get this:

FileSet Object ( [fileSetFiles:protected] => [_dbat] => 0 [_table] => FileSets [_tableat] => FileSets [_where] => [_saved] => [_lasterr] => [_original] => [foreignName] => fileset [fsID] => [fsName] => [uID] => [fsType] => [fsOverrideGlobalPermissions] => )


It definitely seems as though FileSet with ID 0 has had its permissions changed. I looked at the File Manager permissions and Guests are able to view files, so that's obviously not where the problem lies.
melat0nin replied on at Permalink Reply
melat0nin
*bump*

Anyone got any ideas?
nielsb85 replied on at Permalink Best Answer Reply
I'm having a similar problem.

When I am logged out (Guest) and filter files by set, I get an empty array().

When I am logged in, I get a array filled with file objects.

$fl = new FileList();
$fl->filterBySet($fs);
$files = $fl->get();


Wil result in an empty array when logged out (Guest)

However
$fl = new FileList();
$files = $fl->get();


will return all files even as Guest.

I use default user permissions and Guest is able to view files.

Its affecting 2 big projects and is really annoying. Hope there will be a fix soon

[edit]

Just removed $this->setupFilePermissions(); from file_list.php line 352 in /updates/concrete5.6.0.2/concrete/core/models/

fixed my problem but now permissions arent checked for files. But the whole permission model seems a bit buggy.
melat0nin replied on at Permalink Reply
melat0nin
Thanks, I just used

$fl = new FileList();
$files = $fl->get();


to get an array of files to iterate through. It works fine.
tomrice replied on at Permalink Reply
tomrice
I'm also having issues with this. For me, any use of $fl = new FileList(); is working ok when logged in but I get no results at all for guests. I've checked the files and they are set to be viewable to guests. Using Concrete 5.6.

It really screwed a few things up on the site I'm working on. For now I've made a workaround using a php constant in my block controller and an if defined() statement where nielsb85 suggested (thanks) so that this setupFilePermissions() can still be run within file manager and elsewhere but not when using my own code. Obviously that's not ideal though.
mesuva replied on at Permalink Reply
mesuva
Just wondering, has anyone in this thread (or reading this thread) submitted a bug report for this?
I had a look earlier and couldn't find anything related. I'd submit one myself, but I don't have an example to be able to fully document how it is triggered, etc.
nielsb85 replied on at Permalink Reply
I have made a bug report now.
http://www.concrete5.org/index.php?cID=403623...