namespace Wallabag\ImportBundle\Import;
-use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Doctrine\ORM\EntityManager;
use GuzzleHttp\Client;
use Wallabag\CoreBundle\Helper\ContentProxy;
use Craue\ConfigBundle\Util\Config;
-class PocketImport implements ImportInterface
+class PocketImport extends AbstractImport
{
private $user;
- private $em;
- private $contentProxy;
- private $logger;
private $client;
private $consumerKey;
private $skippedEntries = 0;
$this->logger = new NullLogger();
}
- public function setLogger(LoggerInterface $logger)
- {
- $this->logger = $logger;
- }
-
/**
* {@inheritdoc}
*/
*/
public function getDescription()
{
- return 'This importer will import all your Pocket data. Pocket doesn\'t allow us to retrieve content from their service, so the readable content of each article will be re-fetched by wallabag.';
+ return 'import.pocket.description';
}
/**
*
* @param string $redirectUri Redirect url in case of error
*
- * @return string request_token for callback method
+ * @return string|false request_token for callback method
*/
public function getRequestToken($redirectUri)
{
/**
* Get whether articles must be all marked as read.
*/
- public function getRead()
+ public function getMarkAsRead()
{
return $this->markAsRead;
}
}
$entry = new Entry($this->user);
- $entry = $this->contentProxy->updateEntry($entry, $url);
+ $entry = $this->fetchContent($entry, $url);
+
+ // jump to next entry in case of problem while getting content
+ if (false === $entry) {
+ ++$this->skippedEntries;
+ continue;
+ }
// 0, 1, 2 - 1 if the item is archived - 2 if the item should be deleted
- if ($pocketEntry['status'] == 1 | $this->markAsRead) {
+ if ($pocketEntry['status'] == 1 || $this->markAsRead) {
$entry->setArchived(true);
}
- // 0 or 1 - 1 If the item is favorited
+ // 0 or 1 - 1 If the item is starred
if ($pocketEntry['favorite'] == 1) {
$entry->setStarred(true);
}
// flush every 20 entries
if (($i % 20) === 0) {
$this->em->flush();
+
+ // clear only affected entities
+ $this->em->clear(Entry::class);
+ $this->em->clear(Tag::class);
}
++$i;
}