-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4d8e4db
commit 42bb933
Showing
1 changed file
with
10 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,24 @@ | ||
<?php | ||
/** | ||
* This file is part of the login-cidadao project or it's bundles. | ||
* | ||
* (c) Guilherme Donato <guilhermednt on github> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace LoginCidadao\OAuthBundle\Entity; | ||
|
||
use FOS\OAuthServerBundle\Entity\ClientManager as FOSClientManager; | ||
use FOS\OAuthServerBundle\Model\ClientInterface; | ||
use Doctrine\ORM\PersistentCollection; | ||
use LoginCidadao\CoreBundle\Entity\Person; | ||
|
||
class ClientManager extends FOSClientManager | ||
{ | ||
|
||
public function updateClient(ClientInterface $client) | ||
{ | ||
// let's see what happens | ||
$this->em->persist($client); | ||
$this->em->flush(); | ||
return; | ||
|
||
$this->em->getConnection()->beginTransaction(); | ||
if ($client->getId()) { | ||
$this->em->createQuery('DELETE from LoginCidadaoOAuthBundle:ClientPerson where client_id = :id')->setParameter('id', $client->getId()); | ||
} | ||
$this->em->persist($client); | ||
$itens = $client->getPersons(); | ||
if ($itens instanceof PersistentCollection) { | ||
foreach ($itens as $idx => $iten) { | ||
if ($iten instanceof Person) { | ||
$itens->removeElement($iten); | ||
$new = new ClientPerson(); | ||
$new->setClient($client); | ||
$new->setPerson($iten); | ||
$this->em->persist($new); | ||
$itens->add($new); | ||
} | ||
} | ||
} else if (is_array($itens)) { | ||
foreach ($itens as $idx => $iten) { | ||
if ($iten instanceof Person) { | ||
$new = new ClientPerson(); | ||
$new->setClient($client); | ||
$new->setPerson($iten); | ||
$this->em->persist($new); | ||
} else if ($iten instanceof ClientPerson) { | ||
$iten->setClient($client); | ||
$this->em->persist($iten); | ||
} | ||
} | ||
} | ||
$this->em->flush(); | ||
$this->em->getConnection()->commit(); | ||
} | ||
} | ||
} |