add seeders and migrations + rhilip/bencode

This commit is contained in:
xiaomlove
2021-06-08 20:43:47 +08:00
parent 6361f96d62
commit bf49c8c298
135 changed files with 12171 additions and 104 deletions
+47
View File
@@ -0,0 +1,47 @@
<?php
namespace App\Console\Commands\Install;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class InitData extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'install:init_data';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Initialize data.';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
DB::transaction(function () {
$this->call('db:seed');
});
$this->info("[INIT DATA] success.");
return 0;
}
}
+47
View File
@@ -0,0 +1,47 @@
<?php
namespace App\Console\Commands\Install;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class Migrate extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'install:migrate';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Migrate tables.';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
DB::transaction(function () {
$this->call('migrate');
});
$this->info("[MIGRATE TABLE] success.");
return 0;
}
}
+4 -5
View File
@@ -17,6 +17,7 @@ use Illuminate\Encryption\Encrypter;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Storage;
use Rhilip\Bencode\Bencode;
class Test extends Command
{
@@ -51,11 +52,9 @@ class Test extends Command
*/
public function handle()
{
$reader = new Reader(resource_path('geoip/GeoLite2-City.mmdb'));
$record = $reader->city('128.101.101.101');
dump($record->city, $record->country, $record->location);
$record2 = $reader->isp('128.101.101.101');
dump($record2->isp);
$file = storage_path('logs/11270.torrent');
$r = Bencode::load($file);
dd($r);
}
}
+1 -1
View File
@@ -121,7 +121,7 @@ class User extends Authenticatable
public function checkIsNormal(array $fields = ['status', 'enabled'])
{
if (in_array('visible', $fields) && $this->getAttribute('status') != self::STATUS_CONFIRMED) {
if (in_array('status', $fields) && $this->getAttribute('status') != self::STATUS_CONFIRMED) {
throw new \InvalidArgumentException(sprintf('User: %s is not confirmed.', $this->id));
}
if (in_array('enabled', $fields) && $this->getAttribute('enabled') != self::ENABLED_YES) {
+4 -2
View File
@@ -464,10 +464,12 @@ class ExamRepository extends BaseRepository
$join->on("$userTable.id", "=", "$examUserTable.uid")
->on("$examUserTable.status", "=", DB::raw(ExamUser::STATUS_NORMAL));
})
->where('enabled', User::ENABLED_YES)
->where('visible', User::STATUS_CONFIRMED)
->whereRaw("$examUserTable.id is null")
->selectRaw("$userTable.*")
->orderBy("$userTable.id", "asc");
$size = 100;
$size = 1000;
$minId = 0;
$result = 0;
while (true) {
@@ -522,7 +524,7 @@ class ExamRepository extends BaseRepository
$baseQuery->whereRaw(sprintf("case %s else false end", implode(" ", $whenThens)));
}
$size = 100;
$size = 1000;
$minId = 0;
$result = 0;