Move prepareEntry to dedicated place

Yeah first try was ugly, now each part are in the dedicated place.
Also, the date is hardly truncated to 10 chars because Firefox date are 16 chars long and Chrome are 17 chars long. So instead of divised them by a huge number, I prefer to truncate them.
This commit is contained in:
Jeremy Benoist 2016-09-26 07:30:02 +02:00
parent 12d93e6896
commit 990adfb34c
No known key found for this signature in database
GPG key ID: BCA73962457ACC3C
3 changed files with 42 additions and 35 deletions

View file

@ -193,41 +193,6 @@ abstract class BrowserImport extends AbstractImport
return $entry;
}
/**
* {@inheritdoc}
*/
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' => $title,
'html' => '',
'url' => $url,
'is_archived' => $this->markAsRead,
'tags' => '',
'created_at' => $date,
];
if (array_key_exists('tags', $entry) && $entry['tags'] != '') {
$data['tags'] = $entry['tags'];
}
return $data;
}
/**
* {@inheritdoc}
*/

View file

@ -29,4 +29,25 @@ class ChromeImport extends BrowserImport
{
return 'import.chrome.description';
}
/**
* {@inheritdoc}
*/
protected function prepareEntry(array $entry = [])
{
$data = [
'title' => $entry['name'],
'html' => '',
'url' => $entry['url'],
'is_archived' => $this->markAsRead,
'tags' => '',
'created_at' => substr($entry['date_added'], 0, 10),
];
if (array_key_exists('tags', $entry) && $entry['tags'] != '') {
$data['tags'] = $entry['tags'];
}
return $data;
}
}

View file

@ -29,4 +29,25 @@ class FirefoxImport extends BrowserImport
{
return 'import.firefox.description';
}
/**
* {@inheritdoc}
*/
protected function prepareEntry(array $entry = [])
{
$data = [
'title' => $entry['title'],
'html' => '',
'url' => $entry['uri'],
'is_archived' => $this->markAsRead,
'tags' => '',
'created_at' => substr($entry['dateAdded'], 0, 10),
];
if (array_key_exists('tags', $entry) && $entry['tags'] != '') {
$data['tags'] = $entry['tags'];
}
return $data;
}
}