Skip to content

Commit

Permalink
Merge pull request #7799 from laboro/fix/CRM-5780_1.9
Browse files Browse the repository at this point in the history
CRM-5780: Impossible to delete Channel data
  • Loading branch information
alex-n-2k7 authored Jul 8, 2016
2 parents 71b112c + c628a60 commit 70c5232
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/Oro/Bundle/IntegrationBundle/Manager/DeleteManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function delete(Integration $integration)
$deleteProvider->deleteRelatedData($integration);
}
}
$this->removeFromEntityByChannelId('OroIntegrationBundle:Status', $integration);
$this->em->remove($integration);
$this->em->flush();
$this->em->getConnection()->commit();
Expand All @@ -63,4 +64,24 @@ public function delete(Integration $integration)

return true;
}

/**
* Remove records from given entity type related to channel
*
* @param string $entityClassName
*
* @return $this
*/
protected function removeFromEntityByChannelId($entityClassName, Integration $integration)
{
$this->em->getConnection()->executeQuery(
sprintf(
'DELETE FROM %s WHERE channel_id=%s',
$this->em->getClassMetadata($entityClassName)->getTableName(),
$integration->getId()
)
);

return $this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Oro\Bundle\IntegrationBundle\Tests\Unit\Manager;

use Doctrine\ORM\Mapping\ClassMetadata;

use Oro\Bundle\IntegrationBundle\Entity\Channel as Integration;
use Oro\Bundle\IntegrationBundle\Manager\DeleteManager;

Expand Down Expand Up @@ -29,8 +31,15 @@ class ChannelDeleteManagerTest extends \PHPUnit_Framework_TestCase
*/
protected $connection;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|ClassMetadata
*/
protected $entityMetadata;

protected function setUp()
{
$this->entityMetadata = $this->getMockBuilder('\Doctrine\ORM\Mapping\ClassMetadata')
->disableOriginalConstructor()->getMock();
$this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
->disableOriginalConstructor()
->getMock();
Expand All @@ -50,6 +59,9 @@ protected function setUp()

public function testDeleteChannelWithoutErrors()
{
$this->entityMetadata->expects(self::once())->method('getTableName')->willReturn('table');
$this->em->expects(self::once())->method('getClassMetadata')->with('OroIntegrationBundle:Status')
->willReturn($this->entityMetadata);
$this->connection->expects($this->once())
->method('commit');
$this->em->expects($this->any())
Expand All @@ -63,6 +75,9 @@ public function testDeleteChannelWithoutErrors()

public function testDeleteIntegrationWithErrors()
{
$this->entityMetadata->expects(self::once())->method('getTableName')->willReturn('table');
$this->em->expects(self::once())->method('getClassMetadata')->with('OroIntegrationBundle:Status')
->willReturn($this->entityMetadata);
$this->em->expects($this->any())
->method('remove')
->with($this->equalTo($this->testIntegration))
Expand Down

0 comments on commit 70c5232

Please sign in to comment.