[dokuwiki] importoldchangelog: omits metadata

  • From: "Simon Coffey" <spc03@xxxxxxxxxxxx>
  • To: <dokuwiki@xxxxxxxxxxxxx>
  • Date: Mon, 11 Feb 2008 14:35:00 -0000

Hi all,

I posted this on the forum but was advised to repeat it here. Recently on
upgrading from 2006-03-09 to 2007-06-26b I had some problems getting the
blog working, which turned out to be due to the metadata entries for each
page containing no info from before the upgrade.

This in turn was because the importoldchangelog plugin only writes the
.changes files for each page; it doesn't bother writing any .meta files, so
while the changlogs are correct, as far as all the metadata functions are
concerned the information is lost.

For my purposes I fixed this by adding some logic in importOldLog() to
update the metadata for each line processed. Then I realised this was a bit
inefficient due to repeated opening and closing of the same files, so I
wrote a new method for the plugin called savePerPageMetadata() to do the job
in one go:

function savePerPageMetadata($id, &$changes) {
        global $auth;
        ksort($changes); // order by date
        $meta = array();
        // Run through history and populate the metadata array
        foreach ($changes as $date => $tmp) {
                $user = $tmp['user'];
                if ($tmp['type'] === DOKU_CHANGE_TYPE_CREATE) {
                        $meta['date']['created'] = $tmp['date'];
                        if ($user) {
                                $userinfo = $auth->getUserData($user);
                                $meta['creator'] = $userinfo['name'];
                        }
                } else if ($tmp['type'] === DOKU_CHANGE_TYPE_EDIT) {
                        $meta['date']['modified'] = $tmp['date'];
                        if ($user) {
                                $userinfo = $auth->getUserData($user);
                                $meta['contributor'][$user] =
$userinfo['name'];
                        }
                }
        }
        p_set_metadata($id, $meta, true);
}

I called this just before the savePerPageChanges() function in run_import()
(because I think savePerPageChanges() modifies the $changes array). I've
done some cursory testing on my site, and it seems to work, inasmuch as my
blog entries are now properly ordered with the creator field populated.

Hope this is useful; I've not really done any PHP programming before so if
it does get used it'll definitely be worth a thorough checking to make sure
I haven't stuffed anything up... :-)

Cheers,
Simon

p.s. While I'm here, many thanks to all of you who contribute to DokuWiki
and its various plugins; it really is a pleasure to use.

-- 
DokuWiki mailing list - more info at
http://wiki.splitbrain.org/wiki:mailinglist

Other related posts: