181 : void
182 {
183 if ($this->db->tableExists(self::TABLE_VALUE_TO_TASK)) {
184 $this->db->manipulate(
185 'DELETE vt FROM ' . self::TABLE_VALUE_TO_TASK . ' vt'
186 . ' LEFT JOIN ' . self::TABLE_BUCKET . ' b ON b.id = vt.bucket_id'
187 . ' LEFT JOIN ' . self::TABLE_TASK . ' t ON t.id = vt.task_id'
188 . ' LEFT JOIN ' . self::TABLE_VALUE . ' v ON v.id = vt.value_id'
189 . ' WHERE b.id IS NULL OR t.id IS NULL OR v.id IS NULL'
190 );
191 }
192
193 if ($this->db->tableExists(self::TABLE_VALUE)) {
194 $this->db->manipulate(
195 'UPDATE ' . self::TABLE_VALUE
196 . ' SET parent_task_id = NULL'
197 . ' WHERE parent_task_id = 0 OR has_parent_task = 0'
198 );
199
200 $this->db->manipulate(
201 'DELETE v FROM ' . self::TABLE_VALUE . ' v'
202 . ' LEFT JOIN ' . self::TABLE_BUCKET . ' b ON b.id = v.bucket_id'
203 . ' WHERE b.id IS NULL'
204 );
205
206 $this->db->manipulate(
207 'DELETE v FROM ' . self::TABLE_VALUE . ' v'
208 . ' LEFT JOIN ' . self::TABLE_TASK . ' t ON t.id = v.parent_task_id'
209 . ' WHERE v.parent_task_id IS NOT NULL AND t.id IS NULL'
210 );
211 }
212
213 if ($this->db->tableExists(self::TABLE_TASK)) {
214 $this->db->manipulate(
215 'DELETE t FROM ' . self::TABLE_TASK . ' t'
216 . ' LEFT JOIN ' . self::TABLE_BUCKET . ' b ON b.id = t.bucket_id'
217 . ' WHERE b.id IS NULL'
218 );
219 }
220
221 if ($this->db->tableExists(self::TABLE_BUCKET)) {
222 $this->db->manipulate(
223 'UPDATE ' . self::TABLE_BUCKET . ' b'
224 . ' LEFT JOIN ' . self::TABLE_TASK . ' rt ON rt.id = b.root_task_id'
225 . ' SET b.root_task_id = NULL'
226 . ' WHERE b.root_task_id IS NOT NULL AND b.root_task_id != 0 AND rt.id IS NULL'
227 );
228
229 $this->db->manipulate(
230 'UPDATE ' . self::TABLE_BUCKET . ' b'
231 . ' LEFT JOIN ' . self::TABLE_TASK . ' ct ON ct.id = b.current_task_id'
232 . ' SET b.current_task_id = NULL'
233 . ' WHERE b.current_task_id IS NOT NULL AND b.current_task_id != 0 AND ct.id IS NULL'
234 );
235 }
236 }