-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathEvents.php
35 lines (23 loc) · 808 Bytes
/
Events.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
namespace humhub\modules\deleteposts;
use Yii;
use humhub\models\Setting;
class Events
{
public static function onCronRun($event)
{
$controller = $event->sender;
$controller->stdout("Deleting old Posts... ");
if (Yii::$app->controller->action->id == 'daily') {
$days = '-' . Setting::Get('daysOfStore', 'deleteposts') . ' days';
$kako = date('Y-m-d', strtotime($days, time()));
$posts = \humhub\modules\post\models\Post::find()
->where(['<', 'created_at', $kako])
->all();
foreach ($posts as $post) {
$post->delete();
}
}
$controller->stdout('done.' . PHP_EOL, \yii\helpers\Console::FG_GREEN);
}
}