@@ -23,143 +23,143 @@ |
||
23 | 23 | class MediaIndexer |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * @var ResourceStorage |
|
28 | - */ |
|
29 | - protected $storage = null; |
|
30 | - |
|
31 | - /** |
|
32 | - * @param ResourceStorage $storage |
|
33 | - */ |
|
34 | - public function __construct(ResourceStorage $storage) |
|
35 | - { |
|
36 | - $this->storage = $storage; |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * @param \TYPO3\CMS\Core\Resource\File $file |
|
41 | - * @return $this |
|
42 | - */ |
|
43 | - public function updateIndex(File $file) |
|
44 | - { |
|
45 | - $this->getCoreIndexer()->updateIndexEntry($file); |
|
46 | - return $this; |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * @param \TYPO3\CMS\Core\Resource\File $file |
|
51 | - * @return $this |
|
52 | - */ |
|
53 | - public function extractMetadata(File $file) |
|
54 | - { |
|
55 | - |
|
56 | - $extractionServices = $this->getExtractorRegistry()->getExtractorsWithDriverSupport($this->storage->getDriverType()); |
|
57 | - |
|
58 | - $newMetaData = array( |
|
59 | - 0 => $file->_getMetaData() |
|
60 | - ); |
|
61 | - foreach ($extractionServices as $service) { |
|
62 | - if ($service->canProcess($file)) { |
|
63 | - $newMetaData[$service->getPriority()] = $service->extractMetaData($file, $newMetaData); |
|
64 | - } |
|
65 | - } |
|
66 | - |
|
67 | - ksort($newMetaData); |
|
68 | - $metaData = []; |
|
69 | - foreach ($newMetaData as $data) { |
|
70 | - $metaData = array_merge($metaData, $data); |
|
71 | - } |
|
72 | - $file->_updateMetaDataProperties($metaData); |
|
73 | - $this->getMetaDataRepository()->update($file->getUid(), $metaData); |
|
74 | - $this->getFileIndexRepository()->updateIndexingTime($file->getUid()); |
|
75 | - |
|
76 | - return $this; |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * @param \TYPO3\CMS\Core\Resource\File $file |
|
81 | - * @return $this |
|
82 | - */ |
|
83 | - public function applyDefaultCategories(File $file) |
|
84 | - { |
|
85 | - |
|
86 | - $categoryList = ConfigurationUtility::getInstance()->get('default_categories'); |
|
87 | - $categories = GeneralUtility::trimExplode(',', $categoryList, true); |
|
88 | - |
|
89 | - foreach ($categories as $category) { |
|
90 | - $values = array( |
|
91 | - 'uid_local' => $category, |
|
92 | - 'uid_foreign' => $this->getFileMetadataIdentifier($file), |
|
93 | - 'tablenames' => 'sys_file_metadata', |
|
94 | - 'fieldname' => 'categories', |
|
95 | - ); |
|
96 | - $this->getDataService()->insert('sys_category_record_mm', $values); |
|
97 | - } |
|
98 | - |
|
99 | - $metaData['categories'] = count($categories); |
|
100 | - $file->_updateMetaDataProperties($metaData); |
|
101 | - $this->getMetaDataRepository()->update($file->getUid(), $metaData); |
|
102 | - $this->getFileIndexRepository()->updateIndexingTime($file->getUid()); |
|
103 | - return $this; |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Retrieve the file metadata uid which is different from the file uid. |
|
108 | - * |
|
109 | - * @param \TYPO3\CMS\Core\Resource\File $file |
|
110 | - * @return int |
|
111 | - */ |
|
112 | - protected function getFileMetadataIdentifier(File $file) |
|
113 | - { |
|
114 | - $metadataProperties = $file->_getMetaData(); |
|
115 | - return isset($metadataProperties['_ORIG_uid']) ? (int)$metadataProperties['_ORIG_uid'] : (int)$metadataProperties['uid']; |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * Returns an instance of the FileIndexRepository |
|
121 | - * |
|
122 | - * @return FileIndexRepository |
|
123 | - */ |
|
124 | - protected function getFileIndexRepository() |
|
125 | - { |
|
126 | - return FileIndexRepository::getInstance(); |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * Returns an instance of the FileIndexRepository |
|
131 | - * |
|
132 | - * @return MetaDataRepository |
|
133 | - */ |
|
134 | - protected function getMetaDataRepository() |
|
135 | - { |
|
136 | - return MetaDataRepository::getInstance(); |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * Returns an instance of the FileIndexRepository |
|
141 | - * |
|
142 | - * @return ExtractorRegistry |
|
143 | - */ |
|
144 | - protected function getExtractorRegistry() |
|
145 | - { |
|
146 | - return ExtractorRegistry::getInstance(); |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * @return object|DataService |
|
151 | - */ |
|
152 | - protected function getDataService(): DataService |
|
153 | - { |
|
154 | - return GeneralUtility::makeInstance(DataService::class); |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * @return \TYPO3\CMS\Core\Resource\Index\Indexer|object |
|
159 | - */ |
|
160 | - protected function getCoreIndexer() |
|
161 | - { |
|
162 | - return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\Index\Indexer::class, $this->storage); |
|
163 | - } |
|
26 | + /** |
|
27 | + * @var ResourceStorage |
|
28 | + */ |
|
29 | + protected $storage = null; |
|
30 | + |
|
31 | + /** |
|
32 | + * @param ResourceStorage $storage |
|
33 | + */ |
|
34 | + public function __construct(ResourceStorage $storage) |
|
35 | + { |
|
36 | + $this->storage = $storage; |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * @param \TYPO3\CMS\Core\Resource\File $file |
|
41 | + * @return $this |
|
42 | + */ |
|
43 | + public function updateIndex(File $file) |
|
44 | + { |
|
45 | + $this->getCoreIndexer()->updateIndexEntry($file); |
|
46 | + return $this; |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * @param \TYPO3\CMS\Core\Resource\File $file |
|
51 | + * @return $this |
|
52 | + */ |
|
53 | + public function extractMetadata(File $file) |
|
54 | + { |
|
55 | + |
|
56 | + $extractionServices = $this->getExtractorRegistry()->getExtractorsWithDriverSupport($this->storage->getDriverType()); |
|
57 | + |
|
58 | + $newMetaData = array( |
|
59 | + 0 => $file->_getMetaData() |
|
60 | + ); |
|
61 | + foreach ($extractionServices as $service) { |
|
62 | + if ($service->canProcess($file)) { |
|
63 | + $newMetaData[$service->getPriority()] = $service->extractMetaData($file, $newMetaData); |
|
64 | + } |
|
65 | + } |
|
66 | + |
|
67 | + ksort($newMetaData); |
|
68 | + $metaData = []; |
|
69 | + foreach ($newMetaData as $data) { |
|
70 | + $metaData = array_merge($metaData, $data); |
|
71 | + } |
|
72 | + $file->_updateMetaDataProperties($metaData); |
|
73 | + $this->getMetaDataRepository()->update($file->getUid(), $metaData); |
|
74 | + $this->getFileIndexRepository()->updateIndexingTime($file->getUid()); |
|
75 | + |
|
76 | + return $this; |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * @param \TYPO3\CMS\Core\Resource\File $file |
|
81 | + * @return $this |
|
82 | + */ |
|
83 | + public function applyDefaultCategories(File $file) |
|
84 | + { |
|
85 | + |
|
86 | + $categoryList = ConfigurationUtility::getInstance()->get('default_categories'); |
|
87 | + $categories = GeneralUtility::trimExplode(',', $categoryList, true); |
|
88 | + |
|
89 | + foreach ($categories as $category) { |
|
90 | + $values = array( |
|
91 | + 'uid_local' => $category, |
|
92 | + 'uid_foreign' => $this->getFileMetadataIdentifier($file), |
|
93 | + 'tablenames' => 'sys_file_metadata', |
|
94 | + 'fieldname' => 'categories', |
|
95 | + ); |
|
96 | + $this->getDataService()->insert('sys_category_record_mm', $values); |
|
97 | + } |
|
98 | + |
|
99 | + $metaData['categories'] = count($categories); |
|
100 | + $file->_updateMetaDataProperties($metaData); |
|
101 | + $this->getMetaDataRepository()->update($file->getUid(), $metaData); |
|
102 | + $this->getFileIndexRepository()->updateIndexingTime($file->getUid()); |
|
103 | + return $this; |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Retrieve the file metadata uid which is different from the file uid. |
|
108 | + * |
|
109 | + * @param \TYPO3\CMS\Core\Resource\File $file |
|
110 | + * @return int |
|
111 | + */ |
|
112 | + protected function getFileMetadataIdentifier(File $file) |
|
113 | + { |
|
114 | + $metadataProperties = $file->_getMetaData(); |
|
115 | + return isset($metadataProperties['_ORIG_uid']) ? (int)$metadataProperties['_ORIG_uid'] : (int)$metadataProperties['uid']; |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * Returns an instance of the FileIndexRepository |
|
121 | + * |
|
122 | + * @return FileIndexRepository |
|
123 | + */ |
|
124 | + protected function getFileIndexRepository() |
|
125 | + { |
|
126 | + return FileIndexRepository::getInstance(); |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * Returns an instance of the FileIndexRepository |
|
131 | + * |
|
132 | + * @return MetaDataRepository |
|
133 | + */ |
|
134 | + protected function getMetaDataRepository() |
|
135 | + { |
|
136 | + return MetaDataRepository::getInstance(); |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * Returns an instance of the FileIndexRepository |
|
141 | + * |
|
142 | + * @return ExtractorRegistry |
|
143 | + */ |
|
144 | + protected function getExtractorRegistry() |
|
145 | + { |
|
146 | + return ExtractorRegistry::getInstance(); |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * @return object|DataService |
|
151 | + */ |
|
152 | + protected function getDataService(): DataService |
|
153 | + { |
|
154 | + return GeneralUtility::makeInstance(DataService::class); |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * @return \TYPO3\CMS\Core\Resource\Index\Indexer|object |
|
159 | + */ |
|
160 | + protected function getCoreIndexer() |
|
161 | + { |
|
162 | + return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\Index\Indexer::class, $this->storage); |
|
163 | + } |
|
164 | 164 | |
165 | 165 | } |
@@ -20,164 +20,164 @@ |
||
20 | 20 | */ |
21 | 21 | class FileReferenceService |
22 | 22 | { |
23 | - /** |
|
24 | - * Return all references found in sys_file_reference. |
|
25 | - * |
|
26 | - * @param File|int $file |
|
27 | - * @return array |
|
28 | - */ |
|
29 | - public function findFileReferences($file) |
|
30 | - { |
|
31 | - |
|
32 | - $fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file; |
|
33 | - |
|
34 | - // Get the file references of the file. |
|
35 | - return $this->getDataService()->getRecords( |
|
36 | - 'sys_file_reference', |
|
37 | - [ |
|
38 | - 'uid_local' => $fileIdentifier, |
|
39 | - ] |
|
40 | - ); |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * Return soft image references. |
|
45 | - * |
|
46 | - * @param File|int $file |
|
47 | - * @return array |
|
48 | - */ |
|
49 | - public function findSoftImageReferences($file) |
|
50 | - { |
|
51 | - |
|
52 | - $fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file; |
|
53 | - |
|
54 | - // Get the file references of the file in the RTE. |
|
55 | - $softReferences = $this->getDataService()->getRecords( |
|
56 | - 'sys_refindex', |
|
57 | - [ |
|
58 | - 'softref_key' => 'rtehtmlarea_images', |
|
59 | - 'ref_table' => 'sys_file', |
|
60 | - 'ref_uid' => $fileIdentifier, |
|
61 | - ] |
|
62 | - ); |
|
63 | - return $softReferences; |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * Return link image references. |
|
68 | - * |
|
69 | - * @param File|int $file |
|
70 | - * @return array |
|
71 | - */ |
|
72 | - public function findSoftLinkReferences($file) |
|
73 | - { |
|
74 | - |
|
75 | - $fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file; |
|
76 | - |
|
77 | - // Get the link references of the file. |
|
78 | - $softReferences = $this->getDataService()->getRecords( |
|
79 | - 'sys_refindex', |
|
80 | - [ |
|
81 | - 'softref_key' => 'typolink_tag', |
|
82 | - 'ref_table' => 'sys_file', |
|
83 | - 'ref_uid' => $fileIdentifier, |
|
84 | - ] |
|
85 | - ); |
|
86 | - return $softReferences; |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * Count all references found in sys_file_reference. |
|
91 | - * |
|
92 | - * @param File|int $file |
|
93 | - * @return int |
|
94 | - */ |
|
95 | - public function countFileReferences($file) |
|
96 | - { |
|
97 | - $fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file; |
|
98 | - |
|
99 | - return $this->getDataService() |
|
100 | - ->count( |
|
101 | - 'sys_file_reference', |
|
102 | - [ |
|
103 | - 'uid_local' => $fileIdentifier |
|
104 | - ] |
|
105 | - ); |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Count soft image references. |
|
110 | - * |
|
111 | - * @param File|int $file |
|
112 | - * @return int |
|
113 | - */ |
|
114 | - public function countSoftImageReferences($file) |
|
115 | - { |
|
116 | - $fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file; |
|
117 | - |
|
118 | - return $this->getDataService() |
|
119 | - ->count( |
|
120 | - 'sys_refindex', |
|
121 | - [ |
|
122 | - 'softref_key' => 'rtehtmlarea_images', |
|
123 | - 'ref_table' => 'sys_file', |
|
124 | - 'ref_uid' => $fileIdentifier |
|
125 | - ] |
|
126 | - ); |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * Count link image references. |
|
131 | - * |
|
132 | - * @param File|int $file |
|
133 | - * @return int |
|
134 | - */ |
|
135 | - public function countSoftLinkReferences($file) |
|
136 | - { |
|
137 | - $fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file; |
|
138 | - |
|
139 | - return $this->getDataService() |
|
140 | - ->count( |
|
141 | - 'sys_refindex', |
|
142 | - [ |
|
143 | - 'softref_key' => 'typolink_tag', |
|
144 | - 'ref_table' => 'sys_file', |
|
145 | - 'ref_uid' => $fileIdentifier |
|
146 | - ] |
|
147 | - ); |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * Count total reference. |
|
152 | - * |
|
153 | - * @param File|int $file |
|
154 | - * @return int |
|
155 | - */ |
|
156 | - public function countTotalReferences($file) |
|
157 | - { |
|
158 | - $numberOfReferences = $this->countFileReferences($file); |
|
159 | - $numberOfReferences += $this->countSoftImageReferences($file); |
|
160 | - $numberOfReferences += $this->countSoftLinkReferences($file); |
|
161 | - |
|
162 | - return $numberOfReferences; |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * @param string $tableName |
|
167 | - * @return object|QueryBuilder |
|
168 | - */ |
|
169 | - protected function getQueryBuilder($tableName): QueryBuilder |
|
170 | - { |
|
171 | - /** @var ConnectionPool $connectionPool */ |
|
172 | - $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
173 | - return $connectionPool->getQueryBuilderForTable($tableName); |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * @return object|DataService |
|
178 | - */ |
|
179 | - protected function getDataService(): DataService |
|
180 | - { |
|
181 | - return GeneralUtility::makeInstance(DataService::class); |
|
182 | - } |
|
23 | + /** |
|
24 | + * Return all references found in sys_file_reference. |
|
25 | + * |
|
26 | + * @param File|int $file |
|
27 | + * @return array |
|
28 | + */ |
|
29 | + public function findFileReferences($file) |
|
30 | + { |
|
31 | + |
|
32 | + $fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file; |
|
33 | + |
|
34 | + // Get the file references of the file. |
|
35 | + return $this->getDataService()->getRecords( |
|
36 | + 'sys_file_reference', |
|
37 | + [ |
|
38 | + 'uid_local' => $fileIdentifier, |
|
39 | + ] |
|
40 | + ); |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * Return soft image references. |
|
45 | + * |
|
46 | + * @param File|int $file |
|
47 | + * @return array |
|
48 | + */ |
|
49 | + public function findSoftImageReferences($file) |
|
50 | + { |
|
51 | + |
|
52 | + $fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file; |
|
53 | + |
|
54 | + // Get the file references of the file in the RTE. |
|
55 | + $softReferences = $this->getDataService()->getRecords( |
|
56 | + 'sys_refindex', |
|
57 | + [ |
|
58 | + 'softref_key' => 'rtehtmlarea_images', |
|
59 | + 'ref_table' => 'sys_file', |
|
60 | + 'ref_uid' => $fileIdentifier, |
|
61 | + ] |
|
62 | + ); |
|
63 | + return $softReferences; |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * Return link image references. |
|
68 | + * |
|
69 | + * @param File|int $file |
|
70 | + * @return array |
|
71 | + */ |
|
72 | + public function findSoftLinkReferences($file) |
|
73 | + { |
|
74 | + |
|
75 | + $fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file; |
|
76 | + |
|
77 | + // Get the link references of the file. |
|
78 | + $softReferences = $this->getDataService()->getRecords( |
|
79 | + 'sys_refindex', |
|
80 | + [ |
|
81 | + 'softref_key' => 'typolink_tag', |
|
82 | + 'ref_table' => 'sys_file', |
|
83 | + 'ref_uid' => $fileIdentifier, |
|
84 | + ] |
|
85 | + ); |
|
86 | + return $softReferences; |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * Count all references found in sys_file_reference. |
|
91 | + * |
|
92 | + * @param File|int $file |
|
93 | + * @return int |
|
94 | + */ |
|
95 | + public function countFileReferences($file) |
|
96 | + { |
|
97 | + $fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file; |
|
98 | + |
|
99 | + return $this->getDataService() |
|
100 | + ->count( |
|
101 | + 'sys_file_reference', |
|
102 | + [ |
|
103 | + 'uid_local' => $fileIdentifier |
|
104 | + ] |
|
105 | + ); |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Count soft image references. |
|
110 | + * |
|
111 | + * @param File|int $file |
|
112 | + * @return int |
|
113 | + */ |
|
114 | + public function countSoftImageReferences($file) |
|
115 | + { |
|
116 | + $fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file; |
|
117 | + |
|
118 | + return $this->getDataService() |
|
119 | + ->count( |
|
120 | + 'sys_refindex', |
|
121 | + [ |
|
122 | + 'softref_key' => 'rtehtmlarea_images', |
|
123 | + 'ref_table' => 'sys_file', |
|
124 | + 'ref_uid' => $fileIdentifier |
|
125 | + ] |
|
126 | + ); |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * Count link image references. |
|
131 | + * |
|
132 | + * @param File|int $file |
|
133 | + * @return int |
|
134 | + */ |
|
135 | + public function countSoftLinkReferences($file) |
|
136 | + { |
|
137 | + $fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file; |
|
138 | + |
|
139 | + return $this->getDataService() |
|
140 | + ->count( |
|
141 | + 'sys_refindex', |
|
142 | + [ |
|
143 | + 'softref_key' => 'typolink_tag', |
|
144 | + 'ref_table' => 'sys_file', |
|
145 | + 'ref_uid' => $fileIdentifier |
|
146 | + ] |
|
147 | + ); |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * Count total reference. |
|
152 | + * |
|
153 | + * @param File|int $file |
|
154 | + * @return int |
|
155 | + */ |
|
156 | + public function countTotalReferences($file) |
|
157 | + { |
|
158 | + $numberOfReferences = $this->countFileReferences($file); |
|
159 | + $numberOfReferences += $this->countSoftImageReferences($file); |
|
160 | + $numberOfReferences += $this->countSoftLinkReferences($file); |
|
161 | + |
|
162 | + return $numberOfReferences; |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * @param string $tableName |
|
167 | + * @return object|QueryBuilder |
|
168 | + */ |
|
169 | + protected function getQueryBuilder($tableName): QueryBuilder |
|
170 | + { |
|
171 | + /** @var ConnectionPool $connectionPool */ |
|
172 | + $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
173 | + return $connectionPool->getQueryBuilderForTable($tableName); |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * @return object|DataService |
|
178 | + */ |
|
179 | + protected function getDataService(): DataService |
|
180 | + { |
|
181 | + return GeneralUtility::makeInstance(DataService::class); |
|
182 | + } |
|
183 | 183 | } |
@@ -26,340 +26,340 @@ |
||
26 | 26 | class MediaModule implements SingletonInterface |
27 | 27 | { |
28 | 28 | |
29 | - /** |
|
30 | - * @var string |
|
31 | - */ |
|
32 | - const SIGNATURE = 'user_MediaM1'; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var string |
|
36 | - */ |
|
37 | - const PARAMETER_PREFIX = 'tx_media_user_mediam1'; |
|
38 | - |
|
39 | - /** |
|
40 | - * @var ResourceStorage |
|
41 | - */ |
|
42 | - protected $currentStorage; |
|
43 | - |
|
44 | - /** |
|
45 | - * @return string |
|
46 | - */ |
|
47 | - static public function getSignature() |
|
48 | - { |
|
49 | - return self::SIGNATURE; |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * @return string |
|
54 | - */ |
|
55 | - static public function getParameterPrefix() |
|
56 | - { |
|
57 | - return self::PARAMETER_PREFIX; |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Return all storage allowed for the Backend User. |
|
62 | - * |
|
63 | - * @throws \RuntimeException |
|
64 | - * @return ResourceStorage[] |
|
65 | - */ |
|
66 | - public function getAllowedStorages() |
|
67 | - { |
|
68 | - |
|
69 | - $storages = $this->getBackendUser()->getFileStorages(); |
|
70 | - if (empty($storages)) { |
|
71 | - throw new \RuntimeException('No storage is accessible for the current BE User. Forgotten to define a mount point for this BE User?', 1380801970); |
|
72 | - } |
|
73 | - return $storages; |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Returns the current file storage in use. |
|
78 | - * |
|
79 | - * @return ResourceStorage |
|
80 | - */ |
|
81 | - public function getCurrentStorage() |
|
82 | - { |
|
83 | - if (is_null($this->currentStorage)) { |
|
84 | - |
|
85 | - $storageIdentifier = $this->getStorageIdentifierFromSessionOrArguments(); |
|
86 | - |
|
87 | - if ($storageIdentifier > 0) { |
|
88 | - $currentStorage = ResourceFactory::getInstance()->getStorageObject($storageIdentifier); |
|
89 | - } else { |
|
90 | - |
|
91 | - // We differentiate the cases whether the User is admin or not. |
|
92 | - if ($this->getBackendUser()->isAdmin()) { |
|
93 | - |
|
94 | - $currentStorage = ResourceFactory::getInstance()->getDefaultStorage(); |
|
95 | - |
|
96 | - // Not default storage has been flagged in "sys_file_storage". |
|
97 | - // Fallback approach: take the first storage as the current. |
|
98 | - if (!$currentStorage) { |
|
99 | - /** @var $storageRepository StorageRepository */ |
|
100 | - $storageRepository = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class); |
|
101 | - |
|
102 | - $storages = $storageRepository->findAll(); |
|
103 | - $currentStorage = current($storages); |
|
104 | - } |
|
105 | - } else { |
|
106 | - $fileMounts = $this->getBackendUser()->getFileMountRecords(); |
|
107 | - $firstFileMount = current($fileMounts); |
|
108 | - $currentStorage = ResourceFactory::getInstance()->getStorageObject($firstFileMount['base']); |
|
109 | - } |
|
110 | - } |
|
111 | - |
|
112 | - $this->currentStorage = $currentStorage; |
|
113 | - } |
|
114 | - return $this->currentStorage; |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * Retrieve a possible storage identifier from the session or from the arguments. |
|
119 | - * |
|
120 | - * @return int |
|
121 | - */ |
|
122 | - protected function getStorageIdentifierFromSessionOrArguments() |
|
123 | - { |
|
124 | - |
|
125 | - // Default value |
|
126 | - $storageIdentifier = 0; |
|
127 | - |
|
128 | - // Get last selected storage from User settings |
|
129 | - if (SessionUtility::getInstance()->get('lastSelectedStorage') > 0) { |
|
130 | - $storageIdentifier = SessionUtility::getInstance()->get('lastSelectedStorage'); |
|
131 | - } |
|
132 | - |
|
133 | - $argumentPrefix = $this->getModuleLoader()->getParameterPrefix(); |
|
134 | - $arguments = GeneralUtility::_GET($argumentPrefix); |
|
135 | - |
|
136 | - // Override selected storage from the session if GET argument "storage" is detected. |
|
137 | - if (!empty($arguments['storage']) && (int)$arguments['storage'] > 0) { |
|
138 | - $storageIdentifier = (int)$arguments['storage']; |
|
139 | - |
|
140 | - // Save state |
|
141 | - SessionUtility::getInstance()->set('lastSelectedStorage', $storageIdentifier); |
|
142 | - } |
|
143 | - |
|
144 | - return (int)$storageIdentifier; |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * Return the combined parameter from the URL. |
|
149 | - * |
|
150 | - * @return string |
|
151 | - */ |
|
152 | - public function getCombinedIdentifier() |
|
153 | - { |
|
154 | - |
|
155 | - // Fetch possible combined identifier. |
|
156 | - $combinedIdentifier = GeneralUtility::_GET('id'); |
|
157 | - |
|
158 | - if ($combinedIdentifier) { |
|
159 | - |
|
160 | - // Fix a bug at the Core level: the "id" parameter is encoded again when translating file. |
|
161 | - // Add a loop to decode maximum 999 time! |
|
162 | - $semaphore = 0; |
|
163 | - $semaphoreLimit = 999; |
|
164 | - while (!$this->isWellDecoded($combinedIdentifier) && $semaphore < $semaphoreLimit) { |
|
165 | - $combinedIdentifier = urldecode($combinedIdentifier); |
|
166 | - $semaphore++; |
|
167 | - } |
|
168 | - } |
|
169 | - |
|
170 | - return $combinedIdentifier; |
|
171 | - } |
|
172 | - |
|
173 | - /** |
|
174 | - * @param $combinedIdentifier |
|
175 | - * @return bool |
|
176 | - */ |
|
177 | - protected function isWellDecoded($combinedIdentifier) |
|
178 | - { |
|
179 | - return preg_match('/.*:.*/', $combinedIdentifier); |
|
180 | - } |
|
181 | - |
|
182 | - /** |
|
183 | - * @return Folder |
|
184 | - */ |
|
185 | - public function getFirstAvailableFolder() |
|
186 | - { |
|
187 | - |
|
188 | - // Take the first object of the first storage. |
|
189 | - $storages = $this->getBackendUser()->getFileStorages(); |
|
190 | - $storage = reset($storages); |
|
191 | - if ($storage) { |
|
192 | - $folder = $storage->getRootLevelFolder(); |
|
193 | - } else { |
|
194 | - throw new \RuntimeException('Could not find any folder to be displayed.', 1444665954); |
|
195 | - } |
|
196 | - return $folder; |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * @return Folder |
|
201 | - */ |
|
202 | - public function getCurrentFolder() |
|
203 | - { |
|
204 | - |
|
205 | - $combinedIdentifier = $this->getCombinedIdentifier(); |
|
206 | - |
|
207 | - if ($combinedIdentifier) { |
|
208 | - $folder = $this->getFolderForCombinedIdentifier($combinedIdentifier); |
|
209 | - } else { |
|
210 | - $folder = $this->getFirstAvailableFolder(); |
|
211 | - } |
|
212 | - |
|
213 | - return $folder; |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * @param string $combinedIdentifier |
|
218 | - * @return Folder |
|
219 | - */ |
|
220 | - public function getFolderForCombinedIdentifier($combinedIdentifier) |
|
221 | - { |
|
222 | - |
|
223 | - // Code taken from FileListController.php |
|
224 | - $storage = ResourceFactory::getInstance()->getStorageObjectFromCombinedIdentifier($combinedIdentifier); |
|
225 | - $identifier = substr($combinedIdentifier, strpos($combinedIdentifier, ':') + 1); |
|
226 | - if (!$storage->hasFolder($identifier)) { |
|
227 | - $identifier = $storage->getFolderIdentifierFromFileIdentifier($identifier); |
|
228 | - } |
|
229 | - |
|
230 | - // Retrieve the folder object. |
|
231 | - $folder = ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier($storage->getUid() . ':' . $identifier); |
|
232 | - |
|
233 | - // Disallow the rendering of the processing folder (e.g. could be called manually) |
|
234 | - // and all folders without any defined storage |
|
235 | - if ($folder && ($folder->getStorage()->getUid() == 0 || trim($folder->getStorage()->getProcessingFolder()->getIdentifier(), '/') === trim($folder->getIdentifier(), '/'))) { |
|
236 | - $storage = ResourceFactory::getInstance()->getStorageObjectFromCombinedIdentifier($combinedIdentifier); |
|
237 | - $folder = $storage->getRootLevelFolder(); |
|
238 | - } |
|
239 | - |
|
240 | - return $folder; |
|
241 | - } |
|
242 | - |
|
243 | - /** |
|
244 | - * Tell whether the Folder Tree is display or not. |
|
245 | - * |
|
246 | - * @return bool |
|
247 | - */ |
|
248 | - public function hasFolderTree() |
|
249 | - { |
|
250 | - $configuration = $this->getModuleConfiguration(); |
|
251 | - return (bool)$configuration['has_folder_tree']; |
|
252 | - } |
|
253 | - |
|
254 | - /** |
|
255 | - * Tell whether the sub-folders must be included when browsing. |
|
256 | - * |
|
257 | - * @return bool |
|
258 | - */ |
|
259 | - public function hasRecursiveSelection() |
|
260 | - { |
|
261 | - |
|
262 | - $parameterPrefix = $this->getModuleLoader()->getParameterPrefix(); |
|
263 | - $parameters = GeneralUtility::_GET($parameterPrefix); |
|
264 | - |
|
265 | - $hasRecursiveSelection = true; |
|
266 | - if (isset($parameters['hasRecursiveSelection'])) { |
|
267 | - $hasRecursiveSelection = (bool)$parameters['hasRecursiveSelection']; |
|
268 | - } |
|
269 | - |
|
270 | - return $hasRecursiveSelection; |
|
271 | - } |
|
272 | - |
|
273 | - /** |
|
274 | - * Return the target folder for the uploaded file. |
|
275 | - * |
|
276 | - * @param UploadedFileInterface $uploadedFile |
|
277 | - * @param ResourceStorage $storage |
|
278 | - * @return \TYPO3\CMS\Core\Resource\Folder |
|
279 | - */ |
|
280 | - public function getTargetFolderForUploadedFile(UploadedFileInterface $uploadedFile, ResourceStorage $storage) |
|
281 | - { |
|
282 | - |
|
283 | - // default is the root level |
|
284 | - $folder = $storage->getRootLevelFolder(); // get the root folder by default |
|
285 | - |
|
286 | - // Get a possible mount point coming from the storage record. |
|
287 | - $storageRecord = $storage->getStorageRecord(); |
|
288 | - $mountPointIdentifier = $storageRecord['mount_point_file_type_' . $uploadedFile->getType()]; |
|
289 | - if ($mountPointIdentifier > 0) { |
|
290 | - |
|
291 | - // We don't have a Mount Point repository in FAL, so query the database directly. |
|
292 | - $record = $this->getDataService()->getRecord('sys_filemounts', ['uid' => $mountPointIdentifier]); |
|
293 | - |
|
294 | - if (!empty($record['path'])) { |
|
295 | - $folder = $storage->getFolder($record['path']); |
|
296 | - } |
|
297 | - } |
|
298 | - return $folder; |
|
299 | - } |
|
300 | - |
|
301 | - /** |
|
302 | - * Return a new target folder when moving file from one storage to another. |
|
303 | - * |
|
304 | - * @param ResourceStorage $storage |
|
305 | - * @param File $file |
|
306 | - * @return \TYPO3\CMS\Core\Resource\Folder |
|
307 | - */ |
|
308 | - public function getDefaultFolderInStorage(ResourceStorage $storage, File $file) |
|
309 | - { |
|
310 | - |
|
311 | - // default is the root level |
|
312 | - $folder = $storage->getRootLevelFolder(); |
|
313 | - |
|
314 | - // Retrieve storage record and a possible configured mount point. |
|
315 | - $storageRecord = $storage->getStorageRecord(); |
|
316 | - $mountPointIdentifier = $storageRecord['mount_point_file_type_' . $file->getType()]; |
|
317 | - |
|
318 | - if ($mountPointIdentifier > 0) { |
|
319 | - |
|
320 | - // We don't have a Mount Point repository in FAL, so query the database directly. |
|
321 | - $record = $this->getDataService()->getRecord('sys_filemounts', ['uid' => $mountPointIdentifier]); |
|
322 | - if (!empty($record['path'])) { |
|
323 | - $folder = $storage->getFolder($record['path']); |
|
324 | - } |
|
325 | - } |
|
326 | - return $folder; |
|
327 | - } |
|
328 | - |
|
329 | - /** |
|
330 | - * @return array |
|
331 | - */ |
|
332 | - protected function getModuleConfiguration() |
|
333 | - { |
|
334 | - return GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('media'); |
|
335 | - } |
|
336 | - |
|
337 | - /** |
|
338 | - * @return object|DataService |
|
339 | - */ |
|
340 | - protected function getDataService(): DataService |
|
341 | - { |
|
342 | - return GeneralUtility::makeInstance(DataService::class); |
|
343 | - } |
|
344 | - |
|
345 | - /** |
|
346 | - * Returns an instance of the current Backend User. |
|
347 | - * |
|
348 | - * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication |
|
349 | - */ |
|
350 | - protected function getBackendUser() |
|
351 | - { |
|
352 | - return $GLOBALS['BE_USER']; |
|
353 | - } |
|
354 | - |
|
355 | - /** |
|
356 | - * Return the module loader. |
|
357 | - * |
|
358 | - * @return \Fab\Vidi\Module\ModuleLoader|object |
|
359 | - */ |
|
360 | - protected function getModuleLoader() |
|
361 | - { |
|
362 | - return GeneralUtility::makeInstance(\Fab\Vidi\Module\ModuleLoader::class); |
|
363 | - } |
|
29 | + /** |
|
30 | + * @var string |
|
31 | + */ |
|
32 | + const SIGNATURE = 'user_MediaM1'; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var string |
|
36 | + */ |
|
37 | + const PARAMETER_PREFIX = 'tx_media_user_mediam1'; |
|
38 | + |
|
39 | + /** |
|
40 | + * @var ResourceStorage |
|
41 | + */ |
|
42 | + protected $currentStorage; |
|
43 | + |
|
44 | + /** |
|
45 | + * @return string |
|
46 | + */ |
|
47 | + static public function getSignature() |
|
48 | + { |
|
49 | + return self::SIGNATURE; |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * @return string |
|
54 | + */ |
|
55 | + static public function getParameterPrefix() |
|
56 | + { |
|
57 | + return self::PARAMETER_PREFIX; |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Return all storage allowed for the Backend User. |
|
62 | + * |
|
63 | + * @throws \RuntimeException |
|
64 | + * @return ResourceStorage[] |
|
65 | + */ |
|
66 | + public function getAllowedStorages() |
|
67 | + { |
|
68 | + |
|
69 | + $storages = $this->getBackendUser()->getFileStorages(); |
|
70 | + if (empty($storages)) { |
|
71 | + throw new \RuntimeException('No storage is accessible for the current BE User. Forgotten to define a mount point for this BE User?', 1380801970); |
|
72 | + } |
|
73 | + return $storages; |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Returns the current file storage in use. |
|
78 | + * |
|
79 | + * @return ResourceStorage |
|
80 | + */ |
|
81 | + public function getCurrentStorage() |
|
82 | + { |
|
83 | + if (is_null($this->currentStorage)) { |
|
84 | + |
|
85 | + $storageIdentifier = $this->getStorageIdentifierFromSessionOrArguments(); |
|
86 | + |
|
87 | + if ($storageIdentifier > 0) { |
|
88 | + $currentStorage = ResourceFactory::getInstance()->getStorageObject($storageIdentifier); |
|
89 | + } else { |
|
90 | + |
|
91 | + // We differentiate the cases whether the User is admin or not. |
|
92 | + if ($this->getBackendUser()->isAdmin()) { |
|
93 | + |
|
94 | + $currentStorage = ResourceFactory::getInstance()->getDefaultStorage(); |
|
95 | + |
|
96 | + // Not default storage has been flagged in "sys_file_storage". |
|
97 | + // Fallback approach: take the first storage as the current. |
|
98 | + if (!$currentStorage) { |
|
99 | + /** @var $storageRepository StorageRepository */ |
|
100 | + $storageRepository = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class); |
|
101 | + |
|
102 | + $storages = $storageRepository->findAll(); |
|
103 | + $currentStorage = current($storages); |
|
104 | + } |
|
105 | + } else { |
|
106 | + $fileMounts = $this->getBackendUser()->getFileMountRecords(); |
|
107 | + $firstFileMount = current($fileMounts); |
|
108 | + $currentStorage = ResourceFactory::getInstance()->getStorageObject($firstFileMount['base']); |
|
109 | + } |
|
110 | + } |
|
111 | + |
|
112 | + $this->currentStorage = $currentStorage; |
|
113 | + } |
|
114 | + return $this->currentStorage; |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * Retrieve a possible storage identifier from the session or from the arguments. |
|
119 | + * |
|
120 | + * @return int |
|
121 | + */ |
|
122 | + protected function getStorageIdentifierFromSessionOrArguments() |
|
123 | + { |
|
124 | + |
|
125 | + // Default value |
|
126 | + $storageIdentifier = 0; |
|
127 | + |
|
128 | + // Get last selected storage from User settings |
|
129 | + if (SessionUtility::getInstance()->get('lastSelectedStorage') > 0) { |
|
130 | + $storageIdentifier = SessionUtility::getInstance()->get('lastSelectedStorage'); |
|
131 | + } |
|
132 | + |
|
133 | + $argumentPrefix = $this->getModuleLoader()->getParameterPrefix(); |
|
134 | + $arguments = GeneralUtility::_GET($argumentPrefix); |
|
135 | + |
|
136 | + // Override selected storage from the session if GET argument "storage" is detected. |
|
137 | + if (!empty($arguments['storage']) && (int)$arguments['storage'] > 0) { |
|
138 | + $storageIdentifier = (int)$arguments['storage']; |
|
139 | + |
|
140 | + // Save state |
|
141 | + SessionUtility::getInstance()->set('lastSelectedStorage', $storageIdentifier); |
|
142 | + } |
|
143 | + |
|
144 | + return (int)$storageIdentifier; |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * Return the combined parameter from the URL. |
|
149 | + * |
|
150 | + * @return string |
|
151 | + */ |
|
152 | + public function getCombinedIdentifier() |
|
153 | + { |
|
154 | + |
|
155 | + // Fetch possible combined identifier. |
|
156 | + $combinedIdentifier = GeneralUtility::_GET('id'); |
|
157 | + |
|
158 | + if ($combinedIdentifier) { |
|
159 | + |
|
160 | + // Fix a bug at the Core level: the "id" parameter is encoded again when translating file. |
|
161 | + // Add a loop to decode maximum 999 time! |
|
162 | + $semaphore = 0; |
|
163 | + $semaphoreLimit = 999; |
|
164 | + while (!$this->isWellDecoded($combinedIdentifier) && $semaphore < $semaphoreLimit) { |
|
165 | + $combinedIdentifier = urldecode($combinedIdentifier); |
|
166 | + $semaphore++; |
|
167 | + } |
|
168 | + } |
|
169 | + |
|
170 | + return $combinedIdentifier; |
|
171 | + } |
|
172 | + |
|
173 | + /** |
|
174 | + * @param $combinedIdentifier |
|
175 | + * @return bool |
|
176 | + */ |
|
177 | + protected function isWellDecoded($combinedIdentifier) |
|
178 | + { |
|
179 | + return preg_match('/.*:.*/', $combinedIdentifier); |
|
180 | + } |
|
181 | + |
|
182 | + /** |
|
183 | + * @return Folder |
|
184 | + */ |
|
185 | + public function getFirstAvailableFolder() |
|
186 | + { |
|
187 | + |
|
188 | + // Take the first object of the first storage. |
|
189 | + $storages = $this->getBackendUser()->getFileStorages(); |
|
190 | + $storage = reset($storages); |
|
191 | + if ($storage) { |
|
192 | + $folder = $storage->getRootLevelFolder(); |
|
193 | + } else { |
|
194 | + throw new \RuntimeException('Could not find any folder to be displayed.', 1444665954); |
|
195 | + } |
|
196 | + return $folder; |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * @return Folder |
|
201 | + */ |
|
202 | + public function getCurrentFolder() |
|
203 | + { |
|
204 | + |
|
205 | + $combinedIdentifier = $this->getCombinedIdentifier(); |
|
206 | + |
|
207 | + if ($combinedIdentifier) { |
|
208 | + $folder = $this->getFolderForCombinedIdentifier($combinedIdentifier); |
|
209 | + } else { |
|
210 | + $folder = $this->getFirstAvailableFolder(); |
|
211 | + } |
|
212 | + |
|
213 | + return $folder; |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * @param string $combinedIdentifier |
|
218 | + * @return Folder |
|
219 | + */ |
|
220 | + public function getFolderForCombinedIdentifier($combinedIdentifier) |
|
221 | + { |
|
222 | + |
|
223 | + // Code taken from FileListController.php |
|
224 | + $storage = ResourceFactory::getInstance()->getStorageObjectFromCombinedIdentifier($combinedIdentifier); |
|
225 | + $identifier = substr($combinedIdentifier, strpos($combinedIdentifier, ':') + 1); |
|
226 | + if (!$storage->hasFolder($identifier)) { |
|
227 | + $identifier = $storage->getFolderIdentifierFromFileIdentifier($identifier); |
|
228 | + } |
|
229 | + |
|
230 | + // Retrieve the folder object. |
|
231 | + $folder = ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier($storage->getUid() . ':' . $identifier); |
|
232 | + |
|
233 | + // Disallow the rendering of the processing folder (e.g. could be called manually) |
|
234 | + // and all folders without any defined storage |
|
235 | + if ($folder && ($folder->getStorage()->getUid() == 0 || trim($folder->getStorage()->getProcessingFolder()->getIdentifier(), '/') === trim($folder->getIdentifier(), '/'))) { |
|
236 | + $storage = ResourceFactory::getInstance()->getStorageObjectFromCombinedIdentifier($combinedIdentifier); |
|
237 | + $folder = $storage->getRootLevelFolder(); |
|
238 | + } |
|
239 | + |
|
240 | + return $folder; |
|
241 | + } |
|
242 | + |
|
243 | + /** |
|
244 | + * Tell whether the Folder Tree is display or not. |
|
245 | + * |
|
246 | + * @return bool |
|
247 | + */ |
|
248 | + public function hasFolderTree() |
|
249 | + { |
|
250 | + $configuration = $this->getModuleConfiguration(); |
|
251 | + return (bool)$configuration['has_folder_tree']; |
|
252 | + } |
|
253 | + |
|
254 | + /** |
|
255 | + * Tell whether the sub-folders must be included when browsing. |
|
256 | + * |
|
257 | + * @return bool |
|
258 | + */ |
|
259 | + public function hasRecursiveSelection() |
|
260 | + { |
|
261 | + |
|
262 | + $parameterPrefix = $this->getModuleLoader()->getParameterPrefix(); |
|
263 | + $parameters = GeneralUtility::_GET($parameterPrefix); |
|
264 | + |
|
265 | + $hasRecursiveSelection = true; |
|
266 | + if (isset($parameters['hasRecursiveSelection'])) { |
|
267 | + $hasRecursiveSelection = (bool)$parameters['hasRecursiveSelection']; |
|
268 | + } |
|
269 | + |
|
270 | + return $hasRecursiveSelection; |
|
271 | + } |
|
272 | + |
|
273 | + /** |
|
274 | + * Return the target folder for the uploaded file. |
|
275 | + * |
|
276 | + * @param UploadedFileInterface $uploadedFile |
|
277 | + * @param ResourceStorage $storage |
|
278 | + * @return \TYPO3\CMS\Core\Resource\Folder |
|
279 | + */ |
|
280 | + public function getTargetFolderForUploadedFile(UploadedFileInterface $uploadedFile, ResourceStorage $storage) |
|
281 | + { |
|
282 | + |
|
283 | + // default is the root level |
|
284 | + $folder = $storage->getRootLevelFolder(); // get the root folder by default |
|
285 | + |
|
286 | + // Get a possible mount point coming from the storage record. |
|
287 | + $storageRecord = $storage->getStorageRecord(); |
|
288 | + $mountPointIdentifier = $storageRecord['mount_point_file_type_' . $uploadedFile->getType()]; |
|
289 | + if ($mountPointIdentifier > 0) { |
|
290 | + |
|
291 | + // We don't have a Mount Point repository in FAL, so query the database directly. |
|
292 | + $record = $this->getDataService()->getRecord('sys_filemounts', ['uid' => $mountPointIdentifier]); |
|
293 | + |
|
294 | + if (!empty($record['path'])) { |
|
295 | + $folder = $storage->getFolder($record['path']); |
|
296 | + } |
|
297 | + } |
|
298 | + return $folder; |
|
299 | + } |
|
300 | + |
|
301 | + /** |
|
302 | + * Return a new target folder when moving file from one storage to another. |
|
303 | + * |
|
304 | + * @param ResourceStorage $storage |
|
305 | + * @param File $file |
|
306 | + * @return \TYPO3\CMS\Core\Resource\Folder |
|
307 | + */ |
|
308 | + public function getDefaultFolderInStorage(ResourceStorage $storage, File $file) |
|
309 | + { |
|
310 | + |
|
311 | + // default is the root level |
|
312 | + $folder = $storage->getRootLevelFolder(); |
|
313 | + |
|
314 | + // Retrieve storage record and a possible configured mount point. |
|
315 | + $storageRecord = $storage->getStorageRecord(); |
|
316 | + $mountPointIdentifier = $storageRecord['mount_point_file_type_' . $file->getType()]; |
|
317 | + |
|
318 | + if ($mountPointIdentifier > 0) { |
|
319 | + |
|
320 | + // We don't have a Mount Point repository in FAL, so query the database directly. |
|
321 | + $record = $this->getDataService()->getRecord('sys_filemounts', ['uid' => $mountPointIdentifier]); |
|
322 | + if (!empty($record['path'])) { |
|
323 | + $folder = $storage->getFolder($record['path']); |
|
324 | + } |
|
325 | + } |
|
326 | + return $folder; |
|
327 | + } |
|
328 | + |
|
329 | + /** |
|
330 | + * @return array |
|
331 | + */ |
|
332 | + protected function getModuleConfiguration() |
|
333 | + { |
|
334 | + return GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('media'); |
|
335 | + } |
|
336 | + |
|
337 | + /** |
|
338 | + * @return object|DataService |
|
339 | + */ |
|
340 | + protected function getDataService(): DataService |
|
341 | + { |
|
342 | + return GeneralUtility::makeInstance(DataService::class); |
|
343 | + } |
|
344 | + |
|
345 | + /** |
|
346 | + * Returns an instance of the current Backend User. |
|
347 | + * |
|
348 | + * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication |
|
349 | + */ |
|
350 | + protected function getBackendUser() |
|
351 | + { |
|
352 | + return $GLOBALS['BE_USER']; |
|
353 | + } |
|
354 | + |
|
355 | + /** |
|
356 | + * Return the module loader. |
|
357 | + * |
|
358 | + * @return \Fab\Vidi\Module\ModuleLoader|object |
|
359 | + */ |
|
360 | + protected function getModuleLoader() |
|
361 | + { |
|
362 | + return GeneralUtility::makeInstance(\Fab\Vidi\Module\ModuleLoader::class); |
|
363 | + } |
|
364 | 364 | |
365 | 365 | } |
366 | 366 | \ No newline at end of file |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | } |
229 | 229 | |
230 | 230 | // Retrieve the folder object. |
231 | - $folder = ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier($storage->getUid() . ':' . $identifier); |
|
231 | + $folder = ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier($storage->getUid().':'.$identifier); |
|
232 | 232 | |
233 | 233 | // Disallow the rendering of the processing folder (e.g. could be called manually) |
234 | 234 | // and all folders without any defined storage |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | |
286 | 286 | // Get a possible mount point coming from the storage record. |
287 | 287 | $storageRecord = $storage->getStorageRecord(); |
288 | - $mountPointIdentifier = $storageRecord['mount_point_file_type_' . $uploadedFile->getType()]; |
|
288 | + $mountPointIdentifier = $storageRecord['mount_point_file_type_'.$uploadedFile->getType()]; |
|
289 | 289 | if ($mountPointIdentifier > 0) { |
290 | 290 | |
291 | 291 | // We don't have a Mount Point repository in FAL, so query the database directly. |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | |
314 | 314 | // Retrieve storage record and a possible configured mount point. |
315 | 315 | $storageRecord = $storage->getStorageRecord(); |
316 | - $mountPointIdentifier = $storageRecord['mount_point_file_type_' . $file->getType()]; |
|
316 | + $mountPointIdentifier = $storageRecord['mount_point_file_type_'.$file->getType()]; |
|
317 | 317 | |
318 | 318 | if ($mountPointIdentifier > 0) { |
319 | 319 |
@@ -18,191 +18,191 @@ |
||
18 | 18 | class DuplicateFilesCommandController extends CommandController |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $message = []; |
|
25 | - |
|
26 | - /** |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected $duplicateFiles = []; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var \TYPO3\CMS\Core\Mail\MailMessage |
|
33 | - */ |
|
34 | - protected $mailMessage; |
|
35 | - |
|
36 | - /** |
|
37 | - * Check whether the Index is Ok. In case not, display a message on the console. |
|
38 | - * |
|
39 | - * @return void |
|
40 | - */ |
|
41 | - public function analyseCommand() |
|
42 | - { |
|
43 | - |
|
44 | - foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
45 | - |
|
46 | - // For the CLI cause. |
|
47 | - $storage->setEvaluatePermissions(false); |
|
48 | - |
|
49 | - $this->printOut(); |
|
50 | - $this->printOut(sprintf('%s (%s)', $storage->getName(), $storage->getUid())); |
|
51 | - $this->printOut('--------------------------------------------'); |
|
52 | - |
|
53 | - if ($storage->isOnline()) { |
|
54 | - |
|
55 | - $duplicateFiles = $this->getIndexAnalyser()->searchForDuplicateSha1($storage); |
|
56 | - |
|
57 | - // Duplicate file object |
|
58 | - if (empty($duplicateFiles)) { |
|
59 | - $this->printOut(); |
|
60 | - $this->printOut('Looks good, no duplicate files!'); |
|
61 | - } else { |
|
62 | - $this->printOut(); |
|
63 | - $this->printOut('Duplicated identifiers detected:'); |
|
64 | - $this->duplicateFiles[$storage->getUid()] = $duplicateFiles; // Store duplicate files. |
|
65 | - |
|
66 | - foreach ($duplicateFiles as $identifier => $duplicate) { |
|
67 | - |
|
68 | - // build temporary array |
|
69 | - $uids = []; |
|
70 | - foreach ($duplicate as $value) { |
|
71 | - $uids[] = $value['uid']; |
|
72 | - } |
|
73 | - |
|
74 | - $message = sprintf('* uids "%s" having same sha1 %s', |
|
75 | - implode(',', $uids), |
|
76 | - $identifier |
|
77 | - ); |
|
78 | - $this->printOut($message); |
|
79 | - |
|
80 | - } |
|
81 | - } |
|
82 | - } else { |
|
83 | - $this->outputLine('Storage is offline!'); |
|
84 | - } |
|
85 | - } |
|
86 | - |
|
87 | - $to = $this->getTo(); |
|
88 | - if (!empty($to)) { |
|
89 | - $this->sendReport(); |
|
90 | - } |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Print a message and store its content in a variable for the email report. |
|
95 | - * |
|
96 | - * @param string $message |
|
97 | - * @return void |
|
98 | - */ |
|
99 | - protected function printOut($message = '') |
|
100 | - { |
|
101 | - $this->message[] = $message; |
|
102 | - $this->outputLine($message); |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * Send a possible report to an admin. |
|
107 | - * |
|
108 | - * @throws \Exception |
|
109 | - * @return void |
|
110 | - */ |
|
111 | - protected function sendReport() |
|
112 | - { |
|
113 | - if ($this->hasReport()) { |
|
114 | - |
|
115 | - // Prepare email. |
|
116 | - $this->getMailMessage()->setTo($this->getTo()) |
|
117 | - ->setFrom($this->getFrom()) |
|
118 | - ->setSubject('Duplicate records detected!') |
|
119 | - ->setBody(implode("\n", $this->message)); |
|
120 | - |
|
121 | - $isSent = $this->getMailMessage()->send(); |
|
122 | - |
|
123 | - if (!$isSent) { |
|
124 | - throw new \Exception('I could not send a message', 1408343882); |
|
125 | - } |
|
126 | - |
|
127 | - $to = $this->getTo(); |
|
128 | - $this->outputLine(); |
|
129 | - $message = sprintf('Report was sent to %s', key($to)); |
|
130 | - $this->outputLine($message); |
|
131 | - } |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * Send a report |
|
136 | - * |
|
137 | - * @return bool |
|
138 | - */ |
|
139 | - protected function hasReport() |
|
140 | - { |
|
141 | - return !empty($this->duplicateFiles); |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * @return array |
|
146 | - */ |
|
147 | - protected function getTo() |
|
148 | - { |
|
149 | - |
|
150 | - $to = []; |
|
151 | - |
|
152 | - // @todo make me more flexible! |
|
153 | - if (!empty($GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'])) { |
|
154 | - $emailAddress = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress']; |
|
155 | - $name = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName']; |
|
156 | - $to[$emailAddress] = $name; |
|
157 | - |
|
158 | - } |
|
159 | - return $to; |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * @return array |
|
164 | - */ |
|
165 | - protected function getFrom() |
|
166 | - { |
|
167 | - |
|
168 | - $from = []; |
|
169 | - |
|
170 | - // @todo make me more flexible! |
|
171 | - if (!empty($GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'])) { |
|
172 | - $emailAddress = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress']; |
|
173 | - $name = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName']; |
|
174 | - $from[$emailAddress] = $name; |
|
175 | - } |
|
176 | - return $from; |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * @return StorageRepository|object |
|
181 | - */ |
|
182 | - protected function getStorageRepository() |
|
183 | - { |
|
184 | - return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class); |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * @return \TYPO3\CMS\Core\Mail\MailMessage|object |
|
189 | - */ |
|
190 | - public function getMailMessage() |
|
191 | - { |
|
192 | - if (is_null($this->mailMessage)) { |
|
193 | - $this->mailMessage = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Mail\MailMessage::class); |
|
194 | - } |
|
195 | - return $this->mailMessage; |
|
196 | - } |
|
197 | - |
|
198 | - /** |
|
199 | - * Return a pointer to the database. |
|
200 | - * |
|
201 | - * @return \Fab\Media\Index\IndexAnalyser|object |
|
202 | - */ |
|
203 | - protected function getIndexAnalyser() |
|
204 | - { |
|
205 | - return GeneralUtility::makeInstance(\Fab\Media\Index\IndexAnalyser::class); |
|
206 | - } |
|
21 | + /** |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $message = []; |
|
25 | + |
|
26 | + /** |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + protected $duplicateFiles = []; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var \TYPO3\CMS\Core\Mail\MailMessage |
|
33 | + */ |
|
34 | + protected $mailMessage; |
|
35 | + |
|
36 | + /** |
|
37 | + * Check whether the Index is Ok. In case not, display a message on the console. |
|
38 | + * |
|
39 | + * @return void |
|
40 | + */ |
|
41 | + public function analyseCommand() |
|
42 | + { |
|
43 | + |
|
44 | + foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
45 | + |
|
46 | + // For the CLI cause. |
|
47 | + $storage->setEvaluatePermissions(false); |
|
48 | + |
|
49 | + $this->printOut(); |
|
50 | + $this->printOut(sprintf('%s (%s)', $storage->getName(), $storage->getUid())); |
|
51 | + $this->printOut('--------------------------------------------'); |
|
52 | + |
|
53 | + if ($storage->isOnline()) { |
|
54 | + |
|
55 | + $duplicateFiles = $this->getIndexAnalyser()->searchForDuplicateSha1($storage); |
|
56 | + |
|
57 | + // Duplicate file object |
|
58 | + if (empty($duplicateFiles)) { |
|
59 | + $this->printOut(); |
|
60 | + $this->printOut('Looks good, no duplicate files!'); |
|
61 | + } else { |
|
62 | + $this->printOut(); |
|
63 | + $this->printOut('Duplicated identifiers detected:'); |
|
64 | + $this->duplicateFiles[$storage->getUid()] = $duplicateFiles; // Store duplicate files. |
|
65 | + |
|
66 | + foreach ($duplicateFiles as $identifier => $duplicate) { |
|
67 | + |
|
68 | + // build temporary array |
|
69 | + $uids = []; |
|
70 | + foreach ($duplicate as $value) { |
|
71 | + $uids[] = $value['uid']; |
|
72 | + } |
|
73 | + |
|
74 | + $message = sprintf('* uids "%s" having same sha1 %s', |
|
75 | + implode(',', $uids), |
|
76 | + $identifier |
|
77 | + ); |
|
78 | + $this->printOut($message); |
|
79 | + |
|
80 | + } |
|
81 | + } |
|
82 | + } else { |
|
83 | + $this->outputLine('Storage is offline!'); |
|
84 | + } |
|
85 | + } |
|
86 | + |
|
87 | + $to = $this->getTo(); |
|
88 | + if (!empty($to)) { |
|
89 | + $this->sendReport(); |
|
90 | + } |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Print a message and store its content in a variable for the email report. |
|
95 | + * |
|
96 | + * @param string $message |
|
97 | + * @return void |
|
98 | + */ |
|
99 | + protected function printOut($message = '') |
|
100 | + { |
|
101 | + $this->message[] = $message; |
|
102 | + $this->outputLine($message); |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * Send a possible report to an admin. |
|
107 | + * |
|
108 | + * @throws \Exception |
|
109 | + * @return void |
|
110 | + */ |
|
111 | + protected function sendReport() |
|
112 | + { |
|
113 | + if ($this->hasReport()) { |
|
114 | + |
|
115 | + // Prepare email. |
|
116 | + $this->getMailMessage()->setTo($this->getTo()) |
|
117 | + ->setFrom($this->getFrom()) |
|
118 | + ->setSubject('Duplicate records detected!') |
|
119 | + ->setBody(implode("\n", $this->message)); |
|
120 | + |
|
121 | + $isSent = $this->getMailMessage()->send(); |
|
122 | + |
|
123 | + if (!$isSent) { |
|
124 | + throw new \Exception('I could not send a message', 1408343882); |
|
125 | + } |
|
126 | + |
|
127 | + $to = $this->getTo(); |
|
128 | + $this->outputLine(); |
|
129 | + $message = sprintf('Report was sent to %s', key($to)); |
|
130 | + $this->outputLine($message); |
|
131 | + } |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * Send a report |
|
136 | + * |
|
137 | + * @return bool |
|
138 | + */ |
|
139 | + protected function hasReport() |
|
140 | + { |
|
141 | + return !empty($this->duplicateFiles); |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * @return array |
|
146 | + */ |
|
147 | + protected function getTo() |
|
148 | + { |
|
149 | + |
|
150 | + $to = []; |
|
151 | + |
|
152 | + // @todo make me more flexible! |
|
153 | + if (!empty($GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'])) { |
|
154 | + $emailAddress = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress']; |
|
155 | + $name = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName']; |
|
156 | + $to[$emailAddress] = $name; |
|
157 | + |
|
158 | + } |
|
159 | + return $to; |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * @return array |
|
164 | + */ |
|
165 | + protected function getFrom() |
|
166 | + { |
|
167 | + |
|
168 | + $from = []; |
|
169 | + |
|
170 | + // @todo make me more flexible! |
|
171 | + if (!empty($GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'])) { |
|
172 | + $emailAddress = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress']; |
|
173 | + $name = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName']; |
|
174 | + $from[$emailAddress] = $name; |
|
175 | + } |
|
176 | + return $from; |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * @return StorageRepository|object |
|
181 | + */ |
|
182 | + protected function getStorageRepository() |
|
183 | + { |
|
184 | + return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class); |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * @return \TYPO3\CMS\Core\Mail\MailMessage|object |
|
189 | + */ |
|
190 | + public function getMailMessage() |
|
191 | + { |
|
192 | + if (is_null($this->mailMessage)) { |
|
193 | + $this->mailMessage = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Mail\MailMessage::class); |
|
194 | + } |
|
195 | + return $this->mailMessage; |
|
196 | + } |
|
197 | + |
|
198 | + /** |
|
199 | + * Return a pointer to the database. |
|
200 | + * |
|
201 | + * @return \Fab\Media\Index\IndexAnalyser|object |
|
202 | + */ |
|
203 | + protected function getIndexAnalyser() |
|
204 | + { |
|
205 | + return GeneralUtility::makeInstance(\Fab\Media\Index\IndexAnalyser::class); |
|
206 | + } |
|
207 | 207 | |
208 | 208 | } |
@@ -24,105 +24,105 @@ |
||
24 | 24 | class FileCacheCommandController extends CommandController |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * Warm up the cache. Update some caching columns such as "number_of_references" to speed up the search. |
|
29 | - * |
|
30 | - * @return void |
|
31 | - */ |
|
32 | - public function warmUpCommand() |
|
33 | - { |
|
34 | - $numberOfEntries = $this->getCacheService()->warmUp(); |
|
35 | - $message = sprintf('Done! Processed %s entries', $numberOfEntries); |
|
36 | - $this->outputLine($message); |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * Flush all processed files to be used for debugging mainly. |
|
41 | - * |
|
42 | - * @return void |
|
43 | - */ |
|
44 | - public function flushProcessedFilesCommand() |
|
45 | - { |
|
46 | - |
|
47 | - foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
48 | - |
|
49 | - // This only works for local driver |
|
50 | - if ($storage->getDriverType() === 'Local') { |
|
51 | - |
|
52 | - $this->outputLine(); |
|
53 | - $this->outputLine(sprintf('%s (%s)', $storage->getName(), $storage->getUid())); |
|
54 | - $this->outputLine('--------------------------------------------'); |
|
55 | - $this->outputLine(); |
|
56 | - |
|
57 | - #$storage->getProcessingFolder()->delete(true); // will not work |
|
58 | - |
|
59 | - // Well... not really FAL friendly but straightforward for Local drivers. |
|
60 | - $processedDirectoryPath = PATH_site . $storage->getProcessingFolder()->getPublicUrl(); |
|
61 | - $fileIterator = new FilesystemIterator($processedDirectoryPath, FilesystemIterator::SKIP_DOTS); |
|
62 | - $numberOfProcessedFiles = iterator_count($fileIterator); |
|
63 | - |
|
64 | - GeneralUtility::rmdir($processedDirectoryPath, true); |
|
65 | - GeneralUtility::mkdir($processedDirectoryPath); // recreate the directory. |
|
66 | - |
|
67 | - $message = sprintf('Done! Removed %s processed file(s).', $numberOfProcessedFiles); |
|
68 | - $this->outputLine($message); |
|
69 | - |
|
70 | - $count = $this->getDataService() |
|
71 | - ->count( |
|
72 | - 'sys_file_processedfile', |
|
73 | - [ |
|
74 | - 'storage' => $storage->getUid() |
|
75 | - ] |
|
76 | - ); |
|
77 | - |
|
78 | - // Remove the record as well. |
|
79 | - $this->getDataService()->delete('sys_file_processedfile', ['storage' => $storage->getUid()]); |
|
80 | - |
|
81 | - $message = sprintf('Done! Removed %s records from "sys_file_processedfile".', $count); |
|
82 | - $this->outputLine($message); |
|
83 | - } |
|
84 | - |
|
85 | - } |
|
86 | - |
|
87 | - // Remove possible remaining "sys_file_processedfile" |
|
88 | - $this |
|
89 | - ->getConnection('sys_file_processedfile') |
|
90 | - ->query('TRUNCATE sys_file_processedfile'); |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * @return \Fab\Media\Cache\CacheService|object |
|
95 | - */ |
|
96 | - protected function getCacheService() |
|
97 | - { |
|
98 | - return GeneralUtility::makeInstance(\Fab\Media\Cache\CacheService::class); |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * @return StorageRepository|object |
|
103 | - */ |
|
104 | - protected function getStorageRepository() |
|
105 | - { |
|
106 | - return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class); |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * @return object|DataService |
|
111 | - */ |
|
112 | - protected function getDataService(): DataService |
|
113 | - { |
|
114 | - return GeneralUtility::makeInstance(DataService::class); |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * @param string $tableName |
|
119 | - * @return object|Connection |
|
120 | - */ |
|
121 | - protected function getConnection($tableName): Connection |
|
122 | - { |
|
123 | - /** @var ConnectionPool $connectionPool */ |
|
124 | - $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
125 | - return $connectionPool->getConnectionForTable($tableName); |
|
126 | - } |
|
27 | + /** |
|
28 | + * Warm up the cache. Update some caching columns such as "number_of_references" to speed up the search. |
|
29 | + * |
|
30 | + * @return void |
|
31 | + */ |
|
32 | + public function warmUpCommand() |
|
33 | + { |
|
34 | + $numberOfEntries = $this->getCacheService()->warmUp(); |
|
35 | + $message = sprintf('Done! Processed %s entries', $numberOfEntries); |
|
36 | + $this->outputLine($message); |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * Flush all processed files to be used for debugging mainly. |
|
41 | + * |
|
42 | + * @return void |
|
43 | + */ |
|
44 | + public function flushProcessedFilesCommand() |
|
45 | + { |
|
46 | + |
|
47 | + foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
48 | + |
|
49 | + // This only works for local driver |
|
50 | + if ($storage->getDriverType() === 'Local') { |
|
51 | + |
|
52 | + $this->outputLine(); |
|
53 | + $this->outputLine(sprintf('%s (%s)', $storage->getName(), $storage->getUid())); |
|
54 | + $this->outputLine('--------------------------------------------'); |
|
55 | + $this->outputLine(); |
|
56 | + |
|
57 | + #$storage->getProcessingFolder()->delete(true); // will not work |
|
58 | + |
|
59 | + // Well... not really FAL friendly but straightforward for Local drivers. |
|
60 | + $processedDirectoryPath = PATH_site . $storage->getProcessingFolder()->getPublicUrl(); |
|
61 | + $fileIterator = new FilesystemIterator($processedDirectoryPath, FilesystemIterator::SKIP_DOTS); |
|
62 | + $numberOfProcessedFiles = iterator_count($fileIterator); |
|
63 | + |
|
64 | + GeneralUtility::rmdir($processedDirectoryPath, true); |
|
65 | + GeneralUtility::mkdir($processedDirectoryPath); // recreate the directory. |
|
66 | + |
|
67 | + $message = sprintf('Done! Removed %s processed file(s).', $numberOfProcessedFiles); |
|
68 | + $this->outputLine($message); |
|
69 | + |
|
70 | + $count = $this->getDataService() |
|
71 | + ->count( |
|
72 | + 'sys_file_processedfile', |
|
73 | + [ |
|
74 | + 'storage' => $storage->getUid() |
|
75 | + ] |
|
76 | + ); |
|
77 | + |
|
78 | + // Remove the record as well. |
|
79 | + $this->getDataService()->delete('sys_file_processedfile', ['storage' => $storage->getUid()]); |
|
80 | + |
|
81 | + $message = sprintf('Done! Removed %s records from "sys_file_processedfile".', $count); |
|
82 | + $this->outputLine($message); |
|
83 | + } |
|
84 | + |
|
85 | + } |
|
86 | + |
|
87 | + // Remove possible remaining "sys_file_processedfile" |
|
88 | + $this |
|
89 | + ->getConnection('sys_file_processedfile') |
|
90 | + ->query('TRUNCATE sys_file_processedfile'); |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * @return \Fab\Media\Cache\CacheService|object |
|
95 | + */ |
|
96 | + protected function getCacheService() |
|
97 | + { |
|
98 | + return GeneralUtility::makeInstance(\Fab\Media\Cache\CacheService::class); |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * @return StorageRepository|object |
|
103 | + */ |
|
104 | + protected function getStorageRepository() |
|
105 | + { |
|
106 | + return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class); |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * @return object|DataService |
|
111 | + */ |
|
112 | + protected function getDataService(): DataService |
|
113 | + { |
|
114 | + return GeneralUtility::makeInstance(DataService::class); |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * @param string $tableName |
|
119 | + * @return object|Connection |
|
120 | + */ |
|
121 | + protected function getConnection($tableName): Connection |
|
122 | + { |
|
123 | + /** @var ConnectionPool $connectionPool */ |
|
124 | + $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
125 | + return $connectionPool->getConnectionForTable($tableName); |
|
126 | + } |
|
127 | 127 | |
128 | 128 | } |
@@ -57,7 +57,7 @@ |
||
57 | 57 | #$storage->getProcessingFolder()->delete(true); // will not work |
58 | 58 | |
59 | 59 | // Well... not really FAL friendly but straightforward for Local drivers. |
60 | - $processedDirectoryPath = PATH_site . $storage->getProcessingFolder()->getPublicUrl(); |
|
60 | + $processedDirectoryPath = PATH_site.$storage->getProcessingFolder()->getPublicUrl(); |
|
61 | 61 | $fileIterator = new FilesystemIterator($processedDirectoryPath, FilesystemIterator::SKIP_DOTS); |
62 | 62 | $numberOfProcessedFiles = iterator_count($fileIterator); |
63 | 63 |
@@ -18,231 +18,231 @@ |
||
18 | 18 | class MissingFilesCommandController extends CommandController |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $message = []; |
|
25 | - |
|
26 | - /** |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected $missingFiles = []; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var array |
|
33 | - */ |
|
34 | - protected $deletedFiles = []; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var \TYPO3\CMS\Core\Mail\MailMessage |
|
38 | - */ |
|
39 | - protected $mailMessage; |
|
40 | - |
|
41 | - /** |
|
42 | - * Check whether the Index is Ok. In case not, display a message on the console. |
|
43 | - * |
|
44 | - * @return void |
|
45 | - */ |
|
46 | - public function analyseCommand() |
|
47 | - { |
|
48 | - |
|
49 | - foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
50 | - |
|
51 | - // For the CLI cause. |
|
52 | - $storage->setEvaluatePermissions(false); |
|
53 | - |
|
54 | - $this->printOut(); |
|
55 | - $this->printOut(sprintf('%s (%s)', $storage->getName(), $storage->getUid())); |
|
56 | - $this->printOut('--------------------------------------------'); |
|
57 | - |
|
58 | - if ($storage->isOnline()) { |
|
59 | - |
|
60 | - $missingFiles = $this->getIndexAnalyser()->searchForMissingFiles($storage); |
|
61 | - if (empty($missingFiles)) { |
|
62 | - $this->printOut(); |
|
63 | - $this->printOut('Looks good, no missing files!'); |
|
64 | - } else { |
|
65 | - // Missing files... |
|
66 | - $this->printOut(); |
|
67 | - $this->printOut('Missing resources:'); |
|
68 | - $this->missingFiles[$storage->getUid()] = $missingFiles; // Store missing files. |
|
69 | - |
|
70 | - /** @var \TYPO3\CMS\Core\Resource\File $missingFile */ |
|
71 | - foreach ($missingFiles as $missingFile) { |
|
72 | - $message = sprintf('* Missing file "%s" with identifier "%s".', |
|
73 | - $missingFile->getUid(), |
|
74 | - $missingFile->getIdentifier() |
|
75 | - ); |
|
76 | - $this->printOut($message); |
|
77 | - } |
|
78 | - } |
|
79 | - |
|
80 | - } else { |
|
81 | - $this->outputLine('Storage is offline!'); |
|
82 | - } |
|
83 | - } |
|
84 | - |
|
85 | - $to = $this->getTo(); |
|
86 | - if (!empty($to)) { |
|
87 | - $this->sendReport(); |
|
88 | - } |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Delete the missing files which have no file references |
|
93 | - * |
|
94 | - * @return void |
|
95 | - */ |
|
96 | - public function deleteCommand() |
|
97 | - { |
|
98 | - |
|
99 | - foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
100 | - |
|
101 | - // For the CLI cause. |
|
102 | - $storage->setEvaluatePermissions(false); |
|
103 | - |
|
104 | - $this->printOut(); |
|
105 | - $this->printOut(sprintf('%s (%s)', $storage->getName(), $storage->getUid())); |
|
106 | - $this->printOut('--------------------------------------------'); |
|
107 | - |
|
108 | - if ($storage->isOnline()) { |
|
109 | - |
|
110 | - $deletedFiles = $this->getIndexAnalyser()->deleteMissingFiles($storage); |
|
111 | - if (empty($deletedFiles)) { |
|
112 | - $this->printOut(); |
|
113 | - $this->printOut('No files deleted!'); |
|
114 | - } else { |
|
115 | - // Missing files... |
|
116 | - $this->printOut(); |
|
117 | - $this->printOut('Deleted Files:'); |
|
118 | - /** @var \TYPO3\CMS\Core\Resource\File $deletedFile */ |
|
119 | - foreach ($deletedFiles as $deletedFileUid => $deletedFileIdentifier) { |
|
120 | - $message = sprintf('* Deleted file "%s" with identifier "%s".', |
|
121 | - $deletedFileUid, |
|
122 | - $deletedFileIdentifier |
|
123 | - ); |
|
124 | - $this->printOut($message); |
|
125 | - } |
|
126 | - } |
|
127 | - |
|
128 | - } else { |
|
129 | - $this->outputLine('Storage is offline!'); |
|
130 | - } |
|
131 | - } |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * Print a message and store its content in a variable for the email report. |
|
136 | - * |
|
137 | - * @param string $message |
|
138 | - * @return void |
|
139 | - */ |
|
140 | - protected function printOut($message = '') |
|
141 | - { |
|
142 | - $this->message[] = $message; |
|
143 | - $this->outputLine($message); |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * Send a possible report to an admin. |
|
148 | - * |
|
149 | - * @throws \Exception |
|
150 | - * @return void |
|
151 | - */ |
|
152 | - protected function sendReport() |
|
153 | - { |
|
154 | - if ($this->hasReport()) { |
|
155 | - |
|
156 | - // Prepare email. |
|
157 | - $this->getMailMessage()->setTo($this->getTo()) |
|
158 | - ->setFrom($this->getFrom()) |
|
159 | - ->setSubject('Missing files detected!') |
|
160 | - ->setBody(implode("\n", $this->message)); |
|
161 | - |
|
162 | - $isSent = $this->getMailMessage()->send(); |
|
163 | - |
|
164 | - if (!$isSent) { |
|
165 | - throw new \Exception('I could not send a message', 1408343882); |
|
166 | - } |
|
167 | - |
|
168 | - $to = $this->getTo(); |
|
169 | - $this->outputLine(); |
|
170 | - $message = sprintf('Report was sent to %s', key($to)); |
|
171 | - $this->outputLine($message); |
|
172 | - } |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Send a report |
|
177 | - * |
|
178 | - * @return bool |
|
179 | - */ |
|
180 | - protected function hasReport() |
|
181 | - { |
|
182 | - return !empty($this->missingFiles); |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * @return array |
|
187 | - */ |
|
188 | - protected function getTo() |
|
189 | - { |
|
190 | - |
|
191 | - $to = []; |
|
192 | - |
|
193 | - // @todo make me more flexible! |
|
194 | - if (!empty($GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'])) { |
|
195 | - $emailAddress = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress']; |
|
196 | - $name = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName']; |
|
197 | - $to[$emailAddress] = $name; |
|
198 | - |
|
199 | - } |
|
200 | - return $to; |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * @return array |
|
205 | - */ |
|
206 | - protected function getFrom() |
|
207 | - { |
|
208 | - $from = []; |
|
209 | - |
|
210 | - // @todo make me more flexible! |
|
211 | - if (!empty($GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'])) { |
|
212 | - $emailAddress = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress']; |
|
213 | - $name = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName']; |
|
214 | - $from[$emailAddress] = $name; |
|
215 | - } |
|
216 | - return $from; |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * @return StorageRepository|object |
|
221 | - */ |
|
222 | - protected function getStorageRepository() |
|
223 | - { |
|
224 | - return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class); |
|
225 | - } |
|
226 | - |
|
227 | - /** |
|
228 | - * @return \TYPO3\CMS\Core\Mail\MailMessage |
|
229 | - */ |
|
230 | - public function getMailMessage() |
|
231 | - { |
|
232 | - if (is_null($this->mailMessage)) { |
|
233 | - $this->mailMessage = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Mail\MailMessage::class); |
|
234 | - } |
|
235 | - return $this->mailMessage; |
|
236 | - } |
|
237 | - |
|
238 | - /** |
|
239 | - * Return a pointer to the database. |
|
240 | - * |
|
241 | - * @return \Fab\Media\Index\IndexAnalyser|object |
|
242 | - */ |
|
243 | - protected function getIndexAnalyser() |
|
244 | - { |
|
245 | - return GeneralUtility::makeInstance(\Fab\Media\Index\IndexAnalyser::class); |
|
246 | - } |
|
21 | + /** |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $message = []; |
|
25 | + |
|
26 | + /** |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + protected $missingFiles = []; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var array |
|
33 | + */ |
|
34 | + protected $deletedFiles = []; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var \TYPO3\CMS\Core\Mail\MailMessage |
|
38 | + */ |
|
39 | + protected $mailMessage; |
|
40 | + |
|
41 | + /** |
|
42 | + * Check whether the Index is Ok. In case not, display a message on the console. |
|
43 | + * |
|
44 | + * @return void |
|
45 | + */ |
|
46 | + public function analyseCommand() |
|
47 | + { |
|
48 | + |
|
49 | + foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
50 | + |
|
51 | + // For the CLI cause. |
|
52 | + $storage->setEvaluatePermissions(false); |
|
53 | + |
|
54 | + $this->printOut(); |
|
55 | + $this->printOut(sprintf('%s (%s)', $storage->getName(), $storage->getUid())); |
|
56 | + $this->printOut('--------------------------------------------'); |
|
57 | + |
|
58 | + if ($storage->isOnline()) { |
|
59 | + |
|
60 | + $missingFiles = $this->getIndexAnalyser()->searchForMissingFiles($storage); |
|
61 | + if (empty($missingFiles)) { |
|
62 | + $this->printOut(); |
|
63 | + $this->printOut('Looks good, no missing files!'); |
|
64 | + } else { |
|
65 | + // Missing files... |
|
66 | + $this->printOut(); |
|
67 | + $this->printOut('Missing resources:'); |
|
68 | + $this->missingFiles[$storage->getUid()] = $missingFiles; // Store missing files. |
|
69 | + |
|
70 | + /** @var \TYPO3\CMS\Core\Resource\File $missingFile */ |
|
71 | + foreach ($missingFiles as $missingFile) { |
|
72 | + $message = sprintf('* Missing file "%s" with identifier "%s".', |
|
73 | + $missingFile->getUid(), |
|
74 | + $missingFile->getIdentifier() |
|
75 | + ); |
|
76 | + $this->printOut($message); |
|
77 | + } |
|
78 | + } |
|
79 | + |
|
80 | + } else { |
|
81 | + $this->outputLine('Storage is offline!'); |
|
82 | + } |
|
83 | + } |
|
84 | + |
|
85 | + $to = $this->getTo(); |
|
86 | + if (!empty($to)) { |
|
87 | + $this->sendReport(); |
|
88 | + } |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Delete the missing files which have no file references |
|
93 | + * |
|
94 | + * @return void |
|
95 | + */ |
|
96 | + public function deleteCommand() |
|
97 | + { |
|
98 | + |
|
99 | + foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
100 | + |
|
101 | + // For the CLI cause. |
|
102 | + $storage->setEvaluatePermissions(false); |
|
103 | + |
|
104 | + $this->printOut(); |
|
105 | + $this->printOut(sprintf('%s (%s)', $storage->getName(), $storage->getUid())); |
|
106 | + $this->printOut('--------------------------------------------'); |
|
107 | + |
|
108 | + if ($storage->isOnline()) { |
|
109 | + |
|
110 | + $deletedFiles = $this->getIndexAnalyser()->deleteMissingFiles($storage); |
|
111 | + if (empty($deletedFiles)) { |
|
112 | + $this->printOut(); |
|
113 | + $this->printOut('No files deleted!'); |
|
114 | + } else { |
|
115 | + // Missing files... |
|
116 | + $this->printOut(); |
|
117 | + $this->printOut('Deleted Files:'); |
|
118 | + /** @var \TYPO3\CMS\Core\Resource\File $deletedFile */ |
|
119 | + foreach ($deletedFiles as $deletedFileUid => $deletedFileIdentifier) { |
|
120 | + $message = sprintf('* Deleted file "%s" with identifier "%s".', |
|
121 | + $deletedFileUid, |
|
122 | + $deletedFileIdentifier |
|
123 | + ); |
|
124 | + $this->printOut($message); |
|
125 | + } |
|
126 | + } |
|
127 | + |
|
128 | + } else { |
|
129 | + $this->outputLine('Storage is offline!'); |
|
130 | + } |
|
131 | + } |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * Print a message and store its content in a variable for the email report. |
|
136 | + * |
|
137 | + * @param string $message |
|
138 | + * @return void |
|
139 | + */ |
|
140 | + protected function printOut($message = '') |
|
141 | + { |
|
142 | + $this->message[] = $message; |
|
143 | + $this->outputLine($message); |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * Send a possible report to an admin. |
|
148 | + * |
|
149 | + * @throws \Exception |
|
150 | + * @return void |
|
151 | + */ |
|
152 | + protected function sendReport() |
|
153 | + { |
|
154 | + if ($this->hasReport()) { |
|
155 | + |
|
156 | + // Prepare email. |
|
157 | + $this->getMailMessage()->setTo($this->getTo()) |
|
158 | + ->setFrom($this->getFrom()) |
|
159 | + ->setSubject('Missing files detected!') |
|
160 | + ->setBody(implode("\n", $this->message)); |
|
161 | + |
|
162 | + $isSent = $this->getMailMessage()->send(); |
|
163 | + |
|
164 | + if (!$isSent) { |
|
165 | + throw new \Exception('I could not send a message', 1408343882); |
|
166 | + } |
|
167 | + |
|
168 | + $to = $this->getTo(); |
|
169 | + $this->outputLine(); |
|
170 | + $message = sprintf('Report was sent to %s', key($to)); |
|
171 | + $this->outputLine($message); |
|
172 | + } |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Send a report |
|
177 | + * |
|
178 | + * @return bool |
|
179 | + */ |
|
180 | + protected function hasReport() |
|
181 | + { |
|
182 | + return !empty($this->missingFiles); |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * @return array |
|
187 | + */ |
|
188 | + protected function getTo() |
|
189 | + { |
|
190 | + |
|
191 | + $to = []; |
|
192 | + |
|
193 | + // @todo make me more flexible! |
|
194 | + if (!empty($GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'])) { |
|
195 | + $emailAddress = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress']; |
|
196 | + $name = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName']; |
|
197 | + $to[$emailAddress] = $name; |
|
198 | + |
|
199 | + } |
|
200 | + return $to; |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * @return array |
|
205 | + */ |
|
206 | + protected function getFrom() |
|
207 | + { |
|
208 | + $from = []; |
|
209 | + |
|
210 | + // @todo make me more flexible! |
|
211 | + if (!empty($GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'])) { |
|
212 | + $emailAddress = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress']; |
|
213 | + $name = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName']; |
|
214 | + $from[$emailAddress] = $name; |
|
215 | + } |
|
216 | + return $from; |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * @return StorageRepository|object |
|
221 | + */ |
|
222 | + protected function getStorageRepository() |
|
223 | + { |
|
224 | + return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class); |
|
225 | + } |
|
226 | + |
|
227 | + /** |
|
228 | + * @return \TYPO3\CMS\Core\Mail\MailMessage |
|
229 | + */ |
|
230 | + public function getMailMessage() |
|
231 | + { |
|
232 | + if (is_null($this->mailMessage)) { |
|
233 | + $this->mailMessage = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Mail\MailMessage::class); |
|
234 | + } |
|
235 | + return $this->mailMessage; |
|
236 | + } |
|
237 | + |
|
238 | + /** |
|
239 | + * Return a pointer to the database. |
|
240 | + * |
|
241 | + * @return \Fab\Media\Index\IndexAnalyser|object |
|
242 | + */ |
|
243 | + protected function getIndexAnalyser() |
|
244 | + { |
|
245 | + return GeneralUtility::makeInstance(\Fab\Media\Index\IndexAnalyser::class); |
|
246 | + } |
|
247 | 247 | |
248 | 248 | } |
@@ -18,191 +18,191 @@ |
||
18 | 18 | class DuplicateRecordsCommandController extends CommandController |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $message = []; |
|
25 | - |
|
26 | - /** |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected $duplicateRecords = []; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var \TYPO3\CMS\Core\Mail\MailMessage |
|
33 | - */ |
|
34 | - protected $mailMessage; |
|
35 | - |
|
36 | - /** |
|
37 | - * Check whether the Index is Ok. In case not, display a message on the console. |
|
38 | - * |
|
39 | - * @return void |
|
40 | - */ |
|
41 | - public function analyseCommand() |
|
42 | - { |
|
43 | - |
|
44 | - foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
45 | - |
|
46 | - // For the CLI cause. |
|
47 | - $storage->setEvaluatePermissions(false); |
|
48 | - |
|
49 | - $this->printOut(); |
|
50 | - $this->printOut(sprintf('%s (%s)', $storage->getName(), $storage->getUid())); |
|
51 | - $this->printOut('--------------------------------------------'); |
|
52 | - |
|
53 | - if ($storage->isOnline()) { |
|
54 | - |
|
55 | - $duplicateRecords = $this->getIndexAnalyser()->searchForDuplicateIdentifiers($storage); |
|
56 | - |
|
57 | - // Duplicate file object |
|
58 | - if (empty($duplicateRecords)) { |
|
59 | - $this->printOut(); |
|
60 | - $this->printOut('Looks good, no duplicate records!'); |
|
61 | - } else { |
|
62 | - $this->printOut(); |
|
63 | - $this->printOut('Duplicated identifiers detected:'); |
|
64 | - $this->duplicateRecords[$storage->getUid()] = $duplicateRecords; // Store duplicate files. |
|
65 | - |
|
66 | - foreach ($duplicateRecords as $identifier => $duplicate) { |
|
67 | - |
|
68 | - // build temporary array |
|
69 | - $uids = []; |
|
70 | - foreach ($duplicate as $value) { |
|
71 | - $uids[] = $value['uid']; |
|
72 | - } |
|
73 | - |
|
74 | - $message = sprintf('* uids "%s" having same identifier %s', |
|
75 | - implode(',', $uids), |
|
76 | - $identifier |
|
77 | - ); |
|
78 | - $this->printOut($message); |
|
79 | - |
|
80 | - } |
|
81 | - } |
|
82 | - } else { |
|
83 | - $this->outputLine('Storage is offline!'); |
|
84 | - } |
|
85 | - } |
|
86 | - |
|
87 | - $to = $this->getTo(); |
|
88 | - if (!empty($to)) { |
|
89 | - $this->sendReport(); |
|
90 | - } |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Print a message and store its content in a variable for the email report. |
|
95 | - * |
|
96 | - * @param string $message |
|
97 | - * @return void |
|
98 | - */ |
|
99 | - protected function printOut($message = '') |
|
100 | - { |
|
101 | - $this->message[] = $message; |
|
102 | - $this->outputLine($message); |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * Send a possible report to an admin. |
|
107 | - * |
|
108 | - * @throws \Exception |
|
109 | - * @return void |
|
110 | - */ |
|
111 | - protected function sendReport() |
|
112 | - { |
|
113 | - if ($this->hasReport()) { |
|
114 | - |
|
115 | - // Prepare email. |
|
116 | - $this->getMailMessage()->setTo($this->getTo()) |
|
117 | - ->setFrom($this->getFrom()) |
|
118 | - ->setSubject('Duplicate records detected!') |
|
119 | - ->setBody(implode("\n", $this->message)); |
|
120 | - |
|
121 | - $isSent = $this->getMailMessage()->send(); |
|
122 | - |
|
123 | - if (!$isSent) { |
|
124 | - throw new \Exception('I could not send a message', 1408343882); |
|
125 | - } |
|
126 | - |
|
127 | - $to = $this->getTo(); |
|
128 | - $this->outputLine(); |
|
129 | - $message = sprintf('Report was sent to %s', key($to)); |
|
130 | - $this->outputLine($message); |
|
131 | - } |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * Send a report |
|
136 | - * |
|
137 | - * @return bool |
|
138 | - */ |
|
139 | - protected function hasReport() |
|
140 | - { |
|
141 | - return !empty($this->duplicateRecords); |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * @return array |
|
146 | - */ |
|
147 | - protected function getTo() |
|
148 | - { |
|
149 | - |
|
150 | - $to = []; |
|
151 | - |
|
152 | - // @todo make me more flexible! |
|
153 | - if (!empty($GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'])) { |
|
154 | - $emailAddress = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress']; |
|
155 | - $name = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName']; |
|
156 | - $to[$emailAddress] = $name; |
|
157 | - |
|
158 | - } |
|
159 | - return $to; |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * @return array |
|
164 | - */ |
|
165 | - protected function getFrom() |
|
166 | - { |
|
167 | - |
|
168 | - $from = []; |
|
169 | - |
|
170 | - // @todo make me more flexible! |
|
171 | - if (!empty($GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'])) { |
|
172 | - $emailAddress = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress']; |
|
173 | - $name = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName']; |
|
174 | - $from[$emailAddress] = $name; |
|
175 | - } |
|
176 | - return $from; |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * @return StorageRepository|object |
|
181 | - */ |
|
182 | - protected function getStorageRepository() |
|
183 | - { |
|
184 | - return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class); |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * @return \TYPO3\CMS\Core\Mail\MailMessage|object |
|
189 | - */ |
|
190 | - public function getMailMessage() |
|
191 | - { |
|
192 | - if (is_null($this->mailMessage)) { |
|
193 | - $this->mailMessage = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Mail\MailMessage::class); |
|
194 | - } |
|
195 | - return $this->mailMessage; |
|
196 | - } |
|
197 | - |
|
198 | - /** |
|
199 | - * Return a pointer to the database. |
|
200 | - * |
|
201 | - * @return \Fab\Media\Index\IndexAnalyser|object |
|
202 | - */ |
|
203 | - protected function getIndexAnalyser() |
|
204 | - { |
|
205 | - return GeneralUtility::makeInstance(\Fab\Media\Index\IndexAnalyser::class); |
|
206 | - } |
|
21 | + /** |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $message = []; |
|
25 | + |
|
26 | + /** |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + protected $duplicateRecords = []; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var \TYPO3\CMS\Core\Mail\MailMessage |
|
33 | + */ |
|
34 | + protected $mailMessage; |
|
35 | + |
|
36 | + /** |
|
37 | + * Check whether the Index is Ok. In case not, display a message on the console. |
|
38 | + * |
|
39 | + * @return void |
|
40 | + */ |
|
41 | + public function analyseCommand() |
|
42 | + { |
|
43 | + |
|
44 | + foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
45 | + |
|
46 | + // For the CLI cause. |
|
47 | + $storage->setEvaluatePermissions(false); |
|
48 | + |
|
49 | + $this->printOut(); |
|
50 | + $this->printOut(sprintf('%s (%s)', $storage->getName(), $storage->getUid())); |
|
51 | + $this->printOut('--------------------------------------------'); |
|
52 | + |
|
53 | + if ($storage->isOnline()) { |
|
54 | + |
|
55 | + $duplicateRecords = $this->getIndexAnalyser()->searchForDuplicateIdentifiers($storage); |
|
56 | + |
|
57 | + // Duplicate file object |
|
58 | + if (empty($duplicateRecords)) { |
|
59 | + $this->printOut(); |
|
60 | + $this->printOut('Looks good, no duplicate records!'); |
|
61 | + } else { |
|
62 | + $this->printOut(); |
|
63 | + $this->printOut('Duplicated identifiers detected:'); |
|
64 | + $this->duplicateRecords[$storage->getUid()] = $duplicateRecords; // Store duplicate files. |
|
65 | + |
|
66 | + foreach ($duplicateRecords as $identifier => $duplicate) { |
|
67 | + |
|
68 | + // build temporary array |
|
69 | + $uids = []; |
|
70 | + foreach ($duplicate as $value) { |
|
71 | + $uids[] = $value['uid']; |
|
72 | + } |
|
73 | + |
|
74 | + $message = sprintf('* uids "%s" having same identifier %s', |
|
75 | + implode(',', $uids), |
|
76 | + $identifier |
|
77 | + ); |
|
78 | + $this->printOut($message); |
|
79 | + |
|
80 | + } |
|
81 | + } |
|
82 | + } else { |
|
83 | + $this->outputLine('Storage is offline!'); |
|
84 | + } |
|
85 | + } |
|
86 | + |
|
87 | + $to = $this->getTo(); |
|
88 | + if (!empty($to)) { |
|
89 | + $this->sendReport(); |
|
90 | + } |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Print a message and store its content in a variable for the email report. |
|
95 | + * |
|
96 | + * @param string $message |
|
97 | + * @return void |
|
98 | + */ |
|
99 | + protected function printOut($message = '') |
|
100 | + { |
|
101 | + $this->message[] = $message; |
|
102 | + $this->outputLine($message); |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * Send a possible report to an admin. |
|
107 | + * |
|
108 | + * @throws \Exception |
|
109 | + * @return void |
|
110 | + */ |
|
111 | + protected function sendReport() |
|
112 | + { |
|
113 | + if ($this->hasReport()) { |
|
114 | + |
|
115 | + // Prepare email. |
|
116 | + $this->getMailMessage()->setTo($this->getTo()) |
|
117 | + ->setFrom($this->getFrom()) |
|
118 | + ->setSubject('Duplicate records detected!') |
|
119 | + ->setBody(implode("\n", $this->message)); |
|
120 | + |
|
121 | + $isSent = $this->getMailMessage()->send(); |
|
122 | + |
|
123 | + if (!$isSent) { |
|
124 | + throw new \Exception('I could not send a message', 1408343882); |
|
125 | + } |
|
126 | + |
|
127 | + $to = $this->getTo(); |
|
128 | + $this->outputLine(); |
|
129 | + $message = sprintf('Report was sent to %s', key($to)); |
|
130 | + $this->outputLine($message); |
|
131 | + } |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * Send a report |
|
136 | + * |
|
137 | + * @return bool |
|
138 | + */ |
|
139 | + protected function hasReport() |
|
140 | + { |
|
141 | + return !empty($this->duplicateRecords); |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * @return array |
|
146 | + */ |
|
147 | + protected function getTo() |
|
148 | + { |
|
149 | + |
|
150 | + $to = []; |
|
151 | + |
|
152 | + // @todo make me more flexible! |
|
153 | + if (!empty($GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'])) { |
|
154 | + $emailAddress = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress']; |
|
155 | + $name = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName']; |
|
156 | + $to[$emailAddress] = $name; |
|
157 | + |
|
158 | + } |
|
159 | + return $to; |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * @return array |
|
164 | + */ |
|
165 | + protected function getFrom() |
|
166 | + { |
|
167 | + |
|
168 | + $from = []; |
|
169 | + |
|
170 | + // @todo make me more flexible! |
|
171 | + if (!empty($GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'])) { |
|
172 | + $emailAddress = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress']; |
|
173 | + $name = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName']; |
|
174 | + $from[$emailAddress] = $name; |
|
175 | + } |
|
176 | + return $from; |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * @return StorageRepository|object |
|
181 | + */ |
|
182 | + protected function getStorageRepository() |
|
183 | + { |
|
184 | + return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class); |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * @return \TYPO3\CMS\Core\Mail\MailMessage|object |
|
189 | + */ |
|
190 | + public function getMailMessage() |
|
191 | + { |
|
192 | + if (is_null($this->mailMessage)) { |
|
193 | + $this->mailMessage = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Mail\MailMessage::class); |
|
194 | + } |
|
195 | + return $this->mailMessage; |
|
196 | + } |
|
197 | + |
|
198 | + /** |
|
199 | + * Return a pointer to the database. |
|
200 | + * |
|
201 | + * @return \Fab\Media\Index\IndexAnalyser|object |
|
202 | + */ |
|
203 | + protected function getIndexAnalyser() |
|
204 | + { |
|
205 | + return GeneralUtility::makeInstance(\Fab\Media\Index\IndexAnalyser::class); |
|
206 | + } |
|
207 | 207 | |
208 | 208 | } |
@@ -21,137 +21,137 @@ |
||
21 | 21 | class ThumbnailCommandController extends CommandController |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * @throws \TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentTypeException |
|
26 | - * @throws \TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException |
|
27 | - */ |
|
28 | - protected function initializeCommandMethodArguments() |
|
29 | - { |
|
30 | - parent::initializeCommandMethodArguments(); |
|
31 | - if ($this->arguments->hasArgument('configuration')) { |
|
32 | - $propertyMappingConfiguration = $this->arguments->getArgument('configuration')->getPropertyMappingConfiguration(); |
|
33 | - $propertyMappingConfiguration->setTypeConverter( |
|
34 | - $this->objectManager->get(ConfigurationArrayConverter::class) |
|
35 | - ); |
|
36 | - } |
|
37 | - } |
|
38 | - |
|
39 | - |
|
40 | - /** |
|
41 | - * Generate a bunch of thumbnails in advance to speed up the output of the Media BE module. |
|
42 | - * |
|
43 | - * @param int $limit where to stop in the batch processing. |
|
44 | - * @param int $offset where to start in the batch processing. |
|
45 | - * @param array $configuration override the default thumbnail configuration. |
|
46 | - * @param bool $verbose will output a detail result of the thumbnail generation. |
|
47 | - * @return void |
|
48 | - */ |
|
49 | - public function generateCommand($limit = 0, $offset = 0, $configuration = [], $verbose = false) |
|
50 | - { |
|
51 | - |
|
52 | - $this->checkEnvironment(); |
|
53 | - |
|
54 | - foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
55 | - |
|
56 | - // TODO: Make me more flexible by passing thumbnail configuration. For now it will only generate thumbnails for the BE module. |
|
57 | - |
|
58 | - $this->outputLine(); |
|
59 | - $this->outputLine(sprintf('%s (%s)', $storage->getName(), $storage->getUid())); |
|
60 | - $this->outputLine('--------------------------------------------'); |
|
61 | - $this->outputLine(); |
|
62 | - |
|
63 | - if ($storage->isOnline()) { |
|
64 | - |
|
65 | - // For the CLI cause. |
|
66 | - $storage->setEvaluatePermissions(false); |
|
67 | - |
|
68 | - $thumbnailGenerator = $this->getThumbnailGenerator(); |
|
69 | - $thumbnailGenerator |
|
70 | - ->setStorage($storage) |
|
71 | - ->setConfiguration($configuration) |
|
72 | - ->generate($limit, $offset); |
|
73 | - |
|
74 | - if ($verbose) { |
|
75 | - $resultSet = $thumbnailGenerator->getResultSet(); |
|
76 | - foreach ($resultSet as $result) { |
|
77 | - $message = sprintf('* File "%s": %s %s', |
|
78 | - $result['fileUid'], |
|
79 | - $result['fileIdentifier'], |
|
80 | - empty($result['thumbnailUri']) ? '' : ' -> ' . $result['thumbnailUri'] |
|
81 | - ); |
|
82 | - $this->outputLine($message); |
|
83 | - } |
|
84 | - $this->outputLine(); |
|
85 | - } |
|
86 | - |
|
87 | - $message = sprintf('Done! New generated %s thumbnail(s) from %s traversed file(s) of a total of %s files.', |
|
88 | - $thumbnailGenerator->getNumberOfProcessedFiles(), |
|
89 | - $thumbnailGenerator->getNumberOfTraversedFiles(), |
|
90 | - $thumbnailGenerator->getTotalNumberOfFiles() |
|
91 | - ); |
|
92 | - $this->outputLine($message); |
|
93 | - |
|
94 | - // Add warning message if missing files were found along the way. |
|
95 | - if ($thumbnailGenerator->getNumberOfMissingFiles() > 0) { |
|
96 | - |
|
97 | - $message = sprintf('ATTENTION! %s missing file(s) detected.', |
|
98 | - $thumbnailGenerator->getNumberOfMissingFiles() |
|
99 | - ); |
|
100 | - $this->outputLine($message); |
|
101 | - } |
|
102 | - } else { |
|
103 | - $this->outputLine('Storage is offline!'); |
|
104 | - } |
|
105 | - } |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * @return void |
|
110 | - */ |
|
111 | - protected function checkEnvironment() |
|
112 | - { |
|
113 | - $user = $this->getDataService()->getRecord( |
|
114 | - 'be_users', [ |
|
115 | - 'username' => '_cli_lowlevel' |
|
116 | - ]); |
|
117 | - |
|
118 | - if (empty($user)) { |
|
119 | - $this->outputLine('Missing User "_cli_lowlevel" and / or its password.'); |
|
120 | - $this->sendAndExit(1); |
|
121 | - } |
|
122 | - |
|
123 | - $user = $this->getDataService()->getRecord( |
|
124 | - 'be_users', [ |
|
125 | - 'username' => '_cli_scheduler' |
|
126 | - ]); |
|
127 | - |
|
128 | - if (empty($user)) { |
|
129 | - $this->outputLine('Missing User "_cli_scheduler" and / or its password.'); |
|
130 | - $this->sendAndExit(1); |
|
131 | - } |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * @return object|DataService |
|
136 | - */ |
|
137 | - protected function getDataService(): DataService |
|
138 | - { |
|
139 | - return GeneralUtility::makeInstance(DataService::class); |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * @return \Fab\Media\Thumbnail\ThumbnailGenerator|object |
|
144 | - */ |
|
145 | - protected function getThumbnailGenerator() |
|
146 | - { |
|
147 | - return GeneralUtility::makeInstance(\Fab\Media\Thumbnail\ThumbnailGenerator::class); |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * @return StorageRepository|object |
|
152 | - */ |
|
153 | - protected function getStorageRepository() |
|
154 | - { |
|
155 | - return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class); |
|
156 | - } |
|
24 | + /** |
|
25 | + * @throws \TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentTypeException |
|
26 | + * @throws \TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException |
|
27 | + */ |
|
28 | + protected function initializeCommandMethodArguments() |
|
29 | + { |
|
30 | + parent::initializeCommandMethodArguments(); |
|
31 | + if ($this->arguments->hasArgument('configuration')) { |
|
32 | + $propertyMappingConfiguration = $this->arguments->getArgument('configuration')->getPropertyMappingConfiguration(); |
|
33 | + $propertyMappingConfiguration->setTypeConverter( |
|
34 | + $this->objectManager->get(ConfigurationArrayConverter::class) |
|
35 | + ); |
|
36 | + } |
|
37 | + } |
|
38 | + |
|
39 | + |
|
40 | + /** |
|
41 | + * Generate a bunch of thumbnails in advance to speed up the output of the Media BE module. |
|
42 | + * |
|
43 | + * @param int $limit where to stop in the batch processing. |
|
44 | + * @param int $offset where to start in the batch processing. |
|
45 | + * @param array $configuration override the default thumbnail configuration. |
|
46 | + * @param bool $verbose will output a detail result of the thumbnail generation. |
|
47 | + * @return void |
|
48 | + */ |
|
49 | + public function generateCommand($limit = 0, $offset = 0, $configuration = [], $verbose = false) |
|
50 | + { |
|
51 | + |
|
52 | + $this->checkEnvironment(); |
|
53 | + |
|
54 | + foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
55 | + |
|
56 | + // TODO: Make me more flexible by passing thumbnail configuration. For now it will only generate thumbnails for the BE module. |
|
57 | + |
|
58 | + $this->outputLine(); |
|
59 | + $this->outputLine(sprintf('%s (%s)', $storage->getName(), $storage->getUid())); |
|
60 | + $this->outputLine('--------------------------------------------'); |
|
61 | + $this->outputLine(); |
|
62 | + |
|
63 | + if ($storage->isOnline()) { |
|
64 | + |
|
65 | + // For the CLI cause. |
|
66 | + $storage->setEvaluatePermissions(false); |
|
67 | + |
|
68 | + $thumbnailGenerator = $this->getThumbnailGenerator(); |
|
69 | + $thumbnailGenerator |
|
70 | + ->setStorage($storage) |
|
71 | + ->setConfiguration($configuration) |
|
72 | + ->generate($limit, $offset); |
|
73 | + |
|
74 | + if ($verbose) { |
|
75 | + $resultSet = $thumbnailGenerator->getResultSet(); |
|
76 | + foreach ($resultSet as $result) { |
|
77 | + $message = sprintf('* File "%s": %s %s', |
|
78 | + $result['fileUid'], |
|
79 | + $result['fileIdentifier'], |
|
80 | + empty($result['thumbnailUri']) ? '' : ' -> ' . $result['thumbnailUri'] |
|
81 | + ); |
|
82 | + $this->outputLine($message); |
|
83 | + } |
|
84 | + $this->outputLine(); |
|
85 | + } |
|
86 | + |
|
87 | + $message = sprintf('Done! New generated %s thumbnail(s) from %s traversed file(s) of a total of %s files.', |
|
88 | + $thumbnailGenerator->getNumberOfProcessedFiles(), |
|
89 | + $thumbnailGenerator->getNumberOfTraversedFiles(), |
|
90 | + $thumbnailGenerator->getTotalNumberOfFiles() |
|
91 | + ); |
|
92 | + $this->outputLine($message); |
|
93 | + |
|
94 | + // Add warning message if missing files were found along the way. |
|
95 | + if ($thumbnailGenerator->getNumberOfMissingFiles() > 0) { |
|
96 | + |
|
97 | + $message = sprintf('ATTENTION! %s missing file(s) detected.', |
|
98 | + $thumbnailGenerator->getNumberOfMissingFiles() |
|
99 | + ); |
|
100 | + $this->outputLine($message); |
|
101 | + } |
|
102 | + } else { |
|
103 | + $this->outputLine('Storage is offline!'); |
|
104 | + } |
|
105 | + } |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * @return void |
|
110 | + */ |
|
111 | + protected function checkEnvironment() |
|
112 | + { |
|
113 | + $user = $this->getDataService()->getRecord( |
|
114 | + 'be_users', [ |
|
115 | + 'username' => '_cli_lowlevel' |
|
116 | + ]); |
|
117 | + |
|
118 | + if (empty($user)) { |
|
119 | + $this->outputLine('Missing User "_cli_lowlevel" and / or its password.'); |
|
120 | + $this->sendAndExit(1); |
|
121 | + } |
|
122 | + |
|
123 | + $user = $this->getDataService()->getRecord( |
|
124 | + 'be_users', [ |
|
125 | + 'username' => '_cli_scheduler' |
|
126 | + ]); |
|
127 | + |
|
128 | + if (empty($user)) { |
|
129 | + $this->outputLine('Missing User "_cli_scheduler" and / or its password.'); |
|
130 | + $this->sendAndExit(1); |
|
131 | + } |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * @return object|DataService |
|
136 | + */ |
|
137 | + protected function getDataService(): DataService |
|
138 | + { |
|
139 | + return GeneralUtility::makeInstance(DataService::class); |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * @return \Fab\Media\Thumbnail\ThumbnailGenerator|object |
|
144 | + */ |
|
145 | + protected function getThumbnailGenerator() |
|
146 | + { |
|
147 | + return GeneralUtility::makeInstance(\Fab\Media\Thumbnail\ThumbnailGenerator::class); |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * @return StorageRepository|object |
|
152 | + */ |
|
153 | + protected function getStorageRepository() |
|
154 | + { |
|
155 | + return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class); |
|
156 | + } |
|
157 | 157 | } |
@@ -22,213 +22,213 @@ |
||
22 | 22 | class UsageRenderer extends ColumnRendererAbstract |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * Render usage of an asset in the grid. |
|
27 | - * |
|
28 | - * @return string |
|
29 | - */ |
|
30 | - public function render() |
|
31 | - { |
|
32 | - $file = $this->getFileConverter()->convert($this->object); |
|
33 | - |
|
34 | - $result = ''; |
|
35 | - |
|
36 | - // Add number of references on the top! |
|
37 | - if ($this->object['number_of_references'] > 1) { |
|
38 | - $result .= sprintf( |
|
39 | - '<div><strong>%s (%s)</strong></div>', |
|
40 | - $this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:references'), |
|
41 | - $this->object['number_of_references'] |
|
42 | - ); |
|
43 | - } |
|
44 | - |
|
45 | - // Render File usage |
|
46 | - $fileReferences = $this->getFileReferenceService()->findFileReferences($file); |
|
47 | - if (!empty($fileReferences)) { |
|
48 | - |
|
49 | - // Finalize file references assembling. |
|
50 | - $result .= sprintf( |
|
51 | - $this->getWrappingTemplate(), |
|
52 | - $this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:file_reference'), |
|
53 | - $this->assembleOutput($fileReferences, array('referenceIdentifier' => 'uid_foreign', 'tableName' => 'tablenames')) |
|
54 | - ); |
|
55 | - } |
|
56 | - |
|
57 | - // Render link usage in RTE |
|
58 | - $linkSoftReferences = $this->getFileReferenceService()->findSoftLinkReferences($file); |
|
59 | - if (!empty($linkSoftReferences)) { |
|
60 | - |
|
61 | - // Finalize link references assembling. |
|
62 | - $result .= sprintf( |
|
63 | - $this->getWrappingTemplate(), |
|
64 | - $this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:link_references_in_rte'), |
|
65 | - $this->assembleOutput($linkSoftReferences, array('referenceIdentifier' => 'recuid', 'tableName' => 'tablename')) |
|
66 | - ); |
|
67 | - } |
|
68 | - |
|
69 | - // Render image usage in RTE |
|
70 | - $imageSoftReferences = $this->getFileReferenceService()->findSoftImageReferences($file); |
|
71 | - if (!empty($imageSoftReferences)) { |
|
72 | - |
|
73 | - // Finalize image references assembling. |
|
74 | - $result .= sprintf( |
|
75 | - $this->getWrappingTemplate(), |
|
76 | - $this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:image_references_in_rte'), |
|
77 | - $this->assembleOutput($imageSoftReferences, array('referenceIdentifier' => 'recuid', 'tableName' => 'tablename')) |
|
78 | - ); |
|
79 | - } |
|
80 | - |
|
81 | - return $result; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Assemble output reference. |
|
86 | - * |
|
87 | - * @param array $references |
|
88 | - * @param array $mapping |
|
89 | - * @return string |
|
90 | - */ |
|
91 | - protected function assembleOutput(array $references, array $mapping) |
|
92 | - { |
|
93 | - |
|
94 | - $result = ''; |
|
95 | - foreach ($references as $reference) { |
|
96 | - $button = $this->makeLinkButton() |
|
97 | - ->setHref($this->getEditUri($reference, $mapping)) |
|
98 | - ->setClasses('btn-edit-reference') |
|
99 | - ->setIcon($this->getIconFactory()->getIcon('actions-document-open', Icon::SIZE_SMALL)) |
|
100 | - ->render(); |
|
101 | - |
|
102 | - $tableName = $reference[$mapping['tableName']]; |
|
103 | - $identifier = (int)$reference[$mapping['referenceIdentifier']]; |
|
104 | - |
|
105 | - $result .= sprintf( |
|
106 | - '<li title="">%s %s</li>', |
|
107 | - $button, |
|
108 | - $this->computeTitle($tableName, $identifier) |
|
109 | - ); |
|
110 | - } |
|
111 | - |
|
112 | - return $result; |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * @param string $tableName |
|
117 | - * @param int $identifier |
|
118 | - * @return string |
|
119 | - */ |
|
120 | - protected function computeTitle($tableName, $identifier) |
|
121 | - { |
|
122 | - $title = ''; |
|
123 | - if (!empty($GLOBALS['TCA'][$tableName])) { |
|
124 | - $title = $this->getRecordTitle($tableName, $identifier); |
|
125 | - if (!$title) { |
|
126 | - $title = Tca::table($tableName)->getTitle(); |
|
127 | - } |
|
128 | - } |
|
129 | - return $title; |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * @return object|LinkButton |
|
134 | - */ |
|
135 | - protected function makeLinkButton() |
|
136 | - { |
|
137 | - return GeneralUtility::makeInstance(LinkButton::class); |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * @param array $reference |
|
142 | - * @param array $mapping |
|
143 | - * @return string |
|
144 | - */ |
|
145 | - protected function getEditUri(array $reference, array $mapping) |
|
146 | - { |
|
147 | - |
|
148 | - $parameterName = sprintf('edit[%s][%s]', $reference[$mapping['tableName']], $reference[$mapping['referenceIdentifier']]); |
|
149 | - $uri = BackendUtility::getModuleUrl( |
|
150 | - 'record_edit', |
|
151 | - array( |
|
152 | - $parameterName => 'edit', |
|
153 | - 'returnUrl' => $this->getModuleUrl() |
|
154 | - ) |
|
155 | - ); |
|
156 | - return $uri; |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * @return string |
|
161 | - */ |
|
162 | - protected function getModuleUrl() |
|
163 | - { |
|
164 | - |
|
165 | - $additionalParameters = []; |
|
166 | - if (GeneralUtility::_GP('id')) { |
|
167 | - $additionalParameters = array( |
|
168 | - 'id' => urldecode(GeneralUtility::_GP('id')), |
|
169 | - ); |
|
170 | - } |
|
171 | - return BackendUtility::getModuleUrl(GeneralUtility::_GP('route'), $additionalParameters); |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * Return the title given a table name and an identifier. |
|
176 | - * |
|
177 | - * @param string $tableName |
|
178 | - * @param string $identifier |
|
179 | - * @return string |
|
180 | - */ |
|
181 | - protected function getRecordTitle($tableName, $identifier) |
|
182 | - { |
|
183 | - |
|
184 | - $result = ''; |
|
185 | - if ($tableName && (int)$identifier > 0) { |
|
186 | - |
|
187 | - $labelField = Tca::table($tableName)->getLabelField(); |
|
188 | - |
|
189 | - // Get the title of the record. |
|
190 | - $record = $this->getDataService() |
|
191 | - ->getRecord($tableName, ['uid' => $identifier,]); |
|
192 | - |
|
193 | - if (!empty($record[$labelField])) { |
|
194 | - $result = $record[$labelField]; |
|
195 | - } |
|
196 | - } |
|
197 | - |
|
198 | - return $result; |
|
199 | - } |
|
200 | - |
|
201 | - /** |
|
202 | - * @return object|DataService |
|
203 | - */ |
|
204 | - protected function getDataService(): DataService |
|
205 | - { |
|
206 | - return GeneralUtility::makeInstance(DataService::class); |
|
207 | - } |
|
208 | - |
|
209 | - /** |
|
210 | - * Return the wrapping HTML template. |
|
211 | - * |
|
212 | - * @return string |
|
213 | - */ |
|
214 | - protected function getWrappingTemplate() |
|
215 | - { |
|
216 | - return '<div style="text-decoration: underline; margin-top: 10px; margin-bottom: 10px">%s</div><ul class="usage-list">%s</ul>'; |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * @return \Fab\Media\Resource\FileReferenceService|object |
|
221 | - */ |
|
222 | - protected function getFileReferenceService() |
|
223 | - { |
|
224 | - return GeneralUtility::makeInstance(\Fab\Media\Resource\FileReferenceService::class); |
|
225 | - } |
|
226 | - |
|
227 | - /** |
|
228 | - * @return \Fab\Media\TypeConverter\ContentToFileConverter|object |
|
229 | - */ |
|
230 | - protected function getFileConverter() |
|
231 | - { |
|
232 | - return GeneralUtility::makeInstance(\Fab\Media\TypeConverter\ContentToFileConverter::class); |
|
233 | - } |
|
25 | + /** |
|
26 | + * Render usage of an asset in the grid. |
|
27 | + * |
|
28 | + * @return string |
|
29 | + */ |
|
30 | + public function render() |
|
31 | + { |
|
32 | + $file = $this->getFileConverter()->convert($this->object); |
|
33 | + |
|
34 | + $result = ''; |
|
35 | + |
|
36 | + // Add number of references on the top! |
|
37 | + if ($this->object['number_of_references'] > 1) { |
|
38 | + $result .= sprintf( |
|
39 | + '<div><strong>%s (%s)</strong></div>', |
|
40 | + $this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:references'), |
|
41 | + $this->object['number_of_references'] |
|
42 | + ); |
|
43 | + } |
|
44 | + |
|
45 | + // Render File usage |
|
46 | + $fileReferences = $this->getFileReferenceService()->findFileReferences($file); |
|
47 | + if (!empty($fileReferences)) { |
|
48 | + |
|
49 | + // Finalize file references assembling. |
|
50 | + $result .= sprintf( |
|
51 | + $this->getWrappingTemplate(), |
|
52 | + $this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:file_reference'), |
|
53 | + $this->assembleOutput($fileReferences, array('referenceIdentifier' => 'uid_foreign', 'tableName' => 'tablenames')) |
|
54 | + ); |
|
55 | + } |
|
56 | + |
|
57 | + // Render link usage in RTE |
|
58 | + $linkSoftReferences = $this->getFileReferenceService()->findSoftLinkReferences($file); |
|
59 | + if (!empty($linkSoftReferences)) { |
|
60 | + |
|
61 | + // Finalize link references assembling. |
|
62 | + $result .= sprintf( |
|
63 | + $this->getWrappingTemplate(), |
|
64 | + $this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:link_references_in_rte'), |
|
65 | + $this->assembleOutput($linkSoftReferences, array('referenceIdentifier' => 'recuid', 'tableName' => 'tablename')) |
|
66 | + ); |
|
67 | + } |
|
68 | + |
|
69 | + // Render image usage in RTE |
|
70 | + $imageSoftReferences = $this->getFileReferenceService()->findSoftImageReferences($file); |
|
71 | + if (!empty($imageSoftReferences)) { |
|
72 | + |
|
73 | + // Finalize image references assembling. |
|
74 | + $result .= sprintf( |
|
75 | + $this->getWrappingTemplate(), |
|
76 | + $this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:image_references_in_rte'), |
|
77 | + $this->assembleOutput($imageSoftReferences, array('referenceIdentifier' => 'recuid', 'tableName' => 'tablename')) |
|
78 | + ); |
|
79 | + } |
|
80 | + |
|
81 | + return $result; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Assemble output reference. |
|
86 | + * |
|
87 | + * @param array $references |
|
88 | + * @param array $mapping |
|
89 | + * @return string |
|
90 | + */ |
|
91 | + protected function assembleOutput(array $references, array $mapping) |
|
92 | + { |
|
93 | + |
|
94 | + $result = ''; |
|
95 | + foreach ($references as $reference) { |
|
96 | + $button = $this->makeLinkButton() |
|
97 | + ->setHref($this->getEditUri($reference, $mapping)) |
|
98 | + ->setClasses('btn-edit-reference') |
|
99 | + ->setIcon($this->getIconFactory()->getIcon('actions-document-open', Icon::SIZE_SMALL)) |
|
100 | + ->render(); |
|
101 | + |
|
102 | + $tableName = $reference[$mapping['tableName']]; |
|
103 | + $identifier = (int)$reference[$mapping['referenceIdentifier']]; |
|
104 | + |
|
105 | + $result .= sprintf( |
|
106 | + '<li title="">%s %s</li>', |
|
107 | + $button, |
|
108 | + $this->computeTitle($tableName, $identifier) |
|
109 | + ); |
|
110 | + } |
|
111 | + |
|
112 | + return $result; |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * @param string $tableName |
|
117 | + * @param int $identifier |
|
118 | + * @return string |
|
119 | + */ |
|
120 | + protected function computeTitle($tableName, $identifier) |
|
121 | + { |
|
122 | + $title = ''; |
|
123 | + if (!empty($GLOBALS['TCA'][$tableName])) { |
|
124 | + $title = $this->getRecordTitle($tableName, $identifier); |
|
125 | + if (!$title) { |
|
126 | + $title = Tca::table($tableName)->getTitle(); |
|
127 | + } |
|
128 | + } |
|
129 | + return $title; |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * @return object|LinkButton |
|
134 | + */ |
|
135 | + protected function makeLinkButton() |
|
136 | + { |
|
137 | + return GeneralUtility::makeInstance(LinkButton::class); |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * @param array $reference |
|
142 | + * @param array $mapping |
|
143 | + * @return string |
|
144 | + */ |
|
145 | + protected function getEditUri(array $reference, array $mapping) |
|
146 | + { |
|
147 | + |
|
148 | + $parameterName = sprintf('edit[%s][%s]', $reference[$mapping['tableName']], $reference[$mapping['referenceIdentifier']]); |
|
149 | + $uri = BackendUtility::getModuleUrl( |
|
150 | + 'record_edit', |
|
151 | + array( |
|
152 | + $parameterName => 'edit', |
|
153 | + 'returnUrl' => $this->getModuleUrl() |
|
154 | + ) |
|
155 | + ); |
|
156 | + return $uri; |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * @return string |
|
161 | + */ |
|
162 | + protected function getModuleUrl() |
|
163 | + { |
|
164 | + |
|
165 | + $additionalParameters = []; |
|
166 | + if (GeneralUtility::_GP('id')) { |
|
167 | + $additionalParameters = array( |
|
168 | + 'id' => urldecode(GeneralUtility::_GP('id')), |
|
169 | + ); |
|
170 | + } |
|
171 | + return BackendUtility::getModuleUrl(GeneralUtility::_GP('route'), $additionalParameters); |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * Return the title given a table name and an identifier. |
|
176 | + * |
|
177 | + * @param string $tableName |
|
178 | + * @param string $identifier |
|
179 | + * @return string |
|
180 | + */ |
|
181 | + protected function getRecordTitle($tableName, $identifier) |
|
182 | + { |
|
183 | + |
|
184 | + $result = ''; |
|
185 | + if ($tableName && (int)$identifier > 0) { |
|
186 | + |
|
187 | + $labelField = Tca::table($tableName)->getLabelField(); |
|
188 | + |
|
189 | + // Get the title of the record. |
|
190 | + $record = $this->getDataService() |
|
191 | + ->getRecord($tableName, ['uid' => $identifier,]); |
|
192 | + |
|
193 | + if (!empty($record[$labelField])) { |
|
194 | + $result = $record[$labelField]; |
|
195 | + } |
|
196 | + } |
|
197 | + |
|
198 | + return $result; |
|
199 | + } |
|
200 | + |
|
201 | + /** |
|
202 | + * @return object|DataService |
|
203 | + */ |
|
204 | + protected function getDataService(): DataService |
|
205 | + { |
|
206 | + return GeneralUtility::makeInstance(DataService::class); |
|
207 | + } |
|
208 | + |
|
209 | + /** |
|
210 | + * Return the wrapping HTML template. |
|
211 | + * |
|
212 | + * @return string |
|
213 | + */ |
|
214 | + protected function getWrappingTemplate() |
|
215 | + { |
|
216 | + return '<div style="text-decoration: underline; margin-top: 10px; margin-bottom: 10px">%s</div><ul class="usage-list">%s</ul>'; |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * @return \Fab\Media\Resource\FileReferenceService|object |
|
221 | + */ |
|
222 | + protected function getFileReferenceService() |
|
223 | + { |
|
224 | + return GeneralUtility::makeInstance(\Fab\Media\Resource\FileReferenceService::class); |
|
225 | + } |
|
226 | + |
|
227 | + /** |
|
228 | + * @return \Fab\Media\TypeConverter\ContentToFileConverter|object |
|
229 | + */ |
|
230 | + protected function getFileConverter() |
|
231 | + { |
|
232 | + return GeneralUtility::makeInstance(\Fab\Media\TypeConverter\ContentToFileConverter::class); |
|
233 | + } |
|
234 | 234 | } |
@@ -188,7 +188,7 @@ |
||
188 | 188 | |
189 | 189 | // Get the title of the record. |
190 | 190 | $record = $this->getDataService() |
191 | - ->getRecord($tableName, ['uid' => $identifier,]); |
|
191 | + ->getRecord($tableName, ['uid' => $identifier, ]); |
|
192 | 192 | |
193 | 193 | if (!empty($record[$labelField])) { |
194 | 194 | $result = $record[$labelField]; |