diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Helper/ContentProxy.php')
-rw-r--r-- | src/Wallabag/CoreBundle/Helper/ContentProxy.php | 55 |
1 files changed, 2 insertions, 53 deletions
diff --git a/src/Wallabag/CoreBundle/Helper/ContentProxy.php b/src/Wallabag/CoreBundle/Helper/ContentProxy.php index 9a08db3d..4b3e6fbb 100644 --- a/src/Wallabag/CoreBundle/Helper/ContentProxy.php +++ b/src/Wallabag/CoreBundle/Helper/ContentProxy.php | |||
@@ -5,9 +5,7 @@ namespace Wallabag\CoreBundle\Helper; | |||
5 | use Graby\Graby; | 5 | use Graby\Graby; |
6 | use Psr\Log\LoggerInterface; | 6 | use Psr\Log\LoggerInterface; |
7 | use Wallabag\CoreBundle\Entity\Entry; | 7 | use Wallabag\CoreBundle\Entity\Entry; |
8 | use Wallabag\CoreBundle\Entity\Tag; | ||
9 | use Wallabag\CoreBundle\Tools\Utils; | 8 | use Wallabag\CoreBundle\Tools\Utils; |
10 | use Wallabag\CoreBundle\Repository\TagRepository; | ||
11 | use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeExtensionGuesser; | 9 | use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeExtensionGuesser; |
12 | 10 | ||
13 | /** | 11 | /** |
@@ -19,16 +17,15 @@ class ContentProxy | |||
19 | protected $graby; | 17 | protected $graby; |
20 | protected $tagger; | 18 | protected $tagger; |
21 | protected $logger; | 19 | protected $logger; |
22 | protected $tagRepository; | ||
23 | protected $mimeGuesser; | 20 | protected $mimeGuesser; |
24 | protected $fetchingErrorMessage; | 21 | protected $fetchingErrorMessage; |
22 | protected $eventDispatcher; | ||
25 | 23 | ||
26 | public function __construct(Graby $graby, RuleBasedTagger $tagger, TagRepository $tagRepository, LoggerInterface $logger, $fetchingErrorMessage) | 24 | public function __construct(Graby $graby, RuleBasedTagger $tagger, LoggerInterface $logger, $fetchingErrorMessage) |
27 | { | 25 | { |
28 | $this->graby = $graby; | 26 | $this->graby = $graby; |
29 | $this->tagger = $tagger; | 27 | $this->tagger = $tagger; |
30 | $this->logger = $logger; | 28 | $this->logger = $logger; |
31 | $this->tagRepository = $tagRepository; | ||
32 | $this->mimeGuesser = new MimeTypeExtensionGuesser(); | 29 | $this->mimeGuesser = new MimeTypeExtensionGuesser(); |
33 | $this->fetchingErrorMessage = $fetchingErrorMessage; | 30 | $this->fetchingErrorMessage = $fetchingErrorMessage; |
34 | } | 31 | } |
@@ -122,54 +119,6 @@ class ContentProxy | |||
122 | } | 119 | } |
123 | 120 | ||
124 | /** | 121 | /** |
125 | * Assign some tags to an entry. | ||
126 | * | ||
127 | * @param Entry $entry | ||
128 | * @param array|string $tags An array of tag or a string coma separated of tag | ||
129 | * @param array $entitiesReady Entities from the EntityManager which are persisted but not yet flushed | ||
130 | * It is mostly to fix duplicate tag on import @see http://stackoverflow.com/a/7879164/569101 | ||
131 | */ | ||
132 | public function assignTagsToEntry(Entry $entry, $tags, array $entitiesReady = []) | ||
133 | { | ||
134 | if (!is_array($tags)) { | ||
135 | $tags = explode(',', $tags); | ||
136 | } | ||
137 | |||
138 | // keeps only Tag entity from the "not yet flushed entities" | ||
139 | $tagsNotYetFlushed = []; | ||
140 | foreach ($entitiesReady as $entity) { | ||
141 | if ($entity instanceof Tag) { | ||
142 | $tagsNotYetFlushed[$entity->getLabel()] = $entity; | ||
143 | } | ||
144 | } | ||
145 | |||
146 | foreach ($tags as $label) { | ||
147 | $label = trim($label); | ||
148 | |||
149 | // avoid empty tag | ||
150 | if (0 === strlen($label)) { | ||
151 | continue; | ||
152 | } | ||
153 | |||
154 | if (isset($tagsNotYetFlushed[$label])) { | ||
155 | $tagEntity = $tagsNotYetFlushed[$label]; | ||
156 | } else { | ||
157 | $tagEntity = $this->tagRepository->findOneByLabel($label); | ||
158 | |||
159 | if (is_null($tagEntity)) { | ||
160 | $tagEntity = new Tag(); | ||
161 | $tagEntity->setLabel($label); | ||
162 | } | ||
163 | } | ||
164 | |||
165 | // only add the tag on the entry if the relation doesn't exist | ||
166 | if (false === $entry->getTags()->contains($tagEntity)) { | ||
167 | $entry->addTag($tagEntity); | ||
168 | } | ||
169 | } | ||
170 | } | ||
171 | |||
172 | /** | ||
173 | * Validate that the given content as enough value to be used | 122 | * Validate that the given content as enough value to be used |
174 | * instead of fetch the content from the url. | 123 | * instead of fetch the content from the url. |
175 | * | 124 | * |