Skip to content

Commit 5e05f85

Browse files
authored
Merge pull request #16 from FVSoftwareDeveloper/master
Support to Symfony 4.4
2 parents eb903ea + 9bdd7b4 commit 5e05f85

7 files changed

+135
-93
lines changed

Controller/SyncController.php

Lines changed: 47 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -5,51 +5,46 @@
55
use Doctrine\ORM\EntityManager;
66
use Doctrine\ORM\EntityManagerInterface;
77
use Doctrine\ORM\ORMException;
8-
use NTI\SyncBundle\Entity\SyncNewItemState;
98
use NTI\SyncBundle\Interfaces\SyncServiceInterface;
10-
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
9+
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
1110
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
11+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1212
use Symfony\Component\HttpFoundation\JsonResponse;
1313
use Symfony\Component\HttpFoundation\Request;
14-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
15-
use Symfony\Component\Serializer\Serializer;
1614

1715
/**
18-
* Class SyncController
19-
* @package NTI\SyncBundle\Controller
16+
* Class SyncController.
2017
*/
21-
class SyncController extends Controller
18+
class SyncController extends AbstractController
2219
{
2320
/**
24-
* @param Request $request
2521
* @return JsonResponse
2622
* @Route("/summary", name="nti_sync_get_summary")
2723
*/
28-
public function getChangesSummaryAction(Request $request) {
29-
24+
public function getChangesSummaryAction(Request $request)
25+
{
3026
$em = $this->getDoctrine()->getManager();
3127

32-
$syncStates = $em->getRepository('NTISyncBundle:SyncState')->findBy(array(), array("mapping" => "asc"));
33-
$syncStatesArray = json_decode($this->get("jms_serializer")->serialize($syncStates, 'json'), true);
28+
$syncStates = $em->getRepository('NTISyncBundle:SyncState')->findBy([], ['mapping' => 'asc']);
29+
$syncStatesArray = json_decode($this->get('jms_serializer')->serialize($syncStates, 'json'), true);
3430

3531
return new JsonResponse($syncStatesArray, 200);
3632
}
3733

3834
/**
39-
* @param Request $request
4035
* @return JsonResponse
4136
* @Route("/pull", name="nti_sync_pull")
4237
* @Method("GET|POST")
4338
*/
44-
public function pullAction(Request $request) {
39+
public function pullAction(Request $request)
40+
{
41+
$mappings = [];
4542

46-
$mappings = array();
47-
48-
if($request->getMethod() == "GET") {
49-
$mappings = ($request->get('mappings') && is_array($request->get('mappings'))) ? $request->get('mappings') : array();
50-
} elseif ($request->getMethod() == "POST") {
43+
if ('GET' == $request->getMethod()) {
44+
$mappings = ($request->get('mappings') && is_array($request->get('mappings'))) ? $request->get('mappings') : [];
45+
} elseif ('POST' == $request->getMethod()) {
5146
$data = json_decode($request->getContent(), true);
52-
$mappings = (isset($data["mappings"])) ? $data["mappings"] : array();
47+
$mappings = (isset($data['mappings'])) ? $data['mappings'] : [];
5348
}
5449

5550
$resultData = $this->get('nti.sync')->getFromMappings($mappings);
@@ -60,24 +55,22 @@ public function pullAction(Request $request) {
6055
}
6156

6257
/**
63-
* @param Request $request
6458
* @return JsonResponse
6559
* @Route("/push", name="nti_sync_push", methods="POST")
6660
* @Method("POST")
6761
*/
68-
public function pushAction(Request $request) {
69-
62+
public function pushAction(Request $request)
63+
{
7064
$data = json_decode($request->getContent(), true);
7165

72-
$mappings = (isset($data["mappings"])) ? $data["mappings"] : array();
66+
$mappings = (isset($data['mappings'])) ? $data['mappings'] : [];
7367

7468
/** @var EntityManagerInterface $em */
7569
$em = $this->getDoctrine()->getManager();
7670

77-
$results = array();
78-
79-
foreach($mappings as $entry) {
71+
$results = [];
8072

73+
foreach ($mappings as $entry) {
8174
if (!$em->isOpen()) {
8275
try {
8376
$em = EntityManager::create(
@@ -86,17 +79,21 @@ public function pushAction(Request $request) {
8679
$em->getEventManager()
8780
);
8881
} catch (ORMException $e) {
89-
return new JsonResponse(array("error" => "An unknown error occurred while reopening the database connection."), 500);
82+
return new JsonResponse(['error' => 'An unknown error occurred while reopening the database connection.'], 500);
9083
}
9184
}
9285

93-
if(!isset($entry["mapping"]) || !isset($entry["data"])) { continue; }
86+
if (!isset($entry['mapping']) || !isset($entry['data'])) {
87+
continue;
88+
}
9489

95-
$mappingName = $entry["mapping"];
90+
$mappingName = $entry['mapping'];
9691

97-
$mapping = $em->getRepository('NTISyncBundle:SyncMapping')->findOneBy(array("name" => $mappingName));
92+
$mapping = $em->getRepository('NTISyncBundle:SyncMapping')->findOneBy(['name' => $mappingName]);
9893

99-
if(!$mapping) { continue; }
94+
if (!$mapping) {
95+
continue;
96+
}
10097

10198
$syncClass = $mapping->getSyncService();
10299

@@ -106,28 +103,26 @@ public function pushAction(Request $request) {
106103
$em->beginTransaction();
107104

108105
try {
109-
$result = $service->sync($entry["data"], $em, $mapping);
106+
$result = $service->sync($entry['data'], $em, $mapping);
110107
} catch (\Exception $ex) {
111-
112-
113-
$additionalErrors = array();
108+
$additionalErrors = [];
114109

115110
try {
116111
$additionalErrors = $service->onSyncException($ex, $this->container);
117-
$additionalErrors = (is_array($additionalErrors)) ? $additionalErrors : array();
112+
$additionalErrors = (is_array($additionalErrors)) ? $additionalErrors : [];
118113
} catch (\Exception $ex) {
119-
120114
// TBD
121115
}
122116

123-
$result = array(
124-
"error" => "An unknown error occurred while processing the synchronization for this mapping",
125-
"additional_errors" => $additionalErrors,
126-
);
117+
$result = [
118+
'error' => 'An unknown error occurred while processing the synchronization for this mapping',
119+
'additional_errors' => $additionalErrors,
120+
];
127121

128122
$results[$mappingName] = $result;
129123

130124
$em->clear();
125+
131126
continue;
132127
}
133128

@@ -138,28 +133,26 @@ public function pushAction(Request $request) {
138133
} catch (\Exception $ex) {
139134
$em->rollback();
140135

141-
$additionalErrors = array();
136+
$additionalErrors = [];
137+
142138
try {
143139
$additionalErrors = $service->onSyncException($ex, $this->container);
144-
$additionalErrors = (is_array($additionalErrors)) ? $additionalErrors : array();
140+
$additionalErrors = (is_array($additionalErrors)) ? $additionalErrors : [];
145141
} catch (\Exception $ex) {
146142
// TBD
147143
}
148144

149-
$result = array(
150-
"error" => "An unknown error occurred while processing the synchronization for this mapping",
151-
"additional_errors" => $additionalErrors,
152-
);
145+
$result = [
146+
'error' => 'An unknown error occurred while processing the synchronization for this mapping',
147+
'additional_errors' => $additionalErrors,
148+
];
153149

154150
$results[$mappingName] = $result;
155151
}
156-
157152
}
158153

159-
return new JsonResponse(array(
160-
"mappings" => $results
161-
));
162-
154+
return new JsonResponse([
155+
'mappings' => $results,
156+
]);
163157
}
164-
165158
}

Repository/SyncDeleteStateRepository.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,34 @@
22

33
namespace NTI\SyncBundle\Repository;
44

5-
use Doctrine\ORM\EntityRepository;
5+
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
6+
use Doctrine\Common\Persistence\ManagerRegistry;
7+
use NTI\SyncBundle\Entity\SyncDeleteState;
68

79
/**
8-
* SyncDeleteStateRepository
10+
* SyncDeleteStateRepository.
911
*
1012
* This class was generated by the Doctrine ORM. Add your own custom
1113
* repository methods below.
1214
*/
13-
class SyncDeleteStateRepository extends EntityRepository
15+
class SyncDeleteStateRepository extends ServiceEntityRepository
1416
{
15-
public function findFromTimestamp($mappingName, $timestamp) {
17+
public function __construct(ManagerRegistry $registry)
18+
{
19+
parent::__construct($registry, SyncDeleteState::class);
20+
}
21+
22+
public function findFromTimestamp($mappingName, $timestamp)
23+
{
1624
$qb = $this->createQueryBuilder('s');
17-
$qb ->innerJoin('s.mapping', 'm')
25+
$qb->innerJoin('s.mapping', 'm')
1826
->andWhere('m.name = :mappingName')
1927
->setParameter('mappingName', $mappingName)
2028
->andWhere('s.timestamp >= :timestamp')
2129
->setParameter('timestamp', $timestamp)
22-
->orderBy('s.timestamp', 'asc');
30+
->orderBy('s.timestamp', 'asc')
31+
;
32+
2333
return $qb->getQuery()->getResult();
2434
}
2535
}

Repository/SyncFailedItemStateRepository.php

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,51 @@
22

33
namespace NTI\SyncBundle\Repository;
44

5-
use Doctrine\ORM\EntityRepository;
5+
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
6+
use Doctrine\Common\Persistence\ManagerRegistry;
67
use Doctrine\ORM\NonUniqueResultException;
8+
use NTI\SyncBundle\Entity\SyncFailedItemState;
79

810
/**
9-
* SyncFailedItemStateRepository
11+
* SyncFailedItemStateRepository.
1012
*
1113
* This class was generated by the Doctrine ORM. Add your own custom
1214
* repository methods below.
1315
*/
14-
class SyncFailedItemStateRepository extends EntityRepository
16+
class SyncFailedItemStateRepository extends ServiceEntityRepository
1517
{
16-
public function findFromTimestampAndMapping($mappingName, $timestamp) {
18+
public function __construct(ManagerRegistry $registry)
19+
{
20+
parent::__construct($registry, SyncFailedItemState::class);
21+
}
22+
23+
public function findFromTimestampAndMapping($mappingName, $timestamp)
24+
{
1725
$qb = $this->createQueryBuilder('s');
18-
$qb ->innerJoin('s.mapping', 'm')
26+
$qb->innerJoin('s.mapping', 'm')
1927
->andWhere('m.name = :mappingName')
2028
->setParameter('mappingName', $mappingName)
2129
->andWhere('s.timestamp >= :timestamp')
2230
->setParameter('timestamp', $timestamp)
23-
->orderBy('s.timestamp', 'asc');
31+
->orderBy('s.timestamp', 'asc')
32+
;
33+
2434
return $qb->getQuery()->getResult();
2535
}
2636

27-
public function findByUuId($id){
37+
public function findByUuId($id)
38+
{
2839
$qb = $this->getEntityManager()->createQueryBuilder();
2940
$qb->select('item')
3041
->from('NTISyncBundle:SyncFailedItemState', 'item')
3142
->andWhere(
3243
$qb->expr()->eq('item.uuid', $qb->expr()->literal($id))
33-
);
44+
)
45+
;
3446

3547
try {
3648
return $qb->getQuery()->getOneOrNullResult();
37-
}catch (NonUniqueResultException $e){
49+
} catch (NonUniqueResultException $e) {
3850
return null;
3951
}
4052
}

Repository/SyncMappingRepository.php

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

33
namespace NTI\SyncBundle\Repository;
44

5+
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
6+
use Doctrine\Common\Persistence\ManagerRegistry;
7+
use NTI\SyncBundle\Entity\SyncMapping;
8+
59
/**
6-
* SyncMappingRepository
10+
* SyncMappingRepository.
711
*
812
* This class was generated by the Doctrine ORM. Add your own custom
913
* repository methods below.
1014
*/
11-
class SyncMappingRepository extends \Doctrine\ORM\EntityRepository
15+
class SyncMappingRepository extends ServiceEntityRepository
1216
{
17+
public function __construct(ManagerRegistry $registry)
18+
{
19+
parent::__construct($registry, SyncMapping::class);
20+
}
1321
}

Repository/SyncNewItemStateRepository.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,34 @@
22

33
namespace NTI\SyncBundle\Repository;
44

5-
use Doctrine\ORM\EntityRepository;
5+
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
6+
use Doctrine\Common\Persistence\ManagerRegistry;
7+
use NTI\SyncBundle\Entity\SyncNewItemState;
68

79
/**
8-
* SyncNewItemStateRepository
10+
* SyncNewItemStateRepository.
911
*
1012
* This class was generated by the Doctrine ORM. Add your own custom
1113
* repository methods below.
1214
*/
13-
class SyncNewItemStateRepository extends EntityRepository
15+
class SyncNewItemStateRepository extends ServiceEntityRepository
1416
{
15-
public function findFromTimestampAndMapping($mappingName, $timestamp) {
17+
public function __construct(ManagerRegistry $registry)
18+
{
19+
parent::__construct($registry, SyncNewItemState::class);
20+
}
21+
22+
public function findFromTimestampAndMapping($mappingName, $timestamp)
23+
{
1624
$qb = $this->createQueryBuilder('s');
17-
$qb ->innerJoin('s.mapping', 'm')
25+
$qb->innerJoin('s.mapping', 'm')
1826
->andWhere('m.name = :mappingName')
1927
->setParameter('mappingName', $mappingName)
2028
->andWhere('s.timestamp >= :timestamp')
2129
->setParameter('timestamp', $timestamp)
22-
->orderBy('s.timestamp', 'asc');
30+
->orderBy('s.timestamp', 'asc')
31+
;
32+
2333
return $qb->getQuery()->getResult();
2434
}
2535
}

0 commit comments

Comments
 (0)