improve approval notify

This commit is contained in:
xiaomlove
2022-06-18 23:17:34 +08:00
parent 88a92f745d
commit 00d7dc6c37
2 changed files with 15 additions and 12 deletions
+3 -10
View File
@@ -33,19 +33,12 @@ class TorrentOperationLog extends NexusModel
} }
public static function add(array $params) public static function add(array $params, $notifyUser = false)
{ {
$log = self::query()->create($params); $log = self::query()->create($params);
$notifyActionTypes = [ if ($notifyUser) {
self::ACTION_TYPE_APPROVAL_ALLOW, self::notifyUser($log);
self::ACTION_TYPE_APPROVAL_DENY,
self::ACTION_TYPE_APPROVAL_NONE,
];
if (!in_array($params['action_type'], $notifyActionTypes)) {
do_log("actionType: {$params['action_type']}, do not notify");
return $log;
} }
self::notifyUser($log);
return $log; return $log;
} }
+12 -2
View File
@@ -479,24 +479,34 @@ class TorrentRepository extends BaseRepository
} }
$torrentUpdate = $torrentOperationLog = []; $torrentUpdate = $torrentOperationLog = [];
$torrentUpdate['approval_status'] = $params['approval_status']; $torrentUpdate['approval_status'] = $params['approval_status'];
$notifyUser = false;
if ($params['approval_status'] == Torrent::APPROVAL_STATUS_ALLOW) { if ($params['approval_status'] == Torrent::APPROVAL_STATUS_ALLOW) {
$torrentUpdate['banned'] = 'no'; $torrentUpdate['banned'] = 'no';
$torrentUpdate['visible'] = 'yes'; $torrentUpdate['visible'] = 'yes';
if ($torrent->approval_status != $params['approval_status']) { if ($torrent->approval_status != $params['approval_status']) {
$torrentOperationLog['action_type'] = TorrentOperationLog::ACTION_TYPE_APPROVAL_ALLOW; $torrentOperationLog['action_type'] = TorrentOperationLog::ACTION_TYPE_APPROVAL_ALLOW;
} }
if ($torrent->approval_status == Torrent::APPROVAL_STATUS_DENY) {
$notifyUser = true;
}
} elseif ($params['approval_status'] == Torrent::APPROVAL_STATUS_DENY) { } elseif ($params['approval_status'] == Torrent::APPROVAL_STATUS_DENY) {
$torrentUpdate['banned'] = 'yes'; $torrentUpdate['banned'] = 'yes';
$torrentUpdate['visible'] = 'no'; $torrentUpdate['visible'] = 'no';
if ($torrent->approval_status != $params['approval_status']) { if ($torrent->approval_status != $params['approval_status']) {
$torrentOperationLog['action_type'] = TorrentOperationLog::ACTION_TYPE_APPROVAL_DENY; $torrentOperationLog['action_type'] = TorrentOperationLog::ACTION_TYPE_APPROVAL_DENY;
} }
if ($torrent->approval_status == Torrent::APPROVAL_STATUS_ALLOW) {
$notifyUser = true;
}
} elseif ($params['approval_status'] == Torrent::APPROVAL_STATUS_NONE) { } elseif ($params['approval_status'] == Torrent::APPROVAL_STATUS_NONE) {
$torrentUpdate['banned'] = 'no'; $torrentUpdate['banned'] = 'no';
$torrentUpdate['visible'] = 'yes'; $torrentUpdate['visible'] = 'yes';
if ($torrent->approval_status != $params['approval_status']) { if ($torrent->approval_status != $params['approval_status']) {
$torrentOperationLog['action_type'] = TorrentOperationLog::ACTION_TYPE_APPROVAL_NONE; $torrentOperationLog['action_type'] = TorrentOperationLog::ACTION_TYPE_APPROVAL_NONE;
} }
if ($torrent->approval_status == Torrent::APPROVAL_STATUS_DENY) {
$notifyUser = true;
}
} else { } else {
throw new \InvalidArgumentException("Invalid approval_status: " . $params['approval_status']); throw new \InvalidArgumentException("Invalid approval_status: " . $params['approval_status']);
} }
@@ -506,7 +516,7 @@ class TorrentRepository extends BaseRepository
$torrentOperationLog['comment'] = $params['comment'] ?? ''; $torrentOperationLog['comment'] = $params['comment'] ?? '';
} }
NexusDB::transaction(function () use ($torrent, $torrentOperationLog, $torrentUpdate) { NexusDB::transaction(function () use ($torrent, $torrentOperationLog, $torrentUpdate, $notifyUser) {
$log = "torrent: " . $torrent->id; $log = "torrent: " . $torrent->id;
if (!empty($torrentUpdate)) { if (!empty($torrentUpdate)) {
$log .= "[UPDATE_TORRENT]: " . nexus_json_encode($torrentUpdate); $log .= "[UPDATE_TORRENT]: " . nexus_json_encode($torrentUpdate);
@@ -514,7 +524,7 @@ class TorrentRepository extends BaseRepository
} }
if (!empty($torrentOperationLog)) { if (!empty($torrentOperationLog)) {
$log .= "[ADD_TORRENT_OPERATION_LOG]: " . nexus_json_encode($torrentOperationLog); $log .= "[ADD_TORRENT_OPERATION_LOG]: " . nexus_json_encode($torrentOperationLog);
TorrentOperationLog::add($torrentOperationLog); TorrentOperationLog::add($torrentOperationLog, $notifyUser);
} }
do_log($log); do_log($log);
}); });