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