Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
20 / 20 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
OptimizeDocument | |
100.00% |
20 / 20 |
|
100.00% |
3 / 3 |
7 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getContentType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getContent | |
100.00% |
17 / 17 |
|
100.00% |
1 / 1 |
5 |
1 | <?php |
2 | |
3 | /** |
4 | * SOLR optimize document class. |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) Villanova University 2010. |
9 | * |
10 | * This program is free software; you can redistribute it and/or modify |
11 | * it under the terms of the GNU General Public License version 2, |
12 | * as published by the Free Software Foundation. |
13 | * |
14 | * This program is distributed in the hope that it will be useful, |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | * GNU General Public License for more details. |
18 | * |
19 | * You should have received a copy of the GNU General Public License |
20 | * along with this program; if not, write to the Free Software |
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 | * |
23 | * @category VuFind |
24 | * @package Search |
25 | * @author David Maus <maus@hab.de> |
26 | * @author Demian Katz <demian.katz@villanova.edu> |
27 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
28 | * @link https://vufind.org |
29 | */ |
30 | |
31 | namespace VuFindSearch\Backend\Solr\Document; |
32 | |
33 | use XMLWriter; |
34 | |
35 | /** |
36 | * SOLR optimize document class. |
37 | * |
38 | * @category VuFind |
39 | * @package Search |
40 | * @author David Maus <maus@hab.de> |
41 | * @author Demian Katz <demian.katz@villanova.edu> |
42 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
43 | * @link https://vufind.org |
44 | */ |
45 | class OptimizeDocument implements DocumentInterface |
46 | { |
47 | /** |
48 | * Value for waitFlush attribute |
49 | * |
50 | * @var bool |
51 | */ |
52 | protected $waitFlush; |
53 | |
54 | /** |
55 | * Value for waitSearch attribute |
56 | * |
57 | * @var bool |
58 | */ |
59 | protected $waitSearcher; |
60 | |
61 | /** |
62 | * Constructor. |
63 | * |
64 | * @param bool $waitFlush waitFlush attribute value |
65 | * @param bool $waitSearcher waitSearcher attribute value |
66 | */ |
67 | public function __construct(bool $waitFlush = null, bool $waitSearcher = null) |
68 | { |
69 | $this->waitFlush = $waitFlush; |
70 | $this->waitSearcher = $waitSearcher; |
71 | } |
72 | |
73 | /** |
74 | * Return content MIME type. |
75 | * |
76 | * @return string |
77 | */ |
78 | public function getContentType(): string |
79 | { |
80 | return 'text/xml; charset=UTF-8'; |
81 | } |
82 | |
83 | /** |
84 | * Return serialized representation. |
85 | * |
86 | * @return string |
87 | */ |
88 | public function getContent(): string |
89 | { |
90 | $writer = new XMLWriter(); |
91 | $writer->openMemory(); |
92 | $writer->startDocument(); |
93 | $writer->startElement('optimize'); |
94 | if ($this->waitFlush !== null) { |
95 | $writer->writeAttribute( |
96 | 'waitFlush', |
97 | $this->waitFlush ? 'true' : 'false' |
98 | ); |
99 | } |
100 | if ($this->waitSearcher !== null) { |
101 | $writer->writeAttribute( |
102 | 'waitSearcher', |
103 | $this->waitSearcher ? 'true' : 'false' |
104 | ); |
105 | } |
106 | $writer->endElement(); |
107 | $writer->endDocument(); |
108 | return $writer->flush(); |
109 | } |
110 | } |