|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* (c) Kitodo. Key to digital objects e.V. <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* This file is part of the Kitodo and TYPO3 projects. |
|
7
|
|
|
* |
|
8
|
|
|
* @license GNU General Public License version 3 or later. |
|
9
|
|
|
* For the full copyright and license information, please read the |
|
10
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Kitodo\Dlf\Command; |
|
14
|
|
|
|
|
15
|
|
|
use Kitodo\Dlf\Domain\Repository\DocumentRepository; |
|
16
|
|
|
use Symfony\Component\Console\Command\Command; |
|
17
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
18
|
|
|
use TYPO3\CMS\Core\Utility\MathUtility; |
|
19
|
|
|
use TYPO3\CMS\Core\Database\ConnectionPool; |
|
20
|
|
|
use TYPO3\CMS\Core\Database\Connection; |
|
21
|
|
|
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager; |
|
22
|
|
|
use TYPO3\CMS\Extbase\Object\ObjectManager; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Base class for CLI Command classes. |
|
26
|
|
|
* |
|
27
|
|
|
* @author Beatrycze Volk <[email protected]> |
|
28
|
|
|
* @package TYPO3 |
|
29
|
|
|
* @subpackage dlf |
|
30
|
|
|
* @access public |
|
31
|
|
|
*/ |
|
32
|
|
|
class BaseCommand extends Command |
|
33
|
|
|
{ |
|
34
|
|
|
/** |
|
35
|
|
|
* @var DocumentRepository |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $documentRepository; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Initialize the documentRepository based on the given storagePid. |
|
41
|
|
|
* |
|
42
|
|
|
* @param string|string[]|bool|null $inputPid possible pid |
|
43
|
|
|
* |
|
44
|
|
|
* @return int|bool validated storagePid |
|
45
|
|
|
*/ |
|
46
|
|
|
protected function initializeDocumentRepository($storagePid) |
|
47
|
|
|
{ |
|
48
|
|
|
if (MathUtility::canBeInterpretedAsInteger($storagePid)) { |
|
49
|
|
|
$objectManager = GeneralUtility::makeInstance(ObjectManager::class); |
|
50
|
|
|
|
|
51
|
|
|
$configurationManager = $objectManager->get(ConfigurationManager::class); |
|
52
|
|
|
$frameworkConfiguration = $configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK); |
|
53
|
|
|
|
|
54
|
|
|
$frameworkConfiguration['persistence']['storagePid'] = MathUtility::forceIntegerInRange((int) $storagePid, 0); |
|
55
|
|
|
$configurationManager->setConfiguration($frameworkConfiguration); |
|
56
|
|
|
|
|
57
|
|
|
$this->documentRepository = $objectManager->get( |
|
58
|
|
|
DocumentRepository::class |
|
59
|
|
|
); |
|
60
|
|
|
} else { |
|
61
|
|
|
return false; |
|
62
|
|
|
} |
|
63
|
|
|
return MathUtility::forceIntegerInRange((int) $storagePid, 0); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Return matching uid of Solr core depending on the input value. |
|
68
|
|
|
* |
|
69
|
|
|
* @param array $solrCores array of the valid Solr cores |
|
70
|
|
|
* @param string|bool|null $inputSolrId possible uid or name of Solr core |
|
71
|
|
|
* |
|
72
|
|
|
* @return int matching uid of Solr core |
|
73
|
|
|
*/ |
|
74
|
|
|
protected function getSolrCoreUid(array $solrCores, $inputSolrId): int |
|
75
|
|
|
{ |
|
76
|
|
|
if (MathUtility::canBeInterpretedAsInteger($inputSolrId)) { |
|
77
|
|
|
$solrCoreUid = MathUtility::forceIntegerInRange((int) $inputSolrId, 0); |
|
78
|
|
|
} else { |
|
79
|
|
|
$solrCoreUid = $solrCores[$inputSolrId]; |
|
80
|
|
|
} |
|
81
|
|
|
return $solrCoreUid; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Fetches all Solr cores on given page. |
|
86
|
|
|
* |
|
87
|
|
|
* @param int $pageId The UID of the Solr core or 0 to disable indexing |
|
88
|
|
|
* |
|
89
|
|
|
* @return array Array of valid Solr cores |
|
90
|
|
|
*/ |
|
91
|
|
|
protected function getSolrCores(int $pageId): array |
|
92
|
|
|
{ |
|
93
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
|
94
|
|
|
->getQueryBuilderForTable('tx_dlf_solrcores'); |
|
95
|
|
|
|
|
96
|
|
|
$solrCores = []; |
|
97
|
|
|
$result = $queryBuilder |
|
98
|
|
|
->select('uid', 'index_name') |
|
99
|
|
|
->from('tx_dlf_solrcores') |
|
100
|
|
|
->where( |
|
101
|
|
|
$queryBuilder->expr()->eq( |
|
102
|
|
|
'pid', |
|
103
|
|
|
$queryBuilder->createNamedParameter((int) $pageId, Connection::PARAM_INT) |
|
104
|
|
|
) |
|
105
|
|
|
) |
|
106
|
|
|
->execute(); |
|
107
|
|
|
|
|
108
|
|
|
while ($record = $result->fetch()) { |
|
109
|
|
|
$solrCores[$record['index_name']] = $record['uid']; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
return $solrCores; |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|