Skip to content

Commit

Permalink
improve unused view
Browse files Browse the repository at this point in the history
  • Loading branch information
fritzmg committed Oct 8, 2024
1 parent 4c0c947 commit 00a080d
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 71 deletions.
105 changes: 53 additions & 52 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,52 +1,53 @@
{
"name": "inspiredminds/contao-file-usage",
"description": "Contao extension that allows you to search for references of files in the database assisted file manager.",
"type": "contao-bundle",
"license": "LGPL-3.0-or-later",
"homepage": "https://github.com/inspiredminds/contao-file-usage",
"authors": [
{
"name": "Fritz Michael Gschwantner",
"email": "[email protected]",
"role": "Developer"
}
],
"support": {
"issues": "https://github.com/inspiredminds/contao-file-usage/issues",
"source": "https://github.com/inspiredminds/contao-file-usage",
"forum": "https://community.contao.org/de"
},
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/fritzmg"
}
],
"require": {
"php": ">=7.4",
"contao/core-bundle": "^4.9 || ^5.0",
"khill/php-duration": "^1.0",
"symfony/cache": "^4.4 || ^5.4 || ^6.2",
"symfony/config": "^4.4 || ^5.4 || ^6.2",
"symfony/dependency-injection": "^4.4 || ^5.4 || ^6.2",
"symfony/http-kernel": "^4.4 || ^5.4 || ^6.2"
},
"autoload": {
"psr-4": {
"InspiredMinds\\ContaoFileUsage\\": "src/"
}
},
"extra": {
"contao-manager-plugin": "InspiredMinds\\ContaoFileUsage\\ContaoManager\\Plugin"
},
"require-dev": {
"contao/easy-coding-standard": "^6.0",
"contao/rector": "^1.0"
},
"config": {
"allow-plugins": {
"contao-components/installer": true,
"php-http/discovery": false
}
}
}
{
"name": "inspiredminds/contao-file-usage",
"description": "Contao extension that allows you to search for references of files in the database assisted file manager.",
"type": "contao-bundle",
"license": "LGPL-3.0-or-later",
"homepage": "https://github.com/inspiredminds/contao-file-usage",
"authors": [
{
"name": "Fritz Michael Gschwantner",
"email": "[email protected]",
"role": "Developer"
}
],
"support": {
"issues": "https://github.com/inspiredminds/contao-file-usage/issues",
"source": "https://github.com/inspiredminds/contao-file-usage",
"forum": "https://community.contao.org/de"
},
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/fritzmg"
}
],
"require": {
"php": ">=7.4",
"contao/core-bundle": "^4.9 || ^5.0",
"khill/php-duration": "^1.0",
"symfony/cache": "^4.4 || ^5.4 || ^6.2",
"symfony/config": "^4.4 || ^5.4 || ^6.2",
"symfony/dependency-injection": "^4.4 || ^5.4 || ^6.2",
"symfony/http-kernel": "^4.4 || ^5.4 || ^6.2",
"webmozart/path-util": "^2.3"
},
"autoload": {
"psr-4": {
"InspiredMinds\\ContaoFileUsage\\": "src/"
}
},
"extra": {
"contao-manager-plugin": "InspiredMinds\\ContaoFileUsage\\ContaoManager\\Plugin"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.16 || ^3.0",
"rector/rector": "^0.14.5"
},
"config": {
"allow-plugins": {
"contao-components/installer": true,
"php-http/discovery": false
}
}
}
42 changes: 23 additions & 19 deletions src/DataContainer/FolderDataContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Symfony\Component\Cache\Adapter\AdapterInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Contracts\Translation\TranslatorInterface;
use Webmozart\PathUtil\Path;

if (class_exists(FolderDriver::class)) {
class FolderParent extends FolderDriver
Expand All @@ -39,7 +40,7 @@ class FolderParent extends DC_Folder

class FolderDataContainer extends FolderParent
{
protected static $breadcrumbSet = false;
protected static $firstIteration = false;

protected function generateTree($path, $intMargin, $mount = false, $blnProtected = true, $arrClipboard = null, $arrFound = [])
{
Expand All @@ -59,36 +60,39 @@ protected function generateTree($path, $intMargin, $mount = false, $blnProtected
/** @var AdapterInterface $cache */
$cache = $container->get('contao_file_usage.file_usage_cache');

if (!self::$breadcrumbSet && $request->query->get('refresh')) {
if (!self::$firstIteration && $request->query->get('refresh')) {
/** @var FileUsageFinderInterface $finder */
$finder = $container->get('contao_file_usage.finder.file_usage');
$finder->find();
}

$unused = [];
if (!self::$firstIteration) {
$unused = [];
$projectDir = System::getContainer()->getParameter('kernel.project_dir');
$relativePath = Path::makeRelative($path, $projectDir);

foreach (FilesModel::findByType('file') ?? [] as $file) {
$uuid = StringUtil::binToUuid($file->uuid);
/** @var FilesModel $file */
foreach (FilesModel::findBy(["type = 'file'", 'path LIKE ?'], [rtrim($relativePath, '/').'/%']) ?? [] as $file) {
$uuid = StringUtil::binToUuid($file->uuid);

$item = $cache->getItem($uuid);
$item = $cache->getItem($uuid);

if ($item->isHit()) {
/** @var Results $results */
$results = $item->get();
}
if ($item->isHit()) {
/** @var Results $results */
$results = $item->get();
}

if (!$item->isHit() || !$results->hasResults()) {
$unused[] = $file->path;
if (!$item->isHit() || !$results->hasResults()) {
$unused[] = $file->path;
}
}
}

if (!empty($arrFound)) {
$unused = array_intersect($arrFound, $unused);
}
if (!empty($arrFound)) {
$unused = array_intersect($arrFound, $unused);
}

$arrFound = $unused;
$arrFound = $unused;

if (!self::$breadcrumbSet) {
/** @var TranslatorInterface $translator */
$translator = $container->get('translator');

Expand All @@ -110,7 +114,7 @@ protected function generateTree($path, $intMargin, $mount = false, $blnProtected
$GLOBALS['TL_DCA']['tl_files']['list']['global_operations']['unused']['icon'] = 'bundles/contaofileusage/refresh.svg';
$GLOBALS['TL_DCA']['tl_files']['list']['global_operations']['unused']['label'] = $GLOBALS['TL_LANG']['tl_files']['refresh_unused'];

self::$breadcrumbSet = true;
self::$firstIteration = true;
}
}

Expand Down

0 comments on commit 00a080d

Please sign in to comment.