|
3 | 3 | namespace Laravel\Telescope\Storage;
|
4 | 4 |
|
5 | 5 | use DateTimeInterface;
|
| 6 | +use Illuminate\Database\UniqueConstraintViolationException; |
6 | 7 | use Illuminate\Support\Collection;
|
7 | 8 | use Illuminate\Support\Facades\DB;
|
8 | 9 | use Laravel\Telescope\Contracts\ClearableRepository;
|
@@ -189,14 +190,18 @@ protected function storeExceptions(Collection $exceptions)
|
189 | 190 | protected function storeTags(Collection $results)
|
190 | 191 | {
|
191 | 192 | $results->chunk($this->chunkSize)->each(function ($chunked) {
|
192 |
| - $this->table('telescope_entries_tags')->insert($chunked->flatMap(function ($tags, $uuid) { |
193 |
| - return collect($tags)->map(function ($tag) use ($uuid) { |
194 |
| - return [ |
195 |
| - 'entry_uuid' => $uuid, |
196 |
| - 'tag' => $tag, |
197 |
| - ]; |
198 |
| - }); |
199 |
| - })->all()); |
| 193 | + try { |
| 194 | + $this->table('telescope_entries_tags')->insert($chunked->flatMap(function ($tags, $uuid) { |
| 195 | + return collect($tags)->map(function ($tag) use ($uuid) { |
| 196 | + return [ |
| 197 | + 'entry_uuid' => $uuid, |
| 198 | + 'tag' => $tag, |
| 199 | + ]; |
| 200 | + }); |
| 201 | + })->all()); |
| 202 | + } catch (UniqueConstraintViolationException $e) { |
| 203 | + // Ignore tags that already exist... |
| 204 | + } |
200 | 205 | });
|
201 | 206 | }
|
202 | 207 |
|
@@ -246,14 +251,18 @@ public function update(Collection $updates)
|
246 | 251 | protected function updateTags($entry)
|
247 | 252 | {
|
248 | 253 | if (! empty($entry->tagsChanges['added'])) {
|
249 |
| - $this->table('telescope_entries_tags')->insert( |
250 |
| - collect($entry->tagsChanges['added'])->map(function ($tag) use ($entry) { |
251 |
| - return [ |
252 |
| - 'entry_uuid' => $entry->uuid, |
253 |
| - 'tag' => $tag, |
254 |
| - ]; |
255 |
| - })->toArray() |
256 |
| - ); |
| 254 | + try { |
| 255 | + $this->table('telescope_entries_tags')->insert( |
| 256 | + collect($entry->tagsChanges['added'])->map(function ($tag) use ($entry) { |
| 257 | + return [ |
| 258 | + 'entry_uuid' => $entry->uuid, |
| 259 | + 'tag' => $tag, |
| 260 | + ]; |
| 261 | + })->toArray() |
| 262 | + ); |
| 263 | + } catch (UniqueConstraintViolationException $e) { |
| 264 | + // Ignore tags that already exist... |
| 265 | + } |
257 | 266 | }
|
258 | 267 |
|
259 | 268 | collect($entry->tagsChanges['removed'])->each(function ($tag) use ($entry) {
|
|
0 commit comments