/** * {@inheritdoc} */ public function remove(ResourceInterface $resource) { try { return $this->unstableRepository->remove($resource); } catch (\Exception $exception) { return $this->fallbackRepository->remove($resource); } }
function it_removes_not_used_themes(ThemeLoaderInterface $themeLoader, ThemeRepositoryInterface $themeRepository, ThemeInterface $loadedTheme, ThemeInterface $existingAbandonedTheme) { $themeRepository->findAll()->willReturn([$existingAbandonedTheme]); $themeLoader->load()->willReturn([$loadedTheme]); $loadedTheme->getName()->willReturn('theme/name'); $loadedTheme->getParents()->willReturn([]); $themeRepository->findOneByName('theme/name')->willReturn(null); $themeRepository->add($loadedTheme)->shouldBeCalled(); $existingAbandonedTheme->getName()->willReturn('abandoned/theme'); $themeRepository->remove($existingAbandonedTheme)->shouldBeCalled(); $this->synchronize(); }
/** * @param ThemeInterface[] $persistedThemes * @param ThemeInterface[] $loadedThemes * * @return ThemeInterface[] Removed themes */ private function removeAbandonedThemes(array $persistedThemes, array $loadedThemes) { if (0 === count($persistedThemes)) { return []; } $loadedThemesNames = array_map(function (ThemeInterface $theme) { return $theme->getName(); }, $loadedThemes); $removedThemes = []; foreach ($persistedThemes as $persistedTheme) { if (!in_array($persistedTheme->getName(), $loadedThemesNames, true)) { $removedThemes[] = $persistedTheme; $this->themeRepository->remove($persistedTheme); } } return $removedThemes; }