tw: fix cleanup function
Signed-off-by: Varun Patil <radialapps@gmail.com>pull/653/head
parent
4b86dc96cc
commit
34dc2263da
|
@ -221,17 +221,22 @@ class TimelineWrite
|
|||
// Begin transaction
|
||||
$this->connection->beginTransaction();
|
||||
|
||||
// Existence clause
|
||||
$clause = 'SELECT 1 FROM *PREFIX*filecache AS f
|
||||
WHERE f.fileid=m.fileid
|
||||
AND f.path NOT LIKE "files_trashbin/%"';
|
||||
|
||||
// Delete all stale records
|
||||
foreach (DELETE_TABLES as $table) {
|
||||
// Query builder doesn't add the table to delete from,
|
||||
// so we use need to use raw SQL here :/
|
||||
$sql = "DELETE m FROM *PREFIX*{$table} m WHERE NOT EXISTS ({$clause})";
|
||||
$this->connection->executeStatement($sql);
|
||||
$query = $this->connection->getQueryBuilder();
|
||||
$clause = $query
|
||||
->select($query->expr()->literal('1'))
|
||||
->from('filecache', 'f')
|
||||
->where($query->expr()->eq('f.fileid', "*PREFIX*{$table}.fileid"))
|
||||
->andWhere($query->expr()->notLike('f.path', $query->expr()->literal('files_trashbin/%')))
|
||||
->getSQL()
|
||||
;
|
||||
|
||||
$query = $this->connection->getQueryBuilder();
|
||||
$query->delete($table)
|
||||
->where($query->createFunction("NOT EXISTS({$clause})"))
|
||||
->executeStatement()
|
||||
;
|
||||
}
|
||||
|
||||
// Commit transaction
|
||||
|
|
Loading…
Reference in New Issue