Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
93.94% |
31 / 33 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
SitemapCommand | |
93.94% |
31 / 33 |
|
66.67% |
2 / 3 |
9.02 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
configure | |
100.00% |
19 / 19 |
|
100.00% |
1 / 1 |
1 | |||
execute | |
83.33% |
10 / 12 |
|
0.00% |
0 / 1 |
7.23 |
1 | <?php |
2 | |
3 | /** |
4 | * Console command: generate sitemaps |
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 | |
30 | namespace VuFindConsole\Command\Util; |
31 | |
32 | use Symfony\Component\Console\Attribute\AsCommand; |
33 | use Symfony\Component\Console\Command\Command; |
34 | use Symfony\Component\Console\Input\InputInterface; |
35 | use Symfony\Component\Console\Input\InputOption; |
36 | use Symfony\Component\Console\Output\OutputInterface; |
37 | use VuFind\Sitemap\Generator; |
38 | |
39 | /** |
40 | * Console command: generate sitemaps |
41 | * |
42 | * @category VuFind |
43 | * @package Console |
44 | * @author Demian Katz <demian.katz@villanova.edu> |
45 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
46 | * @link https://vufind.org/wiki/development Wiki |
47 | */ |
48 | #[AsCommand( |
49 | name: 'util/sitemap', |
50 | description: 'XML sitemap generator' |
51 | )] |
52 | class SitemapCommand extends Command |
53 | { |
54 | /** |
55 | * Sitemap generator |
56 | * |
57 | * @var Generator |
58 | */ |
59 | protected $generator; |
60 | |
61 | /** |
62 | * Constructor |
63 | * |
64 | * @param Generator $generator Sitemap generator |
65 | * @param string|null $name The name of the command; passing null means it |
66 | * must be set in configure() |
67 | */ |
68 | public function __construct(Generator $generator, $name = null) |
69 | { |
70 | $this->generator = $generator; |
71 | parent::__construct($name); |
72 | } |
73 | |
74 | /** |
75 | * Configure the command. |
76 | * |
77 | * @return void |
78 | */ |
79 | protected function configure() |
80 | { |
81 | $this |
82 | ->setHelp('Generates XML sitemap files.') |
83 | ->addOption( |
84 | 'baseurl', |
85 | null, |
86 | InputOption::VALUE_REQUIRED, |
87 | 'Base URL (overrides the url setting in Site section of config.ini)' |
88 | )->addOption( |
89 | 'basesitemapurl', |
90 | null, |
91 | InputOption::VALUE_REQUIRED, |
92 | 'Base sitemap URL (overrides the url setting in Site section of ' |
93 | . 'config.ini, or baseSitemapUrl in sitemap.ini)' |
94 | )->addOption( |
95 | 'filelocation', |
96 | null, |
97 | InputOption::VALUE_REQUIRED, |
98 | 'Output path (overrides the fileLocation setting in sitemap.ini)' |
99 | ); |
100 | } |
101 | |
102 | /** |
103 | * Run the command. |
104 | * |
105 | * @param InputInterface $input Input object |
106 | * @param OutputInterface $output Output object |
107 | * |
108 | * @return int 0 for success |
109 | */ |
110 | protected function execute(InputInterface $input, OutputInterface $output) |
111 | { |
112 | if ($input->hasOption('verbose') && $input->getOption('verbose')) { |
113 | $this->generator->setVerbose([$output, 'writeln']); |
114 | } |
115 | if ($url = $input->getOption('baseurl')) { |
116 | $this->generator->setBaseUrl($url); |
117 | } |
118 | if ($sitemapUrl = $input->getOption('basesitemapurl')) { |
119 | $this->generator->setBaseSitemapUrl($sitemapUrl); |
120 | } |
121 | if ($fileLocation = $input->getOption('filelocation')) { |
122 | $this->generator->setFileLocation($fileLocation); |
123 | } |
124 | $this->generator->generate(); |
125 | foreach ($this->generator->getWarnings() as $warning) { |
126 | $output->writeln("$warning"); |
127 | } |
128 | return 0; |
129 | } |
130 | } |