1*0173e75dSAndreas Gohr<?php 2*0173e75dSAndreas Gohr/** 3*0173e75dSAndreas Gohr * DokuWiki Plugin struct (Action Component) 4*0173e75dSAndreas Gohr * 5*0173e75dSAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6*0173e75dSAndreas Gohr * @author Andreas Gohr, Michael Große <dokuwiki@cosmocode.de> 7*0173e75dSAndreas Gohr */ 8*0173e75dSAndreas Gohr 9*0173e75dSAndreas Gohr// must be run within Dokuwiki 10*0173e75dSAndreas Gohruse plugin\struct\meta\Assignments; 11*0173e75dSAndreas Gohruse plugin\struct\meta\Schema; 12*0173e75dSAndreas Gohr 13*0173e75dSAndreas Gohrif(!defined('DOKU_INC')) die(); 14*0173e75dSAndreas Gohr 15*0173e75dSAndreas Gohrclass action_plugin_struct_move extends DokuWiki_Action_Plugin { 16*0173e75dSAndreas Gohr 17*0173e75dSAndreas Gohr /** 18*0173e75dSAndreas Gohr * Registers a callback function for a given event 19*0173e75dSAndreas Gohr * 20*0173e75dSAndreas Gohr * @param Doku_Event_Handler $controller DokuWiki's event controller object 21*0173e75dSAndreas Gohr * @return void 22*0173e75dSAndreas Gohr */ 23*0173e75dSAndreas Gohr public function register(Doku_Event_Handler $controller) { 24*0173e75dSAndreas Gohr $controller->register_hook('PLUGIN_MOVE_PAGE_RENAME', 'AFTER', $this, 'handle_move'); 25*0173e75dSAndreas Gohr } 26*0173e75dSAndreas Gohr 27*0173e75dSAndreas Gohr /** 28*0173e75dSAndreas Gohr * Renames all occurances of a page ID in the database 29*0173e75dSAndreas Gohr * 30*0173e75dSAndreas Gohr * @param Doku_Event $event event object by reference 31*0173e75dSAndreas Gohr * @param mixed $param [the parameters passed as fifth argument to register_hook() when this 32*0173e75dSAndreas Gohr * handler was registered] 33*0173e75dSAndreas Gohr * @return bool 34*0173e75dSAndreas Gohr */ 35*0173e75dSAndreas Gohr public function handle_move(Doku_Event $event, $param) { 36*0173e75dSAndreas Gohr /** @var helper_plugin_struct_db $hlp */ 37*0173e75dSAndreas Gohr $hlp = plugin_load('helper', 'struct_db'); 38*0173e75dSAndreas Gohr $db = $hlp->getDB(); 39*0173e75dSAndreas Gohr if(!$db) return false; 40*0173e75dSAndreas Gohr 41*0173e75dSAndreas Gohr $old = $event->data['src_id']; 42*0173e75dSAndreas Gohr $new = $event->data['dst_id']; 43*0173e75dSAndreas Gohr 44*0173e75dSAndreas Gohr // ALL data tables (we don't trust the assigments are still there) 45*0173e75dSAndreas Gohr foreach(Schema::getAll() as $tbl) { 46*0173e75dSAndreas Gohr $sql = "UPDATE data_$tbl SET pid = ? WHERE pid = ?"; 47*0173e75dSAndreas Gohr $db->query($sql, array($new, $old)); 48*0173e75dSAndreas Gohr $sql = "UPDATE multi_$tbl SET pid = ? WHERE pid = ?"; 49*0173e75dSAndreas Gohr $db->query($sql, array($new, $old)); 50*0173e75dSAndreas Gohr } 51*0173e75dSAndreas Gohr // assignments 52*0173e75dSAndreas Gohr $sql = "UPDATE schema_assignments SET pid = ? WHERE pid = ?"; 53*0173e75dSAndreas Gohr $db->query($sql, array($new, $old)); 54*0173e75dSAndreas Gohr // make sure assignments still match patterns; 55*0173e75dSAndreas Gohr $assignments = new Assignments(); 56*0173e75dSAndreas Gohr $assignments->reevaluatePageAssignments($new); 57*0173e75dSAndreas Gohr 58*0173e75dSAndreas Gohr return true; 59*0173e75dSAndreas Gohr } 60*0173e75dSAndreas Gohr} 61