support pg

This commit is contained in:
xiaomlove
2026-04-15 03:27:30 +07:00
parent 4d54e08918
commit 00fdc2d08f
18 changed files with 129 additions and 59 deletions
+9
View File
@@ -0,0 +1,9 @@
<?php
namespace App\Models;
class Faq extends NexusModel
{
protected $table = 'faq';
}
+13
View File
@@ -0,0 +1,13 @@
<?php
namespace App\Models;
use App\Models\Traits\NexusActivityLogTrait;
class RegImage extends NexusModel
{
protected $table = 'regimages';
protected $fillable = ['imagehash', 'imagestring', 'dateline'];
}
+23 -1
View File
@@ -5,6 +5,7 @@ namespace App\Models;
use App\Repositories\TagRepository;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Nexus\Database\NexusDB;
class Torrent extends NexusModel
{
@@ -186,6 +187,19 @@ class Torrent extends NexusModel
self::NFO_VIEW_STYLE_WINDOWS => ['text' => 'Windows-vy'],
];
public function scopeWhereInfoHash($query, string $binaryHash)
{
if (NexusDB::isPgsql()) {
return $query->whereRaw(
"info_hash = decode(?, 'hex')",
[bin2hex($binaryHash)]
);
} elseif (NexusDB::isMysql()) {
return $query->where('info_hash', $binaryHash);
}
throw new \RuntimeException("Not supported database");
}
public function getPickInfoAttribute()
{
$info = self::$pickTypes[$this->picktype] ?? null;
@@ -521,8 +535,16 @@ class Torrent extends NexusModel
public function tags(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
$idsString = TagRepository::getOrderByFieldIdString();
if (NexusDB::isPgsql()) {
$orderByRaw = "array_position(ARRAY[$idsString]::int[], tags.id)";
} else if (NexusDB::isMysql()) {
$orderByRaw = "FIELD(tags.id, $idsString)";
} else {
throw new \RuntimeException("Unsupported database");
}
return $this->belongsToMany(Tag::class, 'torrent_tags', 'torrent_id', 'tag_id')
->orderByRaw(sprintf("field(`tags`.`id`,%s)", TagRepository::getOrderByFieldIdString()));
->orderByRaw($orderByRaw);
}
public function reward_logs(): \Illuminate\Database\Eloquent\Relations\HasMany
+2 -1
View File
@@ -47,10 +47,11 @@ class DashboardRepository extends BaseRepository
'value' => PHP_VERSION,
];
$name = 'mysql_version';
$databaseInfo = NexusDB::getDatabaseVersionInfo();
$result[$name] = [
'name' => $name,
'text' => nexus_trans("dashboard.system_info.$name"),
'value' => NexusDB::select('select version() as info')[0]['info'],
'value' => sprintf("%s: %s", $databaseInfo['dbType'], $databaseInfo['version']),
];
// $name = 'os';
// $result[$name] = [
@@ -2,6 +2,7 @@
namespace App\Services\Captcha\Drivers;
use App\Models\RegImage;
use App\Services\Captcha\CaptchaDriverInterface;
use App\Services\Captcha\Exceptions\CaptchaValidationException;
@@ -67,16 +68,11 @@ class ImageCaptchaDriver implements CaptchaDriverInterface
$random = random_str();
$imagehash = md5($random);
$dateline = time();
$sql = sprintf(
"INSERT INTO `regimages` (`imagehash`, `imagestring`, `dateline`) VALUES ('%s', '%s', '%s')",
mysql_real_escape_string($imagehash),
mysql_real_escape_string($random),
mysql_real_escape_string((string) $dateline)
);
sql_query($sql);
RegImage::query()->insert([
'imagehash' => $imagehash,
'dateline' => $dateline,
'imagestring' => $random,
]);
return $imagehash;
}