mirror of
https://github.com/wallabag/wallabag.git
synced 2024-12-17 02:39:24 +01:00
Some cleanup & refactor
This commit is contained in:
parent
02f6489572
commit
3849a9f323
@ -7,7 +7,7 @@ use Psr\Log\NullLogger;
|
|||||||
use Doctrine\ORM\EntityManager;
|
use Doctrine\ORM\EntityManager;
|
||||||
use Wallabag\CoreBundle\Helper\ContentProxy;
|
use Wallabag\CoreBundle\Helper\ContentProxy;
|
||||||
use Wallabag\CoreBundle\Entity\Entry;
|
use Wallabag\CoreBundle\Entity\Entry;
|
||||||
use Symfony\Component\Security\Core\User\UserInterface;
|
use Wallabag\UserBundle\Entity\User;
|
||||||
use OldSound\RabbitMqBundle\RabbitMq\Producer;
|
use OldSound\RabbitMqBundle\RabbitMq\Producer;
|
||||||
|
|
||||||
abstract class AbstractImport implements ImportInterface
|
abstract class AbstractImport implements ImportInterface
|
||||||
@ -46,9 +46,9 @@ abstract class AbstractImport implements ImportInterface
|
|||||||
* Set current user.
|
* Set current user.
|
||||||
* Could the current *connected* user or one retrieve by the consumer.
|
* Could the current *connected* user or one retrieve by the consumer.
|
||||||
*
|
*
|
||||||
* @param UserInterface $user
|
* @param User $user
|
||||||
*/
|
*/
|
||||||
public function setUser(UserInterface $user)
|
public function setUser(User $user)
|
||||||
{
|
{
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
}
|
}
|
||||||
@ -119,6 +119,32 @@ abstract class AbstractImport implements ImportInterface
|
|||||||
$this->em->flush();
|
$this->em->flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse entries and send them to the queue.
|
||||||
|
* It should just be a simple loop on all item, no call to the database should be done
|
||||||
|
* to speedup queuing.
|
||||||
|
*
|
||||||
|
* Faster parse entries for Producer.
|
||||||
|
* We don't care to make check at this time. They'll be done by the consumer.
|
||||||
|
*
|
||||||
|
* @param array $entries
|
||||||
|
*/
|
||||||
|
protected function parseEntriesForProducer(array $entries)
|
||||||
|
{
|
||||||
|
foreach ($entries as $importedEntry) {
|
||||||
|
// set userId for the producer (it won't know which user is connected)
|
||||||
|
$importedEntry['userId'] = $this->user->getId();
|
||||||
|
|
||||||
|
if ($this->markAsRead) {
|
||||||
|
$importedEntry = $this->setEntryAsRead($importedEntry);
|
||||||
|
}
|
||||||
|
|
||||||
|
++$this->importedEntries;
|
||||||
|
|
||||||
|
$this->producer->publish(json_encode($importedEntry));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse one entry.
|
* Parse one entry.
|
||||||
*
|
*
|
||||||
@ -127,4 +153,14 @@ abstract class AbstractImport implements ImportInterface
|
|||||||
* @return Entry
|
* @return Entry
|
||||||
*/
|
*/
|
||||||
abstract public function parseEntry(array $importedEntry);
|
abstract public function parseEntry(array $importedEntry);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set current imported entry to archived / read.
|
||||||
|
* Implementation is different accross all imports.
|
||||||
|
*
|
||||||
|
* @param array $importedEntry
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
abstract protected function setEntryAsRead(array $importedEntry);
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ class PocketImport extends AbstractImport
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Only used for test purpose
|
* Only used for test purpose.
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
@ -258,24 +258,12 @@ class PocketImport extends AbstractImport
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Faster parse entries for Producer.
|
* {@inheritdoc}
|
||||||
* We don't care to make check at this time. They'll be done by the consumer.
|
|
||||||
*
|
|
||||||
* @param array $entries
|
|
||||||
*/
|
*/
|
||||||
public function parseEntriesForProducer($entries)
|
protected function setEntryAsRead(array $importedEntry)
|
||||||
{
|
{
|
||||||
foreach ($entries as $importedEntry) {
|
|
||||||
// set userId for the producer (it won't know which user is connected)
|
|
||||||
$importedEntry['userId'] = $this->user->getId();
|
|
||||||
|
|
||||||
if ($this->markAsRead) {
|
|
||||||
$importedEntry['status'] = 1;
|
$importedEntry['status'] = 1;
|
||||||
}
|
|
||||||
|
|
||||||
++$this->importedEntries;
|
return $importedEntry;
|
||||||
|
|
||||||
$this->producer->publish(json_encode($importedEntry));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
namespace Wallabag\ImportBundle\Import;
|
namespace Wallabag\ImportBundle\Import;
|
||||||
|
|
||||||
use Wallabag\CoreBundle\Entity\Entry;
|
use Wallabag\CoreBundle\Entity\Entry;
|
||||||
use Wallabag\UserBundle\Entity\User;
|
|
||||||
|
|
||||||
class ReadabilityImport extends AbstractImport
|
class ReadabilityImport extends AbstractImport
|
||||||
{
|
{
|
||||||
@ -136,31 +135,12 @@ class ReadabilityImport extends AbstractImport
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Faster parse entries for Producer.
|
* {@inheritdoc}
|
||||||
* We don't care to make check at this time. They'll be done by the consumer.
|
|
||||||
*
|
|
||||||
* @param array $entries
|
|
||||||
*/
|
*/
|
||||||
protected function parseEntriesForProducer($entries)
|
protected function setEntryAsRead(array $importedEntry)
|
||||||
{
|
{
|
||||||
foreach ($entries as $importedEntry) {
|
|
||||||
// set userId for the producer (it won't know which user is connected)
|
|
||||||
$importedEntry['userId'] = $this->user->getId();
|
|
||||||
|
|
||||||
if ($this->markAsRead) {
|
|
||||||
$importedEntry['archive'] = 1;
|
$importedEntry['archive'] = 1;
|
||||||
}
|
|
||||||
|
|
||||||
++$this->importedEntries;
|
return $importedEntry;
|
||||||
|
|
||||||
// flush every 20 entries
|
|
||||||
if (($i % 20) === 0) {
|
|
||||||
$this->em->flush();
|
|
||||||
}
|
|
||||||
++$i;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->em->flush();
|
|
||||||
$this->em->clear();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,11 +3,9 @@
|
|||||||
namespace Wallabag\ImportBundle\Import;
|
namespace Wallabag\ImportBundle\Import;
|
||||||
|
|
||||||
use Wallabag\CoreBundle\Entity\Entry;
|
use Wallabag\CoreBundle\Entity\Entry;
|
||||||
use Wallabag\UserBundle\Entity\User;
|
|
||||||
|
|
||||||
abstract class WallabagImport extends AbstractImport
|
abstract class WallabagImport extends AbstractImport
|
||||||
{
|
{
|
||||||
protected $user;
|
|
||||||
protected $skippedEntries = 0;
|
protected $skippedEntries = 0;
|
||||||
protected $importedEntries = 0;
|
protected $importedEntries = 0;
|
||||||
protected $filepath;
|
protected $filepath;
|
||||||
|
@ -57,19 +57,13 @@ class WallabagV1Import extends WallabagImport
|
|||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function parseEntriesForProducer($entries)
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function setEntryAsRead(array $importedEntry)
|
||||||
{
|
{
|
||||||
foreach ($entries as $importedEntry) {
|
|
||||||
// set userId for the producer (it won't know which user is connected)
|
|
||||||
$importedEntry['userId'] = $this->user->getId();
|
|
||||||
|
|
||||||
if ($this->markAsRead) {
|
|
||||||
$importedEntry['is_read'] = 1;
|
$importedEntry['is_read'] = 1;
|
||||||
}
|
|
||||||
|
|
||||||
++$this->importedEntries;
|
return $importedEntry;
|
||||||
|
|
||||||
$this->producer->publish(json_encode($importedEntry));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,19 +40,13 @@ class WallabagV2Import extends WallabagImport
|
|||||||
] + $entry;
|
] + $entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function parseEntriesForProducer($entries)
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function setEntryAsRead(array $importedEntry)
|
||||||
{
|
{
|
||||||
foreach ($entries as $importedEntry) {
|
|
||||||
// set userId for the producer (it won't know which user is connected)
|
|
||||||
$importedEntry['userId'] = $this->user->getId();
|
|
||||||
|
|
||||||
if ($this->markAsRead) {
|
|
||||||
$importedEntry['is_archived'] = 1;
|
$importedEntry['is_archived'] = 1;
|
||||||
}
|
|
||||||
|
|
||||||
++$this->importedEntries;
|
return $importedEntry;
|
||||||
|
|
||||||
$this->producer->publish(json_encode($importedEntry));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user