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
|
// Begin transaction
|
||||||
$this->connection->beginTransaction();
|
$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
|
// Delete all stale records
|
||||||
foreach (DELETE_TABLES as $table) {
|
foreach (DELETE_TABLES as $table) {
|
||||||
// Query builder doesn't add the table to delete from,
|
$query = $this->connection->getQueryBuilder();
|
||||||
// so we use need to use raw SQL here :/
|
$clause = $query
|
||||||
$sql = "DELETE m FROM *PREFIX*{$table} m WHERE NOT EXISTS ({$clause})";
|
->select($query->expr()->literal('1'))
|
||||||
$this->connection->executeStatement($sql);
|
->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
|
// Commit transaction
|
||||||
|
|
Loading…
Reference in New Issue