Skip to content

Commit

Permalink
Build page list before moving pages, add $checkonly parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
michitux committed Dec 29, 2012
1 parent 7b5f66e commit 46e6e72
Showing 1 changed file with 43 additions and 31 deletions.
74 changes: 43 additions & 31 deletions admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,44 +373,52 @@ function handle() {
*
* @author Bastian Wolf
* @param $pathToSearch
* @param $opts
* @return unknown_type
* @param array $opts Options for moving the page
* @param bool $checkonly If only the checks if all pages can be moved shall be executed
* @return bool if the move was executed
*/
function _pm_move_recursive($pathToSearch, $opts) {
function _pm_move_recursive($pathToSearch, &$opts, $checkonly = false) {
global $ID;
global $conf;

$pagelist = array();
search($pagelist, $conf['datadir'], 'search_index', array(), $pathToSearch);
$searchOpts = array('depth' => 0, 'skipacl' => true);
search($pagelist, $conf['datadir'], 'search_allpages', $searchOpts, $pathToSearch);

// FIXME: either use ajax for executing the queue and/or store the queue so it can be resumed when the execution
// is aborted.
foreach ($pagelist as $page) {
if ($page['type'] == 'd') {
$pathToSearch = utf8_encodeFN(str_replace(':', '/', $page['id']));
// @fixme shouldn't be necessary as ID already exists
io_createNamespace($page['id']);
// NS to move is this one
$nsOpts = $opts;
$nsOpts['ns'] = $page['id'];
// target NS is this folder under the current target NS
$thisFolder = end(explode(':', $page['id']));
$nsOpts['newns'] .= ':'.$thisFolder;
array_push($this->idsToDelete, $page['id']);
// Recursion
$this->_pm_move_recursive($pathToSearch, $nsOpts);
}
elseif ($page['type'] == 'f') {
$ID = $page['id'];
$pageOpts = $opts;
$pageOpts['ns'] = getNS($ID);
$pageOpts['name'] = noNS($ID);
$pageOpts['newname'] = noNS($ID);
$this->_pm_move_page($pageOpts);
}
else {
$this->errors[] = $this->lang['pm_unknown_file_type'];
return;
}
$ID = $page['id'];
$newID = $this->getNewID($ID, $opts['ns'], $opts['newns']);
$pageOpts = $opts;
$pageOpts['ns'] = getNS($ID);
$pageOpts['name'] = noNS($ID);
$pageOpts['newname'] = noNS($ID);
$pageOpts['newns'] = getNS($newID);
if (!$this->_pm_move_page($pageOpts, $checkonly)) return false;
}
return true;
}

/**
* Get the id of a page after a namespace move
*
* @param string $oldid The old id of the page
* @param string $oldns The old namespace. $oldid needs to be inside $oldns
* @param string $newns The new namespace
* @return string The new id
*/
function getNewID($oldid, $oldns, $newns) {
$newid = $oldid;
if ($oldns != '') {
$newid = substr($oldid, strlen($oldns)+1);
}

if ($newns != '') {
$newid = $newns.':'.$newid;
}

return $newid;
}


Expand All @@ -420,9 +428,10 @@ function _pm_move_recursive($pathToSearch, $opts) {
* @author Gary Owen <[email protected]>, modified by Kay Roesler
*
* @param array $opts
* @param bool $checkonly Only execute the checks if the page can be moved
* @return bool If the move was executed
*/
function _pm_move_page(&$opts) {
function _pm_move_page(&$opts, $checkonly = false) {
global $ID;

// Check we have rights to move this document
Expand Down Expand Up @@ -463,6 +472,8 @@ function _pm_move_page(&$opts) {
return false;
}

if ($checkonly) return true;

/**
* End of init (checks)
*/
Expand Down Expand Up @@ -550,6 +561,7 @@ function _pm_move_page(&$opts) {
}

$event->advise_after();
return true;
}

/**
Expand Down

0 comments on commit 46e6e72

Please sign in to comment.