Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix import netscape #3

Closed
wants to merge 5 commits into from

2 participants

ricardosdl Christian Weiske
ricardosdl

I was having problems importing my bookmarks exported from delicious. I've made some adjustments and now it's working. Maybe you want to check my changes. Comments and opinions are welcome.

ricardosdl

I think I've found the problem with the failed test in https://travis-ci.org/cweiske/SemanticScuttle/builds/3620673

The InnoDB storage engine of Mysql apparently makes the test fail. I've run the tests using InnoDB and MyISAM on Mysql versions 5.1 and 5.5(where the default engine now is InnoDB).

The assertion seems to check the order of bookmarks returned from getBookmarks(). I get different orders with MyIsam and InnoDB. Apparently the clause used to order the bookmarks is bModified DESC. The test is fast enough to insert the bookmarks in the same second. Putting a call to sleep(1) between the creation of bookmark 2 and bookmark 3 makes the test pass, but I don't know if this is the right thing to do.

Christian Weiske
Owner

Thanks for your patches. I've merged the ones that were not already fixed in the meantime (didn't remember your pull request until after the release of 0.98.5, sorry).

Some notes for the future:

  • You can use git commit --amend to change the commit message afterwards if you made typos
  • Delete trailing whitespaces when saving files; some patches had empty lines with spaces only in them
  • PEAR packages can be installed without giving a version; i've adjusted the readme accordingly
Christian Weiske cweiske closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 8, 2012
  1. ricardosdl

    Using a foreach loop avoids Notice warnings when the array doesn't ha…

    ricardosdl authored
    …ve sequential indexes, ex: 0, 1, 3...
Commits on Dec 9, 2012
  1. ricardosdl
  2. ricardosdl
  3. ricardosdl
Commits on Dec 11, 2012
  1. ricardosdl

    The hasTag was always returning false, which probably is a bug. Fixed…

    ricardosdl authored
    … it and added a test to catch it.
This page is out of date. Refresh to see the latest.
18 src/SemanticScuttle/Service/Bookmark2Tag.php
View
@@ -97,12 +97,13 @@ public function attachTags(
$tags_count = is_array($tags)?count($tags):0;
-
- for ($i = 0; $i < $tags_count; $i++) {
- $tags[$i] = trim(utf8_strtolower($tags[$i]));
- if ($fromApi) {
- include_once 'SemanticScuttle/functions.php';
- $tags[$i] = convertTag($tags[$i], 'in');
+ if (is_array($tags)) {
+ foreach($tags as $i => $tag) {
+ $tags[$i] = trim(utf8_strtolower($tags[$i]));
+ if ($fromApi) {
+ include_once 'SemanticScuttle/functions.php';
+ $tags[$i] = convertTag($tags[$i], 'in');
+ }
}
}
@@ -626,13 +627,14 @@ function hasTag($bookmarkid, $tag) {
message_die(GENERAL_ERROR, 'Could not find tag', '', __LINE__, __FILE__, $query, $this->db);
return false;
}
-
+
+ $output = false;
if ($row =& $this->db->sql_fetchrow($dbresult)) {
if ($row['tCount'] > 0) {
$output = true;
}
}
- $output = false;
+
$this->db->sql_freeresult($dbresult);
return $output;
}
2  src/SemanticScuttle/Service/Tag.php
View
@@ -144,7 +144,7 @@ function normalize($tags) {
$tags = utf8_strtolower(trim($tags));
} else {
$tags = array_filter($tags);//remove empty values
- for($i=0; $i<count($tags); $i++) {
+ foreach($tags as $i => $tag) {
$tags[$i] = utf8_strtolower(trim($tags[$i]));
}
}
25 tests/Bookmark2TagTest.php
View
@@ -88,6 +88,21 @@ public function testAttachTagsWithArrayWithEmptyStringAddsSystemUnfiled()
$this->b2ts->getTagsForBookmark($bid, true)
);
}
+
+ public function testAttachTagsWithEmptyStringAddsSystemUnfiled()
+ {
+ $originalDisplayErros = ini_get('display_errors');
+ $originalErrorReporting = ini_get('error_reporting');
+ ini_set('display_errors', 1);
+ error_reporting(E_ALL);
+ $bid = $this->addBookmark(null, null, 0, '');
+ $this->assertEquals(
+ array('system:unfiled'),
+ $this->b2ts->getTagsForBookmark($bid, true)
+ );
+ ini_set('display_errors', $originalDisplayErros);
+ error_reporting($originalErrorReporting);
+ }
@@ -652,5 +667,15 @@ public function testGetContactTagsBeginsWith()
$this->assertContains(array('tag' => 'usertag1', 'bCount' => '1'), $arTags);
$this->assertContains(array('tag' => 'usable', 'bCount' => '2'), $arTags);
}
+
+ public function testHasTag() {
+ $bid = $this->addBookmark(null, null, 0, array('foo'));
+
+ $this->assertTrue($this->b2ts->hasTag($bid, 'foo'));
+ //this test is because we are using the utf8_general_ci encoding,
+ //which removes all accents
+ $this->assertTrue($this->b2ts->hasTag($bid, 'fóo'));
+
+ }
}
?>
3  www/importNetscape.php
View
@@ -67,12 +67,13 @@
$bDatetime = ""; //bDateTime optional
$bCategories = ""; //bCategories optional
+ $bPrivateNote = ""; //bPrivateNote optional
foreach ($attributes[0] as $attribute) {
$att = preg_split('/\s*=\s*/s', $attribute, 2);
$attrTitle = $att[0];
- $attrVal = eregi_replace('"', '&quot;', preg_replace('/([\'"]?)(.*)\1/', '$2', $att[1]));
+ $attrVal = preg_replace('/"/i', '&quot', preg_replace('/([\'"]?)(.*)\1/', '$2', $att[1]));
switch ($attrTitle) {
case "HREF":
Something went wrong with that request. Please try again.