xref: /plugin/renderrevisions/cli.php (revision ed65e3b856e457707d44652dedcf3ee0300b3f7b)
1<?php
2
3use dokuwiki\Search\Indexer;
4use splitbrain\phpcli\Options;
5
6/**
7 * DokuWiki Plugin renderrevisions (CLI Component)
8 *
9 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
10 * @author  Andreas Gohr <dokuwiki@cosmocode.de>
11 */
12class cli_plugin_renderrevisions extends \dokuwiki\Extension\CLIPlugin
13{
14    /** @inheritDoc */
15    protected function setup(Options $options)
16    {
17        $options->setHelp(
18            "Re-render pages if necessary\n" .
19            "\n" .
20            "This command will go through all pages in the wiki (adhering to the skipRegex and matchRegex settings) " .
21            "and re-render them if necessary. This will trigger the renderrevisions plugin mechanism to create " .
22            "a new revision of the page if the content changed."
23        );
24    }
25
26    /** @inheritDoc */
27    protected function main(Options $options)
28    {
29        global $INFO;
30        global $ID;
31        global $ACT;
32
33        $indexer = new Indexer();
34        $pages = $indexer->getPages();
35
36        $action = plugin_load('action', 'renderrevisions_save');
37        [$skipRE, $matchRE] = $action->getRegexps();
38
39        foreach ($pages as $page) {
40            if (
41                ($skipRE && preg_match($skipRE, ":$page")) ||
42                ($matchRE && !preg_match($matchRE, ":$page"))
43            ) {
44                $this->info("Skipping $page");
45                continue;
46            }
47
48            $this->notice("Processing $page");
49            $file = wikiFN($page);
50            try {
51                $ID = $page;
52                $INFO = pageinfo();
53                $ACT = 'show';
54
55                p_cached_output($file, 'xhtml', $page);
56            } catch (\Exception $e) {
57                $this->error("Issues while rendering $page: " . $e->getMessage());
58            }
59        }
60    }
61}
62