Skip to content

Commit

Permalink
MAGETWO-58924: SQL error wait timeout error when saving categories
Browse files Browse the repository at this point in the history
- fix singleton resource
  • Loading branch information
cpartica committed Jan 13, 2017
1 parent 2877f3a commit ef10316
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
namespace Magento\CatalogUrlRewrite\Model\Map;

use Magento\Catalog\Model\ResourceModel\Category;
use Magento\Catalog\Model\ResourceModel\CategoryFactory;
use Magento\Catalog\Model\CategoryRepository;
use Magento\Catalog\Api\Data\CategoryInterface;

Expand All @@ -20,19 +20,19 @@ class DataCategoryHashMap implements HashMapInterface
/** @var CategoryRepository */
private $categoryRepository;

/** @var Category */
private $categoryResource;
/** @var CategoryFactory */
private $categoryResourceFactory;

/**
* @param CategoryRepository $categoryRepository
* @param Category $categoryResource
* @param CategoryFactory $categoryResourceFactory
*/
public function __construct(
CategoryRepository $categoryRepository,
Category $categoryResource
CategoryFactory $categoryResourceFactory
) {
$this->categoryRepository = $categoryRepository;
$this->categoryResource = $categoryResource;
$this->categoryResourceFactory = $categoryResourceFactory;
}

/**
Expand Down Expand Up @@ -70,9 +70,10 @@ public function getData($categoryId, $key)
*/
private function getAllCategoryChildrenIds(CategoryInterface $category)
{
$connection = $this->categoryResource->getConnection();
$categoryResource = $this->categoryResourceFactory->create();
$connection = $categoryResource->getConnection();
$select = $connection->select()
->from($this->categoryResource->getEntityTable(), 'entity_id')
->from($categoryResource->getEntityTable(), 'entity_id')
->where($connection->quoteIdentifier('path') . ' LIKE :c_path');
$bind = ['c_path' => $category->getPath() . '%'];
return $connection->fetchCol($select, $bind);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
*/
namespace Magento\CatalogUrlRewrite\Test\Unit\Model\Map;

use Magento\Catalog\Model\ResourceModel\Category as CategoryResource;
use Magento\Catalog\Model\ResourceModel\CategoryFactory;
use Magento\Catalog\Model\ResourceModel\Category;
use Magento\Framework\DB\Select;
use Magento\Catalog\Model\CategoryRepository;
use Magento\Catalog\Api\Data\CategoryInterface;
Expand All @@ -21,7 +22,10 @@ class DataCategoryHashMapTest extends \PHPUnit_Framework_TestCase
/** @var CategoryRepository|\PHPUnit_Framework_MockObject_MockObject */
private $categoryRepository;

/** @var CategoryResource|\PHPUnit_Framework_MockObject_MockObject */
/** @var CategoryResourceFactory|\PHPUnit_Framework_MockObject_MockObject */
private $categoryResourceFactory;

/** @var Category|\PHPUnit_Framework_MockObject_MockObject */
private $categoryResource;

/** @var DataCategoryHashMap|\PHPUnit_Framework_MockObject_MockObject */
Expand All @@ -30,19 +34,24 @@ class DataCategoryHashMapTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
$this->categoryRepository = $this->getMock(CategoryRepository::class, [], [], '', false);
$this->categoryResourceFactory = $this->getMock(CategoryFactory::class, ['create'], [], '', false);
$this->categoryResource = $this->getMock(
CategoryResource::class,
Category::class,
['getConnection', 'getEntityTable'],
[],
'',
false
);

$this->categoryResourceFactory->expects($this->any())
->method('create')
->willReturn($this->categoryResource);

$this->model = (new ObjectManager($this))->getObject(
DataCategoryHashMap::class,
[
'categoryRepository' => $this->categoryRepository,
'categoryResource' => $this->categoryResource
'categoryResourceFactory' => $this->categoryResourceFactory
]
);
}
Expand Down

0 comments on commit ef10316

Please sign in to comment.