mirror of
https://github.com/wallabag/wallabag.git
synced 2025-09-15 18:57:05 +00:00
Merge branch '2.6' into master
This commit is contained in:
commit
8fd5a5273d
23 changed files with 749 additions and 14 deletions
|
@ -21,6 +21,7 @@ use Wallabag\Import\FirefoxImport;
|
|||
use Wallabag\Import\InstapaperImport;
|
||||
use Wallabag\Import\OmnivoreImport;
|
||||
use Wallabag\Import\PinboardImport;
|
||||
use Wallabag\Import\PocketCsvImport;
|
||||
use Wallabag\Import\PocketHtmlImport;
|
||||
use Wallabag\Import\ReadabilityImport;
|
||||
use Wallabag\Import\ShaarliImport;
|
||||
|
@ -48,6 +49,7 @@ class ImportCommand extends Command
|
|||
private readonly ElcuratorImport $elcuratorImport,
|
||||
private readonly ShaarliImport $shaarliImport,
|
||||
private readonly PocketHtmlImport $pocketHtmlImport,
|
||||
private readonly PocketCsvImport $pocketCsvImport,
|
||||
private readonly OmnivoreImport $omnivoreImport,
|
||||
) {
|
||||
parent::__construct();
|
||||
|
@ -58,7 +60,7 @@ class ImportCommand extends Command
|
|||
$this
|
||||
->addArgument('username', InputArgument::REQUIRED, 'User to populate')
|
||||
->addArgument('filepath', InputArgument::REQUIRED, 'Path to the JSON file')
|
||||
->addOption('importer', null, InputOption::VALUE_OPTIONAL, 'The importer to use: v1, v2, instapaper, pinboard, delicious, readability, firefox, chrome, elcurator, shaarli or pocket', 'v1')
|
||||
->addOption('importer', null, InputOption::VALUE_OPTIONAL, 'The importer to use: v1, v2, instapaper, pinboard, delicious, readability, firefox, chrome, elcurator, shaarli, pocket or pocket_csv', 'v1')
|
||||
->addOption('markAsRead', null, InputOption::VALUE_OPTIONAL, 'Mark all entries as read', false)
|
||||
->addOption('useUserId', null, InputOption::VALUE_NONE, 'Use user id instead of username to find account')
|
||||
->addOption('disableContentUpdate', null, InputOption::VALUE_NONE, 'Disable fetching updated content from URL')
|
||||
|
@ -109,6 +111,7 @@ class ImportCommand extends Command
|
|||
'elcurator' => $this->elcuratorImport,
|
||||
'shaarli' => $this->shaarliImport,
|
||||
'pocket' => $this->pocketHtmlImport,
|
||||
'pocket_csv' => $this->pocketCsvImport,
|
||||
'omnivore' => $this->omnivoreImport,
|
||||
default => $this->wallabagV1Import,
|
||||
};
|
||||
|
|
|
@ -23,6 +23,7 @@ class RabbitMQConsumerTotalProxy
|
|||
private readonly Consumer $elcuratorConsumer,
|
||||
private readonly Consumer $shaarliConsumer,
|
||||
private readonly Consumer $pocketHtmlConsumer,
|
||||
private readonly Consumer $pocketCsvConsumer,
|
||||
private readonly Consumer $omnivoreConsumer,
|
||||
) {
|
||||
}
|
||||
|
@ -75,6 +76,9 @@ class RabbitMQConsumerTotalProxy
|
|||
case 'pocket_html':
|
||||
$consumer = $this->pocketHtmlConsumer;
|
||||
break;
|
||||
case 'pocket_csv':
|
||||
$consumer = $this->pocketCsvConsumer;
|
||||
break;
|
||||
case 'omnivore':
|
||||
$consumer = $this->omnivoreConsumer;
|
||||
break;
|
||||
|
|
|
@ -58,6 +58,7 @@ class ImportController extends AbstractController
|
|||
+ $this->rabbitMQConsumerTotalProxy->getTotalMessage('elcurator')
|
||||
+ $this->rabbitMQConsumerTotalProxy->getTotalMessage('shaarli')
|
||||
+ $this->rabbitMQConsumerTotalProxy->getTotalMessage('pocket_html')
|
||||
+ $this->rabbitMQConsumerTotalProxy->getTotalMessage('pocket_csv')
|
||||
+ $this->rabbitMQConsumerTotalProxy->getTotalMessage('omnivore')
|
||||
;
|
||||
} catch (\Exception) {
|
||||
|
@ -77,6 +78,7 @@ class ImportController extends AbstractController
|
|||
+ $this->redisClient->llen('wallabag.import.elcurator')
|
||||
+ $this->redisClient->llen('wallabag.import.shaarli')
|
||||
+ $this->redisClient->llen('wallabag.import.pocket_html')
|
||||
+ $this->redisClient->llen('wallabag.import.pocket_csv')
|
||||
+ $this->redisClient->llen('wallabag.import.omnivore')
|
||||
;
|
||||
} catch (\Exception) {
|
||||
|
|
46
src/Controller/Import/PocketCsvController.php
Normal file
46
src/Controller/Import/PocketCsvController.php
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace Wallabag\Controller\Import;
|
||||
|
||||
use Craue\ConfigBundle\Util\Config;
|
||||
use OldSound\RabbitMqBundle\RabbitMq\Producer as RabbitMqProducer;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use Wallabag\Import\PocketCsvImport;
|
||||
use Wallabag\Redis\Producer as RedisProducer;
|
||||
|
||||
class PocketCsvController extends HtmlController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly PocketCsvImport $pocketCsvImport,
|
||||
private readonly Config $craueConfig,
|
||||
private readonly RabbitMqProducer $rabbitMqProducer,
|
||||
private readonly RedisProducer $redisProducer,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route(path: '/import/pocket_csv', name: 'import_pocket_csv', methods: ['GET', 'POST'])]
|
||||
#[IsGranted('IMPORT_ENTRIES')]
|
||||
public function indexAction(Request $request, TranslatorInterface $translator)
|
||||
{
|
||||
return parent::indexAction($request, $translator);
|
||||
}
|
||||
|
||||
protected function getImportService()
|
||||
{
|
||||
if ($this->craueConfig->get('import_with_rabbitmq')) {
|
||||
$this->pocketCsvImport->setProducer($this->rabbitMqProducer);
|
||||
} elseif ($this->craueConfig->get('import_with_redis')) {
|
||||
$this->pocketCsvImport->setProducer($this->redisProducer);
|
||||
}
|
||||
|
||||
return $this->pocketCsvImport;
|
||||
}
|
||||
|
||||
protected function getImportTemplate()
|
||||
{
|
||||
return 'Import/PocketCsv/index.html.twig';
|
||||
}
|
||||
}
|
133
src/Import/PocketCsvImport.php
Normal file
133
src/Import/PocketCsvImport.php
Normal file
|
@ -0,0 +1,133 @@
|
|||
<?php
|
||||
|
||||
namespace Wallabag\Import;
|
||||
|
||||
use Wallabag\Entity\Entry;
|
||||
|
||||
class PocketCsvImport extends AbstractImport
|
||||
{
|
||||
protected $filepath;
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'Pocket CSV';
|
||||
}
|
||||
|
||||
public function getUrl()
|
||||
{
|
||||
return 'import_pocket_csv';
|
||||
}
|
||||
|
||||
public function getDescription()
|
||||
{
|
||||
return 'import.pocket_csv.description';
|
||||
}
|
||||
|
||||
public function setFilepath($filepath): static
|
||||
{
|
||||
$this->filepath = $filepath;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function validateEntry(array $importedEntry)
|
||||
{
|
||||
if (empty($importedEntry['url'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function import()
|
||||
{
|
||||
if (!$this->user) {
|
||||
$this->logger->error('Pocket CSV Import: user is not defined');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!file_exists($this->filepath) || !is_readable($this->filepath)) {
|
||||
$this->logger->error('Pocket CSV Import: unable to read file', ['filepath' => $this->filepath]);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$entries = [];
|
||||
$handle = fopen($this->filepath, 'r');
|
||||
while (false !== ($data = fgetcsv($handle, 10240))) {
|
||||
if ('title' === $data[0]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$entries[] = [
|
||||
'url' => $data[1],
|
||||
'title' => $data[0],
|
||||
'is_archived' => 'archive' === $data[4],
|
||||
'created_at' => $data[2],
|
||||
'tags' => $data[3],
|
||||
];
|
||||
}
|
||||
fclose($handle);
|
||||
|
||||
if (empty($entries)) {
|
||||
$this->logger->error('PocketCsvImport: no entries in imported file');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->producer) {
|
||||
$this->parseEntriesForProducer($entries);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->parseEntries($entries);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function parseEntry(array $importedEntry)
|
||||
{
|
||||
$existingEntry = $this->em
|
||||
->getRepository(Entry::class)
|
||||
->findByUrlAndUserId($importedEntry['url'], $this->user->getId());
|
||||
|
||||
if (false !== $existingEntry) {
|
||||
++$this->skippedEntries;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$entry = new Entry($this->user);
|
||||
$entry->setUrl($importedEntry['url']);
|
||||
$entry->setTitle($importedEntry['title']);
|
||||
|
||||
// update entry with content (in case fetching failed, the given entry will be return)
|
||||
$this->fetchContent($entry, $importedEntry['url'], $importedEntry);
|
||||
|
||||
if (!empty($importedEntry['tags'])) {
|
||||
$tags = str_replace('|', ',', $importedEntry['tags']);
|
||||
$this->tagsAssigner->assignTagsToEntry(
|
||||
$entry,
|
||||
$tags,
|
||||
$this->em->getUnitOfWork()->getScheduledEntityInsertions()
|
||||
);
|
||||
}
|
||||
|
||||
$entry->updateArchived($importedEntry['is_archived']);
|
||||
$entry->setCreatedAt(\DateTime::createFromFormat('U', $importedEntry['created_at']));
|
||||
|
||||
$this->em->persist($entry);
|
||||
++$this->importedEntries;
|
||||
|
||||
return $entry;
|
||||
}
|
||||
|
||||
protected function setEntryAsRead(array $importedEntry)
|
||||
{
|
||||
$importedEntry['is_archived'] = 'archive';
|
||||
|
||||
return $importedEntry;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue