[1925] | 1 | <?php |
---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
| 3 | # |
---|
| 4 | # This file is part of Dotclear 2. |
---|
| 5 | # |
---|
| 6 | # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear |
---|
| 7 | # Licensed under the GPL version 2.0 license. |
---|
| 8 | # See LICENSE file or |
---|
| 9 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
| 10 | # |
---|
| 11 | # -- END LICENSE BLOCK ----------------------------------------- |
---|
| 12 | if (!defined('DC_CONTEXT_ADMIN')) { return; } |
---|
| 13 | |
---|
| 14 | /** |
---|
| 15 | @ingroup PLUGIN_MAINTENANCE |
---|
| 16 | @nosubgrouping |
---|
| 17 | @brief Maintenance plugin rest service class. |
---|
| 18 | |
---|
| 19 | Serve maintenance methods via Dotclear's rest API |
---|
| 20 | */ |
---|
| 21 | class dcMaintenanceRest |
---|
| 22 | { |
---|
| 23 | /** |
---|
| 24 | * Serve method to do step by step task for maintenance. |
---|
| 25 | * |
---|
| 26 | * @param core <b>dcCore</b> dcCore instance |
---|
| 27 | * @param get <b>array</b> cleaned $_GET |
---|
| 28 | * @param post <b>array</b> cleaned $_POST |
---|
| 29 | * |
---|
| 30 | * @return <b>xmlTag</b> XML representation of response |
---|
| 31 | */ |
---|
| 32 | public static function step($core, $get, $post) |
---|
| 33 | { |
---|
| 34 | if (!isset($post['task'])) { |
---|
| 35 | throw new Exception('No task ID'); |
---|
| 36 | } |
---|
| 37 | if (!isset($post['code'])) { |
---|
| 38 | throw new Exception('No code ID'); |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | $maintenance = new dcMaintenance($core); |
---|
| 42 | if (($task = $maintenance->getTask($post['task'])) === null) { |
---|
| 43 | throw new Exception('Unknow task ID'); |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | $task->code((integer) $post['code']); |
---|
| 47 | if (($code = $task->execute()) === true) { |
---|
[1959] | 48 | $maintenance->setLog($task->id()); |
---|
[1925] | 49 | $code = 0; |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | $rsp = new xmlTag('step'); |
---|
| 53 | $rsp->code = $code; |
---|
| 54 | $rsp->title = html::escapeHTML($task->success()); |
---|
| 55 | |
---|
| 56 | return $rsp; |
---|
| 57 | } |
---|
| 58 | } |
---|