Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
WriteDocumentCommand
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
5 / 5
5
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
1
 getArguments
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
 getDocument
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getTimeout
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getHandler
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * Command to write a document object to Solr.
5 *
6 * PHP version 8
7 *
8 * Copyright (C) Villanova University 2021.
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   Demian Katz <demian.katz@villanova.edu>
26 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
27 * @link     https://vufind.org
28 */
29
30namespace VuFindSearch\Backend\Solr\Command;
31
32use VuFindSearch\Backend\Solr\Backend;
33use VuFindSearch\Backend\Solr\Document\DocumentInterface;
34use VuFindSearch\ParamBag;
35
36/**
37 * Command to write a document object to Solr.
38 *
39 * @category VuFind
40 * @package  Search
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 */
45class WriteDocumentCommand extends \VuFindSearch\Command\CallMethodCommand
46{
47    /**
48     * Document to write.
49     *
50     * @var DocumentInterface
51     */
52    protected $doc;
53
54    /**
55     * Timeout value.
56     *
57     * @var ?int
58     */
59    protected $timeout;
60
61    /**
62     * Handler to use.
63     *
64     * @var string
65     */
66    protected $handler;
67
68    /**
69     * Constructor.
70     *
71     * @param string            $backendId Search backend identifier
72     * @param DocumentInterface $doc       Document to write
73     * @param ?int              $timeout   Timeout value (null for default)
74     * @param string            $handler   Handler to use
75     * @param ?ParamBag         $params    Search backend parameters
76     */
77    public function __construct(
78        string $backendId,
79        DocumentInterface $doc,
80        int $timeout = null,
81        string $handler = 'update',
82        ?ParamBag $params = null
83    ) {
84        $this->doc = $doc;
85        $this->timeout = $timeout;
86        $this->handler = $handler;
87        parent::__construct(
88            $backendId,
89            Backend::class,
90            'writeDocument',
91            $params
92        );
93    }
94
95    /**
96     * Return search backend interface method arguments.
97     *
98     * @return array
99     */
100    public function getArguments(): array
101    {
102        return [
103            $this->getDocument(),
104            $this->getTimeout(),
105            $this->getHandler(),
106            $this->getSearchParameters(),
107        ];
108    }
109
110    /**
111     * Return document to write.
112     *
113     * @return DocumentInterface
114     */
115    public function getDocument(): DocumentInterface
116    {
117        return $this->doc;
118    }
119
120    /**
121     * Return timeout value.
122     *
123     * @return int|null
124     */
125    public function getTimeout(): ?int
126    {
127        return $this->timeout;
128    }
129
130    /**
131     * Return handler to use.
132     *
133     * @return string
134     */
135    public function getHandler(): string
136    {
137        return $this->handler;
138    }
139}