Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multiple shop id functionality. #101

Merged
merged 3 commits into from
Jan 19, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Resources/config/extractor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ services:
- [ setRelationsCollection, [ @ongr_connections.sync.relations_collection ] ]
- [ setConnection, [ @database_connection ] ]
- [ setStorageFacility, [ @ongr_connections.sync.sync_storage ] ]
- [ setContainer, [ @service_container ]]

ongr_connections.sync.extractor.passthrough_extractor:
class: %ongr_connections.extractor.passthrough_extractor.class%
Expand Down
58 changes: 58 additions & 0 deletions Sync/Extractor/AbstractExtractor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ONGR\ConnectionsBundle\Sync\Extractor;

use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;

/**
* Common actions required for all extractors.
*/
class AbstractExtractor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it's abstract why class is not abstract?

{
/**
* @var ContainerInterface
*/
private $container;

/**
* @param ContainerInterface $container
*/
public function setContainer(ContainerInterface $container)
{
$this->container = $container;
}

/**
* Gets ids of shops from the configuration.
*
* @return array
*/
protected function getShopIds()
{
try {
$shops = $this->getContainer()->getParameter('shop_ids');
} catch (InvalidArgumentException $e) {
$shops = [];
}

return $shops;
}

/**
* @return ContainerInterface
*/
private function getContainer()
{
return $this->container;
}
}
13 changes: 10 additions & 3 deletions Sync/Extractor/DoctrineExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
/**
* Extractor that joins entities for insertion to SyncStorage.
*/
class DoctrineExtractor implements ExtractorInterface
class DoctrineExtractor extends AbstractExtractor implements ExtractorInterface
{
/**
* @var SyncStorageInterface
Expand Down Expand Up @@ -69,7 +69,13 @@ public function extract(BaseDiffItem $item)
$itemId = $itemRow[$idFieldName];

$storage = $this->getStorageFacility();
$storage->save($action, $insertList[JobTableFields::TYPE]['value'], $itemId, $item->getTimestamp());
$storage->save(
$action,
$insertList[JobTableFields::TYPE]['value'],
$itemId,
$item->getTimestamp(),
$this->getShopIds()
);

$statements = $relation->getStatements();
foreach ($statements as $statement) {
Expand Down Expand Up @@ -201,7 +207,8 @@ protected function saveResult(BaseDiffItem $item, Statement $results, $action =
$action,
$row[JobTableFields::TYPE],
$row[JobTableFields::ID],
$item->getTimestamp()
$item->getTimestamp(),
$this->getShopIds()
);
}
}
Expand Down
11 changes: 6 additions & 5 deletions Sync/StorageManager/MysqlStorageManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ public function createStorage($shopId = null, $connection = null)
{
$connection = $connection ? : $this->getConnection();
$schemaManager = $connection->getSchemaManager();
$tableName = $this->getTableName($shopId);

if ($schemaManager->tablesExist([$this->getTableName($shopId)])) {
if ($schemaManager->tablesExist([$tableName])) {
return true;
}

$table = new Table($this->getTableName($shopId));
$table = new Table($tableName);
$this->buildTable($table);
$schemaManager->createTable($table);

Expand Down Expand Up @@ -88,12 +89,11 @@ public function getTableName($shopId = null)
throw new InvalidArgumentException("Invalid table name specified: \"$tableName\"");
}

$suffix = null;
if ($shopId !== null) {
$suffix = '_' . $shopId;
$tableName .= '_' . $shopId;
}

return $tableName . $suffix;
return $tableName;
}

/**
Expand All @@ -104,6 +104,7 @@ public function addRecord($operationType, $documentType, $documentId, DateTime $
if (empty($shopIds)) {
$shopIds = [null];
}

$connection = $this->getConnection();

foreach ($shopIds as $shopId) {
Expand Down
Loading