aboutsummaryrefslogtreecommitdiffhomepage
path: root/application
diff options
context:
space:
mode:
Diffstat (limited to 'application')
-rw-r--r--application/NetscapeBookmarkUtils.php34
-rw-r--r--application/config/ConfigJson.php10
-rw-r--r--application/config/ConfigManager.php6
3 files changed, 38 insertions, 12 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,
diff --git a/application/config/ConfigJson.php b/application/config/ConfigJson.php
index 30908d90..9ef2ef56 100644
--- a/application/config/ConfigJson.php
+++ b/application/config/ConfigJson.php
@@ -21,8 +21,14 @@ class ConfigJson implements ConfigIO
21 $data = str_replace(self::getPhpSuffix(), '', $data); 21 $data = str_replace(self::getPhpSuffix(), '', $data);
22 $data = json_decode($data, true); 22 $data = json_decode($data, true);
23 if ($data === null) { 23 if ($data === null) {
24 $error = json_last_error(); 24 $errorCode = json_last_error();
25 throw new \Exception('An error occurred while parsing JSON file: error code #'. $error); 25 $error = 'An error occurred while parsing JSON configuration file ('. $filepath .'): error code #';
26 $error .= $errorCode. '<br>➜ <code>' . json_last_error_msg() .'</code>';
27 if ($errorCode === JSON_ERROR_SYNTAX) {
28 $error .= '<br>Please check your JSON syntax (without PHP comment tags) using a JSON lint tool such as ';
29 $error .= '<a href="http://jsonlint.com/">jsonlint.com</a>.';
30 }
31 throw new \Exception($error);
26 } 32 }
27 return $data; 33 return $data;
28 } 34 }
diff --git a/application/config/ConfigManager.php b/application/config/ConfigManager.php
index c5eeda08..7bfbfc72 100644
--- a/application/config/ConfigManager.php
+++ b/application/config/ConfigManager.php
@@ -81,7 +81,11 @@ class ConfigManager
81 */ 81 */
82 protected function load() 82 protected function load()
83 { 83 {
84 $this->loadedConfig = $this->configIO->read($this->getConfigFileExt()); 84 try {
85 $this->loadedConfig = $this->configIO->read($this->getConfigFileExt());
86 } catch (\Exception $e) {
87 die($e->getMessage());
88 }
85 $this->setDefaultValues(); 89 $this->setDefaultValues();
86 } 90 }
87 91