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/sapphire/trunk@55081 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2008-05-24 05:19:42 +00:00
parent d18509a3f5
commit 0a3b20e672

View File

@ -391,8 +391,7 @@ class Folder extends File {
new LiteralField("UploadIframe",
$this->getUploadIframe()
)
)/* This has been disabled for now because of it's mass memory consumption
,
),
new Tab(_t('AssetAdmin.UNUSEDFILESTAB', "Unused files"),
new LiteralField("UnusedAssets",
"<div id=\"UnusedAssets\"><h2>"._t('AssetAdmin.UNUSEDFILESTITLE', 'Unused files')."</h2>"
@ -405,7 +404,7 @@ class Folder extends File {
<button class=\"action\">"._t('AssetAdmin.DELETEUNUSEDTHUMBNAILS', 'Delete unused thumbnails')."</button>
</div>"
)
)*/
)
),
new HiddenField("ID")
);
@ -414,6 +413,69 @@ class Folder extends File {
return $fields;
}
/**
* Creates table for displaying unused files.
*
* @returns AssetTableField
*/
protected 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;
}
/**
* 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.
*/
protected 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;
}
/**
* Display the upload form. Returns an iframe tag that will show admin/assets/uploadiframe.