|
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 Symfony\Component\Console\Command\Command; |
|
16
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
17
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
18
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
19
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
|
20
|
|
|
use TYPO3\CMS\Core\Core\Bootstrap; |
|
21
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
22
|
|
|
use TYPO3\CMS\Core\Utility\MathUtility; |
|
23
|
|
|
use Kitodo\Dlf\Command\BaseCommand; |
|
24
|
|
|
use Kitodo\Dlf\Common\Document; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* CLI Command for indexing single documents into database and Solr. |
|
28
|
|
|
* |
|
29
|
|
|
* @author Alexander Bigga <[email protected]> |
|
30
|
|
|
* @package TYPO3 |
|
31
|
|
|
* @subpackage dlf |
|
32
|
|
|
* @access public |
|
33
|
|
|
*/ |
|
34
|
|
|
class IndexCommand extends BaseCommand |
|
35
|
|
|
{ |
|
36
|
|
|
/** |
|
37
|
|
|
* Configure the command by defining the name, options and arguments |
|
38
|
|
|
* |
|
39
|
|
|
* @return void |
|
40
|
|
|
*/ |
|
41
|
|
|
public function configure() |
|
42
|
|
|
{ |
|
43
|
|
|
$this |
|
44
|
|
|
->setDescription('Index single document into database and Solr.') |
|
45
|
|
|
->setHelp('') |
|
46
|
|
|
->addOption( |
|
47
|
|
|
'dry-run', |
|
48
|
|
|
null, |
|
49
|
|
|
InputOption::VALUE_NONE, |
|
50
|
|
|
'If this option is set, the files will not actually be processed but the location URI is shown.' |
|
51
|
|
|
) |
|
52
|
|
|
->addOption( |
|
53
|
|
|
'doc', |
|
54
|
|
|
'd', |
|
55
|
|
|
InputOption::VALUE_REQUIRED, |
|
56
|
|
|
'UID or URL of the document.' |
|
57
|
|
|
) |
|
58
|
|
|
->addOption( |
|
59
|
|
|
'pid', |
|
60
|
|
|
'p', |
|
61
|
|
|
InputOption::VALUE_REQUIRED, |
|
62
|
|
|
'UID of the page the document should be added to.' |
|
63
|
|
|
) |
|
64
|
|
|
->addOption( |
|
65
|
|
|
'solr', |
|
66
|
|
|
's', |
|
67
|
|
|
InputOption::VALUE_REQUIRED, |
|
68
|
|
|
'[UID|index_name] of the Solr core the document should be added to.' |
|
69
|
|
|
); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Executes the command to index the given document to db and solr. |
|
74
|
|
|
* |
|
75
|
|
|
* @param InputInterface $input The input parameters |
|
76
|
|
|
* @param OutputInterface $output The Symfony interface for outputs on console |
|
77
|
|
|
* |
|
78
|
|
|
* @return void |
|
79
|
|
|
*/ |
|
80
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
81
|
|
|
{ |
|
82
|
|
|
// Make sure the _cli_ user is loaded |
|
83
|
|
|
Bootstrap::getInstance()->initializeBackendAuthentication(); |
|
|
|
|
|
|
84
|
|
|
|
|
85
|
|
|
$dryRun = $input->getOption('dry-run') != false ? true : false; |
|
86
|
|
|
|
|
87
|
|
|
$io = new SymfonyStyle($input, $output); |
|
88
|
|
|
$io->title($this->getDescription()); |
|
89
|
|
|
|
|
90
|
|
|
$startingPoint = $this->getStartingPoint($input->getOption('pid')); |
|
91
|
|
|
|
|
92
|
|
|
if ($startingPoint == 0) { |
|
93
|
|
|
$io->error('ERROR: No valid PID (' . $startingPoint . ') given.'); |
|
94
|
|
|
exit(1); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
if ( |
|
98
|
|
|
!empty($input->getOption('solr')) |
|
99
|
|
|
&& !is_array($input->getOption('solr')) |
|
100
|
|
|
) { |
|
101
|
|
|
$allSolrCores = $this->getSolrCores($startingPoint); |
|
102
|
|
|
$solrCoreUid = $this->getSolrCoreUid($allSolrCores, $input->getOption('solr')); |
|
|
|
|
|
|
103
|
|
|
|
|
104
|
|
|
// Abort if solrCoreUid is empty or not in the array of allowed solr cores. |
|
105
|
|
|
if (empty($solrCoreUid) || !in_array($solrCoreUid, $allSolrCores)) { |
|
106
|
|
|
$output_solrCores = []; |
|
107
|
|
|
foreach ($allSolrCores as $index_name => $uid) { |
|
108
|
|
|
$output_solrCores[] = $uid . ' : ' . $index_name; |
|
109
|
|
|
} |
|
110
|
|
|
if (empty($output_solrCores)) { |
|
111
|
|
|
$io->error('ERROR: No valid Solr core ("' . $input->getOption('solr') . '") given. No valid cores found on PID ' . $startingPoint . ".\n"); |
|
112
|
|
|
exit(1); |
|
113
|
|
|
} else { |
|
114
|
|
|
$io->error('ERROR: No valid Solr core ("' . $input->getOption('solr') . '") given. ' . "Valid cores are (<uid>:<index_name>):\n" . implode("\n", $output_solrCores) . "\n"); |
|
115
|
|
|
exit(1); |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
} else { |
|
119
|
|
|
$io->error('ERROR: Required parameter --solr|-s is missing or array.'); |
|
120
|
|
|
exit(1); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
if ( |
|
124
|
|
|
empty($input->getOption('doc')) |
|
125
|
|
|
|| is_array($input->getOption('doc')) |
|
126
|
|
|
|| ( |
|
127
|
|
|
!MathUtility::canBeInterpretedAsInteger($input->getOption('doc')) |
|
128
|
|
|
&& !GeneralUtility::isValidUrl($input->getOption('doc')) |
|
129
|
|
|
) |
|
130
|
|
|
) { |
|
131
|
|
|
$io->error('ERROR: Required parameter --doc|-d is not a valid document UID or URL.'); |
|
132
|
|
|
exit(1); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
// Get the document... |
|
136
|
|
|
$doc = Document::getInstance($input->getOption('doc'), $startingPoint, true); |
|
137
|
|
|
if ($doc->ready) { |
|
138
|
|
|
if ($dryRun) { |
|
139
|
|
|
$io->section('DRY RUN: Would index ' . $doc->uid . ' ("' . $doc->location . '") on UID ' . $startingPoint . ' and Solr core ' . $solrCoreUid . '.'); |
|
140
|
|
|
} else { |
|
141
|
|
|
if ($io->isVerbose()) { |
|
142
|
|
|
$io->section('Indexing ' . $doc->uid . ' ("' . $doc->location . '") on UID ' . $startingPoint . ' and Solr core ' . $solrCoreUid . '.'); |
|
143
|
|
|
} |
|
144
|
|
|
// ...and save it to the database... |
|
145
|
|
|
if (!$doc->save($startingPoint, $solrCoreUid)) { |
|
146
|
|
|
$io->error('ERROR: Document "' . $input->getOption('doc') . '" not saved and indexed.'); |
|
147
|
|
|
exit(1); |
|
148
|
|
|
} |
|
149
|
|
|
} |
|
150
|
|
|
} else { |
|
151
|
|
|
$io->error('ERROR: Document "' . $input->getOption('doc') . '" could not be loaded.'); |
|
152
|
|
|
exit(1); |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
$io->success('All done!'); |
|
156
|
|
|
} |
|
157
|
|
|
} |
|
158
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.