|
1 | 1 | <?php |
2 | 2 |
|
3 | 3 | /** |
4 | | - * DokuWiki Plugin move (Helper Component) |
| 4 | + * DokuWiki Plugin move (Remote Component) |
5 | 5 | * |
6 | 6 | * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html |
7 | 7 | * @author Claus-Justus Heine <[email protected]> |
8 | 8 | */ |
9 | | - |
10 | 9 | class remote_plugin_move extends DokuWiki_Remote_Plugin |
11 | 10 | { |
12 | 11 | /** |
13 | | - * Rename a Wiki page using XMLRPC. |
| 12 | + * Rename/move a given page |
14 | 13 | * |
15 | | - * @param string $fromId |
16 | | - * @param string $toId |
17 | | - * @return int |
| 14 | + * @param string $fromId The original page ID |
| 15 | + * @param string $toId The new page ID |
| 16 | + * @return true Always true when no error occured |
| 17 | + * @throws \dokuwiki\Remote\RemoteException when renaming fails |
18 | 18 | */ |
19 | 19 | public function renamePage(string $fromId, string $toId) |
20 | 20 | { |
21 | | - // Other RPC methods also implicitly sanitze the name, so ... |
22 | 21 | $fromId = cleanID($fromId); |
23 | 22 | $toId = cleanID($toId); |
24 | 23 |
|
25 | 24 | /** @var helper_plugin_move_op $MoveOperator */ |
26 | | - $moveOperator = plugin_load('helper', 'move_op'); |
27 | | - $moveAction = plugin_load('action', 'move_rename'); |
28 | | - |
29 | | - if (!$moveAction->renameOkay($fromId)) { |
30 | | - return 0; |
31 | | - } |
| 25 | + $MoveOperator = plugin_load('helper', 'move_op'); |
32 | 26 |
|
33 | | - if (!$moveOperator->movePage($fromId, $toId)) { |
34 | | - return 0; |
| 27 | + global $MSG; |
| 28 | + $MSG = []; |
| 29 | + if (!$MoveOperator->movePage($fromId, $toId)) { |
| 30 | + throw $this->msgToException($MSG); |
35 | 31 | } |
36 | 32 |
|
37 | | - return 1; |
| 33 | + return true; |
38 | 34 | } |
39 | 35 |
|
40 | 36 | /** |
41 | | - * Rename a Wiki media file using XMLRPC. |
| 37 | + * Rename/move a given media file |
42 | 38 | * |
43 | | - * @param string $fromId |
44 | | - * @param string $toId |
45 | | - * @return int |
| 39 | + * @param string $fromId The original media ID |
| 40 | + * @param string $toId The new media ID |
| 41 | + * @return true Always true when no error occured |
| 42 | + * @throws \dokuwiki\Remote\RemoteException when renaming fails |
46 | 43 | */ |
47 | 44 | public function renameMedia(string $fromId, string $toId) |
48 | 45 | { |
49 | | - // Other RPC methods also implicitly sanitze the name, so ... |
50 | 46 | $fromId = cleanID($fromId); |
51 | 47 | $toId = cleanID($toId); |
52 | 48 |
|
53 | 49 | /** @var helper_plugin_move_op $MoveOperator */ |
54 | | - $moveOperator = plugin_load('helper', 'move_op'); |
| 50 | + $MoveOperator = plugin_load('helper', 'move_op'); |
55 | 51 |
|
56 | | - if (!$moveOperator->moveMedia($fromId, $toId)) { |
57 | | - return 0; |
| 52 | + global $MSG; |
| 53 | + $MSG = []; |
| 54 | + if (!$MoveOperator->moveMedia($fromId, $toId)) { |
| 55 | + throw $this->msgToException($MSG); |
58 | 56 | } |
59 | 57 |
|
60 | | - return 1; |
| 58 | + return true; |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * Get an exception for the first error message found in the DokuWiki message array. |
| 63 | + * |
| 64 | + * Ideally the move operation should throw an exception, but currently only a return code is available. |
| 65 | + * |
| 66 | + * @param array $messages The DokuWiki message array |
| 67 | + * @return \dokuwiki\Remote\RemoteException |
| 68 | + */ |
| 69 | + protected function msgToException($messages) |
| 70 | + { |
| 71 | + foreach ($messages as $msg) { |
| 72 | + if ($msg['lvl'] === -1) { |
| 73 | + // error found return it |
| 74 | + return new \dokuwiki\Remote\RemoteException($msg['msg'], 100); |
| 75 | + } |
| 76 | + } |
| 77 | + // If we reach this point, no error was found |
| 78 | + return new \dokuwiki\Remote\RemoteException('Unknown error', 100); |
61 | 79 | } |
62 | 80 | } |
0 commit comments