Completed
Push — master ( 522461...c89cc2 )
by Fabien
02:24
created

DuplicateRecordsFinderTool::getDatabaseConnection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
namespace Fab\Media\Tool;
3
4
/*
5
 * This file is part of the Fab/Media project under GPLv2 or later.
6
 *
7
 * For the full copyright and license information, please read the
8
 * LICENSE.md file that was distributed with this source code.
9
 */
10
11
use Fab\Vidi\Service\DataService;
12
use TYPO3\CMS\Core\Resource\StorageRepository;
13
use TYPO3\CMS\Core\Utility\GeneralUtility;
14
use Fab\Vidi\Tool\AbstractTool;
15
16
/**
17
 * Search for duplicate files having the same "sha1" and process them.
18
 */
19
class DuplicateRecordsFinderTool extends AbstractTool
20
{
21
22
    /**
23
     * Display the title of the tool on the welcome screen.
24
     *
25
     * @return string
26
     */
27
    public function getTitle()
28
    {
29
        return 'Find duplicate Records';
30
    }
31
32
    /**
33
     * Display the description of the tool in the welcome screen.
34
     *
35
     * @return string
36
     */
37 View Code Duplication
    public function getDescription()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
38
    {
39
        $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/DuplicateRecordsFinder/Launcher.html';
40
        $view = $this->initializeStandaloneView($templateNameAndPath);
41
        $view->assign('sitePath', PATH_site);
42
        return $view->render();
43
    }
44
45
    /**
46
     * Do the job: analyse Index.
47
     *
48
     * @param array $arguments
49
     * @return string
50
     */
51
    public function work(array $arguments = [])
52
    {
53
54
        $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/DuplicateRecordsFinder/WorkResult.html';
55
        $view = $this->initializeStandaloneView($templateNameAndPath);
56
57
        $duplicateRecordsReports = [];
58 View Code Duplication
        foreach ($this->getStorageRepository()->findAll() as $storage) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
59
60
            if ($storage->isOnline()) {
61
                $duplicateFiles = $this->getIndexAnalyser()->searchForDuplicateIdentifiers($storage);
62
                $duplicateRecordsReports[] = array(
63
                    'storage' => $storage,
64
                    'duplicateFiles' => $duplicateFiles,
65
                    'numberOfDuplicateFiles' => count($duplicateFiles),
66
                );
67
            }
68
        }
69
70
        $view->assign('duplicateRecordsReports', $duplicateRecordsReports);
71
72
        return $view->render();
73
    }
74
75
    /**
76
     * Return a pointer to the database.
77
     *
78
     * @return \Fab\Media\Index\IndexAnalyser|object
79
     */
80
    protected function getIndexAnalyser()
81
    {
82
        return GeneralUtility::makeInstance(\Fab\Media\Index\IndexAnalyser::class);
83
    }
84
85
    /**
86
     * @return StorageRepository|object
87
     */
88
    protected function getStorageRepository()
89
    {
90
        return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class);
91
    }
92
93
    /**
94
     * Tell whether the tools should be displayed according to the context.
95
     *
96
     * @return bool
97
     */
98
    public function isShown()
99
    {
100
        return $this->getBackendUser()->isAdmin();
101
    }
102
103
}
104
105