From bf8b501afdfd10a209996b8dc48c7e2179980b06 Mon Sep 17 00:00:00 2001 From: Sean Rand Date: Sun, 28 Apr 2013 18:56:36 +0200 Subject: [PATCH] Fix update.php failing with MySQL MySQL doesn't support the DELETE syntax introduced in commit 15ffa09. This fixes #298. --- daos/mysql/Items.php | 5 ++--- daos/sqlite/Items.php | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/daos/mysql/Items.php b/daos/mysql/Items.php index 23bba194b9..6ca4397dda 100644 --- a/daos/mysql/Items.php +++ b/daos/mysql/Items.php @@ -150,9 +150,8 @@ public function exists($uid) { * @param DateTime $date date to delete all items older than this value [optional] */ public function cleanup(\DateTime $date = NULL) { - \F3::get('db')->exec('DELETE FROM items WHERE id IN ( - SELECT items.id FROM items LEFT JOIN sources - ON items.source=sources.id WHERE sources.id IS NULL)'); + \F3::get('db')->exec('DELETE FROM items USING items LEFT JOIN sources + ON items.source=sources.id WHERE sources.id IS NULL'); if ($date !== NULL) \F3::get('db')->exec('DELETE FROM items WHERE starred=0 AND datetime<:date', array(':date' => $date->format('Y-m-d').' 00:00:00')); diff --git a/daos/sqlite/Items.php b/daos/sqlite/Items.php index 20117e46e6..d5a1e4e5cc 100644 --- a/daos/sqlite/Items.php +++ b/daos/sqlite/Items.php @@ -13,4 +13,20 @@ */ // class Items extends Database { class Items extends \daos\mysql\Items { + + /** + * cleanup orphaned and old items + * + * @return void + * @param DateTime $date date to delete all items older than this value [optional] + */ + public function cleanup(\DateTime $date = NULL) { + \F3::get('db')->exec('DELETE FROM items WHERE id IN ( + SELECT items.id FROM items LEFT JOIN sources + ON items.source=sources.id WHERE sources.id IS NULL)'); + if ($date !== NULL) + \F3::get('db')->exec('DELETE FROM items WHERE starred=0 AND datetime<:date', + array(':date' => $date->format('Y-m-d').' 00:00:00')); + } + }