silverstripe-cms/code/model/SiteTreeFolderExtension.php
Sam Minnee bbc3aaaf9f MINOR: Remove training whitespace.
The main benefit of this is so that authors who make use of
.editorconfig don't end up with whitespace changes in their PRs.

Spaces vs. tabs has been left alone, although that could do with a
tidy-up in SS4 after the switch to PSR-1/2.

The command used was this:

for match in '*.ss' '*.css' '*.scss' '*.html' '*.yml' '*.php' '*.js' '*.csv' '*.inc' '*.php5'; do
	find . -path ./thirdparty -prune -o -type f -name "$match" -exec sed -i '' 's/[[:space:]]\+$//' {} \+
	find . -path ./thirdparty -prune -o -type f -name "$match" | xargs perl -pi -e 's/ +$//'
done
2016-01-07 10:32:05 +13:00

56 lines
1.5 KiB
PHP

<?php
/**
* @todo Cleanup, refactor, test this class
*
* @package cms
* @subpackage model
*/
class SiteTreeFolderExtension extends DataExtension {
/**
* Looks for files used in system and create where clause which contains all ID's of files.
*
* @returns String where clause which will work as filter.
*/
public function getUnusedFilesListFilter() {
$result = DB::query("SELECT DISTINCT \"FileID\" FROM \"SiteTree_ImageTracking\"");
$usedFiles = array();
$where = '';
$classes = ClassInfo::subclassesFor('SiteTree');
if($result->numRecords() > 0) {
while($nextResult = $result->next()) {
$where .= $nextResult['FileID'] . ',';
}
}
foreach($classes as $className) {
$query = new DataQuery($className);
$ids = $query->execute()->column();
if(!count($ids)) continue;
foreach(singleton($className)->hasOne() as $relName => $joinClass) {
if($joinClass == 'Image' || $joinClass == 'File') {
$fieldName = $relName .'ID';
$query = DataList::create($className)->where("$fieldName > 0");
$query->distinct = true;
$query->select(array($fieldName));
$usedFiles = array_merge($usedFiles, $query->execute()->column());
} elseif($joinClass == 'Folder') {
// @todo
}
}
}
if($usedFiles) {
return "\"File\".\"ID\" NOT IN (" . implode(', ', $usedFiles) . ") AND (\"ClassName\" = 'File' OR \"ClassName\" = 'Image')";
} else {
return "(\"ClassName\" = 'File' OR \"ClassName\" = 'Image')";
}
return $where; // @todo - How?
}
}