public static function merge($name, array $names) { $index = array_search($name, $names); if ($index > -1) { array_splice($names, $index, 1); } $into = (new self($name))->bean(); $trash = []; $records = $into->ownRecordList ?: []; if ($into === null) { throw new \Exception('merge into publisher does not exist'); } foreach ($names as $_name) { $trash[] = $publisherBean = (new Publisher($_name))->bean(); if ($publisherBean === null) { throw new \Exception('merge from publisher does not exist'); } foreach ($publisherBean->ownRecordList as $bean) { $records[] = $bean; } $publisherBean->ownRecordList = []; } $into->ownRecordList = $records; R::trashAll($trash); return R::store($into); }
}); // Remove a board. $app->post('/boards/remove', function () use($app, $jsonResponse) { $data = json_decode($app->environment['slim.input']); if (validateToken(true)) { $board = R::load('board', $data->boardId); if ($board->id == $data->boardId) { $before = $board->export(); foreach ($board->sharedUser as $user) { if ($user->defaultBoard == $data->boardId) { $user->defaultBoard = null; R::store($user); } } R::trashAll($board->xownLane); R::trashAll($board->xownCategory); R::trash($board); R::exec('DELETE from board_user WHERE board_id = ?', [$data->boardId]); $jsonResponse->addAlert('success', 'Removed board ' . $board->name . '.'); $actor = getUser(); logAction($actor->username . ' removed board ' . $board->name, $before, null); } $jsonResponse->addBeans(getBoards()); $jsonResponse->users = R::exportAll(getUsers()); } $app->response->setBody($jsonResponse->asJson()); }); $app->post('/autoactions', function () use($app, $jsonResponse) { $data = json_decode($app->environment['slim.input']); if (validateToken(true)) { $board = R::load('board', $data->boardId);
/** * Shorthand method that will delete a collection of beans with *commit* and *rollback* transactions * @param object $beans */ public static function deleteBeans($beans) { R::begin(); try { R::trashAll($beans); R::commit(); } catch (Exception $e) { R::rollback(); } }
public function removePerms() { if ($this->name !== 'Administrator') { $beans = R::findAll('perm', ' group_name = ? ', [$this->name]); R::trashAll($beans); } return $this; }
$customer->website = (string) $input->website; } if (isset($input->ownOptions)) { foreach ($input->ownOptions as $option) { $customerOption = \RedBeanPHP\R::dispense("options", 1); foreach ($option as $key => $val) { $customerOption->{$key} = $val; } $customer->ownOptions[] = $customerOption; } } \RedBeanPHP\R::store($customer); $app->response()->header('Content-Type', 'application/json'); echo json_encode(\RedBeanPHP\R::exportAll($customer)); } else { $app->response()->status(404); } }); // handle DELETE requests $app->delete('/customers/:id', function ($id) use($app) { //\RedBeanPHP\R::dependencies(array('options'=>array('customers'))); // retrieve specified element record $customer = \RedBeanPHP\R::findOne('customers', 'id = ?', array($id)); if ($customer) { \RedBeanPHP\R::trashAll($customer->ownOptions); \RedBeanPHP\R::trash($customer); $app->response()->status(204); } else { $app->response()->status(404); } });