Skip to content

Commit

Permalink
Merge 4.x into 5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
SonataCI committed Feb 14, 2022
2 parents 670ee95 + bb509d0 commit 44d6a78
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 26 deletions.
44 changes: 22 additions & 22 deletions .github/workflows/stale.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@
name: Stale

on:
schedule:
- cron: 0 9-18 * * *
schedule:
- cron: 0 9-18 * * *

jobs:
stale:
runs-on: ubuntu-latest
stale:
runs-on: ubuntu-latest

steps:
- name: Close stale issues and pull requests
uses: actions/stale@v1.1.0
with:
days-before-close: 7
days-before-stale: 180
repo-token: ${{ secrets.GITHUB_TOKEN }}
exempt-issue-label: keep
stale-issue-label: stale
stale-issue-message: >
This issue has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs. Thank you
for your contributions.
stale-pr-label: stale
stale-pr-message: >
This PR has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs. Thank you
for your contributions.
steps:
- name: Close stale issues and pull requests
uses: actions/stale@v1.1.0
with:
days-before-close: 7
days-before-stale: 180
repo-token: ${{ secrets.GITHUB_TOKEN }}
exempt-issue-label: keep
stale-issue-label: stale
stale-issue-message: >
This issue has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs. Thank you
for your contributions.
stale-pr-label: stale
stale-pr-message: >
This PR has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs. Thank you
for your contributions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [4.1.1](https://github.com/sonata-project/SonataMediaBundle/compare/4.1.0...4.1.1) - 2022-02-13
### Fixed
- [[#2280](https://github.com/sonata-project/SonataMediaBundle/pull/2280)] Fix root category check ([@core23](https://github.com/core23))

## [4.1.0](https://github.com/sonata-project/SonataMediaBundle/compare/4.0.1...4.1.0) - 2022-02-12
### Added
- [[#2275](https://github.com/sonata-project/SonataMediaBundle/pull/2275)] Added support for `psr/log` ^3.0 ([@jordisala1991](https://github.com/jordisala1991))
Expand Down
12 changes: 9 additions & 3 deletions src/Listener/ORM/MediaEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,16 @@ private function getRootCategory(MediaInterface $media): CategoryInterface
throw new \RuntimeException(sprintf('There is no context on media %s', $media->getId() ?? ''));
}

if (null === $this->rootCategories || !\array_key_exists($context, $this->rootCategories)) {
throw new \RuntimeException(sprintf('There is no main category related to context: %s', $context));
if (null !== $this->rootCategories) {
foreach ($this->rootCategories as $category) {
$categoryContext = $category->getContext();

if (null !== $categoryContext && $categoryContext->getId() === $context) {
return $category;
}
}
}

return $this->rootCategories[$context];
throw new \RuntimeException(sprintf('There is no main category related to context: %s', $context));
}
}
8 changes: 7 additions & 1 deletion tests/Listener/ORM/MediaEventSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use PHPUnit\Framework\TestCase;
use Sonata\ClassificationBundle\Model\CategoryInterface;
use Sonata\ClassificationBundle\Model\CategoryManagerInterface;
use Sonata\ClassificationBundle\Model\ContextInterface;
use Sonata\MediaBundle\Listener\ORM\MediaEventSubscriber;
use Sonata\MediaBundle\Provider\MediaProviderInterface;
use Sonata\MediaBundle\Provider\Pool;
Expand All @@ -39,12 +40,17 @@ public function testRefetchCategoriesAfterClear(): void
$pool = new Pool('default');
$pool->addProvider('provider', $provider);

$categoryContext = $this->createMock(ContextInterface::class);
$categoryContext->method('getId')->willReturn('context');

$category = $this->createMock(CategoryInterface::class);
$category->method('getContext')->willReturn($categoryContext);

$catManager = $this->createMock(CategoryManagerInterface::class);

$catManager->expects(static::exactly(2))
->method('getAllRootCategories')
->willReturn(['context' => $category]);
->willReturn([$category]);

$subscriber = new MediaEventSubscriber($pool, $catManager);

Expand Down

0 comments on commit 44d6a78

Please sign in to comment.