aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2017-03-11 14:23:05 +0100
committerGitHub <noreply@github.com>2017-03-11 14:23:05 +0100
commit196808e14f4df44faea4d010c062c09f36095d9b (patch)
tree8e5f72c44f813a0da6cbd7a400b2dd37f56a9d9e
parentc4f8360240990d7db55ceccd4bb4d4f67678fce6 (diff)
parent87e9631e4aa7c9f535ee9f97ba3db595117350ab (diff)
downloadShaarli-196808e14f4df44faea4d010c062c09f36095d9b.tar.gz
Shaarli-196808e14f4df44faea4d010c062c09f36095d9b.tar.zst
Shaarli-196808e14f4df44faea4d010c062c09f36095d9b.zip
Merge pull request #779 from ArthurHoaro/feature/import-parser-logs
Link imports are now logged in `data/` folder, and can be debug using…
-rw-r--r--CHANGELOG.md1
-rw-r--r--application/NetscapeBookmarkUtils.php34
-rw-r--r--composer.json2
-rw-r--r--index.php2
-rw-r--r--tests/NetscapeBookmarkUtils/BookmarkImportTest.php42
-rw-r--r--tests/utils/config/configJson.json.php2
6 files changed, 54 insertions, 29 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..ab346f81 100644
--- a/application/NetscapeBookmarkUtils.php
+++ b/application/NetscapeBookmarkUtils.php
@@ -1,7 +1,13 @@
1<?php 1<?php
2 2
3use Psr\Log\LogLevel;
4use Shaarli\Config\ConfigManager;
5use Shaarli\NetscapeBookmarkParser\NetscapeBookmarkParser;
6use Katzgrau\KLogger\Logger;
7
3/** 8/**
4 * Utilities to import and export bookmarks using the Netscape format 9 * Utilities to import and export bookmarks using the Netscape format
10 * TODO: Not static, use a container.
5 */ 11 */
6class NetscapeBookmarkUtils 12class NetscapeBookmarkUtils
7{ 13{
@@ -85,14 +91,14 @@ class NetscapeBookmarkUtils
85 /** 91 /**
86 * Imports Web bookmarks from an uploaded Netscape bookmark dump 92 * Imports Web bookmarks from an uploaded Netscape bookmark dump
87 * 93 *
88 * @param array $post Server $_POST parameters 94 * @param array $post Server $_POST parameters
89 * @param array $files Server $_FILES parameters 95 * @param array $files Server $_FILES parameters
90 * @param LinkDB $linkDb Loaded LinkDB instance 96 * @param LinkDB $linkDb Loaded LinkDB instance
91 * @param string $pagecache Page cache 97 * @param ConfigManager $conf instance
92 * 98 *
93 * @return string Summary of the bookmark import status 99 * @return string Summary of the bookmark import status
94 */ 100 */
95 public static function import($post, $files, $linkDb, $pagecache) 101 public static function import($post, $files, $linkDb, $conf)
96 { 102 {
97 $filename = $files['filetoupload']['name']; 103 $filename = $files['filetoupload']['name'];
98 $filesize = $files['filetoupload']['size']; 104 $filesize = $files['filetoupload']['size'];
@@ -119,10 +125,20 @@ class NetscapeBookmarkUtils
119 $defaultPrivacy = 0; 125 $defaultPrivacy = 0;
120 126
121 $parser = new NetscapeBookmarkParser( 127 $parser = new NetscapeBookmarkParser(
122 true, // nested tag support 128 true, // nested tag support
123 $defaultTags, // additional user-specified tags 129 $defaultTags, // additional user-specified tags
124 strval(1 - $defaultPrivacy) // defaultPub = 1 - defaultPrivacy 130 strval(1 - $defaultPrivacy), // defaultPub = 1 - defaultPrivacy
131 $conf->get('resource.data_dir') // log path, will be overridden
132 );
133 $logger = new Logger(
134 $conf->get('resource.data_dir'),
135 ! $conf->get('dev.debug') ? LogLevel::INFO : LogLevel::DEBUG,
136 [
137 'prefix' => 'import.',
138 'extension' => 'log',
139 ]
125 ); 140 );
141 $parser->setLogger($logger);
126 $bookmarks = $parser->parseString($data); 142 $bookmarks = $parser->parseString($data);
127 143
128 $importCount = 0; 144 $importCount = 0;
@@ -179,7 +195,7 @@ class NetscapeBookmarkUtils
179 $importCount++; 195 $importCount++;
180 } 196 }
181 197
182 $linkDb->save($pagecache); 198 $linkDb->save($conf->get('resource.page_cache'));
183 return self::importStatus( 199 return self::importStatus(
184 $filename, 200 $filename,
185 $filesize, 201 $filesize,
diff --git a/composer.json b/composer.json
index 57851e53..792c43d3 100644
--- a/composer.json
+++ b/composer.json
@@ -11,7 +11,7 @@
11 "keywords": ["bookmark", "link", "share", "web"], 11 "keywords": ["bookmark", "link", "share", "web"],
12 "require": { 12 "require": {
13 "php": ">=5.5", 13 "php": ">=5.5",
14 "shaarli/netscape-bookmark-parser": "1.*", 14 "shaarli/netscape-bookmark-parser": "^2.0",
15 "erusev/parsedown": "1.6", 15 "erusev/parsedown": "1.6",
16 "slim/slim": "^3.0", 16 "slim/slim": "^3.0",
17 "pubsubhubbub/publisher": "dev-master" 17 "pubsubhubbub/publisher": "dev-master"
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..5925a8e1 100644
--- a/tests/NetscapeBookmarkUtils/BookmarkImportTest.php
+++ b/tests/NetscapeBookmarkUtils/BookmarkImportTest.php
@@ -2,6 +2,7 @@
2 2
3require_once 'application/NetscapeBookmarkUtils.php'; 3require_once 'application/NetscapeBookmarkUtils.php';
4 4
5use Shaarli\Config\ConfigManager;
5 6
6/** 7/**
7 * Utility function to load a file's metadata in a $_FILES-like array 8 * Utility function to load a file's metadata in a $_FILES-like array
@@ -43,6 +44,11 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
43 protected $pagecache = 'tests'; 44 protected $pagecache = 'tests';
44 45
45 /** 46 /**
47 * @var ConfigManager instance.
48 */
49 protected $conf;
50
51 /**
46 * @var string Save the current timezone. 52 * @var string Save the current timezone.
47 */ 53 */
48 protected static $defaultTimeZone; 54 protected static $defaultTimeZone;
@@ -65,6 +71,8 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
65 // start with an empty datastore 71 // start with an empty datastore
66 file_put_contents(self::$testDatastore, '<?php /* S7QysKquBQA= */ ?>'); 72 file_put_contents(self::$testDatastore, '<?php /* S7QysKquBQA= */ ?>');
67 $this->linkDb = new LinkDB(self::$testDatastore, true, false); 73 $this->linkDb = new LinkDB(self::$testDatastore, true, false);
74 $this->conf = new ConfigManager('tests/utils/config/configJson');
75 $this->conf->set('resource.page_cache', $this->pagecache);
68 } 76 }
69 77
70 public static function tearDownAfterClass() 78 public static function tearDownAfterClass()
@@ -81,7 +89,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
81 $this->assertEquals( 89 $this->assertEquals(
82 'File empty.htm (0 bytes) has an unknown file format.' 90 'File empty.htm (0 bytes) has an unknown file format.'
83 .' Nothing was imported.', 91 .' Nothing was imported.',
84 NetscapeBookmarkUtils::import(NULL, $files, NULL, NULL) 92 NetscapeBookmarkUtils::import(NULL, $files, NULL, $this->conf)
85 ); 93 );
86 $this->assertEquals(0, count($this->linkDb)); 94 $this->assertEquals(0, count($this->linkDb));
87 } 95 }
@@ -94,7 +102,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
94 $files = file2array('no_doctype.htm'); 102 $files = file2array('no_doctype.htm');
95 $this->assertEquals( 103 $this->assertEquals(
96 'File no_doctype.htm (350 bytes) has an unknown file format. Nothing was imported.', 104 'File no_doctype.htm (350 bytes) has an unknown file format. Nothing was imported.',
97 NetscapeBookmarkUtils::import(NULL, $files, NULL, NULL) 105 NetscapeBookmarkUtils::import(NULL, $files, NULL, $this->conf)
98 ); 106 );
99 $this->assertEquals(0, count($this->linkDb)); 107 $this->assertEquals(0, count($this->linkDb));
100 } 108 }
@@ -108,7 +116,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
108 $this->assertEquals( 116 $this->assertEquals(
109 'File internet_explorer_encoding.htm (356 bytes) was successfully processed:' 117 'File internet_explorer_encoding.htm (356 bytes) was successfully processed:'
110 .' 1 links imported, 0 links overwritten, 0 links skipped.', 118 .' 1 links imported, 0 links overwritten, 0 links skipped.',
111 NetscapeBookmarkUtils::import(array(), $files, $this->linkDb, $this->pagecache) 119 NetscapeBookmarkUtils::import(array(), $files, $this->linkDb, $this->conf)
112 ); 120 );
113 $this->assertEquals(1, count($this->linkDb)); 121 $this->assertEquals(1, count($this->linkDb));
114 $this->assertEquals(0, count_private($this->linkDb)); 122 $this->assertEquals(0, count_private($this->linkDb));
@@ -137,7 +145,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
137 $this->assertEquals( 145 $this->assertEquals(
138 'File netscape_nested.htm (1337 bytes) was successfully processed:' 146 'File netscape_nested.htm (1337 bytes) was successfully processed:'
139 .' 8 links imported, 0 links overwritten, 0 links skipped.', 147 .' 8 links imported, 0 links overwritten, 0 links skipped.',
140 NetscapeBookmarkUtils::import(array(), $files, $this->linkDb, $this->pagecache) 148 NetscapeBookmarkUtils::import(array(), $files, $this->linkDb, $this->conf)
141 ); 149 );
142 $this->assertEquals(8, count($this->linkDb)); 150 $this->assertEquals(8, count($this->linkDb));
143 $this->assertEquals(2, count_private($this->linkDb)); 151 $this->assertEquals(2, count_private($this->linkDb));
@@ -259,7 +267,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
259 $this->assertEquals( 267 $this->assertEquals(
260 'File netscape_basic.htm (482 bytes) was successfully processed:' 268 'File netscape_basic.htm (482 bytes) was successfully processed:'
261 .' 2 links imported, 0 links overwritten, 0 links skipped.', 269 .' 2 links imported, 0 links overwritten, 0 links skipped.',
262 NetscapeBookmarkUtils::import(array(), $files, $this->linkDb, $this->pagecache) 270 NetscapeBookmarkUtils::import(array(), $files, $this->linkDb, $this->conf)
263 ); 271 );
264 272
265 $this->assertEquals(2, count($this->linkDb)); 273 $this->assertEquals(2, count($this->linkDb));
@@ -304,7 +312,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
304 $this->assertEquals( 312 $this->assertEquals(
305 'File netscape_basic.htm (482 bytes) was successfully processed:' 313 'File netscape_basic.htm (482 bytes) was successfully processed:'
306 .' 2 links imported, 0 links overwritten, 0 links skipped.', 314 .' 2 links imported, 0 links overwritten, 0 links skipped.',
307 NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->pagecache) 315 NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf)
308 ); 316 );
309 $this->assertEquals(2, count($this->linkDb)); 317 $this->assertEquals(2, count($this->linkDb));
310 $this->assertEquals(1, count_private($this->linkDb)); 318 $this->assertEquals(1, count_private($this->linkDb));
@@ -348,7 +356,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
348 $this->assertEquals( 356 $this->assertEquals(
349 'File netscape_basic.htm (482 bytes) was successfully processed:' 357 'File netscape_basic.htm (482 bytes) was successfully processed:'
350 .' 2 links imported, 0 links overwritten, 0 links skipped.', 358 .' 2 links imported, 0 links overwritten, 0 links skipped.',
351 NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->pagecache) 359 NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf)
352 ); 360 );
353 $this->assertEquals(2, count($this->linkDb)); 361 $this->assertEquals(2, count($this->linkDb));
354 $this->assertEquals(0, count_private($this->linkDb)); 362 $this->assertEquals(0, count_private($this->linkDb));
@@ -372,7 +380,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
372 $this->assertEquals( 380 $this->assertEquals(
373 'File netscape_basic.htm (482 bytes) was successfully processed:' 381 'File netscape_basic.htm (482 bytes) was successfully processed:'
374 .' 2 links imported, 0 links overwritten, 0 links skipped.', 382 .' 2 links imported, 0 links overwritten, 0 links skipped.',
375 NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->pagecache) 383 NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf)
376 ); 384 );
377 $this->assertEquals(2, count($this->linkDb)); 385 $this->assertEquals(2, count($this->linkDb));
378 $this->assertEquals(2, count_private($this->linkDb)); 386 $this->assertEquals(2, count_private($this->linkDb));
@@ -398,7 +406,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
398 $this->assertEquals( 406 $this->assertEquals(
399 'File netscape_basic.htm (482 bytes) was successfully processed:' 407 'File netscape_basic.htm (482 bytes) was successfully processed:'
400 .' 2 links imported, 0 links overwritten, 0 links skipped.', 408 .' 2 links imported, 0 links overwritten, 0 links skipped.',
401 NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->pagecache) 409 NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf)
402 ); 410 );
403 $this->assertEquals(2, count($this->linkDb)); 411 $this->assertEquals(2, count($this->linkDb));
404 $this->assertEquals(2, count_private($this->linkDb)); 412 $this->assertEquals(2, count_private($this->linkDb));
@@ -418,7 +426,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
418 $this->assertEquals( 426 $this->assertEquals(
419 'File netscape_basic.htm (482 bytes) was successfully processed:' 427 'File netscape_basic.htm (482 bytes) was successfully processed:'
420 .' 2 links imported, 2 links overwritten, 0 links skipped.', 428 .' 2 links imported, 2 links overwritten, 0 links skipped.',
421 NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->pagecache) 429 NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf)
422 ); 430 );
423 $this->assertEquals(2, count($this->linkDb)); 431 $this->assertEquals(2, count($this->linkDb));
424 $this->assertEquals(0, count_private($this->linkDb)); 432 $this->assertEquals(0, count_private($this->linkDb));
@@ -444,7 +452,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
444 $this->assertEquals( 452 $this->assertEquals(
445 'File netscape_basic.htm (482 bytes) was successfully processed:' 453 'File netscape_basic.htm (482 bytes) was successfully processed:'
446 .' 2 links imported, 0 links overwritten, 0 links skipped.', 454 .' 2 links imported, 0 links overwritten, 0 links skipped.',
447 NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->pagecache) 455 NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf)
448 ); 456 );
449 $this->assertEquals(2, count($this->linkDb)); 457 $this->assertEquals(2, count($this->linkDb));
450 $this->assertEquals(0, count_private($this->linkDb)); 458 $this->assertEquals(0, count_private($this->linkDb));
@@ -465,7 +473,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
465 $this->assertEquals( 473 $this->assertEquals(
466 'File netscape_basic.htm (482 bytes) was successfully processed:' 474 'File netscape_basic.htm (482 bytes) was successfully processed:'
467 .' 2 links imported, 2 links overwritten, 0 links skipped.', 475 .' 2 links imported, 2 links overwritten, 0 links skipped.',
468 NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->pagecache) 476 NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf)
469 ); 477 );
470 $this->assertEquals(2, count($this->linkDb)); 478 $this->assertEquals(2, count($this->linkDb));
471 $this->assertEquals(2, count_private($this->linkDb)); 479 $this->assertEquals(2, count_private($this->linkDb));
@@ -489,7 +497,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
489 $this->assertEquals( 497 $this->assertEquals(
490 'File netscape_basic.htm (482 bytes) was successfully processed:' 498 'File netscape_basic.htm (482 bytes) was successfully processed:'
491 .' 2 links imported, 0 links overwritten, 0 links skipped.', 499 .' 2 links imported, 0 links overwritten, 0 links skipped.',
492 NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->pagecache) 500 NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf)
493 ); 501 );
494 $this->assertEquals(2, count($this->linkDb)); 502 $this->assertEquals(2, count($this->linkDb));
495 $this->assertEquals(0, count_private($this->linkDb)); 503 $this->assertEquals(0, count_private($this->linkDb));
@@ -499,7 +507,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
499 $this->assertEquals( 507 $this->assertEquals(
500 'File netscape_basic.htm (482 bytes) was successfully processed:' 508 'File netscape_basic.htm (482 bytes) was successfully processed:'
501 .' 0 links imported, 0 links overwritten, 2 links skipped.', 509 .' 0 links imported, 0 links overwritten, 2 links skipped.',
502 NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->pagecache) 510 NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf)
503 ); 511 );
504 $this->assertEquals(2, count($this->linkDb)); 512 $this->assertEquals(2, count($this->linkDb));
505 $this->assertEquals(0, count_private($this->linkDb)); 513 $this->assertEquals(0, count_private($this->linkDb));
@@ -518,7 +526,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
518 $this->assertEquals( 526 $this->assertEquals(
519 'File netscape_basic.htm (482 bytes) was successfully processed:' 527 'File netscape_basic.htm (482 bytes) was successfully processed:'
520 .' 2 links imported, 0 links overwritten, 0 links skipped.', 528 .' 2 links imported, 0 links overwritten, 0 links skipped.',
521 NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->pagecache) 529 NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf)
522 ); 530 );
523 $this->assertEquals(2, count($this->linkDb)); 531 $this->assertEquals(2, count($this->linkDb));
524 $this->assertEquals(0, count_private($this->linkDb)); 532 $this->assertEquals(0, count_private($this->linkDb));
@@ -545,7 +553,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
545 $this->assertEquals( 553 $this->assertEquals(
546 'File netscape_basic.htm (482 bytes) was successfully processed:' 554 'File netscape_basic.htm (482 bytes) was successfully processed:'
547 .' 2 links imported, 0 links overwritten, 0 links skipped.', 555 .' 2 links imported, 0 links overwritten, 0 links skipped.',
548 NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->pagecache) 556 NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf)
549 ); 557 );
550 $this->assertEquals(2, count($this->linkDb)); 558 $this->assertEquals(2, count($this->linkDb));
551 $this->assertEquals(0, count_private($this->linkDb)); 559 $this->assertEquals(0, count_private($this->linkDb));
@@ -570,7 +578,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
570 $this->assertEquals( 578 $this->assertEquals(
571 'File same_date.htm (453 bytes) was successfully processed:' 579 'File same_date.htm (453 bytes) was successfully processed:'
572 .' 3 links imported, 0 links overwritten, 0 links skipped.', 580 .' 3 links imported, 0 links overwritten, 0 links skipped.',
573 NetscapeBookmarkUtils::import(array(), $files, $this->linkDb, $this->pagecache) 581 NetscapeBookmarkUtils::import(array(), $files, $this->linkDb, $this->conf)
574 ); 582 );
575 $this->assertEquals(3, count($this->linkDb)); 583 $this->assertEquals(3, count($this->linkDb));
576 $this->assertEquals(0, count_private($this->linkDb)); 584 $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": {