xref: /plugin/renderrevisions/cli.php (revision eb84119862ffc9cad04500fcc4c0b2b30f92790d)
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    {
2945a98659SAndreas Gohr        global $INFO;
3045a98659SAndreas Gohr        global $ID;
31707aae1bSAndreas Gohr        global $ACT;
3245a98659SAndreas Gohr
33*eb841198SSzymon Olewniczak        auth_setup(); // make sure ACLs are initialized
34*eb841198SSzymon Olewniczak
35ccbd11b2SAndreas Gohr        $indexer = new Indexer();
36ccbd11b2SAndreas Gohr        $pages = $indexer->getPages();
37ccbd11b2SAndreas Gohr
38b62e3d16SSzymon Olewniczak        $action = plugin_load('action', 'renderrevisions_save');
39ccbd11b2SAndreas Gohr        [$skipRE, $matchRE] = $action->getRegexps();
40ccbd11b2SAndreas Gohr
41ccbd11b2SAndreas Gohr        foreach ($pages as $page) {
42ccbd11b2SAndreas Gohr            if (
43ccbd11b2SAndreas Gohr                ($skipRE && preg_match($skipRE, ":$page")) ||
44ccbd11b2SAndreas Gohr                ($matchRE && !preg_match($matchRE, ":$page"))
45ccbd11b2SAndreas Gohr            ) {
46ccbd11b2SAndreas Gohr                $this->info("Skipping $page");
47ccbd11b2SAndreas Gohr                continue;
48ccbd11b2SAndreas Gohr            }
49ccbd11b2SAndreas Gohr
50ccbd11b2SAndreas Gohr            $this->notice("Processing $page");
51ccbd11b2SAndreas Gohr            $file = wikiFN($page);
52ccbd11b2SAndreas Gohr            try {
5345a98659SAndreas Gohr                $ID = $page;
5445a98659SAndreas Gohr                $INFO = pageinfo();
55707aae1bSAndreas Gohr                $ACT = 'show';
5645a98659SAndreas Gohr
57ccbd11b2SAndreas Gohr                p_cached_output($file, 'xhtml', $page);
58ccbd11b2SAndreas Gohr            } catch (\Exception $e) {
59ccbd11b2SAndreas Gohr                $this->error("Issues while rendering $page: " . $e->getMessage());
60ccbd11b2SAndreas Gohr            }
61ccbd11b2SAndreas Gohr        }
62ccbd11b2SAndreas Gohr    }
63ccbd11b2SAndreas Gohr}
64