Skip to content

Commit

Permalink
Add method findTypeForMigration to ProductAttributeRepository
Browse files Browse the repository at this point in the history
  • Loading branch information
jacquesbh committed Jul 6, 2020
1 parent 601ba3c commit db4786f
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/migrations/Version20171003103916.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function up(Schema $schema): void
$defaultLocale = $this->container->getParameter('locale');
$productAttributeRepository = $this->container->get('sylius.repository.product_attribute');

$productAttributes = $productAttributeRepository->findBy(['type' => SelectAttributeType::TYPE]);
$productAttributes = $productAttributeRepository->findByTypeForMigration(SelectAttributeType::TYPE);
/** @var ProductAttributeInterface $productAttribute */
foreach ($productAttributes as $productAttribute) {
$configuration = $productAttribute->getConfiguration();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\Bundle\CoreBundle\Doctrine\ORM;

use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
use Sylius\Component\Core\Repository\ProductAttributeRepositoryInterface;

class ProductAttributeRepository extends EntityRepository implements ProductAttributeRepositoryInterface
{
/**
* @param string $type
*
* @return array
*/
public function findByTypeForMigration(string $type): array
{
return $this
->createQueryBuilder('o')
->select([
'o.id',
'o.code',
'o.type',
'o.storageType',
'o.configuration',
'o.createdAt',
'o.updatedAt',
'o.position'
])
->where('o.type = :type')
->setParameter('type', $type)
->getQuery()
->getResult()
;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
imports:
- { resource: "@SyliusCoreBundle/Resources/config/app/sylius/sylius_addressing.yml" }
- { resource: "@SyliusCoreBundle/Resources/config/app/sylius/sylius_attribute.yml" }
- { resource: "@SyliusCoreBundle/Resources/config/app/sylius/sylius_channel.yml" }
- { resource: "@SyliusCoreBundle/Resources/config/app/sylius/sylius_inventory.yml" }
- { resource: "@SyliusCoreBundle/Resources/config/app/sylius/sylius_locale.yml" }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This file is part of the Sylius package.
# (c) Paweł Jędrzejewski

sylius_attribute:
resources:
product:
attribute:
classes:
repository: Sylius\Bundle\CoreBundle\Doctrine\ORM\ProductAttributeRepository
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\Component\Core\Repository;

use Sylius\Component\Core\Model\ProductTaxonInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;

interface ProductAttributeRepositoryInterface extends RepositoryInterface
{
/**
* This method is required by Sylius Migration's 20171003103916.
* It avoids error in future migrations for ProductAttributes.
* This method MUST request only existing columns when it's called.
*
* @param string $type
*
* @return array
*/
public function findByTypeForMigration(string $type): array;
}

0 comments on commit db4786f

Please sign in to comment.