Problem with image set display not saving correctly, and solution
Permalink
Hey,
I've recently built a site using concrete5 which heavily features images and image sets.
My clients use the drag and drop feature in the sets area to organise their sets, however for some reason, certain images were not being placed in their correct location after saving.
On checking the database, I found that it was ordering the images correctly, but for some reason when being displayed it wasn't coming out correctly.
I checked the SQL query being generated which was as follows:
All seemed fine, but I was still getting the error - it was then I realised that the images that it was retrieving were also in different sets, and had different fsDisplayOrder numbers depending on the set that was being retrieved. Which meant that there was piece missing from the query after the 'WHERE 1=1' which was:
'AND fsfl.fsID = 19'
I have put a plaster on this by adding modifying the 'createQuery()' function in the file_list.php model like so:
(the added bit is the if statement)
I don't know if this will break something in the future, but I do know it appears to now be working correctly. I hope this helps someone if they have this issue - but would also appreciate it if anyone can see anything horribly wrong with what I have added?
Thanks,
Dan
I've recently built a site using concrete5 which heavily features images and image sets.
My clients use the drag and drop feature in the sets area to organise their sets, however for some reason, certain images were not being placed in their correct location after saving.
On checking the database, I found that it was ordering the images correctly, but for some reason when being displayed it wasn't coming out correctly.
I checked the SQL query being generated which was as follows:
SELECT DISTINCT f.fID, u.uName AS fvAuthorName FROM Files f INNER JOIN FileVersions fv ON f.fID = fv.fID LEFT JOIN Users u ON u.uID = fv.fvAuthorUID LEFT JOIN FileSearchIndexAttributes ON ( fv.fID = FileSearchIndexAttributes.fID ) LEFT JOIN FileSetFiles fsfl ON fsfl.fID = f.fID WHERE 1 =1 AND fvIsApproved = '1' AND f.fID IN ( SELECT DISTINCT fID FROM FileSetFiles WHERE fsID = '19' ) ORDER BY fsDisplayOrder ASC
Viewing 15 lines of 16 lines. View entire code block.
All seemed fine, but I was still getting the error - it was then I realised that the images that it was retrieving were also in different sets, and had different fsDisplayOrder numbers depending on the set that was being retrieved. Which meant that there was piece missing from the query after the 'WHERE 1=1' which was:
'AND fsfl.fsID = 19'
I have put a plaster on this by adding modifying the 'createQuery()' function in the file_list.php model like so:
protected function createQuery(){ if(!$this->queryCreated){ $this->setBaseQuery(); if (count($this->filteredFileSetIDs) == 1) { $this->filter('fsfl.fsID', $this->filteredFileSetIDs[0]); } $this->filter('fvIsApproved', 1); $this->setupAttributeFilters("left join FileSearchIndexAttributes on (fv.fID = FileSearchIndexAttributes.fID)"); $this->setupFilePermissions(); $this->setupFileSetFilters(); $this->queryCreated=1; } }
(the added bit is the if statement)
I don't know if this will break something in the future, but I do know it appears to now be working correctly. I hope this helps someone if they have this issue - but would also appreciate it if anyone can see anything horribly wrong with what I have added?
Thanks,
Dan
This is good work, but can someone extract what needs to be done to fix the problem? I don't know how much of this is description of the problem and what part is the actual fix suggested.
1. create a directory called models in your C5 top directory
2. cp concrete/models/file_list.php models/
3. vi (or whatever you like) models/file_list.php and add the three lines below, indicated by leading "+" sign. (Remove + sign when adding the code, of course.)
protected function createQuery(){
if(!$this->queryCreated){
$this->setBaseQuery();
+ if (count($this->filteredFileSetIDs) == 1) {
+ $this->filter('fsfl.fsID', $this->filteredFileSetIDs[0]);
+ }
$this->filter('fvIsApproved', 1);
$this->setupAttributeFilters("left join FileSearchIndexAttributes on (fv.fID = FileSearchIndexAttributes.fID)");
$this->setupFilePermissions();
$this->setupFileSetFilters();
$this->queryCreated=1;
}
}
hope this helps.
2. cp concrete/models/file_list.php models/
3. vi (or whatever you like) models/file_list.php and add the three lines below, indicated by leading "+" sign. (Remove + sign when adding the code, of course.)
protected function createQuery(){
if(!$this->queryCreated){
$this->setBaseQuery();
+ if (count($this->filteredFileSetIDs) == 1) {
+ $this->filter('fsfl.fsID', $this->filteredFileSetIDs[0]);
+ }
$this->filter('fvIsApproved', 1);
$this->setupAttributeFilters("left join FileSearchIndexAttributes on (fv.fID = FileSearchIndexAttributes.fID)");
$this->setupFilePermissions();
$this->setupFileSetFilters();
$this->queryCreated=1;
}
}
hope this helps.
Thats about right yeah :)
It's literally just that extra if statement thats been added.
It's literally just that extra if statement thats been added.
Thank you very much!!! This solved the problem right away!
(C5 5.4.2.2)
(C5 5.4.2.2)