/** * Register the service provider. * * @return void */ public function register() { /** * ValidationException handler * * This catches ValidationException and Logs it, then returns the users back * */ App::error(function (ValidationException $e, $code, $fromConsole) { Log::error('ValidationException - ' . $e->getMessage()); return Redirect::back()->withInput()->withErrors($e->get()); }); App::error(function (QueryException $e, $code, $fromConsole) { Log::error('QueryException - ' . $e->getMessage()); return $this->showError(3, $e); }); /** * TokenMismatchException handler * * Handle CSRF mismatches */ App::error(function (TokenMismatchException $e, $code, $fromConsole) { Log::error('TokenMismatchException: ip: ' . Request::ip()); Site::set('title', 'Oops!'); return $this->showError(2, $e); }); /** * ModelNotFoundException handler * * What happens if a specific model cant be found. */ App::error(function (ModelNotFoundException $e, $code, $fromConsole) { Messages::add('error', 'That Id is invalid'); if (URL::previous() !== URL::to('')) { return Redirect::back(); } else { return Redirect::to('admin'); } }); }
/** * * Remove the project alongside deploy dir. * @param type $id * @return type */ public function get_delete($id) { $project = Projects::find($id); $m = new Messages(); if (!$project) { $m->add('error', "Unknown project!"); return Redirect::to(handles('orchestra::resources/githubdeploys'))->with('message', $m->serialize()); } $proj = new Githubdeploys\Release(); $proj->deleteProject($project); if ($project->delete()) { Deploys::where('project_id', '=', $id)->delete(); $m->add('success', "Project deleted alongside deploy path!"); } else { $m->add('error', "Could not remove project from the database!"); } return Redirect::to(handles('orchestra::resources/githubdeploys'))->with('message', $m->serialize()); }
/** * * Delete release. * @param type $id * @return type */ public function get_delete($id = null) { $release = new Deploys(); $release = $release->findWithProject($id); if (!$release) { $m = new Messages(); $m->add('error', "Unknown release!"); return Redirect::to(handles('orchestra::resources/githubdeploys'))->with('message', $m->serialize()); } $project = (object) $release[0]->relationships['projects']; $release = (object) $release[0]->attributes; $rel = new \Githubdeploys\Release(); $response = $rel->deleteRelease($project, $release); $m = new Messages(); if (isset($response['error'])) { foreach ($response['error'] as $r) { $m->add('error', $r); } } else { foreach ($response['success'] as $r) { $m->add('success', $r); } /* * We have to reinitialise $release because it's not an instance * of the model \Githubdeploys\Deploys anymore. Read above the code^ */ if (Deploys::find($release->id)->delete()) { $m->add('success', sprintf("Release %i (%s) has been deleted from the database.", $release->id, $release->release)); } else { $m->add('error', sprintf("Could not delete release %i from the database.", $release->id)); } } return Redirect::to(Request::referrer())->with('message', $m->serialize()); }