dokufreaks/plugin-blogtng

feature: page move function

Opened this issue · 3 comments

Hi,

I really like blogtng.
There is just one thing I'm missing.
It would be nice if blogtng would provide a function for other plugins which allows moving of pages.
So e.g. dw-editx could also move pages stored in blogtng database without losing the comments and tags of it.

Because there is no responds until now I'd like to know whether this request is accepted or not.

This function is one of the few reasons I can't use blogtng for the wiki of my company.

On short term i don't expect improvements on this area.
There have been some developments with respect to the page move pluign https://github.com/michitux/DokuWiki-Pagemove-Plugin/ by @michitux
When these developments (somewhere in future) are released it can be nice to come back to this issue and see what is possible to perform updates of BlogTNG metadata with triggers from moves with this plugin.

I had a look at this when I implemented the pagemove plugin. The new pagemove plugin provides an event that other plugins can use in order to move their data. I wrote some code for a new action component in action/pagemove.php which doesn't work as such but should provide a general idea of how that could/should work. The main problem is that the md5sum of the page id is used as primary id which means that also all comments for that page need to be updated.

<?php
/**
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Michael Hamann <michael@content-space.de>
 */

// must be run within Dokuwiki
if (!defined('DOKU_INC')) die();

class action_plugin_blogtng_pagemove extends DokuWiki_Action_Plugin{
    private $entry = null;
    private $tags = array();

    function register(&$controller) {
        $controller->register_hook('PAGEMOVE_PAGE_RENAME', 'BEFORE', $this, 'get_data', array());
        $controller->register_hook('PAGEMOVE_PAGE_RENAME', 'AFTER', $this, 'update_data', array());
    }

    function get_data($event, $params) {
        global $ID;
        $old_pid = md5($ID);

        /** @var helper_plugin_blogtng_entry $entryhelper */
        $entryhelper =& plugin_load('helper', 'blogtng_entry');

        if ($entryhelper->load_by_pid($old_pid) === helper_plugin_blogtng_entry::RET_OK) {
            $this->entry = $entryhelper->entry;
            $taghelper = $entryhelper->getTagHelper();
            $this->tags = $taghelper->tags;
            $entryhelper->delete();
        }
    }

    function update_data(&$event, $params) {
        if (!is_null($this->entry)) {
            $new_id = $event->data['opts']['new_id'];

            $new_pid = md5($new_id);

            /** @var helper_plugin_blogtng_entry $entryhelper */
            $entryhelper =& plugin_load('helper', 'blogtng_entry');

            $entryhelper->load_by_pid($new_pid);
            $entryhelper->entry['page'] = $new_id;
            $entryhelper->set($this->entry);
            $entryhelper->save();

            $taghelper = $entryhelper->getTagHelper();
            $taghelper->set($this->tags);
            $taghelper->save();
        }
    }
}