Add ability to define created_at for all import

At the moment only Readability & wallabag v2 import allow created_at import.
Pocket removed `time_added` field from their API v2 to v3...
And wallabag v1 doesn't export that value.
This commit is contained in:
Jeremy Benoist 2016-09-09 09:36:07 +02:00
parent 3aca0a9f00
commit 6d65c0a8b0
No known key found for this signature in database
GPG key ID: BCA73962457ACC3C
8 changed files with 47 additions and 2 deletions

View file

@ -410,7 +410,22 @@ class Entry
}
/**
* @return string
* Set created_at.
* Only used when importing data from an other service.
*
* @param DateTime $createdAt
*
* @return Entry
*/
public function setCreatedAt(\DateTime $createdAt)
{
$this->createdAt = $createdAt;
return $this;
}
/**
* @return DateTime
*/
public function getCreatedAt()
{
@ -418,7 +433,7 @@ class Entry
}
/**
* @return string
* @return DateTime
*/
public function getUpdatedAt()
{

View file

@ -193,6 +193,11 @@ class PocketImport extends AbstractImport
$this->client = $client;
}
/**
* {@inheritdoc}
*
* @see https://getpocket.com/developer/docs/v3/retrieve
*/
public function parseEntry(array $importedEntry)
{
$url = isset($importedEntry['resolved_url']) && $importedEntry['resolved_url'] != '' ? $importedEntry['resolved_url'] : $importedEntry['given_url'];

View file

@ -89,6 +89,9 @@ class ReadabilityImport extends AbstractImport
return true;
}
/**
* {@inheritdoc}
*/
public function parseEntry(array $importedEntry)
{
$existingEntry = $this->em
@ -108,6 +111,7 @@ class ReadabilityImport extends AbstractImport
'language' => '',
'is_archived' => $importedEntry['archive'] || $this->markAsRead,
'is_starred' => $importedEntry['favorite'],
'created_at' => $importedEntry['date_added'],
];
$entry = $this->fetchContent(
@ -125,6 +129,7 @@ class ReadabilityImport extends AbstractImport
$entry->setArchived($data['is_archived']);
$entry->setStarred($data['is_starred']);
$entry->setCreatedAt(new \DateTime($data['created_at']));
$this->em->persist($entry);
++$this->importedEntries;

View file

@ -139,6 +139,10 @@ abstract class WallabagImport extends AbstractImport
$entry->setArchived($data['is_archived']);
$entry->setStarred($data['is_starred']);
if (!empty($data['created_at'])) {
$entry->setCreatedAt(new \DateTime($data['created_at']));
}
$this->em->persist($entry);
++$this->importedEntries;

View file

@ -42,6 +42,7 @@ class WallabagV1Import extends WallabagImport
'is_archived' => $entry['is_read'] || $this->markAsRead,
'is_starred' => $entry['is_fav'],
'tags' => '',
'created_at' => '',
];
// force content to be refreshed in case on bad fetch in the v1 installation

View file

@ -49,6 +49,13 @@ class ReadabilityControllerTest extends WallabagCoreTestCase
$this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
$this->assertContains('flashes.import.notice.summary', $body[0]);
$this->assertNotEmpty($content->getMimetype());
$this->assertNotEmpty($content->getPreviewPicture());
$this->assertNotEmpty($content->getLanguage());
$this->assertEquals(0, count($content->getTags()));
$this->assertInstanceOf(\DateTime::class, $content->getCreatedAt());
$this->assertEquals('2016-08-25', $content->getCreatedAt()->format('Y-m-d'));
}
public function testImportReadabilityWithFileAndMarkAllAsRead()

View file

@ -56,6 +56,12 @@ class WallabagV1ControllerTest extends WallabagCoreTestCase
$this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
$this->assertContains('flashes.import.notice.summary', $body[0]);
$this->assertEmpty($content->getMimetype());
$this->assertEmpty($content->getPreviewPicture());
$this->assertEmpty($content->getLanguage());
$this->assertEquals(1, count($content->getTags()));
$this->assertInstanceOf(\DateTime::class, $content->getCreatedAt());
}
public function testImportWallabagWithFileAndMarkAllAsRead()

View file

@ -67,6 +67,8 @@ class WallabagV2ControllerTest extends WallabagCoreTestCase
$this->assertNotEmpty($content->getPreviewPicture());
$this->assertNotEmpty($content->getLanguage());
$this->assertEquals(2, count($content->getTags()));
$this->assertInstanceOf(\DateTime::class, $content->getCreatedAt());
$this->assertEquals('2016-09-08', $content->getCreatedAt()->format('Y-m-d'));
}
public function testImportWallabagWithEmptyFile()