BUGFIX: Fixed the code for the unused file list, although the feature is still disabled.

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@99816 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2010-02-24 04:42:46 +00:00
parent 6be8d8b56b
commit 1c5dc228a7

View File

@ -372,10 +372,10 @@ class Folder extends File {
new LiteralField("UploadIframe",
$this->getUploadIframe()
)
)/*,
),
new Tab("UnusedFiles", _t('Folder.UNUSEDFILESTAB', "Unused files"),
new Folder_UnusedAssetsField($this)
)*/
)
),
new HiddenField("ID")
);
@ -394,7 +394,7 @@ class Folder extends File {
*
* @returns String where clause which will work as filter.
*/
public function getUsedFilesList() {
public function getUnusedFilesListFilter() {
$result = DB::query("SELECT DISTINCT \"FileID\" FROM \"SiteTree_ImageTracking\"");
$usedFiles = array();
$where = '';
@ -403,7 +403,7 @@ class Folder extends File {
if($result->numRecords() > 0) {
while($nextResult = $result->next()) {
$where .= $nextResult['FileID'] . ',';
}
}
}
foreach($classes as $className) {
@ -411,26 +411,26 @@ class Folder extends File {
$ids = $query->execute()->column();
if(!count($ids)) continue;
foreach(singleton($className)->has_one() as $fieldName => $joinClass) {
foreach(singleton($className)->has_one() as $relName => $joinClass) {
if($joinClass == 'Image' || $joinClass == 'File') {
foreach($ids as $id) {
$object = DataObject::get_by_id($className, (int) $id);
if($object && $object->$fieldName != NULL) $usedFiles[] = $object->$fieldName;
unset($object);
}
$fieldName = $relName .'ID';
$query = singleton($className)->extendedSQL("$fieldName > 0");
$query->distinct = true;
$query->select = array($fieldName);
$usedFiles = array_merge($usedFiles, $query->execute()->column());
} elseif($joinClass == 'Folder') {
// @todo
}
}
}
foreach($usedFiles as $file) {
$where .= $file->ID . ',';
if($usedFiles) {
return "\"File\".\"ID\" NOT IN (" . implode(', ', $usedFiles) . ") AND (\"ClassName\" = 'File' OR \"ClassName\" = 'Image')";
} else {
return "(\"ClassName\" = 'File' OR \"ClassName\" = 'Image')";
}
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;
}
@ -493,7 +493,7 @@ class Folder_UnusedAssetsField extends CompositeField {
* @returns AssetTableField
*/
protected function getAssetList() {
$where = $this->folder->getUsedFilesList();
$where = $this->folder->getUnusedFilesListFilter();
$assetList = new AssetTableField(
$this->folder,
"AssetList",