Skip to content

Commit

Permalink
add event news_created
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaomlove committed Apr 2, 2024
1 parent 4ad0d7a commit 8d07ad9
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 4 deletions.
2 changes: 2 additions & 0 deletions app/Console/Commands/FireEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Console\Commands;

use App\Events\NewsCreated;
use App\Events\TorrentCreated;
use App\Events\UserDestroyed;
use App\Events\UserDisabled;
Expand Down Expand Up @@ -29,6 +30,7 @@ class FireEvent extends Command
"user_destroyed" => UserDestroyed::class,
"user_disabled" => UserDisabled::class,
"user_enabled" => UserEnabled::class,
"news_created" => NewsCreated::class,
];

/**
Expand Down
38 changes: 38 additions & 0 deletions app/Events/NewsCreated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class NewsCreated
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public int $id;

/**
* Create a new event instance.
*
* @return void
*/
public function __construct(int $id)
{
$this->id = $id;
}

/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('channel-name');
}
}
2 changes: 1 addition & 1 deletion app/Repositories/TorrentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ public function getPiecesHashCache($piecesHash): array
if (is_array($arr) && isset($arr['torrent_id'], $arr['pieces_hash'])) {
$out[$arr['pieces_hash']] = $arr['torrent_id'];
} else {
do_log(sprintf("%s, invalid item: %s(%s)", $logPrefix, var_export($item, true), gettype($item)), 'error');
do_log(sprintf("%s, invalid item: %s(%s)", $logPrefix, var_export($item, true), gettype($item)));
}
}
return $out;
Expand Down
2 changes: 1 addition & 1 deletion include/constants.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.8.12');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2024-04-01');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2024-04-03');
defined('IN_TRACKER') || define('IN_TRACKER', false);
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
Expand Down
6 changes: 4 additions & 2 deletions public/news.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@
$notify = 'no';
sql_query("INSERT INTO news (userid, added, body, title, notify) VALUES (".sqlesc($CURUSER['id']) . ", $added, " . sqlesc($body) . ", " . sqlesc($title) . ", " . sqlesc($notify).")") or sqlerr(__FILE__, __LINE__);
$Cache->delete_value('recent_news',true);
if (mysql_affected_rows() != 1)
stderr($lang_news['std_error'], $lang_news['std_something_weird_happened']);
if (mysql_affected_rows() != 1) {
stderr($lang_news['std_error'], $lang_news['std_something_weird_happened']);
}
fire_event("news_created", mysql_insert_id());
header("Location: " . get_protocol_prefix() . "$BASEURL/index.php");
}

Expand Down

0 comments on commit 8d07ad9

Please sign in to comment.