]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | ||
3 | namespace Wallabag\ImportBundle\Import; | |
4 | ||
5 | class WallabagV1Import extends WallabagImport | |
6 | { | |
7 | protected $fetchingErrorMessage; | |
8 | protected $fetchingErrorMessageTitle; | |
9 | ||
10 | public function __construct($em, $contentProxy, $tagsAssigner, $eventDispatcher, $fetchingErrorMessageTitle, $fetchingErrorMessage) | |
11 | { | |
12 | $this->fetchingErrorMessageTitle = $fetchingErrorMessageTitle; | |
13 | $this->fetchingErrorMessage = $fetchingErrorMessage; | |
14 | ||
15 | parent::__construct($em, $contentProxy, $tagsAssigner, $eventDispatcher); | |
16 | } | |
17 | ||
18 | /** | |
19 | * {@inheritdoc} | |
20 | */ | |
21 | public function getName() | |
22 | { | |
23 | return 'wallabag v1'; | |
24 | } | |
25 | ||
26 | /** | |
27 | * {@inheritdoc} | |
28 | */ | |
29 | public function getUrl() | |
30 | { | |
31 | return 'import_wallabag_v1'; | |
32 | } | |
33 | ||
34 | /** | |
35 | * {@inheritdoc} | |
36 | */ | |
37 | public function getDescription() | |
38 | { | |
39 | return 'import.wallabag_v1.description'; | |
40 | } | |
41 | ||
42 | /** | |
43 | * {@inheritdoc} | |
44 | */ | |
45 | protected function prepareEntry($entry = []) | |
46 | { | |
47 | $data = [ | |
48 | 'title' => $entry['title'], | |
49 | 'html' => $entry['content'], | |
50 | 'url' => $entry['url'], | |
51 | 'is_archived' => $entry['is_read'] || $this->markAsRead, | |
52 | 'is_starred' => $entry['is_fav'], | |
53 | 'tags' => '', | |
54 | 'created_at' => '', | |
55 | ]; | |
56 | ||
57 | // In case of a bad fetch in v1, replace title and content with v2 error strings | |
58 | // If fetching fails again, they will get this instead of the v1 strings | |
59 | if (\in_array($entry['title'], $this->untitled, true)) { | |
60 | $data['title'] = $this->fetchingErrorMessageTitle; | |
61 | $data['html'] = $this->fetchingErrorMessage; | |
62 | } | |
63 | ||
64 | if (\array_key_exists('tags', $entry) && '' !== $entry['tags']) { | |
65 | $data['tags'] = $entry['tags']; | |
66 | } | |
67 | ||
68 | return $data; | |
69 | } | |
70 | ||
71 | /** | |
72 | * {@inheritdoc} | |
73 | */ | |
74 | protected function setEntryAsRead(array $importedEntry) | |
75 | { | |
76 | $importedEntry['is_read'] = 1; | |
77 | ||
78 | return $importedEntry; | |
79 | } | |
80 | } |