55 lines
1.1 KiB
PHP
55 lines
1.1 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Undocumented class
|
|
*/
|
|
class stCleanTaskLogTask extends stTask
|
|
{
|
|
const LIMIT = 100;
|
|
|
|
private $criteria = null;
|
|
|
|
public function count(): int
|
|
{
|
|
return TaskLogPeer::doCount($this->getCriteria());
|
|
}
|
|
|
|
public function execute(int $offset): int
|
|
{
|
|
$criteria = $this->getCriteria();
|
|
$criteria->setLimit(self::LIMIT);
|
|
|
|
$logs = TaskLogPeer::doSelect($criteria);
|
|
|
|
if (empty($logs))
|
|
{
|
|
return $this->doCount();
|
|
}
|
|
|
|
foreach ($logs as $log)
|
|
{
|
|
$log->delete();
|
|
$offset++;
|
|
}
|
|
|
|
return $offset;
|
|
}
|
|
|
|
public function finished()
|
|
{
|
|
Propel::getConnection()->executeQuery(sprintf('OPTIMIZE TABLE `%s`', TaskLogPeer::TABLE_NAME));
|
|
}
|
|
|
|
protected function getCriteria(): Criteria
|
|
{
|
|
if (null === $this->criteria)
|
|
{
|
|
$date = new DateTime();
|
|
|
|
$this->criteria = new Criteria();
|
|
$this->criteria->add(TaskLogPeer::CREATED_AT, $date->modify('-5 days')->format('Y-m-d H:i:s'), Criteria::LESS_EQUAL);
|
|
}
|
|
|
|
return $this->criteria;
|
|
}
|
|
} |