aboutsummaryrefslogtreecommitdiffhomepage
path: root/application
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 /application
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…
Diffstat (limited to 'application')
-rw-r--r--application/NetscapeBookmarkUtils.php34
1 files changed, 25 insertions, 9 deletions
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,