-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathEvents.php
More file actions
67 lines (61 loc) · 2.14 KB
/
Events.php
File metadata and controls
67 lines (61 loc) · 2.14 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
namespace sij\humhub\modules\rss;
use Yii;
use yii\helpers\Url;
use yii\helpers\Console;
use humhub\modules\content\models\ContentContainer;
use humhub\modules\content\models\ContentContainerModuleState;
use humhub\modules\space\models\Space;
class Events
{
/**
* Defines what to do if admin menu is initialized.
*
* @param $event
*/
public static function onAdminMenuInit($event)
{
$event->sender->addItem([
'label' => 'RSS',
'url' => Url::to(['/rss/admin']),
'group' => 'manage',
'icon' => '<i class="fa fa-rss"></i>',
'isActive' => (
Yii::$app->controller->module &&
Yii::$app->controller->module->id == 'rss' &&
Yii::$app->controller->id == 'admin'
),
'sortOrder' => 99999,
]);
}
/**
* Tasks on hourly cron job
*
* @param \yii\base\Event $event
*/
public static function onCron($event)
{
try {
Console::stdout("Updating RSS news feeds...\n");
$ccmsEnabled = ContentContainerModuleState::find()->
where(['module_id' => 'rss'])->
andWhere(['module_state' => 1])->
each();
foreach ( $ccmsEnabled as $ccms ) {
$cc = ContentContainer::findOne($ccms->contentcontainer_id);
$space = Space::findOne($cc->pk);
$interval= $space->getSetting('interval', 'rss', 60);
$lastrun= $space->getSetting('lastrun', 'rss', '');
if (! empty($lastrun) && time() < ($interval * 60 + $lastrun))
continue;
$space->setSetting('lastrun', time(), 'rss');
Console::stdout(" Queueing update for space \"" . $space->name . "\"\n");
Yii::$app->queue->push(new jobs\GetFeedUpdates(['space' => $space, 'force' => false]));
}
Console::stdout(Console::renderColoredString("%gdone.%n\n", 1));
} catch (\Throwable $e) {
$event->sender->stderr($e->getMessage()."\n");
Yii::error($e);
}
}
}