2021-09-11 09:57:13 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @brief zoneclearFeedServer, a plugin for Dotclear 2
|
2021-11-06 15:30:19 +00:00
|
|
|
*
|
2021-09-11 09:57:13 +00:00
|
|
|
* @package Dotclear
|
|
|
|
* @subpackage Plugin
|
2021-11-06 15:30:19 +00:00
|
|
|
*
|
2021-09-11 09:57:13 +00:00
|
|
|
* @author Jean-Christian Denis, BG, Pierre Van Glabeke
|
2021-11-06 15:30:19 +00:00
|
|
|
*
|
2021-09-11 09:57:13 +00:00
|
|
|
* @copyright Jean-Christian Denis
|
|
|
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
|
|
|
*/
|
2023-05-07 22:40:58 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Dotclear\Plugin\zoneclearFeedServer;
|
|
|
|
|
|
|
|
use dcCore;
|
|
|
|
use Dotclear\Database\Cursor;
|
|
|
|
use Dotclear\Plugin\activityReport\{
|
|
|
|
Action,
|
|
|
|
ActivityReport,
|
|
|
|
Group
|
|
|
|
};
|
2021-09-11 09:57:13 +00:00
|
|
|
|
2023-05-07 22:40:58 +00:00
|
|
|
/**
|
|
|
|
* Add feeds actions to the plugin activity report.
|
|
|
|
*/
|
|
|
|
class ActivityReportActions
|
2022-12-10 21:20:42 +00:00
|
|
|
{
|
2023-05-07 22:40:58 +00:00
|
|
|
public static function init(): void
|
2022-12-10 21:20:42 +00:00
|
|
|
{
|
2023-05-07 22:40:58 +00:00
|
|
|
$group = new Group(My::id(), My::name());
|
|
|
|
|
|
|
|
$group->add(new Action(
|
|
|
|
'updateFeed',
|
|
|
|
__('Feed properties update'),
|
|
|
|
__('Feed named "%s" point to "%s" has been updated by "%s"'),
|
|
|
|
'zoneclearFeedServerAfterUpdateFeed',
|
|
|
|
function (Cursor $cur, int $id): void {
|
|
|
|
$user = dcCore::app()->auth?->getInfo('user_cn');
|
|
|
|
if (!is_string($user)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$rs = ZoneclearFeedServer::instance()->getFeeds(['feed_id' => $id]);
|
|
|
|
if ($rs->isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$row = new FeedRow($rs);
|
|
|
|
|
2022-12-10 22:27:55 +00:00
|
|
|
$logs = [
|
2023-05-07 22:40:58 +00:00
|
|
|
$row->name,
|
|
|
|
$row->feed,
|
|
|
|
$user,
|
2022-12-10 22:27:55 +00:00
|
|
|
];
|
|
|
|
|
2023-05-07 22:40:58 +00:00
|
|
|
ActivityReport::instance()->addLog(My::id(), 'updateFeed', $logs);
|
2022-12-10 22:27:55 +00:00
|
|
|
}
|
2023-05-07 22:40:58 +00:00
|
|
|
));
|
|
|
|
|
|
|
|
$group->add(new Action(
|
|
|
|
'addFeed',
|
|
|
|
__('Feed creation'),
|
|
|
|
__('A new feed named "%s" point to "%s" was added by "%s"'),
|
|
|
|
'zoneclearFeedServerAfterAddFeed',
|
|
|
|
function (Cursor $cur, int $id): void {
|
|
|
|
$user = dcCore::app()->auth?->getInfo('user_cn');
|
2023-05-12 22:08:46 +00:00
|
|
|
if (!is_string($user)
|
|
|
|
|| !is_string($cur->getField('feed_name'))
|
|
|
|
|| !is_string($cur->getField('feed_feed'))
|
|
|
|
) {
|
2023-05-07 22:40:58 +00:00
|
|
|
return;
|
2022-12-10 22:27:55 +00:00
|
|
|
}
|
2023-05-07 22:40:58 +00:00
|
|
|
$logs = [
|
|
|
|
$cur->getField('feed_name'),
|
|
|
|
$cur->getField('feed_feed'),
|
|
|
|
$user,
|
|
|
|
];
|
|
|
|
|
|
|
|
ActivityReport::instance()->addLog(My::id(), 'addFeed', $logs);
|
2022-12-10 22:27:55 +00:00
|
|
|
}
|
2023-05-07 22:40:58 +00:00
|
|
|
));
|
|
|
|
|
|
|
|
$group->add(new Action(
|
|
|
|
'enableFeed',
|
|
|
|
__('Feed status'),
|
|
|
|
__('Feed named "%s" point to "%s" has been set to "%s"'),
|
|
|
|
'zoneclearFeedServerAfterEnableFeed',
|
|
|
|
function (int $id, bool $enable, int $time): void {
|
|
|
|
$rs = ZoneclearFeedServer::instance()->getFeeds(['feed_id' => $id]);
|
|
|
|
if ($rs->isEmpty()) {
|
|
|
|
return;
|
2022-12-10 22:27:55 +00:00
|
|
|
}
|
2023-05-07 22:40:58 +00:00
|
|
|
$row = new FeedRow($rs);
|
|
|
|
|
|
|
|
$logs = [
|
|
|
|
$row->name,
|
|
|
|
$row->feed,
|
|
|
|
$enable ? 'enabled' : 'disabled',
|
|
|
|
];
|
|
|
|
|
|
|
|
ActivityReport::instance()->addLog(My::id(), 'enableFeed', $logs);
|
2022-12-10 22:27:55 +00:00
|
|
|
}
|
2023-05-07 22:40:58 +00:00
|
|
|
));
|
|
|
|
|
|
|
|
$group->add(new Action(
|
|
|
|
'deleteFeed',
|
|
|
|
__('Feed deletion'),
|
2022-12-10 21:20:42 +00:00
|
|
|
__('Feed named "%s" point to "%s" has been deleted by "%s"'),
|
2023-05-07 22:40:58 +00:00
|
|
|
'zoneclearFeedServerBeforeDeleteFeed',
|
|
|
|
function (int $id): void {
|
|
|
|
$rs = ZoneclearFeedServer::instance()->getFeeds(['feed_id' => $id]);
|
|
|
|
if ($rs->isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$row = new FeedRow($rs);
|
|
|
|
|
|
|
|
$user = dcCore::app()->auth?->getInfo('user_cn');
|
|
|
|
if (!is_string($user)) {
|
|
|
|
return;
|
|
|
|
}
|
2022-12-10 22:27:55 +00:00
|
|
|
|
|
|
|
$logs = [
|
2023-05-07 22:40:58 +00:00
|
|
|
$row->name,
|
|
|
|
$row->feed,
|
|
|
|
$user,
|
2022-12-10 22:27:55 +00:00
|
|
|
];
|
|
|
|
|
2023-05-07 22:40:58 +00:00
|
|
|
ActivityReport::instance()->addLog(My::id(), 'deleteFeed', $logs);
|
2022-12-10 22:27:55 +00:00
|
|
|
}
|
2023-05-07 22:40:58 +00:00
|
|
|
));
|
2022-12-10 22:27:55 +00:00
|
|
|
|
2023-05-07 22:40:58 +00:00
|
|
|
$group->add(new Action(
|
|
|
|
'checkFeedUpdate',
|
|
|
|
__('Check feed update'),
|
|
|
|
__('Feed named "%s" has been updated automatically'),
|
|
|
|
'zoneclearFeedServerAfterCheckFeedUpdate',
|
|
|
|
function (FeedRow $row): void {
|
2022-12-10 22:27:55 +00:00
|
|
|
$logs = [
|
2023-05-07 22:40:58 +00:00
|
|
|
$row->name,
|
2022-12-10 22:27:55 +00:00
|
|
|
];
|
|
|
|
|
2023-05-07 22:40:58 +00:00
|
|
|
ActivityReport::instance()->addLog(My::id(), 'checkFeedUpdate', $logs);
|
2022-12-10 22:27:55 +00:00
|
|
|
}
|
2023-05-07 22:40:58 +00:00
|
|
|
));
|
|
|
|
|
|
|
|
ActivityReport::instance()->groups->add($group);
|
2021-09-11 09:57:13 +00:00
|
|
|
}
|
2021-11-06 15:30:19 +00:00
|
|
|
}
|