Conditions | 7 |
Paths | 11 |
Total Lines | 31 |
Code Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 2 | Features | 0 |
1 | <?php |
||
15 | public function run(Storage $storage) |
||
16 | { |
||
17 | parent::run($storage); |
||
18 | |||
19 | if ($this->matchedSitemapItem->regex == false) { |
||
20 | if (isset($this->parameters['document'])) { |
||
21 | $this->parameters['document'] = $storage->getDocumentBySlug($this->parameters['document']); |
||
22 | } else { |
||
23 | throw new \Exception('When not using a regex, you need to set the parameter `document` with the path to the document in this sitemap item: ' . $this->matchedSitemapItem->title); |
||
24 | } |
||
25 | } else { |
||
26 | $relativeDocumentUri = current($this->matchedSitemapItem->matches[1]); |
||
27 | if (isset($this->parameters['folder'])) { |
||
28 | if (substr($this->parameters['folder'], -1) !== '/') { |
||
29 | $this->parameters['folder'] = $this->parameters['folder'] . '/'; |
||
30 | } |
||
31 | $relativeDocumentUri = $this->parameters['folder'] . $relativeDocumentUri; |
||
32 | } |
||
33 | |||
34 | $document = $storage->getDocumentBySlug($relativeDocumentUri); |
||
35 | |||
36 | if ($document->type == 'folder') { |
||
37 | throw new \Exception('The found document is a folder.'); |
||
38 | } |
||
39 | |||
40 | if ($document->state != 'published') { |
||
41 | throw new \Exception('Found document is unpublished.'); |
||
42 | } |
||
43 | $this->parameters['document'] = $document; |
||
44 | } |
||
45 | } |
||
46 | } |
||
47 | } |