@@ -14,69 +14,69 @@ |
||
14 | 14 | |
15 | 15 | class NumberOfReferencesFacet implements FacetInterface |
16 | 16 | { |
17 | - protected string $name = 'number_of_references'; |
|
17 | + protected string $name = 'number_of_references'; |
|
18 | 18 | |
19 | - protected string $label = 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:usage'; |
|
19 | + protected string $label = 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:usage'; |
|
20 | 20 | |
21 | - protected array $suggestions = [ |
|
22 | - '0', '1', '2', '3', 'etc...' |
|
23 | - ]; |
|
24 | - protected string $dataType = 'sys_file'; |
|
21 | + protected array $suggestions = [ |
|
22 | + '0', '1', '2', '3', 'etc...' |
|
23 | + ]; |
|
24 | + protected string $dataType = 'sys_file'; |
|
25 | 25 | |
26 | - public function getName(): string |
|
27 | - { |
|
28 | - return $this->name; |
|
29 | - } |
|
26 | + public function getName(): string |
|
27 | + { |
|
28 | + return $this->name; |
|
29 | + } |
|
30 | 30 | |
31 | - public function getLabel(): string |
|
32 | - { |
|
33 | - return $this->getLanguageService()->sL($this->label); |
|
34 | - } |
|
31 | + public function getLabel(): string |
|
32 | + { |
|
33 | + return $this->getLanguageService()->sL($this->label); |
|
34 | + } |
|
35 | 35 | |
36 | - public function getSuggestions(): array |
|
37 | - { |
|
38 | - return $this->suggestions; |
|
39 | - } |
|
36 | + public function getSuggestions(): array |
|
37 | + { |
|
38 | + return $this->suggestions; |
|
39 | + } |
|
40 | 40 | |
41 | - public function hasSuggestions(): bool |
|
42 | - { |
|
43 | - return true; |
|
44 | - } |
|
41 | + public function hasSuggestions(): bool |
|
42 | + { |
|
43 | + return true; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * @param string $dataType |
|
48 | - * @return $this |
|
49 | - */ |
|
50 | - public function setDataType($dataType): NumberOfReferencesFacet |
|
51 | - { |
|
52 | - $this->dataType = $dataType; |
|
53 | - return $this; |
|
54 | - } |
|
46 | + /** |
|
47 | + * @param string $dataType |
|
48 | + * @return $this |
|
49 | + */ |
|
50 | + public function setDataType($dataType): NumberOfReferencesFacet |
|
51 | + { |
|
52 | + $this->dataType = $dataType; |
|
53 | + return $this; |
|
54 | + } |
|
55 | 55 | |
56 | - public function canModifyMatcher(): bool |
|
57 | - { |
|
58 | - return false; |
|
59 | - } |
|
56 | + public function canModifyMatcher(): bool |
|
57 | + { |
|
58 | + return false; |
|
59 | + } |
|
60 | 60 | |
61 | - public function modifyMatcher(Matcher $matcher, $value): Matcher |
|
62 | - { |
|
63 | - return $matcher; |
|
64 | - } |
|
61 | + public function modifyMatcher(Matcher $matcher, $value): Matcher |
|
62 | + { |
|
63 | + return $matcher; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * Magic method implementation for retrieving state. |
|
68 | - * |
|
69 | - * @param array $states |
|
70 | - * @return $this |
|
71 | - */ |
|
72 | - public static function __set_state($states) |
|
73 | - { |
|
74 | - return new NumberOfReferencesFacet(); |
|
75 | - } |
|
66 | + /** |
|
67 | + * Magic method implementation for retrieving state. |
|
68 | + * |
|
69 | + * @param array $states |
|
70 | + * @return $this |
|
71 | + */ |
|
72 | + public static function __set_state($states) |
|
73 | + { |
|
74 | + return new NumberOfReferencesFacet(); |
|
75 | + } |
|
76 | 76 | |
77 | - protected function getLanguageService(): LanguageService |
|
78 | - { |
|
79 | - return $GLOBALS['LANG']; |
|
80 | - } |
|
77 | + protected function getLanguageService(): LanguageService |
|
78 | + { |
|
79 | + return $GLOBALS['LANG']; |
|
80 | + } |
|
81 | 81 | |
82 | 82 | } |
@@ -15,79 +15,79 @@ |
||
15 | 15 | |
16 | 16 | class TypeFacet implements FacetInterface |
17 | 17 | { |
18 | - protected string $name = 'type'; |
|
19 | - |
|
20 | - protected string $label = 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:type'; |
|
21 | - |
|
22 | - protected array $suggestions = [ |
|
23 | - File::FILETYPE_TEXT => 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:type_1', |
|
24 | - File::FILETYPE_IMAGE => 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:type_2', |
|
25 | - File::FILETYPE_AUDIO => 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:type_3', |
|
26 | - File::FILETYPE_VIDEO => 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:type_4', |
|
27 | - File::FILETYPE_APPLICATION => 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:type_5', |
|
28 | - ]; |
|
29 | - |
|
30 | - protected string $dataType = ''; |
|
31 | - |
|
32 | - public function getName(): string |
|
33 | - { |
|
34 | - return $this->name; |
|
35 | - } |
|
36 | - |
|
37 | - public function getLabel(): string |
|
38 | - { |
|
39 | - return $this->getLanguageService()->sL($this->label); |
|
40 | - } |
|
41 | - |
|
42 | - public function getSuggestions(): array |
|
43 | - { |
|
44 | - $suggestions = []; |
|
45 | - foreach ($this->suggestions as $key => $label) { |
|
46 | - $suggestions[] = array($key => $this->getLanguageService()->sL($label)); |
|
47 | - } |
|
48 | - |
|
49 | - return $suggestions; |
|
50 | - } |
|
51 | - |
|
52 | - public function hasSuggestions(): bool |
|
53 | - { |
|
54 | - return true; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @param string $dataType |
|
59 | - * @return $this |
|
60 | - */ |
|
61 | - public function setDataType($dataType): TypeFacet |
|
62 | - { |
|
63 | - $this->dataType = $dataType; |
|
64 | - return $this; |
|
65 | - } |
|
66 | - |
|
67 | - public function canModifyMatcher(): bool |
|
68 | - { |
|
69 | - return false; |
|
70 | - } |
|
71 | - |
|
72 | - public function modifyMatcher(Matcher $matcher, $value): Matcher |
|
73 | - { |
|
74 | - return $matcher; |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Magic method implementation for retrieving state. |
|
79 | - * |
|
80 | - * @param array $states |
|
81 | - * @return $this |
|
82 | - */ |
|
83 | - public static function __set_state($states) |
|
84 | - { |
|
85 | - return new TypeFacet(); |
|
86 | - } |
|
87 | - |
|
88 | - protected function getLanguageService(): LanguageService |
|
89 | - { |
|
90 | - return $GLOBALS['LANG']; |
|
91 | - } |
|
18 | + protected string $name = 'type'; |
|
19 | + |
|
20 | + protected string $label = 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:type'; |
|
21 | + |
|
22 | + protected array $suggestions = [ |
|
23 | + File::FILETYPE_TEXT => 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:type_1', |
|
24 | + File::FILETYPE_IMAGE => 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:type_2', |
|
25 | + File::FILETYPE_AUDIO => 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:type_3', |
|
26 | + File::FILETYPE_VIDEO => 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:type_4', |
|
27 | + File::FILETYPE_APPLICATION => 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:type_5', |
|
28 | + ]; |
|
29 | + |
|
30 | + protected string $dataType = ''; |
|
31 | + |
|
32 | + public function getName(): string |
|
33 | + { |
|
34 | + return $this->name; |
|
35 | + } |
|
36 | + |
|
37 | + public function getLabel(): string |
|
38 | + { |
|
39 | + return $this->getLanguageService()->sL($this->label); |
|
40 | + } |
|
41 | + |
|
42 | + public function getSuggestions(): array |
|
43 | + { |
|
44 | + $suggestions = []; |
|
45 | + foreach ($this->suggestions as $key => $label) { |
|
46 | + $suggestions[] = array($key => $this->getLanguageService()->sL($label)); |
|
47 | + } |
|
48 | + |
|
49 | + return $suggestions; |
|
50 | + } |
|
51 | + |
|
52 | + public function hasSuggestions(): bool |
|
53 | + { |
|
54 | + return true; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @param string $dataType |
|
59 | + * @return $this |
|
60 | + */ |
|
61 | + public function setDataType($dataType): TypeFacet |
|
62 | + { |
|
63 | + $this->dataType = $dataType; |
|
64 | + return $this; |
|
65 | + } |
|
66 | + |
|
67 | + public function canModifyMatcher(): bool |
|
68 | + { |
|
69 | + return false; |
|
70 | + } |
|
71 | + |
|
72 | + public function modifyMatcher(Matcher $matcher, $value): Matcher |
|
73 | + { |
|
74 | + return $matcher; |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Magic method implementation for retrieving state. |
|
79 | + * |
|
80 | + * @param array $states |
|
81 | + * @return $this |
|
82 | + */ |
|
83 | + public static function __set_state($states) |
|
84 | + { |
|
85 | + return new TypeFacet(); |
|
86 | + } |
|
87 | + |
|
88 | + protected function getLanguageService(): LanguageService |
|
89 | + { |
|
90 | + return $GLOBALS['LANG']; |
|
91 | + } |
|
92 | 92 | |
93 | 93 | } |
@@ -21,219 +21,219 @@ |
||
21 | 21 | */ |
22 | 22 | class FileReferenceService |
23 | 23 | { |
24 | - /** |
|
25 | - * Return all references found in sys_file_reference. |
|
26 | - * |
|
27 | - * @param File|int $file |
|
28 | - */ |
|
29 | - public function findFileReferences($file): array |
|
30 | - { |
|
31 | - $fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file; |
|
32 | - |
|
33 | - // Get the file references of the file. |
|
34 | - return $this->getDataService()->getRecords( |
|
35 | - 'sys_file_reference', |
|
36 | - [ |
|
37 | - 'uid_local' => $fileIdentifier, |
|
38 | - ] |
|
39 | - ); |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * Return soft image references. |
|
44 | - * |
|
45 | - * @param File|int $file |
|
46 | - */ |
|
47 | - public function findSoftImageReferences($file): array |
|
48 | - { |
|
49 | - $fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file; |
|
50 | - |
|
51 | - // Get the file references of the file in the RTE. |
|
52 | - $softReferences = $this->getDataService()->getRecords( |
|
53 | - 'sys_refindex', |
|
54 | - [ |
|
55 | - 'softref_key' => 'rtehtmlarea_images', |
|
56 | - 'ref_table' => 'sys_file', |
|
57 | - 'ref_uid' => $fileIdentifier, |
|
58 | - ] |
|
59 | - ); |
|
60 | - return $softReferences; |
|
61 | - } |
|
62 | - |
|
63 | - protected function findFileIndexReferences(File $file): array |
|
64 | - { |
|
65 | - $queryBuilder = $this->getQueryBuilder('sys_refindex'); |
|
66 | - return $queryBuilder |
|
67 | - ->select('*') |
|
68 | - ->from('sys_refindex') |
|
69 | - ->where( |
|
70 | - $queryBuilder->expr()->eq( |
|
71 | - 'ref_table', |
|
72 | - $queryBuilder->createNamedParameter('sys_file') |
|
73 | - ), |
|
74 | - $queryBuilder->expr()->eq( |
|
75 | - 'ref_uid', |
|
76 | - $queryBuilder->createNamedParameter($file->getUid(), Connection::PARAM_INT) |
|
77 | - ), |
|
78 | - $queryBuilder->expr()->neq( |
|
79 | - 'tablename', |
|
80 | - $queryBuilder->createNamedParameter('sys_file_metadata') |
|
81 | - ) |
|
82 | - ) |
|
83 | - ->executeQuery() |
|
84 | - ->fetchAllAssociative(); |
|
85 | - } |
|
86 | - |
|
87 | - public function findContentIndexReferences(File $file): array |
|
88 | - { |
|
89 | - $queryBuilder = $this->getQueryBuilder('sys_refindex'); |
|
90 | - $relatedIndexReferences = []; |
|
91 | - foreach ($this->findFileIndexReferences($file) as $fileIndexReference) { |
|
92 | - $relatedIndexReference = $queryBuilder |
|
93 | - ->select('*') |
|
94 | - ->from('sys_refindex') |
|
95 | - ->where( |
|
96 | - $queryBuilder->expr()->eq( |
|
97 | - 'ref_table', |
|
98 | - $queryBuilder->createNamedParameter('sys_file_reference') |
|
99 | - ), |
|
100 | - $queryBuilder->expr()->eq( |
|
101 | - 'ref_uid', |
|
102 | - $queryBuilder->createNamedParameter($fileIndexReference['recuid'], Connection::PARAM_INT) |
|
103 | - ), |
|
104 | - $queryBuilder->expr()->neq( |
|
105 | - 'tablename', |
|
106 | - $queryBuilder->createNamedParameter('sys_file_metadata') |
|
107 | - ) |
|
108 | - ) |
|
109 | - ->executeQuery() |
|
110 | - ->fetchAssociative(); |
|
111 | - |
|
112 | - if ($relatedIndexReference) { |
|
113 | - $relatedIndexReferences[] = $relatedIndexReference; |
|
114 | - } |
|
115 | - } |
|
116 | - return $relatedIndexReferences; |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Return link image references. |
|
121 | - * |
|
122 | - * @param File|int $file |
|
123 | - */ |
|
124 | - public function findSoftLinkReferences($file) |
|
125 | - { |
|
126 | - $fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file; |
|
127 | - |
|
128 | - // Get the link references of the file. |
|
129 | - $softReferences = $this->getDataService()->getRecords( |
|
130 | - 'sys_refindex', |
|
131 | - [ |
|
132 | - 'softref_key' => 'typolink_tag', |
|
133 | - 'ref_table' => 'sys_file', |
|
134 | - 'ref_uid' => $fileIdentifier, |
|
135 | - ] |
|
136 | - ); |
|
137 | - return $softReferences; |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * @param File|int $file |
|
142 | - */ |
|
143 | - public function countTotalReferences($file): int |
|
144 | - { |
|
145 | - |
|
146 | - $fileUid = $file instanceof File |
|
147 | - ? $file->getUid() |
|
148 | - : $file; |
|
149 | - |
|
150 | - $numberOfReferences = $this->countFileReferences($fileUid); |
|
151 | - $numberOfReferences += $this->countSoftImageReferences($fileUid); |
|
152 | - $numberOfReferences += $this->countSoftLinkReferences($fileUid); |
|
153 | - $numberOfReferences += $this->countFileIndexReferences($fileUid); |
|
154 | - |
|
155 | - return $numberOfReferences; |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * Count all references found in sys_file_reference. |
|
160 | - */ |
|
161 | - protected function countFileReferences(int $fileUid): int |
|
162 | - { |
|
163 | - return $this->getDataService() |
|
164 | - ->count( |
|
165 | - 'sys_file_reference', |
|
166 | - [ |
|
167 | - 'uid_local' => $fileUid |
|
168 | - ] |
|
169 | - ); |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * Count soft image references. |
|
174 | - */ |
|
175 | - protected function countSoftImageReferences(int $fileUid): int |
|
176 | - { |
|
177 | - return $this->getDataService() |
|
178 | - ->count( |
|
179 | - 'sys_refindex', |
|
180 | - [ |
|
181 | - 'softref_key' => 'rtehtmlarea_images', |
|
182 | - 'ref_table' => 'sys_file', |
|
183 | - 'ref_uid' => $fileUid |
|
184 | - ] |
|
185 | - ); |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * Count link image references. |
|
190 | - */ |
|
191 | - protected function countSoftLinkReferences(int $fileUid): int |
|
192 | - { |
|
193 | - return $this->getDataService() |
|
194 | - ->count( |
|
195 | - 'sys_refindex', |
|
196 | - [ |
|
197 | - 'softref_key' => 'typolink_tag', |
|
198 | - 'ref_table' => 'sys_file', |
|
199 | - 'ref_uid' => $fileUid |
|
200 | - ] |
|
201 | - ); |
|
202 | - } |
|
203 | - |
|
204 | - protected function countFileIndexReferences(int $fileUid): int |
|
205 | - { |
|
206 | - $queryBuilder = $this->getQueryBuilder('sys_refindex'); |
|
207 | - return (int)$queryBuilder |
|
208 | - ->count('*') |
|
209 | - ->from('sys_refindex') |
|
210 | - ->where( |
|
211 | - $queryBuilder->expr()->eq( |
|
212 | - 'ref_table', |
|
213 | - $queryBuilder->createNamedParameter('sys_file') |
|
214 | - ), |
|
215 | - $queryBuilder->expr()->eq( |
|
216 | - 'ref_uid', |
|
217 | - $queryBuilder->createNamedParameter($fileUid, Connection::PARAM_INT) |
|
218 | - ), |
|
219 | - $queryBuilder->expr()->neq( |
|
220 | - 'tablename', |
|
221 | - $queryBuilder->createNamedParameter('sys_file_metadata') |
|
222 | - ) |
|
223 | - ) |
|
224 | - ->executeQuery() |
|
225 | - ->fetchOne(); |
|
226 | - } |
|
227 | - |
|
228 | - protected function getQueryBuilder(string $tableName): QueryBuilder |
|
229 | - { |
|
230 | - /** @var ConnectionPool $connectionPool */ |
|
231 | - $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
232 | - return $connectionPool->getQueryBuilderForTable($tableName); |
|
233 | - } |
|
234 | - |
|
235 | - protected function getDataService(): DataService |
|
236 | - { |
|
237 | - return GeneralUtility::makeInstance(DataService::class); |
|
238 | - } |
|
24 | + /** |
|
25 | + * Return all references found in sys_file_reference. |
|
26 | + * |
|
27 | + * @param File|int $file |
|
28 | + */ |
|
29 | + public function findFileReferences($file): array |
|
30 | + { |
|
31 | + $fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file; |
|
32 | + |
|
33 | + // Get the file references of the file. |
|
34 | + return $this->getDataService()->getRecords( |
|
35 | + 'sys_file_reference', |
|
36 | + [ |
|
37 | + 'uid_local' => $fileIdentifier, |
|
38 | + ] |
|
39 | + ); |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * Return soft image references. |
|
44 | + * |
|
45 | + * @param File|int $file |
|
46 | + */ |
|
47 | + public function findSoftImageReferences($file): array |
|
48 | + { |
|
49 | + $fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file; |
|
50 | + |
|
51 | + // Get the file references of the file in the RTE. |
|
52 | + $softReferences = $this->getDataService()->getRecords( |
|
53 | + 'sys_refindex', |
|
54 | + [ |
|
55 | + 'softref_key' => 'rtehtmlarea_images', |
|
56 | + 'ref_table' => 'sys_file', |
|
57 | + 'ref_uid' => $fileIdentifier, |
|
58 | + ] |
|
59 | + ); |
|
60 | + return $softReferences; |
|
61 | + } |
|
62 | + |
|
63 | + protected function findFileIndexReferences(File $file): array |
|
64 | + { |
|
65 | + $queryBuilder = $this->getQueryBuilder('sys_refindex'); |
|
66 | + return $queryBuilder |
|
67 | + ->select('*') |
|
68 | + ->from('sys_refindex') |
|
69 | + ->where( |
|
70 | + $queryBuilder->expr()->eq( |
|
71 | + 'ref_table', |
|
72 | + $queryBuilder->createNamedParameter('sys_file') |
|
73 | + ), |
|
74 | + $queryBuilder->expr()->eq( |
|
75 | + 'ref_uid', |
|
76 | + $queryBuilder->createNamedParameter($file->getUid(), Connection::PARAM_INT) |
|
77 | + ), |
|
78 | + $queryBuilder->expr()->neq( |
|
79 | + 'tablename', |
|
80 | + $queryBuilder->createNamedParameter('sys_file_metadata') |
|
81 | + ) |
|
82 | + ) |
|
83 | + ->executeQuery() |
|
84 | + ->fetchAllAssociative(); |
|
85 | + } |
|
86 | + |
|
87 | + public function findContentIndexReferences(File $file): array |
|
88 | + { |
|
89 | + $queryBuilder = $this->getQueryBuilder('sys_refindex'); |
|
90 | + $relatedIndexReferences = []; |
|
91 | + foreach ($this->findFileIndexReferences($file) as $fileIndexReference) { |
|
92 | + $relatedIndexReference = $queryBuilder |
|
93 | + ->select('*') |
|
94 | + ->from('sys_refindex') |
|
95 | + ->where( |
|
96 | + $queryBuilder->expr()->eq( |
|
97 | + 'ref_table', |
|
98 | + $queryBuilder->createNamedParameter('sys_file_reference') |
|
99 | + ), |
|
100 | + $queryBuilder->expr()->eq( |
|
101 | + 'ref_uid', |
|
102 | + $queryBuilder->createNamedParameter($fileIndexReference['recuid'], Connection::PARAM_INT) |
|
103 | + ), |
|
104 | + $queryBuilder->expr()->neq( |
|
105 | + 'tablename', |
|
106 | + $queryBuilder->createNamedParameter('sys_file_metadata') |
|
107 | + ) |
|
108 | + ) |
|
109 | + ->executeQuery() |
|
110 | + ->fetchAssociative(); |
|
111 | + |
|
112 | + if ($relatedIndexReference) { |
|
113 | + $relatedIndexReferences[] = $relatedIndexReference; |
|
114 | + } |
|
115 | + } |
|
116 | + return $relatedIndexReferences; |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Return link image references. |
|
121 | + * |
|
122 | + * @param File|int $file |
|
123 | + */ |
|
124 | + public function findSoftLinkReferences($file) |
|
125 | + { |
|
126 | + $fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file; |
|
127 | + |
|
128 | + // Get the link references of the file. |
|
129 | + $softReferences = $this->getDataService()->getRecords( |
|
130 | + 'sys_refindex', |
|
131 | + [ |
|
132 | + 'softref_key' => 'typolink_tag', |
|
133 | + 'ref_table' => 'sys_file', |
|
134 | + 'ref_uid' => $fileIdentifier, |
|
135 | + ] |
|
136 | + ); |
|
137 | + return $softReferences; |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * @param File|int $file |
|
142 | + */ |
|
143 | + public function countTotalReferences($file): int |
|
144 | + { |
|
145 | + |
|
146 | + $fileUid = $file instanceof File |
|
147 | + ? $file->getUid() |
|
148 | + : $file; |
|
149 | + |
|
150 | + $numberOfReferences = $this->countFileReferences($fileUid); |
|
151 | + $numberOfReferences += $this->countSoftImageReferences($fileUid); |
|
152 | + $numberOfReferences += $this->countSoftLinkReferences($fileUid); |
|
153 | + $numberOfReferences += $this->countFileIndexReferences($fileUid); |
|
154 | + |
|
155 | + return $numberOfReferences; |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * Count all references found in sys_file_reference. |
|
160 | + */ |
|
161 | + protected function countFileReferences(int $fileUid): int |
|
162 | + { |
|
163 | + return $this->getDataService() |
|
164 | + ->count( |
|
165 | + 'sys_file_reference', |
|
166 | + [ |
|
167 | + 'uid_local' => $fileUid |
|
168 | + ] |
|
169 | + ); |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * Count soft image references. |
|
174 | + */ |
|
175 | + protected function countSoftImageReferences(int $fileUid): int |
|
176 | + { |
|
177 | + return $this->getDataService() |
|
178 | + ->count( |
|
179 | + 'sys_refindex', |
|
180 | + [ |
|
181 | + 'softref_key' => 'rtehtmlarea_images', |
|
182 | + 'ref_table' => 'sys_file', |
|
183 | + 'ref_uid' => $fileUid |
|
184 | + ] |
|
185 | + ); |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * Count link image references. |
|
190 | + */ |
|
191 | + protected function countSoftLinkReferences(int $fileUid): int |
|
192 | + { |
|
193 | + return $this->getDataService() |
|
194 | + ->count( |
|
195 | + 'sys_refindex', |
|
196 | + [ |
|
197 | + 'softref_key' => 'typolink_tag', |
|
198 | + 'ref_table' => 'sys_file', |
|
199 | + 'ref_uid' => $fileUid |
|
200 | + ] |
|
201 | + ); |
|
202 | + } |
|
203 | + |
|
204 | + protected function countFileIndexReferences(int $fileUid): int |
|
205 | + { |
|
206 | + $queryBuilder = $this->getQueryBuilder('sys_refindex'); |
|
207 | + return (int)$queryBuilder |
|
208 | + ->count('*') |
|
209 | + ->from('sys_refindex') |
|
210 | + ->where( |
|
211 | + $queryBuilder->expr()->eq( |
|
212 | + 'ref_table', |
|
213 | + $queryBuilder->createNamedParameter('sys_file') |
|
214 | + ), |
|
215 | + $queryBuilder->expr()->eq( |
|
216 | + 'ref_uid', |
|
217 | + $queryBuilder->createNamedParameter($fileUid, Connection::PARAM_INT) |
|
218 | + ), |
|
219 | + $queryBuilder->expr()->neq( |
|
220 | + 'tablename', |
|
221 | + $queryBuilder->createNamedParameter('sys_file_metadata') |
|
222 | + ) |
|
223 | + ) |
|
224 | + ->executeQuery() |
|
225 | + ->fetchOne(); |
|
226 | + } |
|
227 | + |
|
228 | + protected function getQueryBuilder(string $tableName): QueryBuilder |
|
229 | + { |
|
230 | + /** @var ConnectionPool $connectionPool */ |
|
231 | + $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
232 | + return $connectionPool->getQueryBuilderForTable($tableName); |
|
233 | + } |
|
234 | + |
|
235 | + protected function getDataService(): DataService |
|
236 | + { |
|
237 | + return GeneralUtility::makeInstance(DataService::class); |
|
238 | + } |
|
239 | 239 | } |