aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche/Database.class.php
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2014-03-07 13:26:56 +0100
committerNicolas LÅ“uillet <nicolas@loeuillet.org>2014-03-07 13:26:56 +0100
commitded2c63312c32c85f386d6cd8cd7085d8a9407e9 (patch)
tree4de5518586a1f45a3947d780962f264deaa0482d /inc/poche/Database.class.php
parent25114854b3e6b42c7be5e21a62539d8f23d3a10e (diff)
parentbf79463070c0dc96eacc52a949c1e3ad356817c0 (diff)
downloadwallabag-ded2c63312c32c85f386d6cd8cd7085d8a9407e9.tar.gz
wallabag-ded2c63312c32c85f386d6cd8cd7085d8a9407e9.tar.zst
wallabag-ded2c63312c32c85f386d6cd8cd7085d8a9407e9.zip
Merge pull request #532 from wallabag/upload-file
New import system
Diffstat (limited to 'inc/poche/Database.class.php')
-rwxr-xr-xinc/poche/Database.class.php67
1 files changed, 46 insertions, 21 deletions
diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php
index c998fe14..edc775f5 100755
--- a/inc/poche/Database.class.php
+++ b/inc/poche/Database.class.php
@@ -230,8 +230,30 @@ class Database {
230 } 230 }
231 } 231 }
232 232
233 public function updateContentAndTitle($id, $title, $body, $user_id) {
234 $sql_action = 'UPDATE entries SET content = ?, title = ? WHERE id=? AND user_id=?';
235 $params_action = array($body, $title, $id, $user_id);
236 $query = $this->executeQuery($sql_action, $params_action);
237
238 return $query;
239 }
240
241 public function retrieveUnfetchedEntries($user_id, $limit) {
242
243 $sql_limit = "LIMIT 0,".$limit;
244 if (STORAGE == 'postgres') {
245 $sql_limit = "LIMIT ".$limit." OFFSET 0";
246 }
247
248 $sql = "SELECT * FROM entries WHERE (content = '' OR content IS NULL) AND user_id=? ORDER BY id " . $sql_limit;
249 $query = $this->executeQuery($sql, array($user_id));
250 $entries = $query->fetchAll();
251
252 return $entries;
253 }
254
233 public function retrieveAll($user_id) { 255 public function retrieveAll($user_id) {
234 $sql = "SELECT * FROM entries WHERE user_id=? ORDER BY id"; 256 $sql = "SELECT * FROM entries WHERE content <> '' AND user_id=? ORDER BY id";
235 $query = $this->executeQuery($sql, array($user_id)); 257 $query = $this->executeQuery($sql, array($user_id));
236 $entries = $query->fetchAll(); 258 $entries = $query->fetchAll();
237 259
@@ -250,7 +272,7 @@ class Database {
250 272
251 public function retrieveOneByURL($url, $user_id) { 273 public function retrieveOneByURL($url, $user_id) {
252 $entry = NULL; 274 $entry = NULL;
253 $sql = "SELECT * FROM entries WHERE url=? AND user_id=?"; 275 $sql = "SELECT * FROM entries WHERE content <> '' AND url=? AND user_id=?";
254 $params = array($url, $user_id); 276 $params = array($url, $user_id);
255 $query = $this->executeQuery($sql, $params); 277 $query = $this->executeQuery($sql, $params);
256 $entry = $query->fetchAll(); 278 $entry = $query->fetchAll();
@@ -267,21 +289,22 @@ class Database {
267 public function getEntriesByView($view, $user_id, $limit = '', $tag_id = 0) { 289 public function getEntriesByView($view, $user_id, $limit = '', $tag_id = 0) {
268 switch ($view) { 290 switch ($view) {
269 case 'archive': 291 case 'archive':
270 $sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? "; 292 $sql = "SELECT * FROM entries WHERE content <> '' AND user_id=? AND is_read=? ";
271 $params = array($user_id, 1); 293 $params = array($user_id, 1);
272 break; 294 break;
273 case 'fav' : 295 case 'fav' :
274 $sql = "SELECT * FROM entries WHERE user_id=? AND is_fav=? "; 296 $sql = "SELECT * FROM entries WHERE content <> '' AND user_id=? AND is_fav=? ";
275 $params = array($user_id, 1); 297 $params = array($user_id, 1);
276 break; 298 break;
277 case 'tag' : 299 case 'tag' :
278 $sql = "SELECT entries.* FROM entries 300 $sql = "SELECT entries.* FROM entries
279 LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id 301 LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id
280 WHERE entries.user_id=? AND tags_entries.tag_id = ? "; 302 WHERE entries.content <> '' AND
303 entries.user_id=? AND tags_entries.tag_id = ? ";
281 $params = array($user_id, $tag_id); 304 $params = array($user_id, $tag_id);
282 break; 305 break;
283 default: 306 default:
284 $sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? "; 307 $sql = "SELECT * FROM entries WHERE content <> '' AND user_id=? AND is_read=? ";
285 $params = array($user_id, 0); 308 $params = array($user_id, 0);
286 break; 309 break;
287 } 310 }
@@ -294,24 +317,25 @@ class Database {
294 return $entries; 317 return $entries;
295 } 318 }
296 319
297 public function getEntriesByViewCount($view, $user_id, $tag_id = 0) { 320 public function getEntriesByViewCount($view, $user_id, $tag_id = 0) {
298 switch ($view) { 321 switch ($view) {
299 case 'archive': 322 case 'archive':
300 $sql = "SELECT count(*) FROM entries WHERE user_id=? AND is_read=? "; 323 $sql = "SELECT count(*) FROM entries WHERE content <> '' AND user_id=? AND is_read=? ";
301 $params = array($user_id, 1); 324 $params = array($user_id, 1);
302 break; 325 break;
303 case 'fav' : 326 case 'fav' :
304 $sql = "SELECT count(*) FROM entries WHERE user_id=? AND is_fav=? "; 327 $sql = "SELECT count(*) FROM entries WHERE content <> '' AND user_id=? AND is_fav=? ";
305 $params = array($user_id, 1); 328 $params = array($user_id, 1);
306 break; 329 break;
307 case 'tag' : 330 case 'tag' :
308 $sql = "SELECT count(*) FROM entries 331 $sql = "SELECT count(*) FROM entries
309 LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id 332 LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id
310 WHERE entries.user_id=? AND tags_entries.tag_id = ? "; 333 WHERE entries.content <> '' AND
311 $params = array($user_id, $tag_id); 334 entries.user_id=? AND tags_entries.tag_id = ? ";
312 break; 335 $params = array($user_id, $tag_id);
336 break;
313 default: 337 default:
314 $sql = "SELECT count(*) FROM entries WHERE user_id=? AND is_read=? "; 338 $sql = "SELECT count(*) FROM entries WHERE content <> '' AND user_id=? AND is_read=? ";
315 $params = array($user_id, 0); 339 $params = array($user_id, 0);
316 break; 340 break;
317 } 341 }
@@ -319,7 +343,7 @@ class Database {
319 $query = $this->executeQuery($sql, $params); 343 $query = $this->executeQuery($sql, $params);
320 list($count) = $query->fetch(); 344 list($count) = $query->fetch();
321 345
322 return $count; 346 return $count;
323 } 347 }
324 348
325 public function updateContent($id, $content, $user_id) { 349 public function updateContent($id, $content, $user_id) {
@@ -369,7 +393,7 @@ class Database {
369 $sql = "SELECT DISTINCT tags.* FROM tags 393 $sql = "SELECT DISTINCT tags.* FROM tags
370 LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id 394 LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id
371 LEFT JOIN entries ON tags_entries.entry_id=entries.id 395 LEFT JOIN entries ON tags_entries.entry_id=entries.id
372 WHERE entries.user_id=?"; 396 WHERE entries.content <> '' AND entries.user_id=?";
373 $query = $this->executeQuery($sql, array($user_id)); 397 $query = $this->executeQuery($sql, array($user_id));
374 $tags = $query->fetchAll(); 398 $tags = $query->fetchAll();
375 399
@@ -381,7 +405,7 @@ class Database {
381 $sql = "SELECT DISTINCT tags.* FROM tags 405 $sql = "SELECT DISTINCT tags.* FROM tags
382 LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id 406 LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id
383 LEFT JOIN entries ON tags_entries.entry_id=entries.id 407 LEFT JOIN entries ON tags_entries.entry_id=entries.id
384 WHERE tags.id=? AND entries.user_id=?"; 408 WHERE entries.content <> '' AND tags.id=? AND entries.user_id=?";
385 $params = array(intval($id), $user_id); 409 $params = array(intval($id), $user_id);
386 $query = $this->executeQuery($sql, $params); 410 $query = $this->executeQuery($sql, $params);
387 $tag = $query->fetchAll(); 411 $tag = $query->fetchAll();
@@ -393,7 +417,8 @@ class Database {
393 $sql = 417 $sql =
394 "SELECT entries.* FROM entries 418 "SELECT entries.* FROM entries
395 LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id 419 LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id
396 WHERE tags_entries.tag_id = ? AND entries.user_id=?"; 420 WHERE entries.content <> '' AND
421 tags_entries.tag_id = ? AND entries.user_id=?";
397 $query = $this->executeQuery($sql, array($tag_id, $user_id)); 422 $query = $this->executeQuery($sql, array($tag_id, $user_id));
398 $entries = $query->fetchAll(); 423 $entries = $query->fetchAll();
399 424