aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md1
-rw-r--r--application/NetscapeBookmarkUtils.php33
-rw-r--r--index.php2
-rw-r--r--tests/NetscapeBookmarkUtils/BookmarkImportTest.php41
-rw-r--r--tests/utils/config/configJson.json.php2
5 files changed, 51 insertions, 28 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1a87a8ca..44ac06ff 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -28,6 +28,7 @@ Theming:
28- Add OpenSearch to feed templates 28- Add OpenSearch to feed templates
29- Add `campaign_` to the URL cleanup pattern list 29- Add `campaign_` to the URL cleanup pattern list
30- Add an AUTHORS file and Makefile target to list authors from Git commit data 30- Add an AUTHORS file and Makefile target to list authors from Git commit data
31- Link imports are now logged in `data/` folder, and can be debug using `dev.debug=true` setting.
31 32
32### Changed 33### Changed
33- Docker: enable nginx URL rewriting for the REST API 34- Docker: enable nginx URL rewriting for the REST API
diff --git a/application/NetscapeBookmarkUtils.php b/application/NetscapeBookmarkUtils.php
index e7148d00..f467a074 100644
--- a/application/NetscapeBookmarkUtils.php
+++ b/application/NetscapeBookmarkUtils.php
@@ -1,7 +1,12 @@
1<?php 1<?php
2 2
3use Psr\Log\LogLevel;
4use Shaarli\NetscapeBookmarkParser\NetscapeBookmarkParser;
5use Katzgrau\KLogger\Logger;
6
3/** 7/**
4 * Utilities to import and export bookmarks using the Netscape format 8 * Utilities to import and export bookmarks using the Netscape format
9 * TODO: Not static, use a container.
5 */ 10 */
6class NetscapeBookmarkUtils 11class NetscapeBookmarkUtils
7{ 12{
@@ -85,14 +90,14 @@ class NetscapeBookmarkUtils
85 /** 90 /**
86 * Imports Web bookmarks from an uploaded Netscape bookmark dump 91 * Imports Web bookmarks from an uploaded Netscape bookmark dump
87 * 92 *
88 * @param array $post Server $_POST parameters 93 * @param array $post Server $_POST parameters
89 * @param array $files Server $_FILES parameters 94 * @param array $files Server $_FILES parameters
90 * @param LinkDB $linkDb Loaded LinkDB instance 95 * @param LinkDB $linkDb Loaded LinkDB instance
91 * @param string $pagecache Page cache 96 * @param ConfigManager $conf instance
92 * 97 *
93 * @return string Summary of the bookmark import status 98 * @return string Summary of the bookmark import status
94 */ 99 */
95 public static function import($post, $files, $linkDb, $pagecache) 100 public static function import($post, $files, $linkDb, $conf)
96 { 101 {
97 $filename = $files['filetoupload']['name']; 102 $filename = $files['filetoupload']['name'];
98 $filesize = $files['filetoupload']['size']; 103 $filesize = $files['filetoupload']['size'];
@@ -119,10 +124,20 @@ class NetscapeBookmarkUtils
119 $defaultPrivacy = 0; 124 $defaultPrivacy = 0;
120 125
121 $parser = new NetscapeBookmarkParser( 126 $parser = new NetscapeBookmarkParser(
122 true, // nested tag support 127 true, // nested tag support
123 $defaultTags, // additional user-specified tags 128 $defaultTags, // additional user-specified tags
124 strval(1 - $defaultPrivacy) // defaultPub = 1 - defaultPrivacy 129 strval(1 - $defaultPrivacy), // defaultPub = 1 - defaultPrivacy
130 $conf->get('resource.data_dir') // log path, will be overridden
131 );
132 $logger = new Logger(
133 $conf->get('resource.data_dir'),
134 ! $conf->get('dev.debug') ? LogLevel::INFO : LogLevel::DEBUG,
135 [
136 'prefix' => 'import.',
137 'extension' => 'log',
138 ]
125 ); 139 );
140 $parser->setLogger($logger);
126 $bookmarks = $parser->parseString($data); 141 $bookmarks = $parser->parseString($data);
127 142
128 $importCount = 0; 143 $importCount = 0;
@@ -179,7 +194,7 @@ class NetscapeBookmarkUtils
179 $importCount++; 194 $importCount++;
180 } 195 }
181 196
182 $linkDb->save($pagecache); 197 $linkDb->save($conf->get('resource.page_cache'));
183 return self::importStatus( 198 return self::importStatus(
184 $filename, 199 $filename,
185 $filesize, 200 $filesize,
diff --git a/index.php b/index.php
index 3c2bb1d2..cc7f3ca3 100644
--- a/index.php
+++ b/index.php
@@ -1528,7 +1528,7 @@ function renderPage($conf, $pluginManager, $LINKSDB)
1528 $_POST, 1528 $_POST,
1529 $_FILES, 1529 $_FILES,
1530 $LINKSDB, 1530 $LINKSDB,
1531 $conf->get('resource.page_cache') 1531 $conf
1532 ); 1532 );
1533 echo '<script>alert("'.$status.'");document.location=\'?do=' 1533 echo '<script>alert("'.$status.'");document.location=\'?do='
1534 .Router::$PAGE_IMPORT .'\';</script>'; 1534 .Router::$PAGE_IMPORT .'\';</script>';
diff --git a/tests/NetscapeBookmarkUtils/BookmarkImportTest.php b/tests/NetscapeBookmarkUtils/BookmarkImportTest.php
index 0ca07eac..36425d85 100644
--- a/tests/NetscapeBookmarkUtils/BookmarkImportTest.php
+++ b/tests/NetscapeBookmarkUtils/BookmarkImportTest.php
@@ -43,6 +43,11 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
43 protected $pagecache = 'tests'; 43 protected $pagecache = 'tests';
44 44
45 /** 45 /**
46 * @var ConfigManager instance.
47 */
48 protected $conf;
49
50 /**
46 * @var string Save the current timezone. 51 * @var string Save the current timezone.
47 */ 52 */
48 protected static $defaultTimeZone; 53 protected static $defaultTimeZone;
@@ -65,6 +70,8 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
65 // start with an empty datastore 70 // start with an empty datastore
66 file_put_contents(self::$testDatastore, '<?php /* S7QysKquBQA= */ ?>'); 71 file_put_contents(self::$testDatastore, '<?php /* S7QysKquBQA= */ ?>');
67 $this->linkDb = new LinkDB(self::$testDatastore, true, false); 72 $this->linkDb = new LinkDB(self::$testDatastore, true, false);
73 $this->conf = new ConfigManager('tests/utils/config/configJson');
74 $this->conf->set('resource.page_cache', $this->pagecache);
68 } 75 }
69 76
70 public static function tearDownAfterClass() 77 public static function tearDownAfterClass()
@@ -81,7 +88,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
81 $this->assertEquals( 88 $this->assertEquals(
82 'File empty.htm (0 bytes) has an unknown file format.' 89 'File empty.htm (0 bytes) has an unknown file format.'
83 .' Nothing was imported.', 90 .' Nothing was imported.',
84 NetscapeBookmarkUtils::import(NULL, $files, NULL, NULL) 91 NetscapeBookmarkUtils::import(NULL, $files, NULL, $this->conf)
85 ); 92 );
86 $this->assertEquals(0, count($this->linkDb)); 93 $this->assertEquals(0, count($this->linkDb));
87 } 94 }
@@ -94,7 +101,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
94 $files = file2array('no_doctype.htm'); 101 $files = file2array('no_doctype.htm');
95 $this->assertEquals( 102 $this->assertEquals(
96 'File no_doctype.htm (350 bytes) has an unknown file format. Nothing was imported.', 103 'File no_doctype.htm (350 bytes) has an unknown file format. Nothing was imported.',
97 NetscapeBookmarkUtils::import(NULL, $files, NULL, NULL) 104 NetscapeBookmarkUtils::import(NULL, $files, NULL, $this->conf)
98 ); 105 );
99 $this->assertEquals(0, count($this->linkDb)); 106 $this->assertEquals(0, count($this->linkDb));
100 } 107 }
@@ -108,7 +115,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
108 $this->assertEquals( 115 $this->assertEquals(
109 'File internet_explorer_encoding.htm (356 bytes) was successfully processed:' 116 'File internet_explorer_encoding.htm (356 bytes) was successfully processed:'
110 .' 1 links imported, 0 links overwritten, 0 links skipped.', 117 .' 1 links imported, 0 links overwritten, 0 links skipped.',
111 NetscapeBookmarkUtils::import(array(), $files, $this->linkDb, $this->pagecache) 118 NetscapeBookmarkUtils::import(array(), $files, $this->linkDb, $this->conf)
112 ); 119 );
113 $this->assertEquals(1, count($this->linkDb)); 120 $this->assertEquals(1, count($this->linkDb));
114 $this->assertEquals(0, count_private($this->linkDb)); 121 $this->assertEquals(0, count_private($this->linkDb));
@@ -137,7 +144,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
137 $this->assertEquals( 144 $this->assertEquals(
138 'File netscape_nested.htm (1337 bytes) was successfully processed:' 145 'File netscape_nested.htm (1337 bytes) was successfully processed:'
139 .' 8 links imported, 0 links overwritten, 0 links skipped.', 146 .' 8 links imported, 0 links overwritten, 0 links skipped.',
140 NetscapeBookmarkUtils::import(array(), $files, $this->linkDb, $this->pagecache) 147 NetscapeBookmarkUtils::import(array(), $files, $this->linkDb, $this->conf)
141 ); 148 );
142 $this->assertEquals(8, count($this->linkDb)); 149 $this->assertEquals(8, count($this->linkDb));
143 $this->assertEquals(2, count_private($this->linkDb)); 150 $this->assertEquals(2, count_private($this->linkDb));
@@ -259,7 +266,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
259 $this->assertEquals( 266 $this->assertEquals(
260 'File netscape_basic.htm (482 bytes) was successfully processed:' 267 'File netscape_basic.htm (482 bytes) was successfully processed:'
261 .' 2 links imported, 0 links overwritten, 0 links skipped.', 268 .' 2 links imported, 0 links overwritten, 0 links skipped.',
262 NetscapeBookmarkUtils::import(array(), $files, $this->linkDb, $this->pagecache) 269 NetscapeBookmarkUtils::import(array(), $files, $this->linkDb, $this->conf)
263 ); 270 );
264 271
265 $this->assertEquals(2, count($this->linkDb)); 272 $this->assertEquals(2, count($this->linkDb));
@@ -304,7 +311,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
304 $this->assertEquals( 311 $this->assertEquals(
305 'File netscape_basic.htm (482 bytes) was successfully processed:' 312 'File netscape_basic.htm (482 bytes) was successfully processed:'
306 .' 2 links imported, 0 links overwritten, 0 links skipped.', 313 .' 2 links imported, 0 links overwritten, 0 links skipped.',
307 NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->pagecache) 314 NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf)
308 ); 315 );
309 $this->assertEquals(2, count($this->linkDb)); 316 $this->assertEquals(2, count($this->linkDb));
310 $this->assertEquals(1, count_private($this->linkDb)); 317 $this->assertEquals(1, count_private($this->linkDb));
@@ -348,7 +355,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
348 $this->assertEquals( 355 $this->assertEquals(
349 'File netscape_basic.htm (482 bytes) was successfully processed:' 356 'File netscape_basic.htm (482 bytes) was successfully processed:'
350 .' 2 links imported, 0 links overwritten, 0 links skipped.', 357 .' 2 links imported, 0 links overwritten, 0 links skipped.',
351 NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->pagecache) 358 NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf)
352 ); 359 );
353 $this->assertEquals(2, count($this->linkDb)); 360 $this->assertEquals(2, count($this->linkDb));
354 $this->assertEquals(0, count_private($this->linkDb)); 361 $this->assertEquals(0, count_private($this->linkDb));
@@ -372,7 +379,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
372 $this->assertEquals( 379 $this->assertEquals(
373 'File netscape_basic.htm (482 bytes) was successfully processed:' 380 'File netscape_basic.htm (482 bytes) was successfully processed:'
374 .' 2 links imported, 0 links overwritten, 0 links skipped.', 381 .' 2 links imported, 0 links overwritten, 0 links skipped.',
375 NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->pagecache) 382 NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf)
376 ); 383 );
377 $this->assertEquals(2, count($this->linkDb)); 384 $this->assertEquals(2, count($this->linkDb));
378 $this->assertEquals(2, count_private($this->linkDb)); 385 $this->assertEquals(2, count_private($this->linkDb));
@@ -398,7 +405,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
398 $this->assertEquals( 405 $this->assertEquals(
399 'File netscape_basic.htm (482 bytes) was successfully processed:' 406 'File netscape_basic.htm (482 bytes) was successfully processed:'
400 .' 2 links imported, 0 links overwritten, 0 links skipped.', 407 .' 2 links imported, 0 links overwritten, 0 links skipped.',
401 NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->pagecache) 408 NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf)
402 ); 409 );
403 $this->assertEquals(2, count($this->linkDb)); 410 $this->assertEquals(2, count($this->linkDb));
404 $this->assertEquals(2, count_private($this->linkDb)); 411 $this->assertEquals(2, count_private($this->linkDb));
@@ -418,7 +425,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
418 $this->assertEquals( 425 $this->assertEquals(
419 'File netscape_basic.htm (482 bytes) was successfully processed:' 426 'File netscape_basic.htm (482 bytes) was successfully processed:'
420 .' 2 links imported, 2 links overwritten, 0 links skipped.', 427 .' 2 links imported, 2 links overwritten, 0 links skipped.',
421 NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->pagecache) 428 NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf)
422 ); 429 );
423 $this->assertEquals(2, count($this->linkDb)); 430 $this->assertEquals(2, count($this->linkDb));
424 $this->assertEquals(0, count_private($this->linkDb)); 431 $this->assertEquals(0, count_private($this->linkDb));
@@ -444,7 +451,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
444 $this->assertEquals( 451 $this->assertEquals(
445 'File netscape_basic.htm (482 bytes) was successfully processed:' 452 'File netscape_basic.htm (482 bytes) was successfully processed:'
446 .' 2 links imported, 0 links overwritten, 0 links skipped.', 453 .' 2 links imported, 0 links overwritten, 0 links skipped.',
447 NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->pagecache) 454 NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf)
448 ); 455 );
449 $this->assertEquals(2, count($this->linkDb)); 456 $this->assertEquals(2, count($this->linkDb));
450 $this->assertEquals(0, count_private($this->linkDb)); 457 $this->assertEquals(0, count_private($this->linkDb));
@@ -465,7 +472,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
465 $this->assertEquals( 472 $this->assertEquals(
466 'File netscape_basic.htm (482 bytes) was successfully processed:' 473 'File netscape_basic.htm (482 bytes) was successfully processed:'
467 .' 2 links imported, 2 links overwritten, 0 links skipped.', 474 .' 2 links imported, 2 links overwritten, 0 links skipped.',
468 NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->pagecache) 475 NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf)
469 ); 476 );
470 $this->assertEquals(2, count($this->linkDb)); 477 $this->assertEquals(2, count($this->linkDb));
471 $this->assertEquals(2, count_private($this->linkDb)); 478 $this->assertEquals(2, count_private($this->linkDb));
@@ -489,7 +496,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
489 $this->assertEquals( 496 $this->assertEquals(
490 'File netscape_basic.htm (482 bytes) was successfully processed:' 497 'File netscape_basic.htm (482 bytes) was successfully processed:'
491 .' 2 links imported, 0 links overwritten, 0 links skipped.', 498 .' 2 links imported, 0 links overwritten, 0 links skipped.',
492 NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->pagecache) 499 NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf)
493 ); 500 );
494 $this->assertEquals(2, count($this->linkDb)); 501 $this->assertEquals(2, count($this->linkDb));
495 $this->assertEquals(0, count_private($this->linkDb)); 502 $this->assertEquals(0, count_private($this->linkDb));
@@ -499,7 +506,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
499 $this->assertEquals( 506 $this->assertEquals(
500 'File netscape_basic.htm (482 bytes) was successfully processed:' 507 'File netscape_basic.htm (482 bytes) was successfully processed:'
501 .' 0 links imported, 0 links overwritten, 2 links skipped.', 508 .' 0 links imported, 0 links overwritten, 2 links skipped.',
502 NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->pagecache) 509 NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf)
503 ); 510 );
504 $this->assertEquals(2, count($this->linkDb)); 511 $this->assertEquals(2, count($this->linkDb));
505 $this->assertEquals(0, count_private($this->linkDb)); 512 $this->assertEquals(0, count_private($this->linkDb));
@@ -518,7 +525,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
518 $this->assertEquals( 525 $this->assertEquals(
519 'File netscape_basic.htm (482 bytes) was successfully processed:' 526 'File netscape_basic.htm (482 bytes) was successfully processed:'
520 .' 2 links imported, 0 links overwritten, 0 links skipped.', 527 .' 2 links imported, 0 links overwritten, 0 links skipped.',
521 NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->pagecache) 528 NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf)
522 ); 529 );
523 $this->assertEquals(2, count($this->linkDb)); 530 $this->assertEquals(2, count($this->linkDb));
524 $this->assertEquals(0, count_private($this->linkDb)); 531 $this->assertEquals(0, count_private($this->linkDb));
@@ -545,7 +552,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
545 $this->assertEquals( 552 $this->assertEquals(
546 'File netscape_basic.htm (482 bytes) was successfully processed:' 553 'File netscape_basic.htm (482 bytes) was successfully processed:'
547 .' 2 links imported, 0 links overwritten, 0 links skipped.', 554 .' 2 links imported, 0 links overwritten, 0 links skipped.',
548 NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->pagecache) 555 NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf)
549 ); 556 );
550 $this->assertEquals(2, count($this->linkDb)); 557 $this->assertEquals(2, count($this->linkDb));
551 $this->assertEquals(0, count_private($this->linkDb)); 558 $this->assertEquals(0, count_private($this->linkDb));
@@ -570,7 +577,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
570 $this->assertEquals( 577 $this->assertEquals(
571 'File same_date.htm (453 bytes) was successfully processed:' 578 'File same_date.htm (453 bytes) was successfully processed:'
572 .' 3 links imported, 0 links overwritten, 0 links skipped.', 579 .' 3 links imported, 0 links overwritten, 0 links skipped.',
573 NetscapeBookmarkUtils::import(array(), $files, $this->linkDb, $this->pagecache) 580 NetscapeBookmarkUtils::import(array(), $files, $this->linkDb, $this->conf)
574 ); 581 );
575 $this->assertEquals(3, count($this->linkDb)); 582 $this->assertEquals(3, count($this->linkDb));
576 $this->assertEquals(0, count_private($this->linkDb)); 583 $this->assertEquals(0, count_private($this->linkDb));
diff --git a/tests/utils/config/configJson.json.php b/tests/utils/config/configJson.json.php
index 13d38c66..9c9288f3 100644
--- a/tests/utils/config/configJson.json.php
+++ b/tests/utils/config/configJson.json.php
@@ -24,7 +24,7 @@
24 }, 24 },
25 "resource": { 25 "resource": {
26 "datastore": "tests\/utils\/config\/datastore.php", 26 "datastore": "tests\/utils\/config\/datastore.php",
27 "data_dir": "tests\/utils\/config", 27 "data_dir": "sandbox/",
28 "raintpl_tpl": "tpl/" 28 "raintpl_tpl": "tpl/"
29 }, 29 },
30 "plugins": { 30 "plugins": {