Skip to content

Commit a516ee5

Browse files
committed
#29411: Naming update
1 parent 60da76c commit a516ee5

File tree

3 files changed

+28
-52
lines changed

3 files changed

+28
-52
lines changed

app/code/Magento/MediaGalleryUi/Controller/Adminhtml/Directories/GetTree.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Magento\Framework\App\Action\HttpGetActionInterface;
1212
use Magento\Framework\Controller\Result\Json;
1313
use Magento\Framework\Controller\ResultFactory;
14-
use Magento\MediaGalleryUi\Model\Directories\FolderTree;
14+
use Magento\MediaGalleryUi\Model\Directories\GetDirectoryTree;
1515
use Psr\Log\LoggerInterface;
1616

1717
/**
@@ -33,33 +33,35 @@ class GetTree extends Action implements HttpGetActionInterface
3333
private $logger;
3434

3535
/**
36-
* @var FolderTree
36+
* @var GetDirectoryTree
3737
*/
38-
private $folderTree;
38+
private $getDirectoryTree;
3939

4040
/**
4141
* Constructor
4242
*
4343
* @param Action\Context $context
4444
* @param LoggerInterface $logger
45-
* @param FolderTree $folderTree
45+
* @param GetDirectoryTree $getDirectoryTree
4646
*/
4747
public function __construct(
4848
Action\Context $context,
4949
LoggerInterface $logger,
50-
FolderTree $folderTree
50+
GetDirectoryTree $getDirectoryTree
5151
) {
5252
parent::__construct($context);
5353
$this->logger = $logger;
54-
$this->folderTree = $folderTree;
54+
$this->getDirectoryTree = $getDirectoryTree;
5555
}
5656
/**
5757
* @inheritdoc
5858
*/
5959
public function execute()
6060
{
6161
try {
62-
$responseContent[] = $this->folderTree->buildTree();
62+
$responseContent = [
63+
$this->getDirectoryTree->execute()
64+
];
6365
$responseCode = self::HTTP_OK;
6466
} catch (\Exception $exception) {
6567
$this->logger->critical($exception);

app/code/Magento/MediaGalleryUi/Model/Directories/FolderTree.php renamed to app/code/Magento/MediaGalleryUi/Model/Directories/GetDirectoryTree.php

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,58 +7,61 @@
77

88
namespace Magento\MediaGalleryUi\Model\Directories;
99

10+
use Magento\Framework\App\Filesystem\DirectoryList;
1011
use Magento\Framework\Exception\ValidatorException;
1112
use Magento\Framework\Filesystem;
1213
use Magento\Framework\Filesystem\Directory\Read;
1314
use Magento\MediaGalleryApi\Api\IsPathExcludedInterface;
1415

1516
/**
16-
* Build folder tree structure by path
17+
* Build media gallery folder tree structure by path
1718
*/
18-
class FolderTree
19+
class GetDirectoryTree
1920
{
2021
/**
2122
* @var Filesystem
2223
*/
2324
private $filesystem;
2425

25-
/**
26-
* @var string
27-
*/
28-
private $path;
29-
3026
/**
3127
* @var IsPathExcludedInterface
3228
*/
3329
private $isPathExcluded;
3430

3531
/**
36-
* Constructor
37-
*
3832
* @param Filesystem $filesystem
39-
* @param string $path
4033
* @param IsPathExcludedInterface $isPathExcluded
4134
*/
4235
public function __construct(
4336
Filesystem $filesystem,
44-
string $path,
4537
IsPathExcludedInterface $isPathExcluded
4638
) {
4739
$this->filesystem = $filesystem;
48-
$this->path = $path;
4940
$this->isPathExcluded = $isPathExcluded;
5041
}
5142

5243
/**
5344
* Return directory folder structure in array
5445
*
55-
* @param bool $skipRoot
5646
* @return array
5747
* @throws ValidatorException
5848
*/
59-
public function buildTree(bool $skipRoot = true): array
49+
public function execute(): array
6050
{
61-
return $this->buildFolderTree($this->getDirectories(), $skipRoot);
51+
$tree = [
52+
'name' => 'root',
53+
'path' => '/',
54+
'children' => []
55+
];
56+
$directories = $this->getDirectories();
57+
foreach ($directories as $idx => &$node) {
58+
$node['children'] = [];
59+
$result = $this->findParent($node, $tree);
60+
$parent = &$result['treeNode'];
61+
62+
$parent['children'][] = &$directories[$idx];
63+
}
64+
return $tree['children'];
6265
}
6366

6467
/**
@@ -72,7 +75,7 @@ private function getDirectories(): array
7275
$directories = [];
7376

7477
/** @var Read $directory */
75-
$directory = $this->filesystem->getDirectoryRead($this->path);
78+
$directory = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA);
7679

7780
if (!$directory->isDirectory()) {
7881
return $directories;
@@ -96,30 +99,6 @@ private function getDirectories(): array
9699
return $directories;
97100
}
98101

99-
/**
100-
* Build folder tree structure by provided directories path
101-
*
102-
* @param array $directories
103-
* @param bool $skipRoot
104-
* @return array
105-
*/
106-
private function buildFolderTree(array $directories, bool $skipRoot): array
107-
{
108-
$tree = [
109-
'name' => 'root',
110-
'path' => '/',
111-
'children' => []
112-
];
113-
foreach ($directories as $idx => &$node) {
114-
$node['children'] = [];
115-
$result = $this->findParent($node, $tree);
116-
$parent = & $result['treeNode'];
117-
118-
$parent['children'][] =& $directories[$idx];
119-
}
120-
return $skipRoot ? $tree['children'] : $tree;
121-
}
122-
123102
/**
124103
* Find parent directory
125104
*

app/code/Magento/MediaGalleryUi/etc/di.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@
2828
</argument>
2929
</arguments>
3030
</type>
31-
<type name="Magento\MediaGalleryUi\Model\Directories\FolderTree">
32-
<arguments>
33-
<argument name="path" xsi:type="string">media</argument>
34-
</arguments>
35-
</type>
3631
<type name="Magento\MediaGalleryUi\Model\AssetDetailsProvider\Type">
3732
<arguments>
3833
<argument name="types" xsi:type="array">

0 commit comments

Comments
 (0)