Skip to content
This repository was archived by the owner on Nov 3, 2021. It is now read-only.

Commit df9ded6

Browse files
authored
Merge pull request #234 from LexicForLXD/fix/diverses
Fix/diverses
2 parents 26d972a + a29e745 commit df9ded6

25 files changed

Lines changed: 498 additions & 255 deletions

src/AppBundle/Controller/BackupController.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use AppBundle\Exception\WrongInputExceptionArray;
1212
use AppBundle\Worker\BackupWorker;
1313
use Doctrine\ORM\EntityManagerInterface;
14-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
14+
use Symfony\Component\Routing\Annotation\Route;
1515
use Swagger\Annotations as OAS;
1616
use Symfony\Component\HttpFoundation\Request;
1717
use Symfony\Component\HttpFoundation\Response;
@@ -325,4 +325,30 @@ public function storeBackupAction(Request $request, EntityManagerInterface $em,
325325
}
326326

327327

328+
/**
329+
* Return all backups from on schedule
330+
*
331+
* @Route("/schedules/{scheduleId}/backups", name="get_schedule_backups", methods={"GET"})
332+
*
333+
* @param int $scheduleId
334+
* @param EntityManagerInterface $em
335+
* @throws ElementNotFoundException
336+
* @return Response
337+
*/
338+
public function getBackupsFromSchedule($scheduleId, EntityManagerInterface $em)
339+
{
340+
$backupSchedule = $this->getDoctrine()->getRepository(BackupSchedule::class)->find($id);
341+
342+
if (!$backupSchedule) {
343+
throw new ElementNotFoundException(
344+
'No BackupSchedule for id ' . $scheduleId . ' found'
345+
);
346+
}
347+
348+
$backups = $backupSchedule->getBackups();
349+
350+
$serializer = $this->get('jms_serializer');
351+
$response = $serializer->serialize($backups, 'json');
352+
return new Response($response, 200);
353+
}
328354
}

src/AppBundle/Controller/BackupDestinationController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace AppBundle\Controller;
44

5-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
5+
use Symfony\Component\Routing\Annotation\Route;
66
use Symfony\Component\HttpFoundation\Request;
77
use Doctrine\ORM\EntityManagerInterface;
88
use Symfony\Component\HttpFoundation\Response;

src/AppBundle/Controller/BackupScheduleController.php

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
namespace AppBundle\Controller;
44

55

6-
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
76

8-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
7+
use Symfony\Component\Routing\Annotation\Route;
98
use Swagger\Annotations as OAS;
109
use Symfony\Component\HttpFoundation\Request;
1110
use Symfony\Component\HttpFoundation\JsonResponse;
@@ -23,7 +22,7 @@
2322
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
2423

2524

26-
class BackupScheduleController extends Controller
25+
class BackupScheduleController extends BaseController
2726
{
2827

2928
/**
@@ -356,28 +355,7 @@ public function indexBackupScheduleAction()
356355
}
357356

358357

359-
/**
360-
* Validates a BackupSchedule Object and returns array with errors.
361-
*
362-
* @param BackupSchedule $object
363-
* @return array|bool
364-
* @throws WrongInputExceptionArray
365-
*/
366-
private function validation(BackupSchedule $object)
367-
{
368-
$validator = $this->get('validator');
369-
$errors = $validator->validate($object);
370358

371-
if (count($errors) > 0) {
372-
$errorArray = array();
373-
foreach ($errors as $error) {
374-
$errorArray[$error->getPropertyPath()] = $error->getMessage();
375-
}
376-
throw new WrongInputExceptionArray($errorArray);
377-
378-
}
379-
return false;
380-
}
381359

382360

383361
/**

src/AppBundle/Controller/ContainerController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
use AppBundle\Entity\Image;
2828
use AppBundle\Entity\ImageAlias;
2929

30-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
30+
use Symfony\Component\Routing\Annotation\Route;
3131
use Swagger\Annotations as OAS;
3232

3333

src/AppBundle/Controller/ContainerStateController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
use Doctrine\ORM\EntityManagerInterface;
1616

17-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
17+
use Symfony\Component\Routing\Annotation\Route;
1818
use Swagger\Annotations as OAS;
1919

2020

src/AppBundle/Controller/CorsProxyController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ class CorsProxyController extends BaseController
2727
* @throws ConnectionErrorException
2828
* @throws WrongInputException
2929
*/
30-
public function corsProxy(CorsProxyApi $api, Request $request){
30+
public function corsProxy(CorsProxyApi $api, Request $request)
31+
{
3132
$url = $request->query->get('url');
32-
if(!$url){
33+
if (!$url) {
3334
throw new WrongInputException("No URL provided");
3435
}
3536
$result = $api->getUrl($url);

src/AppBundle/Controller/DefaultController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace AppBundle\Controller;
44

5-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
5+
use Symfony\Component\Routing\Annotation\Route;
66
use Symfony\Component\HttpFoundation\Request;
77
use Swagger\Annotations as SWG;
88

@@ -19,7 +19,7 @@ public function indexAction()
1919
{
2020
// replace this example code with whatever you need
2121
return $this->render('default/index.html.twig', [
22-
'base_dir' => realpath($this->getParameter('kernel.project_dir')).DIRECTORY_SEPARATOR,
22+
'base_dir' => realpath($this->getParameter('kernel.project_dir')) . DIRECTORY_SEPARATOR,
2323
]);
2424
}
2525
}

src/AppBundle/Controller/HostController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use AppBundle\Entity\Host;
1313
use AppBundle\Exception\ElementNotFoundException;
1414
use Httpful\Exception\ConnectionErrorException;
15-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
15+
use Symfony\Component\Routing\Annotation\Route;
1616
use Symfony\Component\HttpFoundation\Request;
1717
use Doctrine\ORM\EntityManagerInterface;
1818
use Symfony\Component\HttpFoundation\Response;

src/AppBundle/Controller/ImageAliasController.php

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use AppBundle\Exception\WrongInputException;
99
use AppBundle\Exception\WrongInputExceptionArray;
1010
use AppBundle\Service\LxdApi\ImageAliasApi;
11-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
11+
use Symfony\Component\Routing\Annotation\Route;
1212
use Symfony\Component\HttpFoundation\Request;
1313
use Swagger\Annotations as OAS;
1414
use Symfony\Component\HttpFoundation\Response;
@@ -76,7 +76,7 @@ public function createAliasForImage($imageId, Request $request, ImageAliasApi $i
7676
);
7777
}
7878

79-
if(!$image->isFinished()){
79+
if (!$image->isFinished()) {
8080
throw new WrongInputException('ImageAlias creation is only supported for Images where the creation process is finished');
8181
}
8282

@@ -93,8 +93,8 @@ public function createAliasForImage($imageId, Request $request, ImageAliasApi $i
9393

9494
$result = $imageAliasApi->createAliasForImageByFingerprint($image->getHost(), $imageAlias, $image->getFingerprint());
9595

96-
if($result->code != 201 || $result->body->status_code != 200){
97-
throw new WrongInputException('LXD-Error - '.$result->body->error);
96+
if ($result->code != 201 || $result->body->status_code != 200) {
97+
throw new WrongInputException('LXD-Error - ' . $result->body->error);
9898
}
9999

100100
$em = $this->getDoctrine()->getManager();
@@ -143,7 +143,8 @@ public function createAliasForImage($imageId, Request $request, ImageAliasApi $i
143143
* @throws WrongInputException
144144
* @throws \Httpful\Exception\ConnectionErrorException
145145
*/
146-
public function deleteImageAlias($aliasId, ImageAliasApi $imageAliasApi){
146+
public function deleteImageAlias($aliasId, ImageAliasApi $imageAliasApi)
147+
{
147148
$imageAlias = $this->getDoctrine()->getRepository(ImageAlias::class)->find($aliasId);
148149

149150
if (!$imageAlias) {
@@ -154,14 +155,14 @@ public function deleteImageAlias($aliasId, ImageAliasApi $imageAliasApi){
154155

155156
$image = $imageAlias->getImage();
156157

157-
if(!$image->isFinished()){
158+
if (!$image->isFinished()) {
158159
throw new WrongInputException('Deleting of the ImageAlias for an Image which is in the creation process is not possible');
159160
}
160161

161162
$result = $imageAliasApi->removeAliasByName($image->getHost(), $imageAlias->getName());
162163

163-
if($result->code != 200 || $result->body->status_code != 200){
164-
throw new WrongInputException('LXD-Error - '.$result->body->error);
164+
if ($result->code != 200 || $result->body->status_code != 200) {
165+
throw new WrongInputException('LXD-Error - ' . $result->body->error);
165166
}
166167

167168
$image->removeAlias($imageAlias);
@@ -229,7 +230,8 @@ public function deleteImageAlias($aliasId, ImageAliasApi $imageAliasApi){
229230
* @throws \Httpful\Exception\ConnectionErrorException
230231
* @throws WrongInputExceptionArray
231232
*/
232-
public function editImageAlias($aliasId, Request $request,ImageAliasApi $imageAliasApi){
233+
public function editImageAlias($aliasId, Request $request, ImageAliasApi $imageAliasApi)
234+
{
233235
$imageAlias = $this->getDoctrine()->getRepository(ImageAlias::class)->find($aliasId);
234236

235237
if (!$imageAlias) {
@@ -240,12 +242,12 @@ public function editImageAlias($aliasId, Request $request,ImageAliasApi $imageAl
240242

241243
$image = $imageAlias->getImage();
242244

243-
if(!$image->isFinished()){
245+
if (!$image->isFinished()) {
244246
throw new WrongInputException('Editing of the ImageAlias for an Image which is in the creation process is not possible');
245247
}
246248

247249
$previousName = null;
248-
if ($request->request->has('name')){
250+
if ($request->request->has('name')) {
249251
$previousName = $imageAlias->getName();
250252
$imageAlias->setName($request->request->get('name'));
251253
}
@@ -262,18 +264,18 @@ public function editImageAlias($aliasId, Request $request,ImageAliasApi $imageAl
262264
}
263265

264266
//Check if a name update via LXD is necessary
265-
if($previousName != null && $previousName != $imageAlias->getName()){
267+
if ($previousName != null && $previousName != $imageAlias->getName()) {
266268
$result = $imageAliasApi->editAliasName($image->getHost(), $imageAlias, $previousName);
267-
if($result->code != 201 || $result->body->status_code != 200){
268-
throw new WrongInputException('LXD-Error - '.$result->body->error);
269+
if ($result->code != 201 || $result->body->status_code != 200) {
270+
throw new WrongInputException('LXD-Error - ' . $result->body->error);
269271
}
270272
}
271273

272274
//Check if a description update via LXD is necessary
273-
if($previousDescription != null && $previousDescription != $imageAlias->getDescription()){
275+
if ($previousDescription != null && $previousDescription != $imageAlias->getDescription()) {
274276
$result = $imageAliasApi->editAliasDescription($image->getHost(), $imageAlias);
275-
if($result->code != 200 || $result->body->status_code != 200){
276-
throw new WrongInputException('LXD-Error - '.$result->body->error);
277+
if ($result->code != 200 || $result->body->status_code != 200) {
278+
throw new WrongInputException('LXD-Error - ' . $result->body->error);
277279
}
278280
}
279281

0 commit comments

Comments
 (0)