Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
42.86% covered (danger)
42.86%
9 / 21
33.33% covered (danger)
33.33%
1 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
HarvestOaiCommand
42.86% covered (danger)
42.86%
9 / 21
33.33% covered (danger)
33.33%
1 / 3
12.72
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 checkLocalSetting
8.33% covered (danger)
8.33%
1 / 12
0.00% covered (danger)
0.00%
0 / 1
5.08
 execute
85.71% covered (warning)
85.71%
6 / 7
0.00% covered (danger)
0.00%
0 / 1
3.03
1<?php
2
3/**
4 * Console command: VuFind-specific customizations to OAI-PMH harvest command
5 *
6 * PHP version 8
7 *
8 * Copyright (C) Villanova University 2020.
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  Console
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/wiki/development Wiki
28 */
29
30namespace VuFindConsole\Command\Harvest;
31
32use Symfony\Component\Console\Attribute\AsCommand;
33use Symfony\Component\Console\Input\InputInterface;
34use Symfony\Component\Console\Output\OutputInterface;
35use VuFind\Config\PathResolver;
36use VuFindHarvest\OaiPmh\HarvesterFactory;
37
38/**
39 * Console command: VuFind-specific customizations to OAI-PMH harvest command
40 *
41 * @category VuFind
42 * @package  Console
43 * @author   Demian Katz <demian.katz@villanova.edu>
44 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
45 * @link     https://vufind.org/wiki/development Wiki
46 */
47#[AsCommand(
48    name: 'harvest/harvest_oai',
49    description: 'OAI-PMH harvester'
50)]
51class HarvestOaiCommand extends \VuFindHarvest\OaiPmh\HarvesterCommand
52{
53    /**
54     * Config file path resolver
55     *
56     * @var PathResolver
57     */
58    protected $pathResolver;
59
60    /**
61     * Constructor
62     *
63     * @param Client           $client       HTTP client (omit for default)
64     * @param string           $harvestRoot  Root directory for harvesting (omit for
65     * default)
66     * @param HarvesterFactory $factory      Harvester factory (omit for default)
67     * @param bool             $silent       Should we suppress output?
68     * @param string|null      $name         The name of the command; passing null
69     * means it must be set in configure()
70     * @param PathResolver     $pathResolver Config file path resolver
71     */
72    public function __construct(
73        $client = null,
74        $harvestRoot = null,
75        HarvesterFactory $factory = null,
76        $silent = false,
77        $name = null,
78        PathResolver $pathResolver = null
79    ) {
80        parent::__construct($client, $harvestRoot, $factory, $silent, $name);
81        $this->pathResolver = $pathResolver;
82    }
83
84    /**
85     * Warn the user if VUFIND_LOCAL_DIR is not set.
86     *
87     * @param OutputInterface $output Output object
88     *
89     * @return void
90     */
91    protected function checkLocalSetting(OutputInterface $output)
92    {
93        if (!getenv('VUFIND_LOCAL_DIR')) {
94            $output->writeln(
95                'WARNING: The VUFIND_LOCAL_DIR environment variable is not set.'
96            );
97            $output->writeln(
98                'This should point to your local configuration directory (i.e.'
99            );
100            $output->writeln(realpath(APPLICATION_PATH . '/local') . ').');
101            $output->writeln(
102                'Without it, inappropriate default settings may be loaded.'
103            );
104            $output->writeln('');
105        }
106    }
107
108    /**
109     * Run the command.
110     *
111     * @param InputInterface  $input  Input object
112     * @param OutputInterface $output Output object
113     *
114     * @return int 0 for success
115     */
116    protected function execute(InputInterface $input, OutputInterface $output)
117    {
118        $this->checkLocalSetting($output);
119
120        // Add the default --ini setting if missing:
121        if (!$input->getOption('ini')) {
122            $ini = $this->pathResolver
123                ? $this->pathResolver->getConfigPath('oai.ini', 'harvest')
124                : \VuFind\Config\Locator::getConfigPath('oai.ini', 'harvest');
125            $input->setOption('ini', $ini);
126        }
127        return parent::execute($input, $output);
128    }
129}