BUGFIX Re-enabled "Unused files" tab in AssetAdmin (fixed memory problems)

MINOR Moved getUsedFilesList() and getAssetList() from AssetAdmin to Folder (needed for Folder->getCMSFields()), changed their visibility from private to protected

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@55081 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2008-05-24 05:19:42 +00:00
parent 168b9673d7
commit 4af9a5b5a2

View File

@ -35,6 +35,7 @@ class AssetAdmin extends LeftAndMain {
'save',
'savefile',
'uploadiframe',
'deleteUnusedThumbnails' => 'ADMIN'
);
public function Link($action = null) {
@ -701,70 +702,6 @@ JS;
echo "statusMessage('"._t('AssetAdmin.THUMBSDELETED', 'All unused thumbnails have been deleted')."','good')";
}
/**
* 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.
*/
private function getUsedFilesList() {
$result = DB::query("SELECT DISTINCT FileID FROM SiteTree_ImageTracking");
$usedFiles = array();
$where = "";
if($result->numRecords() > 0) {
while($nextResult = $result->next()){
$where .= $nextResult['FileID'] . ',';
}
}
$classes = ClassInfo::subclassesFor('SiteTree');
foreach($classes as $className) {
$query = singleton($className)->extendedSQL();
$ids = $query->execute()->column();
if(!count($ids)) continue;
foreach(singleton($className)->has_one() as $fieldName => $joinClass) {
if($joinClass == 'Image' || $joinClass == 'File') {
foreach($ids as $id) {
$object = DataObject::get_by_id($className, $id);
if($object->$fieldName != NULL) $usedFiles[] = $object->$fieldName;
unset($object);
}
} elseif($joinClass == 'Folder') {
// @todo
}
}
}
foreach($usedFiles as $file) {
$where .= $file->ID . ',';
}
if($where == "") return "(ClassName = 'File' OR ClassName = 'Image')";
$where = substr($where,0,strlen($where)-1);
$where = "`File`.ID NOT IN (" . $where . ") AND (ClassName = 'File' OR ClassName = 'Image')";
return $where;
}
/**
* Creates table for displaying unused files.
*
* @returns AssetTableField
*/
private function getAssetList() {
$where = $this->getUsedFilesList();
$assetList = new AssetTableField(
$this,
"AssetList",
"File",
array("Title" => _t('AssetAdmin.TITLE', "Title"), "LinkedURL" => _t('AssetAdmin.FILENAME', "Filename")),
"",
$where
);
$assetList->setPopupCaption(_t('AssetAdmin.VIEWASSET', "View Asset"));
$assetList->setPermissions(array("show","delete"));
$assetList->Markable = false;
return $assetList;
}
/**
* Creates array containg all unused thumbnails.
* Array is created in three steps: