This commit refactors the method processTaskStrategy() of some SimpleWorker child classes to use Doctrine instead of Paris. In this commit are included all the classes that it was only necessary to change the method signature as they were receiving a ScheduledTask object as the first parameter but didn't use it. Now they receive a ScheduledTaskEntity object as the first param. [MAILPOET-3843]
29 lines
844 B
PHP
29 lines
844 B
PHP
<?php
|
|
|
|
namespace MailPoet\Cron\Workers;
|
|
|
|
use MailPoet\Entities\ScheduledTaskEntity;
|
|
use MailPoet\Subscribers\ImportExport\Export\Export;
|
|
use MailPoetVendor\Carbon\Carbon;
|
|
|
|
class ExportFilesCleanup extends SimpleWorker {
|
|
const TASK_TYPE = 'export_files_cleanup';
|
|
const DELETE_FILES_AFTER_X_DAYS = 1;
|
|
|
|
public function processTaskStrategy(ScheduledTaskEntity $task, $timer) {
|
|
$iterator = new \GlobIterator(Export::getExportPath() . '/' . Export::getFilePrefix() . '*.*');
|
|
foreach ($iterator as $file) {
|
|
if (is_string($file)) {
|
|
continue;
|
|
}
|
|
$name = $file->getPathname();
|
|
$created = $file->getMTime();
|
|
$now = new Carbon();
|
|
if (Carbon::createFromTimestamp((int)$created)->lessThan($now->subDays(self::DELETE_FILES_AFTER_X_DAYS))) {
|
|
unlink($name);
|
|
};
|
|
}
|
|
return true;
|
|
}
|
|
}
|