refactor model event again

This commit is contained in:
xiaomlove
2024-04-26 03:21:35 +08:00
parent ae29693549
commit 8a44a0a269
12 changed files with 136 additions and 31 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.8.12');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2024-04-25');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2024-04-26');
defined('IN_TRACKER') || define('IN_TRACKER', false);
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
+3 -3
View File
@@ -3114,9 +3114,9 @@ function loggedinorreturn($mainpage = false) {
function deletetorrent($id, $notify = false) {
$idArr = is_array($id) ? $id : [$id];
$torrentInfo = \Nexus\Database\NexusDB::table("torrents")
$torrentInfo = \App\Models\Torrent::query()
->whereIn("id", $idArr)
->get(['id', 'pieces_hash'])
->get()
->KeyBy("id")
;
$torrentRep = new \App\Repositories\TorrentRepository();
@@ -3146,7 +3146,7 @@ function deletetorrent($id, $notify = false) {
$meiliSearchRep->deleteDocuments($idArr);
if (is_int($id)) {
do_action("torrent_delete", $id);
fire_event("torrent_deleted", $id);
fire_event("torrent_deleted", $torrentInfo->get($id));
}
}
+9 -2
View File
@@ -1237,7 +1237,14 @@ function get_snatch_info($torrentId, $userId)
return mysql_fetch_assoc(sql_query(sprintf('select * from snatched where torrentid = %s and userid = %s order by id desc limit 1', $torrentId, $userId)));
}
function fire_event(string $name, int $id): void
function fire_event(string $name, \Illuminate\Database\Eloquent\Model $model, \Illuminate\Database\Eloquent\Model $oldModel = null): void
{
executeCommand("event:fire --name=$name --id=$id", "string", true, false);
$idKey = \Illuminate\Support\Str::random();
$idKeyOld = "";
\Nexus\Database\NexusDB::cache_put($idKey, serialize($model));
if ($oldModel) {
$idKeyOld = \Illuminate\Support\Str::random();
\Nexus\Database\NexusDB::cache_put($idKeyOld, serialize($oldModel));
}
executeCommand("event:fire --name=$name --idKey=$idKey --idKeyOld=$idKeyOld", "string", true, false);
}