mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-15 21:41:03 +08:00
buy torrent add lock for update + improve disabled func check
This commit is contained in:
@@ -254,10 +254,14 @@ class BonusRepository extends BaseRepository
|
||||
|
||||
public function consumeToBuyTorrent($uid, $torrentId, $channel = 'Web'): bool
|
||||
{
|
||||
$user = User::query()->findOrFail($uid);
|
||||
$torrent = Torrent::query()->findOrFail($torrentId, Torrent::$commentFields);
|
||||
$requireBonus = $torrent->price;
|
||||
NexusDB::transaction(function () use ($user, $requireBonus, $torrent, $channel) {
|
||||
NexusDB::transaction(function () use ($requireBonus, $torrent, $channel, $uid) {
|
||||
$userQuery = User::query();
|
||||
if ($requireBonus > 0) {
|
||||
$userQuery = $userQuery->lockForUpdate();
|
||||
}
|
||||
$user = $userQuery->findOrFail($uid);
|
||||
$comment = nexus_trans('bonus.comment_buy_torrent', [
|
||||
'bonus' => $requireBonus,
|
||||
'torrent_id' => $torrent->id,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.8.4');
|
||||
defined('RELEASE_DATE') || define('RELEASE_DATE', '2023-06-01');
|
||||
defined('RELEASE_DATE') || define('RELEASE_DATE', '2023-06-02');
|
||||
defined('IN_TRACKER') || define('IN_TRACKER', false);
|
||||
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
|
||||
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
|
||||
|
||||
@@ -32,13 +32,11 @@ class Install
|
||||
'UID_STARTS',
|
||||
];
|
||||
|
||||
protected array $requiredExtensions = ['ctype', 'curl', 'fileinfo', 'json', 'mbstring', 'openssl', 'pdo_mysql', 'tokenizer', 'xml', 'mysqli', 'bcmath', 'redis', 'gd', 'gmp', 'Zend OPcache'];
|
||||
protected array $requiredExtensions = ['ctype', 'curl', 'fileinfo', 'json', 'mbstring', 'openssl', 'pdo_mysql', 'tokenizer', 'xml', 'mysqli', 'bcmath', 'redis', 'gd', 'gmp', 'Zend OPcache', 'pcntl', 'posix', 'sockets'];
|
||||
protected array $optionalExtensions = [
|
||||
['name' => 'pcntl', 'desc' => "If use Octane and 'Current' showing 0, make sure it's on php -m"],
|
||||
['name' => 'posix', 'desc' => "If use Octane and 'Current' showing 0, make sure it's on php -m"],
|
||||
['name' => 'sockets', 'desc' => "If use roadrunner for Octane, make sure 'current' shows 1"],
|
||||
['name' => 'swoole', 'desc' => "If use swoole for Octane, make sure 'current' shows 1"],
|
||||
// ['name' => 'swoole', 'desc' => "If use swoole for Octane, make sure 'current' shows 1"],
|
||||
];
|
||||
protected array $requiredFunctions = ['symlink', 'putenv', 'proc_open', 'proc_get_status', 'exec', 'pcntl_signal', 'pcntl_alarm', 'pcntl_async_signals'];
|
||||
|
||||
protected string $lockFile = 'install.lock';
|
||||
|
||||
@@ -165,9 +163,8 @@ class Install
|
||||
'result' => $this->yesOrNo(version_compare(PHP_VERSION, $this->minimumPhpVersion, '>=')),
|
||||
];
|
||||
|
||||
$requiredFunctions = ['symlink', 'putenv', 'proc_open', 'proc_get_status', 'exec'];
|
||||
$disabledFunctions = [];
|
||||
foreach ($requiredFunctions as $fn) {
|
||||
foreach ($this->requiredFunctions as $fn) {
|
||||
if (!function_exists($fn)) {
|
||||
$disabledFunctions[] = $fn;
|
||||
}
|
||||
|
||||
@@ -224,19 +224,11 @@ if (
|
||||
return intval($exists);
|
||||
});
|
||||
if (!$hasBuy) {
|
||||
$lock = new \Nexus\Database\NexusLock("buying_torrent:$userid", 10);
|
||||
if (!$lock->get()) {
|
||||
$msg = "buying torrent, wait!";
|
||||
do_log("[ANNOUNCE] user: $userid, torrent: $torrentid, $msg", 'error');
|
||||
err($msg);
|
||||
}
|
||||
$bonusRep = new \App\Repositories\BonusRepository();
|
||||
try {
|
||||
$bonusRep->consumeToBuyTorrent($az['id'], $torrent['id'], 'Web');
|
||||
$lock->release();
|
||||
$redis->set($hasBuyCacheKey, 1, $hasBuyCacheTime);
|
||||
} catch (\Exception $exception) {
|
||||
$lock->release();
|
||||
$msg = $exception->getMessage();
|
||||
do_log("[ANNOUNCE] user: $userid, torrent: $torrentid, $msg " . $exception->getTraceAsString(), 'error');
|
||||
err($msg);
|
||||
|
||||
Reference in New Issue
Block a user