Update Firefox file

With real data, the previous looks more than a Chrome converted file.
Also, fix date conversion (hope so).
This commit is contained in:
Jeremy Benoist 2016-09-25 22:24:07 +02:00
parent 27acc6ddb8
commit 12d93e6896
No known key found for this signature in database
GPG key ID: BCA73962457ACC3C
4 changed files with 91 additions and 78 deletions

View file

@ -136,27 +136,27 @@ abstract class BrowserImport extends AbstractImport
*/
public function parseEntry(array $importedEntry)
{
if ((!key_exists('guid', $importedEntry) || (!key_exists('id', $importedEntry))) && is_array(reset($importedEntry))) {
if ((!array_key_exists('guid', $importedEntry) || (!array_key_exists('id', $importedEntry))) && is_array(reset($importedEntry))) {
$this->parseEntries($importedEntry);
return;
}
if (key_exists('children', $importedEntry)) {
if (array_key_exists('children', $importedEntry)) {
$this->parseEntries($importedEntry['children']);
return;
}
if (!key_exists('uri', $importedEntry) && !key_exists('url', $importedEntry)) {
if (!array_key_exists('uri', $importedEntry) && !array_key_exists('url', $importedEntry)) {
return;
}
$firefox = key_exists('uri', $importedEntry);
$url = array_key_exists('uri', $importedEntry) ? $importedEntry['uri'] : $importedEntry['url'];
$existingEntry = $this->em
->getRepository('WallabagCoreBundle:Entry')
->findByUrlAndUserId(($firefox) ? $importedEntry['uri'] : $importedEntry['url'], $this->user->getId());
->findByUrlAndUserId($url, $this->user->getId());
if (false !== $existingEntry) {
++$this->skippedEntries;
@ -184,7 +184,7 @@ abstract class BrowserImport extends AbstractImport
if (!empty($data['created_at'])) {
$dt = new \DateTime();
$entry->setCreatedAt($dt->setTimestamp($data['created_at'] / 1000));
$entry->setCreatedAt($dt->setTimestamp($data['created_at']));
}
$this->em->persist($entry);
@ -196,17 +196,29 @@ abstract class BrowserImport extends AbstractImport
/**
* {@inheritdoc}
*/
protected function prepareEntry($entry = [])
protected function prepareEntry(array $entry = [])
{
$url = array_key_exists('uri', $entry) ? $entry['uri'] : $entry['url'];
$date = array_key_exists('date_added', $entry) ? $entry['date_added'] : $entry['dateAdded'];
$title = array_key_exists('name', $entry) ? $entry['name'] : $entry['title'];
if (16 === strlen($date)) {
// firefox ...
$date = (int) ceil($date / 1000000);
} else if (17 === strlen($date)) {
// chrome ...
$date = (int) ceil($date / 10000000);
} else {
$date = '';
}
$data = [
'title' => $entry['name'],
'title' => $title,
'html' => '',
'url' => $entry['url'],
'url' => $url,
'is_archived' => $this->markAsRead,
'tags' => '',
// date are in format like "13118829474385693"
// and it'll be devided by 1000 in AbstractImport
'created_at' => (int) ceil($entry['date_added'] / 10000),
'created_at' => $date,
];
if (array_key_exists('tags', $entry) && $entry['tags'] != '') {

View file

@ -135,8 +135,8 @@ class FirefoxControllerTest extends WallabagCoreTestCase
$this->assertEmpty($content->getLanguage());
$createdAt = $content->getCreatedAt();
$this->assertEquals('2011', $createdAt->format('Y'));
$this->assertEquals('07', $createdAt->format('m'));
$this->assertEquals('2013', $createdAt->format('Y'));
$this->assertEquals('12', $createdAt->format('m'));
}
public function testImportWallabagWithEmptyFile()

View file

@ -61,7 +61,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase
->disableOriginalConstructor()
->getMock();
$entryRepo->expects($this->exactly(4))
$entryRepo->expects($this->exactly(2))
->method('findByUrlAndUserId')
->willReturn(false);
@ -75,14 +75,14 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase
->getMock();
$this->contentProxy
->expects($this->exactly(4))
->expects($this->exactly(2))
->method('updateEntry')
->willReturn($entry);
$res = $firefoxImport->import();
$this->assertTrue($res);
$this->assertEquals(['skipped' => 0, 'imported' => 4, 'queued' => 0], $firefoxImport->getSummary());
$this->assertEquals(['skipped' => 0, 'imported' => 2, 'queued' => 0], $firefoxImport->getSummary());
}
public function testImportAndMarkAllAsRead()
@ -94,7 +94,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase
->disableOriginalConstructor()
->getMock();
$entryRepo->expects($this->exactly(4))
$entryRepo->expects($this->exactly(2))
->method('findByUrlAndUserId')
->will($this->onConsecutiveCalls(false, true));
@ -120,7 +120,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($res);
$this->assertEquals(['skipped' => 3, 'imported' => 1, 'queued' => 0], $firefoxImport->getSummary());
$this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $firefoxImport->getSummary());
}
public function testImportWithRabbit()

View file

@ -1,61 +1,62 @@
{
"checksum": "ef1e30cddf64cb94c63d7835640165be",
"roots": {
"bookmark_bar": {
"children": [ {
"date_added": "13112787540531997",
"id": "7",
"name": "Terrorisme: les sombres prédictions du directeur de la DGSI",
"type": "url",
"url": "http://www.lefigaro.fr/actualite-france/2016/07/12/01016-20160712ARTFIG00016-terrorisme-les-sombres-perspectives-de-patrick-calvar-directeur-de-la-dgsi.php"
} ],
"date_added": "13112787380480144",
"date_modified": "13112787542724942",
"id": "1",
"name": "Bookmarks bar",
"type": "folder"
},
"other": {
"children": [ {
"date_added": "13112787503900822",
"id": "6",
"name": "Parser for Exported Bookmarks HTML file of Google Chrome and Mozilla in Java - Stack Overflow",
"type": "url",
"url": "http://stackoverflow.com/questions/15017163/parser-for-exported-bookmarks-html-file-of-google-chrome-and-mozilla-in-java"
}, {
"children": [ {
"date_added": "13112787564443378",
"id": "9",
"name": "Orange offre un meilleur réseau mobile que Bouygues et SFR, Free derrière - L'Express L'Expansion",
"type": "url",
"url": "http://lexpansion.lexpress.fr/high-tech/orange-offre-un-meilleur-reseau-mobile-que-bouygues-et-sfr-free-derriere_1811554.html"
} ],
"date_added": "13112787556763735",
"date_modified": "13112794390493325",
"id": "8",
"name": "test",
"type": "folder"
}, {
"date_added": "13112794390493325",
"id": "12",
"name": "JSON Formatter & Validator",
"type": "url",
"url": "https://jsonformatter.curiousconcept.com/"
} ],
"date_added": "13112787380480151",
"date_modified": "13112794393509988",
"id": "2",
"name": "Other bookmarks",
"type": "folder"
},
"synced": {
"children": [ ],
"date_added": "13112787380480155",
"date_modified": "0",
"id": "3",
"name": "Mobile bookmarks",
"type": "folder"
}
},
"version": 1
"guid": "root________",
"title": "",
"index": 0,
"dateAdded": 1388166091504000,
"lastModified": 1472897622350000,
"id": 1,
"type": "text/x-moz-place-container",
"root": "placesRoot",
"children": [
{
"guid": "toolbar_____",
"title": "Barre personnelle",
"index": 1,
"dateAdded": 1388166091504000,
"lastModified": 1472897622263000,
"id": 3,
"annos": [
{
"name": "bookmarkProperties/description",
"flags": 0,
"expires": 4,
"value": "Ajoutez des marque-pages dans ce dossier pour les voir apparaître sur votre barre personnelle"
}
],
"type": "text/x-moz-place-container",
"root": "toolbarFolder",
"children": [
{
"guid": "tard77lzbC5H",
"title": "Orange offre un meilleur réseau mobile que Bouygues et SFR, Free derrière - L'Express L'Expansion",
"index": 1,
"dateAdded": 1388166091644000,
"lastModified": 1388166091644000,
"id": 4,
"type": "text/x-moz-place",
"uri": "http://lexpansion.lexpress.fr/high-tech/orange-offre-un-meilleur-reseau-mobile-que-bouygues-et-sfr-free-derriere_1811554.html"
},
{
"guid": "E385l9vZ_LVn",
"title": "Parser for Exported Bookmarks HTML file of Google Chrome and Mozilla in Java",
"index": 1,
"dateAdded": 1388166091544000,
"lastModified": 1388166091545000,
"id": 5,
"type": "text/x-moz-place",
"uri": "http://stackoverflow.com/questions/15017163/parser-for-exported-bookmarks-html-file-of-google-chrome-and-mozilla-in-java"
}
]
},
{
"guid": "unfiled_____",
"title": "Autres marque-pages",
"index": 3,
"dateAdded": 1388166091504000,
"lastModified": 1388166091542000,
"id": 6,
"type": "text/x-moz-place-container",
"root": "unfiledBookmarksFolder"
}
]
}