2015-12-30 12:26:30 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Wallabag\ImportBundle\Import;
|
|
|
|
|
2022-08-27 18:22:48 +00:00
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
2022-08-27 18:57:18 +00:00
|
|
|
use Psr\Log\LoggerInterface;
|
2022-08-27 18:22:48 +00:00
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
|
|
|
use Wallabag\CoreBundle\Helper\ContentProxy;
|
|
|
|
use Wallabag\CoreBundle\Helper\TagsAssigner;
|
|
|
|
|
2016-03-28 14:43:33 +00:00
|
|
|
class WallabagV1Import extends WallabagImport
|
2015-12-30 12:26:30 +00:00
|
|
|
{
|
2016-12-16 14:46:21 +00:00
|
|
|
protected $fetchingErrorMessage;
|
|
|
|
protected $fetchingErrorMessageTitle;
|
|
|
|
|
2022-08-27 18:57:18 +00:00
|
|
|
public function __construct(EntityManagerInterface $em, ContentProxy $contentProxy, TagsAssigner $tagsAssigner, EventDispatcherInterface $eventDispatcher, LoggerInterface $logger, $fetchingErrorMessageTitle, $fetchingErrorMessage)
|
2016-12-16 14:46:21 +00:00
|
|
|
{
|
|
|
|
$this->fetchingErrorMessageTitle = $fetchingErrorMessageTitle;
|
|
|
|
$this->fetchingErrorMessage = $fetchingErrorMessage;
|
|
|
|
|
2022-08-27 18:57:18 +00:00
|
|
|
parent::__construct($em, $contentProxy, $tagsAssigner, $eventDispatcher, $logger);
|
2016-12-16 14:46:21 +00:00
|
|
|
}
|
|
|
|
|
2015-12-30 12:26:30 +00:00
|
|
|
public function getName()
|
|
|
|
{
|
2016-01-05 21:38:09 +00:00
|
|
|
return 'wallabag v1';
|
2015-12-30 12:26:30 +00:00
|
|
|
}
|
|
|
|
|
2015-12-31 10:24:46 +00:00
|
|
|
public function getUrl()
|
|
|
|
{
|
|
|
|
return 'import_wallabag_v1';
|
|
|
|
}
|
|
|
|
|
2015-12-30 12:26:30 +00:00
|
|
|
public function getDescription()
|
|
|
|
{
|
2016-03-09 07:59:08 +00:00
|
|
|
return 'import.wallabag_v1.description';
|
2015-12-30 12:26:30 +00:00
|
|
|
}
|
|
|
|
|
2016-09-04 19:49:21 +00:00
|
|
|
protected function prepareEntry($entry = [])
|
2016-03-28 14:43:33 +00:00
|
|
|
{
|
|
|
|
$data = [
|
|
|
|
'title' => $entry['title'],
|
|
|
|
'html' => $entry['content'],
|
|
|
|
'url' => $entry['url'],
|
2016-09-04 19:49:21 +00:00
|
|
|
'is_archived' => $entry['is_read'] || $this->markAsRead,
|
2016-03-28 14:43:33 +00:00
|
|
|
'is_starred' => $entry['is_fav'],
|
|
|
|
'tags' => '',
|
2016-09-09 07:36:07 +00:00
|
|
|
'created_at' => '',
|
2015-12-30 12:26:30 +00:00
|
|
|
];
|
|
|
|
|
2016-12-16 14:46:21 +00:00
|
|
|
// In case of a bad fetch in v1, replace title and content with v2 error strings
|
|
|
|
// If fetching fails again, they will get this instead of the v1 strings
|
2018-09-05 12:25:32 +00:00
|
|
|
if (\in_array($entry['title'], $this->untitled, true)) {
|
2016-12-16 14:46:21 +00:00
|
|
|
$data['title'] = $this->fetchingErrorMessageTitle;
|
|
|
|
$data['html'] = $this->fetchingErrorMessage;
|
2023-07-28 12:58:43 +00:00
|
|
|
$entry['is_not_parsed'] = 1;
|
2016-03-28 14:43:33 +00:00
|
|
|
}
|
2015-12-31 10:24:46 +00:00
|
|
|
|
2019-02-11 10:50:24 +00:00
|
|
|
if (\array_key_exists('tags', $entry) && '' !== $entry['tags']) {
|
2016-03-28 14:43:33 +00:00
|
|
|
$data['tags'] = $entry['tags'];
|
2015-12-30 12:26:30 +00:00
|
|
|
}
|
|
|
|
|
2016-03-28 14:43:33 +00:00
|
|
|
return $data;
|
2015-12-30 12:26:30 +00:00
|
|
|
}
|
2016-09-04 19:49:21 +00:00
|
|
|
|
2016-09-05 05:50:10 +00:00
|
|
|
protected function setEntryAsRead(array $importedEntry)
|
2016-09-04 19:49:21 +00:00
|
|
|
{
|
2016-09-05 05:50:10 +00:00
|
|
|
$importedEntry['is_read'] = 1;
|
2016-09-04 19:49:21 +00:00
|
|
|
|
2016-09-05 05:50:10 +00:00
|
|
|
return $importedEntry;
|
2016-09-04 19:49:21 +00:00
|
|
|
}
|
2015-12-30 12:26:30 +00:00
|
|
|
}
|