cleanupJobs(); $this->cleanupScheduledJobLog(); $this->cleanupAttachments(); } protected function cleanupJobs() { $query = "DELETE FROM `job` WHERE DATE(modified_at) < '".$this->getDate()."' "; $pdo = $this->getEntityManager()->getPDO(); $sth = $pdo->prepare($query); $sth->execute(); } protected function cleanupScheduledJobLog() { $lastTenRecords = "SELECT c.id FROM ( SELECT i1.id FROM scheduled_job_log_record i1 CROSS JOIN scheduled_job_log_record i2 ON ( i1.scheduled_job_id = i2.scheduled_job_id AND i1.id < i2.id ) GROUP BY i1.id HAVING COUNT( * ) <10 ORDER BY i1.created_at DESC ) AS c"; $query = "DELETE FROM `scheduled_job_log_record` WHERE DATE(created_at) < '".$this->getDate()."' AND id NOT IN (".$lastTenRecords.") "; $pdo = $this->getEntityManager()->getPDO(); $sth = $pdo->prepare($query); $sth->execute(); } protected function getDate($format = 'Y-m-d') { $datetime = new \DateTime(); $datetime->modify($this->period); return $datetime->format($format); } protected function cleanupAttachments() { $dateBefore = date('Y-m-d H:i:s', time() - 3600 * 24); $collection = $this->getEntityManager()->getRepository('Attachment')->where(array( 'role' => array( 'Import File', 'Export File' ), 'createdAt<' => $dateBefore ))->limit(0, 100)->find(); foreach ($collection as $e) { $this->getEntityManager()->removeEntity($e); } } }