ronanchilvers /
deploy
| 1 | <?php |
||
| 2 | |||
| 3 | namespace App\Controller\Project; |
||
| 4 | |||
| 5 | use App\Controller\Traits\ProjectTrait; |
||
| 6 | use App\Facades\Log; |
||
| 7 | use App\Facades\Provider; |
||
| 8 | use App\Facades\Router; |
||
| 9 | use App\Facades\Security; |
||
| 10 | use App\Facades\Session; |
||
| 11 | use App\Facades\View; |
||
| 12 | use App\Model\Deployment; |
||
| 13 | use App\Model\Event; |
||
| 14 | use App\Model\Project; |
||
| 15 | use App\Queue\DeployJob; |
||
| 16 | use App\Queue\ReactivateJob; |
||
| 17 | use Exception; |
||
| 18 | use Psr\Http\Message\ResponseInterface; |
||
| 19 | use Psr\Http\Message\ServerRequestInterface; |
||
| 20 | use Ronanchilvers\Foundation\Facade\Queue; |
||
| 21 | use Ronanchilvers\Foundation\Queue\Exception\FailedDispatchException; |
||
| 22 | use Ronanchilvers\Orm\Orm; |
||
| 23 | use Ronanchilvers\Utility\Str; |
||
| 24 | use RuntimeException; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Controller for the index |
||
| 28 | * |
||
| 29 | * @author Ronan Chilvers <[email protected]> |
||
| 30 | */ |
||
| 31 | class SettingsController |
||
| 32 | { |
||
| 33 | use ProjectTrait; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Edit action |
||
| 37 | * |
||
| 38 | * @author Ronan Chilvers <[email protected]> |
||
| 39 | */ |
||
| 40 | public function edit( |
||
| 41 | ServerRequestInterface $request, |
||
| 42 | ResponseInterface $response, |
||
| 43 | $args |
||
| 44 | ) { |
||
| 45 | if (!$project = $this->projectFromArgs($args)) { |
||
| 46 | return $response->withRedirect( |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 47 | Router::pathFor('project.index') |
||
| 48 | ); |
||
| 49 | } |
||
| 50 | if ('POST' == $request->getMethod()) { |
||
| 51 | $data = $request->getParsedBody()['project']; |
||
| 52 | $project->fromArray($data); |
||
| 53 | if ($project->saveWithValidation()) { |
||
| 54 | Session::flash([ |
||
| 55 | 'heading' => 'Project saved' |
||
| 56 | ]); |
||
| 57 | return $response->withRedirect( |
||
| 58 | Router::pathFor('project.edit', [ |
||
| 59 | 'key' => $project->key |
||
| 60 | ]) |
||
| 61 | ); |
||
| 62 | } |
||
| 63 | } |
||
| 64 | |||
| 65 | return View::render( |
||
| 66 | $response, |
||
| 67 | 'project/edit.html.twig', |
||
| 68 | [ |
||
| 69 | 'project' => $project, |
||
| 70 | 'providers' => Provider::getOptions(), |
||
| 71 | ] |
||
| 72 | ); |
||
| 73 | } |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Webhook settings |
||
| 77 | * |
||
| 78 | * @author Ronan Chilvers <[email protected]> |
||
| 79 | */ |
||
| 80 | public function webhooks( |
||
| 81 | ServerRequestInterface $request, |
||
| 82 | ResponseInterface $response, |
||
| 83 | $args |
||
| 84 | ) { |
||
| 85 | if (!$project = $this->projectFromArgs($args)) { |
||
| 86 | return $response->withRedirect( |
||
| 87 | Router::pathFor('project.index') |
||
| 88 | ); |
||
| 89 | } |
||
| 90 | if ('POST' == $request->getMethod()) { |
||
| 91 | $data = $request->getParsedBody()['project']; |
||
| 92 | $project->fromArray($data); |
||
| 93 | if ($project->saveWithValidation()) { |
||
| 94 | Session::flash([ |
||
| 95 | 'heading' => 'Project saved' |
||
| 96 | ]); |
||
| 97 | return $response->withRedirect( |
||
| 98 | Router::pathFor('project.edit', [ |
||
| 99 | 'key' => $project->key |
||
| 100 | ]) |
||
| 101 | ); |
||
| 102 | } |
||
| 103 | } |
||
| 104 | |||
| 105 | return View::render( |
||
| 106 | $response, |
||
| 107 | 'project/webhooks.html.twig', |
||
| 108 | [ |
||
| 109 | 'project' => $project, |
||
| 110 | 'providers' => Provider::getOptions(), |
||
| 111 | ] |
||
| 112 | ); |
||
| 113 | } |
||
| 114 | } |
||
| 115 |