aboutsummaryrefslogtreecommitdiffhomepage
path: root/application
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2017-02-09 20:54:56 +0100
committerArthurHoaro <arthur@hoa.ro>2017-03-10 18:46:53 +0100
commit48417aed1d83f1566c039529faf0354ec3b42e4b (patch)
tree60a6a584e1ee868165d97d2a9d51a546c720abbb /application
parent844021ab4c0d3dd6c26704648a736fa53244c914 (diff)
downloadShaarli-48417aed1d83f1566c039529faf0354ec3b42e4b.tar.gz
Shaarli-48417aed1d83f1566c039529faf0354ec3b42e4b.tar.zst
Shaarli-48417aed1d83f1566c039529faf0354ec3b42e4b.zip
Link imports are now logged in `data/` folder, and can be debug using `dev.debug=true` setting
related to #741 and #681
Diffstat (limited to 'application')
-rw-r--r--application/NetscapeBookmarkUtils.php33
1 files changed, 24 insertions, 9 deletions
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,