10173e75dSAndreas Gohr<?php 20173e75dSAndreas Gohr/** 30173e75dSAndreas Gohr * DokuWiki Plugin struct (Action Component) 40173e75dSAndreas Gohr * 50173e75dSAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 60173e75dSAndreas Gohr * @author Andreas Gohr, Michael Große <dokuwiki@cosmocode.de> 70173e75dSAndreas Gohr */ 80173e75dSAndreas Gohr 90173e75dSAndreas Gohr// must be run within Dokuwiki 10ba766201SAndreas Gohruse dokuwiki\plugin\struct\meta\Assignments; 11ba766201SAndreas Gohruse dokuwiki\plugin\struct\meta\Schema; 120173e75dSAndreas Gohr 130173e75dSAndreas Gohrif(!defined('DOKU_INC')) die(); 140173e75dSAndreas Gohr 150173e75dSAndreas Gohrclass action_plugin_struct_move extends DokuWiki_Action_Plugin { 160173e75dSAndreas Gohr 170173e75dSAndreas Gohr /** 180173e75dSAndreas Gohr * Registers a callback function for a given event 190173e75dSAndreas Gohr * 200173e75dSAndreas Gohr * @param Doku_Event_Handler $controller DokuWiki's event controller object 210173e75dSAndreas Gohr * @return void 220173e75dSAndreas Gohr */ 230173e75dSAndreas Gohr public function register(Doku_Event_Handler $controller) { 240173e75dSAndreas Gohr $controller->register_hook('PLUGIN_MOVE_PAGE_RENAME', 'AFTER', $this, 'handle_move'); 250173e75dSAndreas Gohr } 260173e75dSAndreas Gohr 270173e75dSAndreas Gohr /** 280173e75dSAndreas Gohr * Renames all occurances of a page ID in the database 290173e75dSAndreas Gohr * 300173e75dSAndreas Gohr * @param Doku_Event $event event object by reference 310173e75dSAndreas Gohr * @param mixed $param [the parameters passed as fifth argument to register_hook() when this 320173e75dSAndreas Gohr * handler was registered] 330173e75dSAndreas Gohr * @return bool 340173e75dSAndreas Gohr */ 350173e75dSAndreas Gohr public function handle_move(Doku_Event $event, $param) { 360173e75dSAndreas Gohr /** @var helper_plugin_struct_db $hlp */ 370173e75dSAndreas Gohr $hlp = plugin_load('helper', 'struct_db'); 38*7cbcfbdbSAndreas Gohr $db = $hlp->getDB(false); 390173e75dSAndreas Gohr if(!$db) return false; 400173e75dSAndreas Gohr $old = $event->data['src_id']; 410173e75dSAndreas Gohr $new = $event->data['dst_id']; 420173e75dSAndreas Gohr 430173e75dSAndreas Gohr // ALL data tables (we don't trust the assigments are still there) 44e0e1cf44SAndreas Gohr foreach(Schema::getAll('page') as $tbl) { 450173e75dSAndreas Gohr $sql = "UPDATE data_$tbl SET pid = ? WHERE pid = ?"; 460173e75dSAndreas Gohr $db->query($sql, array($new, $old)); 470173e75dSAndreas Gohr $sql = "UPDATE multi_$tbl SET pid = ? WHERE pid = ?"; 480173e75dSAndreas Gohr $db->query($sql, array($new, $old)); 490173e75dSAndreas Gohr } 500173e75dSAndreas Gohr // assignments 510173e75dSAndreas Gohr $sql = "UPDATE schema_assignments SET pid = ? WHERE pid = ?"; 520173e75dSAndreas Gohr $db->query($sql, array($new, $old)); 530173e75dSAndreas Gohr // make sure assignments still match patterns; 54025cb9daSAndreas Gohr $assignments = Assignments::getInstance(); 550173e75dSAndreas Gohr $assignments->reevaluatePageAssignments($new); 560173e75dSAndreas Gohr 57606635f3SAndreas Gohr // titles 58606635f3SAndreas Gohr $sql = "UPDATE titles SET pid = ? WHERE pid = ?"; 59606635f3SAndreas Gohr $db->query($sql, array($new, $old)); 60606635f3SAndreas Gohr 610173e75dSAndreas Gohr return true; 620173e75dSAndreas Gohr } 630173e75dSAndreas Gohr} 64