public function undo() { $this->autoRender = false; if ($this->request->is('post')) { return json_encode(History::undo($this->Session)); } }
public function undo() { $ids = explode(',', $this->params()->id); $this->changes = HistoryChange::emptyCollection(); foreach ($ids as $id) { $this->changes[] = HistoryChange::where("id = ?", $id)->first(); } $histories = []; $total_histories = 0; foreach ($this->changes as $change) { if (isset($histories[$change->history_id])) { continue; } $histories[$change->history_id] = true; $total_histories += 1; } if ($total_histories > 1 && !$this->current_user->is_privileged_or_higher()) { $this->respond_to_error("Only privileged users can undo more than one change at once", ['status' => 403]); return; } $errors = []; History::undo($this->changes, $this->current_user, $this->params()->redo == "1", $errors); $error_texts = []; $successful = 0; $failed = 0; foreach ($this->changes as $change) { $objectHash = spl_object_hash($change); if (empty($errors[$objectHash])) { $successful += 1; continue; } $failed += 1; switch ($errors[$objectHash]) { case 'denied': $error_texts[] = "Some changes were not made because you do not have access to make them."; break; } } $error_texts = array_unique($error_texts); $this->respond_to_success("Changes made.", ['action' => "index"], ['api' => ['successful' => $successful, 'failed' => $failed, 'errors' => $error_texts]]); }