1
0
mirror of https://github.com/owncloud/bookmarks.git synced 2025-02-23 20:54:23 +01:00

Merge pull request #275 from owncloud/backport-264-stable8

[stable8] Fix overwrite of bookmarks when importing links without URL
This commit is contained in:
blizzz 2016-08-07 13:02:58 +02:00 committed by GitHub
commit 7e3c210f2e

View File

@ -428,6 +428,11 @@ class Bookmarks {
*/
public static function addBookmark($userid, IDb $db, $url, $title, $tags = array(), $description = '', $is_public = false) {
$public = $is_public ? 1 : 0;
$url_without_prefix = trim(substr($url, strpos($url, "://") + 3)); // Removes everything from the url before the "://" pattern (included)
if($url_without_prefix === '') {
throw new \InvalidArgumentException('Bookmark URL is missing');
}
$enc_url_noprefix = htmlspecialchars_decode($url_without_prefix);
$enc_url = htmlspecialchars_decode($url);
// Change lastmodified date if the record if already exists
$sql = "SELECT * from `*PREFIX*bookmarks` WHERE `url` = ? AND `user_id` = ?";
@ -519,8 +524,12 @@ class Bookmarks {
$dom->loadHTMLFile($file);
$links = $dom->getElementsByTagName('a');
$l = \OC::$server->getL10NFactory()->get('bookmarks');
$errors = [];
// Reintroduce transaction here!?
foreach ($links as $link) {
/* @var \DOMElement $link */
$title = $link->nodeValue;
$ref = $link->getAttribute("href");
$tag_str = '';
@ -531,11 +540,15 @@ class Bookmarks {
$desc_str = '';
if ($link->hasAttribute("description"))
$desc_str = $link->getAttribute("description");
try {
self::addBookmark($user, $db, $ref, $title, $tags, $desc_str);
} catch (\InvalidArgumentException $e) {
\OC::$server->getLogger()->logException($e, ['app' => 'bookmarks']);
$errors[] = $l->t('Failed to import one bookmark, because: ') . $e->getMessage();
}
}
return array();
return $errors;
}
/**