aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/NetscapeBookmarkUtils.php
diff options
context:
space:
mode:
authorVirtualTam <virtualtam+github@flibidi.net>2017-10-08 16:35:57 +0200
committerGitHub <noreply@github.com>2017-10-08 16:35:57 +0200
commit9f32160c323e77237e4051056c1f1061586cc12e (patch)
treec8203cd553fa770f2067ce04d30579ee1aa2f60f /application/NetscapeBookmarkUtils.php
parent0a496258af71ab77eacb9e7ccd27471a65b61fa0 (diff)
parent66e74d50d38a6fea8fc904a1746157633de7cc65 (diff)
downloadShaarli-9f32160c323e77237e4051056c1f1061586cc12e.tar.gz
Shaarli-9f32160c323e77237e4051056c1f1061586cc12e.tar.zst
Shaarli-9f32160c323e77237e4051056c1f1061586cc12e.zip
Merge pull request #992 from ArthurHoaro/feature/import-history
Don't write History for link import
Diffstat (limited to 'application/NetscapeBookmarkUtils.php')
-rw-r--r--application/NetscapeBookmarkUtils.php16
1 files changed, 11 insertions, 5 deletions
diff --git a/application/NetscapeBookmarkUtils.php b/application/NetscapeBookmarkUtils.php
index 2a10ff22..31796367 100644
--- a/application/NetscapeBookmarkUtils.php
+++ b/application/NetscapeBookmarkUtils.php
@@ -66,6 +66,7 @@ class NetscapeBookmarkUtils
66 * @param int $importCount how many links were imported 66 * @param int $importCount how many links were imported
67 * @param int $overwriteCount how many links were overwritten 67 * @param int $overwriteCount how many links were overwritten
68 * @param int $skipCount how many links were skipped 68 * @param int $skipCount how many links were skipped
69 * @param int $duration how many seconds did the import take
69 * 70 *
70 * @return string Summary of the bookmark import status 71 * @return string Summary of the bookmark import status
71 */ 72 */
@@ -74,14 +75,16 @@ class NetscapeBookmarkUtils
74 $filesize, 75 $filesize,
75 $importCount=0, 76 $importCount=0,
76 $overwriteCount=0, 77 $overwriteCount=0,
77 $skipCount=0 78 $skipCount=0,
79 $duration=0
78 ) 80 )
79 { 81 {
80 $status = 'File '.$filename.' ('.$filesize.' bytes) '; 82 $status = 'File '.$filename.' ('.$filesize.' bytes) ';
81 if ($importCount == 0 && $overwriteCount == 0 && $skipCount == 0) { 83 if ($importCount == 0 && $overwriteCount == 0 && $skipCount == 0) {
82 $status .= 'has an unknown file format. Nothing was imported.'; 84 $status .= 'has an unknown file format. Nothing was imported.';
83 } else { 85 } else {
84 $status .= 'was successfully processed: '.$importCount.' links imported, '; 86 $status .= 'was successfully processed in '. $duration .' seconds: ';
87 $status .= $importCount.' links imported, ';
85 $status .= $overwriteCount.' links overwritten, '; 88 $status .= $overwriteCount.' links overwritten, ';
86 $status .= $skipCount.' links skipped.'; 89 $status .= $skipCount.' links skipped.';
87 } 90 }
@@ -101,6 +104,7 @@ class NetscapeBookmarkUtils
101 */ 104 */
102 public static function import($post, $files, $linkDb, $conf, $history) 105 public static function import($post, $files, $linkDb, $conf, $history)
103 { 106 {
107 $start = time();
104 $filename = $files['filetoupload']['name']; 108 $filename = $files['filetoupload']['name'];
105 $filesize = $files['filetoupload']['size']; 109 $filesize = $files['filetoupload']['size'];
106 $data = file_get_contents($files['filetoupload']['tmp_name']); 110 $data = file_get_contents($files['filetoupload']['tmp_name']);
@@ -184,7 +188,6 @@ class NetscapeBookmarkUtils
184 $linkDb[$existingLink['id']] = $newLink; 188 $linkDb[$existingLink['id']] = $newLink;
185 $importCount++; 189 $importCount++;
186 $overwriteCount++; 190 $overwriteCount++;
187 $history->updateLink($newLink);
188 continue; 191 continue;
189 } 192 }
190 193
@@ -196,16 +199,19 @@ class NetscapeBookmarkUtils
196 $newLink['shorturl'] = link_small_hash($newLink['created'], $newLink['id']); 199 $newLink['shorturl'] = link_small_hash($newLink['created'], $newLink['id']);
197 $linkDb[$newLink['id']] = $newLink; 200 $linkDb[$newLink['id']] = $newLink;
198 $importCount++; 201 $importCount++;
199 $history->addLink($newLink);
200 } 202 }
201 203
202 $linkDb->save($conf->get('resource.page_cache')); 204 $linkDb->save($conf->get('resource.page_cache'));
205 $history->importLinks();
206
207 $duration = time() - $start;
203 return self::importStatus( 208 return self::importStatus(
204 $filename, 209 $filename,
205 $filesize, 210 $filesize,
206 $importCount, 211 $importCount,
207 $overwriteCount, 212 $overwriteCount,
208 $skipCount 213 $skipCount,
214 $duration
209 ); 215 );
210 } 216 }
211} 217}