From c09ea2debc339e04f54f4777d2241ffba442bd59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gytis=20Kar=C4=8Diauskas?= Date: Fri, 30 Jan 2015 16:12:30 +0200 Subject: [PATCH] Remove Entity\SyncJobs. --- Entity/SyncJob.php | 270 ------------------ Sync/DiffProvider/Binlog/BinlogParser.php | 12 +- Sync/DiffProvider/Item/DiffItemFactory.php | 8 +- .../Sync/Binlog/BinlogParserTest.php | 20 +- 4 files changed, 20 insertions(+), 290 deletions(-) delete mode 100644 Entity/SyncJob.php diff --git a/Entity/SyncJob.php b/Entity/SyncJob.php deleted file mode 100644 index 0afe40f..0000000 --- a/Entity/SyncJob.php +++ /dev/null @@ -1,270 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace ONGR\ConnectionsBundle\Entity; - -use Doctrine\ORM\Mapping as ORM; - -/** - * Entity for data synchronization job. - * - * @ORM\Entity - * @ORM\Table("ongr_sync_jobs") - */ -class SyncJob -{ - const TYPE_CREATE = 'C'; - const TYPE_UPDATE = 'U'; - const TYPE_DELETE = 'D'; - - const STATUS_NEW = 0; - const STATUS_DONE = 1; - - const UPDATE_TYPE_PARTIAL = 0; - const UPDATE_TYPE_FULL = 1; - - /** - * @var int - * - * @ORM\Column - * @ORM\Id - * - * @ORM\GeneratedValue(strategy="IDENTITY") - */ - protected $id; - - /** - * @var string - * - * @ORM\Column - */ - protected $type; - - /** - * @var int - * - * @ORM\Column(name="`status`") - */ - protected $status; - - /** - * @var string - * - * @ORM\Column(name="document_type") - */ - protected $documentType; - - /** - * @var string - * - * @ORM\Column(name="document_id") - */ - protected $documentId; - - /** - * @var int - * - * @ORM\Column(name="update_type") - */ - protected $updateType; - - /** - * @var \DateTime - * - * @ORM\Column(name="`timestamp`", type="datetime") - */ - protected $timestamp; - - /** - * @var mixed - */ - protected $documentData; - - /** - * Returns entity ID. - * - * @return int - * - * @codeCoverageIgnore - */ - public function getId() - { - return $this->id; - } - - /** - * Sets record type. - * - * @param string $type - * - * @return SyncJob - */ - public function setType($type) - { - $this->type = $type; - - return $this; - } - - /** - * Returns record type. - * - * @return string - */ - public function getType() - { - return $this->type; - } - - /** - * Sets record status. - * - * @param int $status - * - * @return SyncJob - */ - public function setStatus($status) - { - $this->status = $status; - - return $this; - } - - /** - * Returns record status. - * - * @return int - */ - public function getStatus() - { - return $this->status; - } - - /** - * Sets document type. - * - * @param string $type - * - * @return SyncJob - */ - public function setDocumentType($type) - { - $this->documentType = $type; - - return $this; - } - - /** - * Returns document type. - * - * @return string - */ - public function getDocumentType() - { - return $this->documentType; - } - - /** - * Sets document ID. - * - * @param string $documentId - * - * @return SyncJob - */ - public function setDocumentId($documentId) - { - $this->documentId = $documentId; - - return $this; - } - - /** - * Returns document ID. - * - * @return string - */ - public function getDocumentId() - { - return $this->documentId; - } - - /** - * Sets update type. - * - * @param int $updateType - * - * @return SyncJob - */ - public function setUpdateType($updateType) - { - $this->updateType = $updateType; - - return $this; - } - - /** - * Returns update type. - * - * @return int - */ - public function getUpdateType() - { - return $this->updateType; - } - - /** - * Sets record timestamp. - * - * @param \DateTime $datetime - * - * @return SyncJob - */ - public function setTimestamp(\DateTime $datetime) - { - $this->timestamp = $datetime; - - return $this; - } - - /** - * Returns record timestamp. - * - * @return \DateTime - */ - public function getTimestamp() - { - return $this->timestamp; - } - - /** - * Sets document data. - * - * @param mixed $documentData - * - * @return SyncJob - */ - public function setDocumentData($documentData) - { - $this->documentData = $documentData; - - return $this; - } - - /** - * Returns document data. - * - * @return mixed - */ - public function getDocumentData() - { - return $this->documentData; - } -} diff --git a/Sync/DiffProvider/Binlog/BinlogParser.php b/Sync/DiffProvider/Binlog/BinlogParser.php index afc78bc..8b233c7 100644 --- a/Sync/DiffProvider/Binlog/BinlogParser.php +++ b/Sync/DiffProvider/Binlog/BinlogParser.php @@ -11,7 +11,7 @@ namespace ONGR\ConnectionsBundle\Sync\DiffProvider\Binlog; -use ONGR\ConnectionsBundle\Entity\SyncJob; +use ONGR\ConnectionsBundle\Sync\ActionTypes; /** * Parses binary log data (Interpreter). @@ -225,11 +225,11 @@ protected function parseQuery() $this->getNextLine(self::LINE_TYPE_QUERY); - if ($buffer['type'] == SyncJob::TYPE_DELETE || $buffer['type'] === SyncJob::TYPE_UPDATE) { + if ($buffer['type'] == ActionTypes::DELETE || $buffer['type'] === ActionTypes::UPDATE) { $buffer['where'] = $this->handleStatement($this->lastLine, self::STATEMENT_TYPE_WHERE); } - if ($buffer['type'] == SyncJob::TYPE_CREATE || $buffer['type'] === SyncJob::TYPE_UPDATE) { + if ($buffer['type'] == ActionTypes::CREATE || $buffer['type'] === ActionTypes::UPDATE) { $buffer['set'] = $this->handleStatement($this->lastLine, self::STATEMENT_TYPE_SET); } @@ -487,11 +487,11 @@ protected function detectQueryType($type) { switch ($type) { case 'INSERT INTO': - return SyncJob::TYPE_CREATE; + return ActionTypes::CREATE; case 'UPDATE': - return SyncJob::TYPE_UPDATE; + return ActionTypes::UPDATE; case 'DELETE FROM': - return SyncJob::TYPE_DELETE; + return ActionTypes::DELETE; default: throw new \UnexpectedValueException("Unknown statement of type {$type}"); } diff --git a/Sync/DiffProvider/Item/DiffItemFactory.php b/Sync/DiffProvider/Item/DiffItemFactory.php index 4ea2619..260be69 100644 --- a/Sync/DiffProvider/Item/DiffItemFactory.php +++ b/Sync/DiffProvider/Item/DiffItemFactory.php @@ -11,7 +11,7 @@ namespace ONGR\ConnectionsBundle\Sync\DiffProvider\Item; -use ONGR\ConnectionsBundle\Entity\SyncJob; +use ONGR\ConnectionsBundle\Sync\ActionTypes; /** * DiffItem factory. @@ -29,11 +29,11 @@ class DiffItemFactory public static function create($type) { switch ($type) { - case SyncJob::TYPE_CREATE: + case ActionTypes::CREATE: return new CreateDiffItem(); - case SyncJob::TYPE_UPDATE: + case ActionTypes::UPDATE: return new UpdateDiffItem(); - case SyncJob::TYPE_DELETE: + case ActionTypes::DELETE: return new DeleteDiffItem(); default: throw new \InvalidArgumentException("Invalid type {$type}"); diff --git a/Tests/Functional/Sync/Binlog/BinlogParserTest.php b/Tests/Functional/Sync/Binlog/BinlogParserTest.php index 8aaf235..8b756a5 100644 --- a/Tests/Functional/Sync/Binlog/BinlogParserTest.php +++ b/Tests/Functional/Sync/Binlog/BinlogParserTest.php @@ -11,7 +11,7 @@ namespace ONGR\ConnectionsBundle\Tests\Functional\Sync\Binlog; -use ONGR\ConnectionsBundle\Entity\SyncJob; +use ONGR\ConnectionsBundle\Sync\ActionTypes; use ONGR\ConnectionsBundle\Sync\DiffProvider\Binlog\BinlogParser; use ONGR\ConnectionsBundle\Tests\Functional\TestBase; use PHPUnit_Framework_MockObject_MockObject as MockObject; @@ -43,7 +43,7 @@ public function getTestParseData() BinlogParser::PARAM_DATE => new \DateTime('2014-09-05 10:32:58'), BinlogParser::PARAM_POSITION => 522, BinlogParser::PARAM_QUERY => [ - 'type' => SyncJob::TYPE_CREATE, + 'type' => ActionTypes::CREATE, 'table' => 'test', 'set' => [ 1 => '1', @@ -55,7 +55,7 @@ public function getTestParseData() BinlogParser::PARAM_DATE => new \DateTime('2014-09-05 10:34:06'), BinlogParser::PARAM_POSITION => 710, BinlogParser::PARAM_QUERY => [ - 'type' => SyncJob::TYPE_CREATE, + 'type' => ActionTypes::CREATE, 'table' => 'test', 'set' => [ 1 => '2', @@ -67,7 +67,7 @@ public function getTestParseData() BinlogParser::PARAM_DATE => new \DateTime('2014-09-05 10:34:39'), BinlogParser::PARAM_POSITION => 923, BinlogParser::PARAM_QUERY => [ - 'type' => SyncJob::TYPE_UPDATE, + 'type' => ActionTypes::UPDATE, 'table' => 'test', 'where' => [ 1 => '2', @@ -83,7 +83,7 @@ public function getTestParseData() BinlogParser::PARAM_DATE => new \DateTime('2014-09-05 10:35:22'), BinlogParser::PARAM_POSITION => 1190, BinlogParser::PARAM_QUERY => [ - 'type' => SyncJob::TYPE_UPDATE, + 'type' => ActionTypes::UPDATE, 'table' => 'test', 'where' => [ 1 => '1', @@ -99,7 +99,7 @@ public function getTestParseData() BinlogParser::PARAM_DATE => new \DateTime('2014-09-05 10:35:22'), BinlogParser::PARAM_POSITION => 1190, BinlogParser::PARAM_QUERY => [ - 'type' => SyncJob::TYPE_UPDATE, + 'type' => ActionTypes::UPDATE, 'table' => 'test', 'where' => [ 1 => '2', @@ -115,7 +115,7 @@ public function getTestParseData() BinlogParser::PARAM_DATE => new \DateTime('2014-09-05 10:35:46'), BinlogParser::PARAM_POSITION => 1387, BinlogParser::PARAM_QUERY => [ - 'type' => SyncJob::TYPE_DELETE, + 'type' => ActionTypes::DELETE, 'table' => 'test', 'where' => [ 1 => '1', @@ -127,7 +127,7 @@ public function getTestParseData() BinlogParser::PARAM_DATE => new \DateTime('2014-09-05 10:35:52'), BinlogParser::PARAM_POSITION => 1584, BinlogParser::PARAM_QUERY => [ - 'type' => SyncJob::TYPE_DELETE, + 'type' => ActionTypes::DELETE, 'table' => 'test', 'where' => [ 1 => '2', @@ -246,7 +246,7 @@ public function testSetFailure() $parser ->expects($this->once()) ->method('handleStart') - ->willReturn(['type' => SyncJob::TYPE_CREATE]); + ->willReturn(['type' => ActionTypes::CREATE]); $parser ->expects($this->any()) @@ -280,7 +280,7 @@ public function testWhereFailure() $parser ->expects($this->once()) ->method('handleStart') - ->willReturn(['type' => SyncJob::TYPE_DELETE]); + ->willReturn(['type' => ActionTypes::DELETE]); $parser ->expects($this->any())