diff options
author | VirtualTam <virtualtam@flibidi.net> | 2016-10-20 21:19:51 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2016-11-05 14:30:13 +0100 |
commit | 72ccf0723c419618b2b6a822721628a9188bcbf0 (patch) | |
tree | af7399b7222b08132635900b235990aba3d115fd | |
parent | 9098432441bc836f571bdc3cc5f307942fdd3c13 (diff) | |
download | Shaarli-72ccf0723c419618b2b6a822721628a9188bcbf0.tar.gz Shaarli-72ccf0723c419618b2b6a822721628a9188bcbf0.tar.zst Shaarli-72ccf0723c419618b2b6a822721628a9188bcbf0.zip |
LinkDB: update datastore method names
Relates to https://github.com/shaarli/Shaarli/issues/95
Signed-off-by: VirtualTam <virtualtam@flibidi.net>
-rw-r--r-- | application/LinkDB.php | 16 | ||||
-rw-r--r-- | application/NetscapeBookmarkUtils.php | 2 | ||||
-rw-r--r-- | application/Updater.php | 2 | ||||
-rw-r--r-- | index.php | 8 | ||||
-rw-r--r-- | tests/LinkDBTest.php | 8 |
5 files changed, 18 insertions, 18 deletions
diff --git a/application/LinkDB.php b/application/LinkDB.php index 2d42c514..f5f209f6 100644 --- a/application/LinkDB.php +++ b/application/LinkDB.php | |||
@@ -100,8 +100,8 @@ class LinkDB implements Iterator, Countable, ArrayAccess | |||
100 | $this->hidePublicLinks = $hidePublicLinks; | 100 | $this->hidePublicLinks = $hidePublicLinks; |
101 | $this->redirector = $redirector; | 101 | $this->redirector = $redirector; |
102 | $this->redirectorEncode = $redirectorEncode === true; | 102 | $this->redirectorEncode = $redirectorEncode === true; |
103 | $this->checkDB(); | 103 | $this->check(); |
104 | $this->readDB(); | 104 | $this->read(); |
105 | } | 105 | } |
106 | 106 | ||
107 | /** | 107 | /** |
@@ -210,7 +210,7 @@ class LinkDB implements Iterator, Countable, ArrayAccess | |||
210 | * | 210 | * |
211 | * If no DB file is found, creates a dummy DB. | 211 | * If no DB file is found, creates a dummy DB. |
212 | */ | 212 | */ |
213 | private function checkDB() | 213 | private function check() |
214 | { | 214 | { |
215 | if (file_exists($this->datastore)) { | 215 | if (file_exists($this->datastore)) { |
216 | return; | 216 | return; |
@@ -243,13 +243,13 @@ You use the community supported version of the original Shaarli project, by Seba | |||
243 | $this->links[$link['linkdate']] = $link; | 243 | $this->links[$link['linkdate']] = $link; |
244 | 244 | ||
245 | // Write database to disk | 245 | // Write database to disk |
246 | $this->writeDB(); | 246 | $this->write(); |
247 | } | 247 | } |
248 | 248 | ||
249 | /** | 249 | /** |
250 | * Reads database from disk to memory | 250 | * Reads database from disk to memory |
251 | */ | 251 | */ |
252 | private function readDB() | 252 | private function read() |
253 | { | 253 | { |
254 | 254 | ||
255 | // Public links are hidden and user not logged in => nothing to show | 255 | // Public links are hidden and user not logged in => nothing to show |
@@ -315,7 +315,7 @@ You use the community supported version of the original Shaarli project, by Seba | |||
315 | * | 315 | * |
316 | * @throws IOException the datastore is not writable | 316 | * @throws IOException the datastore is not writable |
317 | */ | 317 | */ |
318 | private function writeDB() | 318 | private function write() |
319 | { | 319 | { |
320 | if (is_file($this->datastore) && !is_writeable($this->datastore)) { | 320 | if (is_file($this->datastore) && !is_writeable($this->datastore)) { |
321 | // The datastore exists but is not writeable | 321 | // The datastore exists but is not writeable |
@@ -337,14 +337,14 @@ You use the community supported version of the original Shaarli project, by Seba | |||
337 | * | 337 | * |
338 | * @param string $pageCacheDir page cache directory | 338 | * @param string $pageCacheDir page cache directory |
339 | */ | 339 | */ |
340 | public function savedb($pageCacheDir) | 340 | public function save($pageCacheDir) |
341 | { | 341 | { |
342 | if (!$this->loggedIn) { | 342 | if (!$this->loggedIn) { |
343 | // TODO: raise an Exception instead | 343 | // TODO: raise an Exception instead |
344 | die('You are not authorized to change the database.'); | 344 | die('You are not authorized to change the database.'); |
345 | } | 345 | } |
346 | 346 | ||
347 | $this->writeDB(); | 347 | $this->write(); |
348 | 348 | ||
349 | invalidateCaches($pageCacheDir); | 349 | invalidateCaches($pageCacheDir); |
350 | } | 350 | } |
diff --git a/application/NetscapeBookmarkUtils.php b/application/NetscapeBookmarkUtils.php index d6840d37..dd21f05b 100644 --- a/application/NetscapeBookmarkUtils.php +++ b/application/NetscapeBookmarkUtils.php | |||
@@ -183,7 +183,7 @@ class NetscapeBookmarkUtils | |||
183 | $importCount++; | 183 | $importCount++; |
184 | } | 184 | } |
185 | 185 | ||
186 | $linkDb->savedb($pagecache); | 186 | $linkDb->save($pagecache); |
187 | return self::importStatus( | 187 | return self::importStatus( |
188 | $filename, | 188 | $filename, |
189 | $filesize, | 189 | $filesize, |
diff --git a/application/Updater.php b/application/Updater.php index 90913235..36eddd4f 100644 --- a/application/Updater.php +++ b/application/Updater.php | |||
@@ -143,7 +143,7 @@ class Updater | |||
143 | $link['tags'] = implode(' ', array_unique(LinkFilter::tagsStrToArray($link['tags'], true))); | 143 | $link['tags'] = implode(' ', array_unique(LinkFilter::tagsStrToArray($link['tags'], true))); |
144 | $this->linkDB[$link['linkdate']] = $link; | 144 | $this->linkDB[$link['linkdate']] = $link; |
145 | } | 145 | } |
146 | $this->linkDB->savedb($this->conf->get('resource.page_cache')); | 146 | $this->linkDB->save($this->conf->get('resource.page_cache')); |
147 | return true; | 147 | return true; |
148 | } | 148 | } |
149 | 149 | ||
@@ -1211,7 +1211,7 @@ function renderPage($conf, $pluginManager) | |||
1211 | $value['tags']=trim(implode(' ',$tags)); | 1211 | $value['tags']=trim(implode(' ',$tags)); |
1212 | $LINKSDB[$key]=$value; | 1212 | $LINKSDB[$key]=$value; |
1213 | } | 1213 | } |
1214 | $LINKSDB->savedb($conf->get('resource.page_cache')); | 1214 | $LINKSDB->save($conf->get('resource.page_cache')); |
1215 | echo '<script>alert("Tag was removed from '.count($linksToAlter).' links.");document.location=\'?\';</script>'; | 1215 | echo '<script>alert("Tag was removed from '.count($linksToAlter).' links.");document.location=\'?\';</script>'; |
1216 | exit; | 1216 | exit; |
1217 | } | 1217 | } |
@@ -1228,7 +1228,7 @@ function renderPage($conf, $pluginManager) | |||
1228 | $value['tags']=trim(implode(' ',$tags)); | 1228 | $value['tags']=trim(implode(' ',$tags)); |
1229 | $LINKSDB[$key]=$value; | 1229 | $LINKSDB[$key]=$value; |
1230 | } | 1230 | } |
1231 | $LINKSDB->savedb($conf->get('resource.page_cache')); // Save to disk. | 1231 | $LINKSDB->save($conf->get('resource.page_cache')); // Save to disk. |
1232 | echo '<script>alert("Tag was renamed in '.count($linksToAlter).' links.");document.location=\'?searchtags='.urlencode($_POST['totag']).'\';</script>'; | 1232 | echo '<script>alert("Tag was renamed in '.count($linksToAlter).' links.");document.location=\'?searchtags='.urlencode($_POST['totag']).'\';</script>'; |
1233 | exit; | 1233 | exit; |
1234 | } | 1234 | } |
@@ -1283,7 +1283,7 @@ function renderPage($conf, $pluginManager) | |||
1283 | $pluginManager->executeHooks('save_link', $link); | 1283 | $pluginManager->executeHooks('save_link', $link); |
1284 | 1284 | ||
1285 | $LINKSDB[$linkdate] = $link; | 1285 | $LINKSDB[$linkdate] = $link; |
1286 | $LINKSDB->savedb($conf->get('resource.page_cache')); | 1286 | $LINKSDB->save($conf->get('resource.page_cache')); |
1287 | pubsubhub($conf); | 1287 | pubsubhub($conf); |
1288 | 1288 | ||
1289 | // If we are called from the bookmarklet, we must close the popup: | 1289 | // If we are called from the bookmarklet, we must close the popup: |
@@ -1325,7 +1325,7 @@ function renderPage($conf, $pluginManager) | |||
1325 | $pluginManager->executeHooks('delete_link', $LINKSDB[$linkdate]); | 1325 | $pluginManager->executeHooks('delete_link', $LINKSDB[$linkdate]); |
1326 | 1326 | ||
1327 | unset($LINKSDB[$linkdate]); | 1327 | unset($LINKSDB[$linkdate]); |
1328 | $LINKSDB->savedb('resource.page_cache'); // save to disk | 1328 | $LINKSDB->save('resource.page_cache'); // save to disk |
1329 | 1329 | ||
1330 | // If we are called from the bookmarklet, we must close the popup: | 1330 | // If we are called from the bookmarklet, we must close the popup: |
1331 | if (isset($_GET['source']) && ($_GET['source']=='bookmarklet' || $_GET['source']=='firefoxsocialapi')) { echo '<script>self.close();</script>'; exit; } | 1331 | if (isset($_GET['source']) && ($_GET['source']=='bookmarklet' || $_GET['source']=='firefoxsocialapi')) { echo '<script>self.close();</script>'; exit; } |
diff --git a/tests/LinkDBTest.php b/tests/LinkDBTest.php index 43652e72..9d79386c 100644 --- a/tests/LinkDBTest.php +++ b/tests/LinkDBTest.php | |||
@@ -117,7 +117,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
117 | unlink(self::$testDatastore); | 117 | unlink(self::$testDatastore); |
118 | $this->assertFileNotExists(self::$testDatastore); | 118 | $this->assertFileNotExists(self::$testDatastore); |
119 | 119 | ||
120 | $checkDB = self::getMethod('checkDB'); | 120 | $checkDB = self::getMethod('check'); |
121 | $checkDB->invokeArgs($linkDB, array()); | 121 | $checkDB->invokeArgs($linkDB, array()); |
122 | $this->assertFileExists(self::$testDatastore); | 122 | $this->assertFileExists(self::$testDatastore); |
123 | 123 | ||
@@ -134,7 +134,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
134 | $datastoreSize = filesize(self::$testDatastore); | 134 | $datastoreSize = filesize(self::$testDatastore); |
135 | $this->assertGreaterThan(0, $datastoreSize); | 135 | $this->assertGreaterThan(0, $datastoreSize); |
136 | 136 | ||
137 | $checkDB = self::getMethod('checkDB'); | 137 | $checkDB = self::getMethod('check'); |
138 | $checkDB->invokeArgs($linkDB, array()); | 138 | $checkDB->invokeArgs($linkDB, array()); |
139 | 139 | ||
140 | // ensure the datastore is left unmodified | 140 | // ensure the datastore is left unmodified |
@@ -180,7 +180,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
180 | /** | 180 | /** |
181 | * Save the links to the DB | 181 | * Save the links to the DB |
182 | */ | 182 | */ |
183 | public function testSaveDB() | 183 | public function testSave() |
184 | { | 184 | { |
185 | $testDB = new LinkDB(self::$testDatastore, true, false); | 185 | $testDB = new LinkDB(self::$testDatastore, true, false); |
186 | $dbSize = sizeof($testDB); | 186 | $dbSize = sizeof($testDB); |
@@ -194,7 +194,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
194 | 'tags'=>'unit test' | 194 | 'tags'=>'unit test' |
195 | ); | 195 | ); |
196 | $testDB[$link['linkdate']] = $link; | 196 | $testDB[$link['linkdate']] = $link; |
197 | $testDB->savedb('tests'); | 197 | $testDB->save('tests'); |
198 | 198 | ||
199 | $testDB = new LinkDB(self::$testDatastore, true, false); | 199 | $testDB = new LinkDB(self::$testDatastore, true, false); |
200 | $this->assertEquals($dbSize + 1, sizeof($testDB)); | 200 | $this->assertEquals($dbSize + 1, sizeof($testDB)); |