Skip to content

Commit

Permalink
[framework] fix blog category visibility calculation (#3503)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitek-rostislav authored Oct 18, 2024
2 parents db1f453 + ec82a50 commit a6339a2
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/Migrations/Version20241014125411.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace Shopsys\FrameworkBundle\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Shopsys\MigrationBundle\Component\Doctrine\Migrations\AbstractMigration;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;

class Version20241014125411 extends AbstractMigration implements ContainerAwareInterface
{
use MultidomainMigrationTrait;

/**
* @param \Doctrine\DBAL\Schema\Schema $schema
*/
public function up(Schema $schema): void
{
foreach ($this->getAllDomainIds() as $domainId) {
$this->sql('INSERT INTO blog_category_domains (blog_category_id, domain_id, enabled, visible) VALUES (1, :domain_id, true, true) ON CONFLICT DO NOTHING', [
'domain_id' => $domainId,
]);
}
}

/**
* @param \Doctrine\DBAL\Schema\Schema $schema
*/
public function down(Schema $schema): void
{
}
}
10 changes: 10 additions & 0 deletions src/Model/Blog/Category/BlogCategoryFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,16 @@ public function getVisibleByUuid(int $domainId, string $uuid): BlogCategory
return $this->blogCategoryRepository->getVisibleByUuid($domainId, $uuid);
}

/**
* @param int $domainId
* @param int[] $blogCategoryIds
* @return \Shopsys\FrameworkBundle\Model\Blog\Category\BlogCategory[]
*/
public function getVisibleByIds(int $domainId, array $blogCategoryIds): array
{
return $this->blogCategoryRepository->getVisibleByIds($domainId, $blogCategoryIds);
}

/**
* @param \Shopsys\FrameworkBundle\Model\Blog\Category\BlogCategory $blogCategory
*/
Expand Down
14 changes: 14 additions & 0 deletions src/Model/Blog/Category/BlogCategoryRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,20 @@ public function getVisibleByUuid(int $domainId, string $uuid): BlogCategory
return $blogCategory;
}

/**
* @param int $domainId
* @param int[] $blogCategoryIds
* @return \Shopsys\FrameworkBundle\Model\Blog\Category\BlogCategory[]
*/
public function getVisibleByIds(int $domainId, array $blogCategoryIds): array
{
return $this->getAllVisibleByDomainIdQueryBuilder($domainId)
->andWhere('bc.id IN (:blogCategoryIds)')
->setParameter('blogCategoryIds', $blogCategoryIds)
->getQuery()
->getResult();
}

/**
* @param int $domainId
* @return int|null
Expand Down

0 comments on commit a6339a2

Please sign in to comment.