Netscape bookmark parser: bump to new major version

Apply breaking changes of the new version:
  - parsed bookmarks have different field names
  - default values (private and tags) are no longer handled by the library
  - constructor signature has been updated
This commit is contained in:
ArthurHoaro 2022-08-13 16:08:11 +02:00
parent 130008da03
commit bde1fdcb48
3 changed files with 42 additions and 36 deletions

View file

@ -109,15 +109,9 @@ class NetscapeBookmarkUtils
);
}
// bookmarks are imported as public by default
$defaultPrivacy = 0;
// Optionally Force all imported link to be either public or private.
$forcedPrivateStatus = !empty($post['privacy']) ? (string) $post['privacy'] : null;
$parser = new NetscapeBookmarkParser(
true, // nested tag support
$defaultTags, // additional user-specified tags
strval(1 - $defaultPrivacy), // defaultPub = 1 - defaultPrivacy
$this->conf->get('resource.data_dir') // log path, will be overridden
);
$logger = new Logger(
$this->conf->get('resource.data_dir'),
!$this->conf->get('dev.debug') ? LogLevel::INFO : LogLevel::DEBUG,
@ -126,7 +120,8 @@ class NetscapeBookmarkUtils
'extension' => 'log',
]
);
$parser->setLogger($logger);
$parser = new NetscapeBookmarkParser([], $logger);
$bookmarks = $parser->parseString($data);
$importCount = 0;
@ -134,19 +129,18 @@ class NetscapeBookmarkUtils
$skipCount = 0;
foreach ($bookmarks as $bkm) {
$private = $defaultPrivacy;
if (empty($post['privacy']) || $post['privacy'] == 'default') {
// use value from the imported file
$private = $bkm['pub'] == '1' ? 0 : 1;
} elseif ($post['privacy'] == 'private') {
if ($forcedPrivateStatus == 'private') {
// all imported bookmarks are private
$private = 1;
} elseif ($post['privacy'] == 'public') {
$isPrivate = true;
} elseif ($forcedPrivateStatus == 'public') {
// all imported bookmarks are public
$private = 0;
$isPrivate = false;
} else {
// Use private value from imported file or default to public
$isPrivate = isset($bkm['public']) && !$bkm['public'];
}
$link = $this->bookmarkService->findByUrl($bkm['uri']);
$link = $this->bookmarkService->findByUrl($bkm['url']);
$existingLink = $link !== null;
if (! $existingLink) {
$link = new Bookmark();
@ -162,15 +156,19 @@ class NetscapeBookmarkUtils
$link->setUpdated(new DateTime());
$overwriteCount++;
} else {
$newLinkDate = new DateTime('@' . strval($bkm['time']));
$newLinkDate = new DateTime('@' . $bkm['dateCreated']);
$newLinkDate->setTimezone(new DateTimeZone(date_default_timezone_get()));
$link->setCreated($newLinkDate);
}
$link->setTitle($bkm['title']);
$link->setUrl($bkm['uri'], $this->conf->get('security.allowed_protocols'));
$link->setDescription($bkm['note']);
$link->setPrivate($private);
if (!empty($defaultTags)) {
$bkm['tags'] = array_merge($defaultTags, $bkm['tags']);
}
$link->setTitle($bkm['name']);
$link->setUrl($bkm['url'], $this->conf->get('security.allowed_protocols'));
$link->setDescription($bkm['description']);
$link->setPrivate($isPrivate);
$link->setTags($bkm['tags']);
$this->bookmarkService->addOrSet($link, false);

View file

@ -26,7 +26,7 @@
"katzgrau/klogger": "^1.2",
"malkusch/lock": "^2.1",
"pubsubhubbub/publisher": "dev-master",
"shaarli/netscape-bookmark-parser": "^3.0",
"shaarli/netscape-bookmark-parser": "^4.0",
"slim/slim": "^3.0"
},
"require-dev": {

32
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "83852dec81e299a117a81206a5091472",
"content-hash": "326e743376bd043cd7de28c02b5ac1d5",
"packages": [
{
"name": "arthurhoaro/web-thumbnailer",
@ -806,21 +806,21 @@
},
{
"name": "shaarli/netscape-bookmark-parser",
"version": "v3.2.0",
"version": "v4.0.0",
"source": {
"type": "git",
"url": "https://github.com/shaarli/netscape-bookmark-parser.git",
"reference": "5b2eb8d478f5e6938359e116880763e6b1892e62"
"reference": "aa024e5731959966660d98fcefe27deada40d88e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/shaarli/netscape-bookmark-parser/zipball/5b2eb8d478f5e6938359e116880763e6b1892e62",
"reference": "5b2eb8d478f5e6938359e116880763e6b1892e62",
"url": "https://api.github.com/repos/shaarli/netscape-bookmark-parser/zipball/aa024e5731959966660d98fcefe27deada40d88e",
"reference": "aa024e5731959966660d98fcefe27deada40d88e",
"shasum": ""
},
"require": {
"katzgrau/klogger": "~1.0",
"php": ">=7.1"
"php": ">=7.1",
"psr/log": "^1.1"
},
"require-dev": {
"phpunit/phpunit": "^7.0 || ^8.0 || ^9.0",
@ -828,9 +828,9 @@
},
"type": "library",
"autoload": {
"files": [
"NetscapeBookmarkParser.php"
]
"psr-4": {
"Shaarli\\NetscapeBookmarkParser\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
@ -848,21 +848,29 @@
"email": "virtualtam@flibidi.net",
"homepage": "https://github.com/virtualtam",
"role": "Developer"
},
{
"name": "Matthias Morin",
"email": "mat@tangoman.io",
"homepage": "https://github.com/TangoMan75",
"role": "Developer"
}
],
"description": "Generic Netscape bookmark parser",
"homepage": "https://github.com/shaarli/netscape-bookmark-parser",
"keywords": [
"bookmark",
"decoder",
"encoder",
"link",
"netscape",
"parse"
],
"support": {
"issues": "https://github.com/shaarli/netscape-bookmark-parser/issues",
"source": "https://github.com/shaarli/netscape-bookmark-parser/tree/v3.2.0"
"source": "https://github.com/shaarli/netscape-bookmark-parser/tree/v4.0.0"
},
"time": "2021-01-31T09:39:07+00:00"
"time": "2022-08-13T09:57:26+00:00"
},
{
"name": "slim/slim",