1<?php
2/**
3 * DokuWiki Plugin dataau (Admin Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Andreas Gohr <gohr@cosmocode.de>
7 */
8
9// must be run within Dokuwiki
10if (!defined('DOKU_INC')) die();
11
12/**
13 * Let admin remove non-existing pages from sqlite db
14 */
15class admin_plugin_dataau_clean extends DokuWiki_Admin_Plugin {
16
17    /**
18     * will hold the dataau helper plugin
19     * @var helper_plugin_data
20     */
21    protected $dthlp = null;
22
23    /**
24     * Constructor. Load helper plugin
25     */
26    public function __construct(){
27        $this->dthlp = plugin_load('helper', 'dataau');
28    }
29
30    /**
31     * Determine position in list in admin window
32     * Lower values are sorted up
33     *
34     * @return int
35     */
36    public function getMenuSort() {
37        return 502;
38    }
39
40    /**
41     * Return true for access only by admins (config:superuser) or false if managers are allowed as well
42     *
43     * @return bool
44     */
45    public function forAdminOnly() {
46        return true;
47    }
48
49    /**
50     * Return the text that is displayed at the main admin menu
51     *
52     * @param string $language lang code
53     * @return string menu string
54     */
55    public function getMenuText($language) {
56        return $this->getLang('menu_clean');
57    }
58
59    /**
60     * Carry out required processing
61     */
62    public function handle() {
63        if(!isset($_REQUEST['dataau_go']) || !checkSecurityToken()) return;
64
65        $sqlite = $this->dthlp->_getDB();
66        if(!$sqlite) return;
67
68        $res  = $sqlite->query("SELECT pid, page FROM pages");
69        $rows = $sqlite->res2arr($res);
70
71        $count = 0;
72        foreach($rows as $row){
73            if(!page_exists($row['page'])){
74                $sqlite->query('DELETE FROM dataau WHERE pid = ?',$row['pid']);
75                $sqlite->query('DELETE FROM pages WHERE pid = ?',$row['pid']);
76                $count++;
77            }
78        }
79
80        msg(sprintf($this->getLang('pages_del'),$count),1);
81    }
82
83    /**
84     * Render HTML output
85     */
86    public function html() {
87
88        echo $this->locale_xhtml('intro_clean');
89
90        $form = new Doku_Form(array('method'=>'post'));
91        $form->addHidden('page','dataau_clean');
92        $form->addHidden('dataau_go','go');
93
94        $form->addElement(form_makeButton('submit','admin',$this->getLang('submit_clean')));
95        $form->printForm();
96    }
97
98}
99
100// vim:ts=4:sw=4:et:enc=utf-8:
101