migrations check if table exists

This commit is contained in:
xiaomlove
2021-06-09 15:11:02 +08:00
parent 5c4c2ccf8f
commit c771ff9ef1
96 changed files with 339 additions and 17 deletions
+1
View File
@@ -62,3 +62,4 @@ GOOGLE_DRIVE_REFRESH_TOKEN=
GOOGLE_DRIVE_FOLDER_ID=
GEOIP2_DATABASE=
EXAM_PROGRESS_UPDATE_PROBABILITY=60
+37 -10
View File
@@ -319,6 +319,16 @@ class ExamRepository extends BaseRepository
ExamProgress::query()->insert($insert);
do_log("[addProgress] " . nexus_json_encode($insert));
/**
* Updating progress is more performance intensive and will only be done with a certain probability
*/
$probability = (int)nexus_env('EXAM_PROGRESS_UPDATE_PROBABILITY', 60);
$random = mt_rand(1, 100);
do_log("probability: $probability, random: $random");
if ($random > $probability) {
do_log("[SKIP_UPDATE_PROGRESS], random: $random > probability: $probability", 'warning');
return true;
}
$examProgress = $this->calculateProgress($examUser);
$examProgressFormatted = $this->getProgressFormatted($exam, $examProgress);
$examNotPassed = array_filter($examProgressFormatted, function ($item) {
@@ -452,31 +462,48 @@ class ExamRepository extends BaseRepository
return false;
}
if ($exams->count() > 1) {
do_log("Valid and discovered exam more than 1.", "warning");
do_log("Valid and discovered exam more than 1.", "error");
return false;
}
/** @var Exam $exam */
$exam = $exams->first();
$filters = $exam->filters;
do_log("exam: {$exam->id}, filters: " . nexus_json_encode($filters));
$userTable = (new User())->getTable();
$examUserTable = (new ExamUser())->getTable();
$baseQuery = User::query()
->leftJoin($examUserTable, function (JoinClause $join) use ($examUserTable, $userTable) {
$join->on("$userTable.id", "=", "$examUserTable.uid")
->on("$examUserTable.status", "=", DB::raw(ExamUser::STATUS_NORMAL));
$join->on("$userTable.id", "=", "$examUserTable.uid");
})
->where('enabled', User::ENABLED_YES)
->where('visible', User::STATUS_CONFIRMED)
->where("$userTable.enabled", User::ENABLED_YES)
->where("$userTable.status", User::STATUS_CONFIRMED)
->whereRaw("$examUserTable.id is null")
->selectRaw("$userTable.*")
->orderBy("$userTable.id", "asc");
if (empty($filters->classes)) {
do_log("{$exam->id} no classes.");
return false;
} else {
$baseQuery->whereIn("$userTable.class", $filters->classes);
}
if (empty($filters->register_time_range) || empty($filters->register_time_range[0]) || empty($filters->register_time_range[1])) {
do_log("{$exam->id} no register_time_range.");
return false;
} else {
$baseQuery->where("$userTable.added", ">=", Carbon::parse($filters->register_time_range[0])->toDateTimeString())
->where("$userTable.added", '<=', Carbon::parse($filters->register_time_range[1])->toDateTimeString());
}
$size = 1000;
$minId = 0;
$result = 0;
while (true) {
$logPrefix = sprintf('[%s], exam: %s, size: %s', __FUNCTION__, $exam->id , $size);
$users = (clone $baseQuery)->where("$userTable.id", ">", $minId)->limit($size)->get();
do_log("$logPrefix, query: " . last_query() . ", counts: " . $users->count());
if ($users->isEmpty()) {
do_log("$logPrefix, no more data..." . last_query());
do_log("no more data...");
break;
}
$insert = [];
@@ -484,10 +511,10 @@ class ExamRepository extends BaseRepository
foreach ($users as $user) {
$minId = $user->id;
$currentLogPrefix = sprintf("$logPrefix, user: %s", $user->id);
if (!$this->isExamMatchUser($exam, $user)) {
do_log("$currentLogPrefix, exam not match this user.");
continue;
}
// if (!$this->isExamMatchUser($exam, $user)) {
// do_log("$currentLogPrefix, exam not match this user.");
// continue;
// }
$insert[] = [
'uid' => $user->id,
'exam_id' => $exam->id,
@@ -13,6 +13,9 @@ class CreatePersonalAccessTokensTable extends Migration
*/
public function up()
{
if (Schema::hasTable('personal_access_tokens')) {
return;
}
Schema::create('personal_access_tokens', function (Blueprint $table) {
$table->bigIncrements('id');
$table->morphs('tokenable');
@@ -13,6 +13,9 @@ class CreateAdclicksTable extends Migration
*/
public function up()
{
if (Schema::hasTable('adclicks')) {
return;
}
Schema::create('adclicks', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('adid')->nullable();
@@ -13,6 +13,9 @@ class CreateAdminpanelTable extends Migration
*/
public function up()
{
if (Schema::hasTable('adminpanel')) {
return;
}
Schema::create('adminpanel', function (Blueprint $table) {
$table->tinyIncrements('id');
$table->string('name', 128)->default('');
@@ -13,6 +13,9 @@ class CreateAdvertisementsTable extends Migration
*/
public function up()
{
if (Schema::hasTable('advertisements')) {
return;
}
Schema::create('advertisements', function (Blueprint $table) {
$table->mediumIncrements('id');
$table->boolean('enabled')->default(0);
@@ -13,6 +13,9 @@ class CreateAgentAllowedExceptionTable extends Migration
*/
public function up()
{
if (Schema::hasTable('agent_allowed_exception')) {
return;
}
Schema::create('agent_allowed_exception', function (Blueprint $table) {
$table->unsignedTinyInteger('family_id')->default(0)->index('family_id');
$table->string('name', 100)->default('');
@@ -13,6 +13,9 @@ class CreateAgentAllowedFamilyTable extends Migration
*/
public function up()
{
if (Schema::hasTable('agent_allowed_family')) {
return;
}
Schema::create('agent_allowed_family', function (Blueprint $table) {
$table->tinyIncrements('id');
$table->string('family', 50)->default('');
@@ -13,6 +13,9 @@ class CreateAllowedemailsTable extends Migration
*/
public function up()
{
if (Schema::hasTable('allowedemails')) {
return;
}
Schema::create('allowedemails', function (Blueprint $table) {
$table->integer('id', true);
$table->mediumText('value');
@@ -13,6 +13,9 @@ class CreateAttachmentsTable extends Migration
*/
public function up()
{
if (Schema::hasTable('attachments')) {
return;
}
Schema::create('attachments', function (Blueprint $table) {
$table->increments('id');
$table->unsignedMediumInteger('userid')->default(0);
@@ -13,6 +13,9 @@ class CreateAttendanceTable extends Migration
*/
public function up()
{
if (Schema::hasTable('attendance')) {
return;
}
Schema::create('attendance', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedInteger('uid')->default(0)->index('idx_uid');
@@ -13,6 +13,9 @@ class CreateAudiocodecsTable extends Migration
*/
public function up()
{
if (Schema::hasTable('audiocodecs')) {
return;
}
Schema::create('audiocodecs', function (Blueprint $table) {
$table->tinyIncrements('id');
$table->string('name', 30)->default('');
@@ -13,6 +13,9 @@ class CreateAvpsTable extends Migration
*/
public function up()
{
if (Schema::hasTable('avps')) {
return;
}
Schema::create('avps', function (Blueprint $table) {
$table->string('arg', 20)->default('')->primary();
$table->text('value_s');
@@ -13,6 +13,9 @@ class CreateBannedemailsTable extends Migration
*/
public function up()
{
if (Schema::hasTable('bannedemails')) {
return;
}
Schema::create('bannedemails', function (Blueprint $table) {
$table->integer('id', true);
$table->mediumText('value');
@@ -13,6 +13,9 @@ class CreateBansTable extends Migration
*/
public function up()
{
if (Schema::hasTable('bans')) {
return;
}
Schema::create('bans', function (Blueprint $table) {
$table->smallIncrements('id');
$table->dateTime('added')->nullable();
@@ -13,6 +13,9 @@ class CreateBitbucketTable extends Migration
*/
public function up()
{
if (Schema::hasTable('bitbucket')) {
return;
}
Schema::create('bitbucket', function (Blueprint $table) {
$table->increments('id');
$table->unsignedMediumInteger('owner')->default(0);
@@ -13,6 +13,9 @@ class CreateBlocksTable extends Migration
*/
public function up()
{
if (Schema::hasTable('blocks')) {
return;
}
Schema::create('blocks', function (Blueprint $table) {
$table->increments('id');
$table->unsignedMediumInteger('userid')->default(0);
@@ -13,6 +13,9 @@ class CreateBookmarksTable extends Migration
*/
public function up()
{
if (Schema::hasTable('bookmarks')) {
return;
}
Schema::create('bookmarks', function (Blueprint $table) {
$table->increments('id');
$table->unsignedMediumInteger('torrentid')->default(0);
@@ -13,6 +13,9 @@ class CreateCategoriesTable extends Migration
*/
public function up()
{
if (Schema::hasTable('categories')) {
return;
}
Schema::create('categories', function (Blueprint $table) {
$table->smallIncrements('id');
$table->unsignedTinyInteger('mode')->default(1);
@@ -13,6 +13,9 @@ class CreateCaticonsTable extends Migration
*/
public function up()
{
if (Schema::hasTable('caticons')) {
return;
}
Schema::create('caticons', function (Blueprint $table) {
$table->tinyIncrements('id');
$table->string('name', 64)->default('');
@@ -13,6 +13,9 @@ class CreateCheatersTable extends Migration
*/
public function up()
{
if (Schema::hasTable('cheaters')) {
return;
}
Schema::create('cheaters', function (Blueprint $table) {
$table->mediumIncrements('id');
$table->dateTime('added')->nullable();
@@ -13,6 +13,9 @@ class CreateChronicleTable extends Migration
*/
public function up()
{
if (Schema::hasTable('chronicle')) {
return;
}
Schema::create('chronicle', function (Blueprint $table) {
$table->mediumIncrements('id');
$table->unsignedMediumInteger('userid')->default(0);
@@ -13,6 +13,9 @@ class CreateCodecsTable extends Migration
*/
public function up()
{
if (Schema::hasTable('codecs')) {
return;
}
Schema::create('codecs', function (Blueprint $table) {
$table->tinyIncrements('id');
$table->string('name', 30)->default('');
@@ -13,6 +13,9 @@ class CreateCommentsTable extends Migration
*/
public function up()
{
if (Schema::hasTable('comments')) {
return;
}
Schema::create('comments', function (Blueprint $table) {
$table->increments('id');
$table->unsignedMediumInteger('user')->default(0)->index('user');
@@ -13,6 +13,9 @@ class CreateCountriesTable extends Migration
*/
public function up()
{
if (Schema::hasTable('countries')) {
return;
}
Schema::create('countries', function (Blueprint $table) {
$table->smallIncrements('id');
$table->string('name', 50)->default('');
@@ -13,6 +13,9 @@ class CreateDownloadspeedTable extends Migration
*/
public function up()
{
if (Schema::hasTable('downloadspeed')) {
return;
}
Schema::create('downloadspeed', function (Blueprint $table) {
$table->tinyIncrements('id');
$table->string('name', 50)->default('');
@@ -13,6 +13,9 @@ class CreateExamProgressTable extends Migration
*/
public function up()
{
if (Schema::hasTable('exam_progress')) {
return;
}
Schema::create('exam_progress', function (Blueprint $table) {
$table->bigIncrements('id');
$table->integer('exam_user_id')->index();
@@ -13,6 +13,9 @@ class CreateExamUsersTable extends Migration
*/
public function up()
{
if (Schema::hasTable('exam_users')) {
return;
}
Schema::create('exam_users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->integer('uid')->index();
@@ -13,6 +13,9 @@ class CreateExamsTable extends Migration
*/
public function up()
{
if (Schema::hasTable('exams')) {
return;
}
Schema::create('exams', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
@@ -13,6 +13,9 @@ class CreateFailedJobsTable extends Migration
*/
public function up()
{
if (Schema::hasTable('failed_jobs')) {
return;
}
Schema::create('failed_jobs', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('uuid')->unique();
@@ -13,6 +13,9 @@ class CreateFaqTable extends Migration
*/
public function up()
{
if (Schema::hasTable('faq')) {
return;
}
Schema::create('faq', function (Blueprint $table) {
$table->smallIncrements('id');
$table->unsignedSmallInteger('link_id')->default(0);
@@ -13,6 +13,9 @@ class CreateFilesTable extends Migration
*/
public function up()
{
if (Schema::hasTable('files')) {
return;
}
Schema::create('files', function (Blueprint $table) {
$table->increments('id');
$table->unsignedMediumInteger('torrent')->default(0)->index('torrent');
@@ -13,6 +13,9 @@ class CreateForummodsTable extends Migration
*/
public function up()
{
if (Schema::hasTable('forummods')) {
return;
}
Schema::create('forummods', function (Blueprint $table) {
$table->smallIncrements('id');
$table->unsignedSmallInteger('forumid')->default(0)->index('forumid');
@@ -13,6 +13,9 @@ class CreateForumsTable extends Migration
*/
public function up()
{
if (Schema::hasTable('forums')) {
return;
}
Schema::create('forums', function (Blueprint $table) {
$table->smallIncrements('id');
$table->unsignedSmallInteger('sort')->default(0);
@@ -13,6 +13,9 @@ class CreateFriendsTable extends Migration
*/
public function up()
{
if (Schema::hasTable('friends')) {
return;
}
Schema::create('friends', function (Blueprint $table) {
$table->increments('id');
$table->unsignedMediumInteger('userid')->default(0);
@@ -13,6 +13,9 @@ class CreateFunTable extends Migration
*/
public function up()
{
if (Schema::hasTable('fun')) {
return;
}
Schema::create('fun', function (Blueprint $table) {
$table->mediumIncrements('id');
$table->unsignedMediumInteger('userid')->default(0);
@@ -13,6 +13,9 @@ class CreateFundsTable extends Migration
*/
public function up()
{
if (Schema::hasTable('funds')) {
return;
}
Schema::create('funds', function (Blueprint $table) {
$table->increments('id');
$table->decimal('usd')->default(0.00);
@@ -13,6 +13,9 @@ class CreateFunvotesTable extends Migration
*/
public function up()
{
if (Schema::hasTable('funvotes')) {
return;
}
Schema::create('funvotes', function (Blueprint $table) {
$table->unsignedMediumInteger('funid');
$table->unsignedMediumInteger('userid');
@@ -13,6 +13,9 @@ class CreateInvitesTable extends Migration
*/
public function up()
{
if (Schema::hasTable('invites')) {
return;
}
Schema::create('invites', function (Blueprint $table) {
$table->increments('id');
$table->unsignedMediumInteger('inviter')->default(0);
@@ -13,6 +13,9 @@ class CreateIplogTable extends Migration
*/
public function up()
{
if (Schema::hasTable('iplog')) {
return;
}
Schema::create('iplog', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('ip', 64)->default('');
@@ -13,6 +13,9 @@ class CreateIspTable extends Migration
*/
public function up()
{
if (Schema::hasTable('isp')) {
return;
}
Schema::create('isp', function (Blueprint $table) {
$table->tinyIncrements('id');
$table->string('name', 50)->nullable();
@@ -13,6 +13,9 @@ class CreateLanguageTable extends Migration
*/
public function up()
{
if (Schema::hasTable('language')) {
return;
}
Schema::create('language', function (Blueprint $table) {
$table->smallIncrements('id');
$table->string('lang_name', 50)->default('');
@@ -13,6 +13,9 @@ class CreateLinksTable extends Migration
*/
public function up()
{
if (Schema::hasTable('links')) {
return;
}
Schema::create('links', function (Blueprint $table) {
$table->tinyIncrements('id');
$table->string('name', 30)->default('');
@@ -13,6 +13,9 @@ class CreateLocationsTable extends Migration
*/
public function up()
{
if (Schema::hasTable('locations')) {
return;
}
Schema::create('locations', function (Blueprint $table) {
$table->increments('id');
$table->string('name', 50)->nullable();
@@ -13,6 +13,9 @@ class CreateLoginattemptsTable extends Migration
*/
public function up()
{
if (Schema::hasTable('loginattempts')) {
return;
}
Schema::create('loginattempts', function (Blueprint $table) {
$table->increments('id');
$table->string('ip', 64)->default('');
@@ -13,6 +13,9 @@ class CreateMagicTable extends Migration
*/
public function up()
{
if (Schema::hasTable('magic')) {
return;
}
Schema::create('magic', function (Blueprint $table) {
$table->bigIncrements('id');
$table->integer('torrentid')->default(0)->index('idx_torrentid');
@@ -13,6 +13,9 @@ class CreateMediaTable extends Migration
*/
public function up()
{
if (Schema::hasTable('media')) {
return;
}
Schema::create('media', function (Blueprint $table) {
$table->tinyIncrements('id');
$table->string('name', 30)->default('');
@@ -13,6 +13,9 @@ class CreateMessagesTable extends Migration
*/
public function up()
{
if (Schema::hasTable('messages')) {
return;
}
Schema::create('messages', function (Blueprint $table) {
$table->increments('id');
$table->unsignedMediumInteger('sender')->default(0)->index('sender');
@@ -13,6 +13,9 @@ class CreateModpanelTable extends Migration
*/
public function up()
{
if (Schema::hasTable('modpanel')) {
return;
}
Schema::create('modpanel', function (Blueprint $table) {
$table->tinyIncrements('id');
$table->string('name', 128)->default('');
@@ -13,6 +13,9 @@ class CreateNewsTable extends Migration
*/
public function up()
{
if (Schema::hasTable('news')) {
return;
}
Schema::create('news', function (Blueprint $table) {
$table->mediumIncrements('id');
$table->unsignedMediumInteger('userid')->default(0);
@@ -13,6 +13,9 @@ class CreateOffersTable extends Migration
*/
public function up()
{
if (Schema::hasTable('offers')) {
return;
}
Schema::create('offers', function (Blueprint $table) {
$table->mediumIncrements('id');
$table->unsignedMediumInteger('userid')->default(0)->index('userid');
@@ -13,6 +13,9 @@ class CreateOffervotesTable extends Migration
*/
public function up()
{
if (Schema::hasTable('offervotes')) {
return;
}
Schema::create('offervotes', function (Blueprint $table) {
$table->increments('id');
$table->unsignedMediumInteger('offerid')->default(0);
@@ -13,6 +13,9 @@ class CreateOverforumsTable extends Migration
*/
public function up()
{
if (Schema::hasTable('overforums')) {
return;
}
Schema::create('overforums', function (Blueprint $table) {
$table->smallIncrements('id');
$table->string('name', 60)->default('');
@@ -13,6 +13,9 @@ class CreatePeersTable extends Migration
*/
public function up()
{
if (Schema::hasTable('peers')) {
return;
}
Schema::create('peers', function (Blueprint $table) {
$table->increments('id');
$table->unsignedMediumInteger('torrent')->default(0)->index('torrent');
@@ -13,6 +13,9 @@ class CreatePmboxesTable extends Migration
*/
public function up()
{
if (Schema::hasTable('pmboxes')) {
return;
}
Schema::create('pmboxes', function (Blueprint $table) {
$table->mediumIncrements('id');
$table->unsignedMediumInteger('userid')->default(0);
@@ -13,6 +13,9 @@ class CreatePollanswersTable extends Migration
*/
public function up()
{
if (Schema::hasTable('pollanswers')) {
return;
}
Schema::create('pollanswers', function (Blueprint $table) {
$table->increments('id');
$table->unsignedMediumInteger('pollid')->default(0)->index('pollid');
@@ -13,6 +13,9 @@ class CreatePollsTable extends Migration
*/
public function up()
{
if (Schema::hasTable('polls')) {
return;
}
Schema::create('polls', function (Blueprint $table) {
$table->mediumIncrements('id');
$table->dateTime('added')->nullable();
@@ -13,6 +13,9 @@ class CreatePostsTable extends Migration
*/
public function up()
{
if (Schema::hasTable('posts')) {
return;
}
Schema::create('posts', function (Blueprint $table) {
$table->increments('id');
$table->unsignedMediumInteger('topicid')->default(0);
@@ -13,6 +13,9 @@ class CreateProcessingsTable extends Migration
*/
public function up()
{
if (Schema::hasTable('processings')) {
return;
}
Schema::create('processings', function (Blueprint $table) {
$table->tinyIncrements('id');
$table->string('name', 30)->default('');
@@ -13,6 +13,9 @@ class CreateProlinkclicksTable extends Migration
*/
public function up()
{
if (Schema::hasTable('prolinkclicks')) {
return;
}
Schema::create('prolinkclicks', function (Blueprint $table) {
$table->increments('id');
$table->unsignedMediumInteger('userid')->default(0);
@@ -13,6 +13,9 @@ class CreateReadpostsTable extends Migration
*/
public function up()
{
if (Schema::hasTable('readposts')) {
return;
}
Schema::create('readposts', function (Blueprint $table) {
$table->increments('id');
$table->unsignedMediumInteger('userid')->default(0)->index('userid');
@@ -13,6 +13,9 @@ class CreateRegimagesTable extends Migration
*/
public function up()
{
if (Schema::hasTable('regimages')) {
return;
}
Schema::create('regimages', function (Blueprint $table) {
$table->mediumIncrements('id');
$table->string('imagehash', 32)->default('');
@@ -13,6 +13,9 @@ class CreateReportsTable extends Migration
*/
public function up()
{
if (Schema::hasTable('reports')) {
return;
}
Schema::create('reports', function (Blueprint $table) {
$table->mediumIncrements('id');
$table->unsignedMediumInteger('addedby')->default(0);
@@ -13,6 +13,9 @@ class CreateRequestsTable extends Migration
*/
public function up()
{
if (Schema::hasTable('requests')) {
return;
}
Schema::create('requests', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('userid')->default(0)->index('userid');
@@ -13,6 +13,9 @@ class CreateResreqTable extends Migration
*/
public function up()
{
if (Schema::hasTable('resreq')) {
return;
}
Schema::create('resreq', function (Blueprint $table) {
$table->integer('id', true);
$table->integer('reqid')->default(0)->index('reqid');
@@ -13,6 +13,9 @@ class CreateRulesTable extends Migration
*/
public function up()
{
if (Schema::hasTable('rules')) {
return;
}
Schema::create('rules', function (Blueprint $table) {
$table->smallIncrements('id');
$table->unsignedSmallInteger('lang_id')->default(6);
@@ -13,6 +13,9 @@ class CreateSchoolsTable extends Migration
*/
public function up()
{
if (Schema::hasTable('schools')) {
return;
}
Schema::create('schools', function (Blueprint $table) {
$table->smallIncrements('id');
$table->string('name', 50)->nullable();
@@ -13,6 +13,9 @@ class CreateSearchboxFieldsTable extends Migration
*/
public function up()
{
if (Schema::hasTable('searchbox_fields')) {
return;
}
Schema::create('searchbox_fields', function (Blueprint $table) {
$table->integer('id', true);
$table->integer('searchbox_id');
@@ -13,6 +13,9 @@ class CreateSearchboxTable extends Migration
*/
public function up()
{
if (Schema::hasTable('searchbox')) {
return;
}
Schema::create('searchbox', function (Blueprint $table) {
$table->smallIncrements('id');
$table->string('name', 30)->nullable();
@@ -13,6 +13,9 @@ class CreateSecondiconsTable extends Migration
*/
public function up()
{
if (Schema::hasTable('secondicons')) {
return;
}
Schema::create('secondicons', function (Blueprint $table) {
$table->smallIncrements('id');
$table->unsignedTinyInteger('source')->default(0);
@@ -13,6 +13,9 @@ class CreateSettingsTable extends Migration
*/
public function up()
{
if (Schema::hasTable('settings')) {
return;
}
Schema::create('settings', function (Blueprint $table) {
$table->integer('id', true);
$table->string('name')->default('')->unique('uniqe_name');
@@ -13,6 +13,9 @@ class CreateShoutboxTable extends Migration
*/
public function up()
{
if (Schema::hasTable('shoutbox')) {
return;
}
Schema::create('shoutbox', function (Blueprint $table) {
$table->integer('id', true);
$table->unsignedMediumInteger('userid')->default(0);
@@ -13,6 +13,9 @@ class CreateSitelogTable extends Migration
*/
public function up()
{
if (Schema::hasTable('sitelog')) {
return;
}
Schema::create('sitelog', function (Blueprint $table) {
$table->increments('id');
$table->dateTime('added')->nullable()->index('added');
@@ -13,6 +13,9 @@ class CreateSnatchedTable extends Migration
*/
public function up()
{
if (Schema::hasTable('snatched')) {
return;
}
Schema::create('snatched', function (Blueprint $table) {
$table->integer('id', true);
$table->unsignedMediumInteger('torrentid')->default(0);
@@ -13,6 +13,9 @@ class CreateSourcesTable extends Migration
*/
public function up()
{
if (Schema::hasTable('sources')) {
return;
}
Schema::create('sources', function (Blueprint $table) {
$table->tinyIncrements('id');
$table->string('name', 30)->default('');
@@ -13,6 +13,9 @@ class CreateStaffmessagesTable extends Migration
*/
public function up()
{
if (Schema::hasTable('staffmessages')) {
return;
}
Schema::create('staffmessages', function (Blueprint $table) {
$table->mediumIncrements('id');
$table->unsignedMediumInteger('sender')->default(0);
@@ -13,6 +13,9 @@ class CreateStandardsTable extends Migration
*/
public function up()
{
if (Schema::hasTable('standards')) {
return;
}
Schema::create('standards', function (Blueprint $table) {
$table->tinyIncrements('id');
$table->string('name', 30)->default('');
@@ -13,6 +13,9 @@ class CreateStylesheetsTable extends Migration
*/
public function up()
{
if (Schema::hasTable('stylesheets')) {
return;
}
Schema::create('stylesheets', function (Blueprint $table) {
$table->tinyIncrements('id');
$table->string('uri')->default('');
@@ -13,6 +13,9 @@ class CreateSubsTable extends Migration
*/
public function up()
{
if (Schema::hasTable('subs')) {
return;
}
Schema::create('subs', function (Blueprint $table) {
$table->increments('id');
$table->unsignedMediumInteger('torrent_id')->default(0);
@@ -13,6 +13,9 @@ class CreateSuggestTable extends Migration
*/
public function up()
{
if (Schema::hasTable('suggest')) {
return;
}
Schema::create('suggest', function (Blueprint $table) {
$table->increments('id');
$table->string('keywords')->default('')->index('keywords');
@@ -13,6 +13,9 @@ class CreateSysoppanelTable extends Migration
*/
public function up()
{
if (Schema::hasTable('sysoppanel')) {
return;
}
Schema::create('sysoppanel', function (Blueprint $table) {
$table->tinyIncrements('id');
$table->string('name', 128)->default('');
@@ -13,6 +13,9 @@ class CreateTeamsTable extends Migration
*/
public function up()
{
if (Schema::hasTable('teams')) {
return;
}
Schema::create('teams', function (Blueprint $table) {
$table->tinyIncrements('id');
$table->string('name', 30)->default('');
@@ -13,6 +13,9 @@ class CreateThanksTable extends Migration
*/
public function up()
{
if (Schema::hasTable('thanks')) {
return;
}
Schema::create('thanks', function (Blueprint $table) {
$table->increments('id');
$table->unsignedMediumInteger('torrentid')->default(0);
@@ -13,6 +13,9 @@ class CreateTopicsTable extends Migration
*/
public function up()
{
if (Schema::hasTable('topics')) {
return;
}
Schema::create('topics', function (Blueprint $table) {
$table->mediumIncrements('id');
$table->unsignedMediumInteger('userid')->default(0)->index('userid');
@@ -13,6 +13,9 @@ class CreateTorrentSecretsTable extends Migration
*/
public function up()
{
if (Schema::hasTable('torrent_secrets')) {
return;
}
Schema::create('torrent_secrets', function (Blueprint $table) {
$table->integer('id', true);
$table->integer('uid')->index('idx_uid');
@@ -13,6 +13,9 @@ class CreateTorrentsCustomFieldValuesTable extends Migration
*/
public function up()
{
if (Schema::hasTable('torrents_custom_field_values')) {
return;
}
Schema::create('torrents_custom_field_values', function (Blueprint $table) {
$table->integer('id', true);
$table->integer('torrent_id')->default(0)->index('idx_torrent_id');
@@ -13,6 +13,9 @@ class CreateTorrentsCustomFieldsTable extends Migration
*/
public function up()
{
if (Schema::hasTable('torrents_custom_fields')) {
return;
}
Schema::create('torrents_custom_fields', function (Blueprint $table) {
$table->integer('id', true);
$table->string('name')->default('');
@@ -13,6 +13,9 @@ class CreateTorrentsStateTable extends Migration
*/
public function up()
{
if (Schema::hasTable('torrents_state')) {
return;
}
Schema::create('torrents_state', function (Blueprint $table) {
$table->unsignedTinyInteger('global_sp_state')->default(1);
});
@@ -13,6 +13,9 @@ class CreateTorrentsTable extends Migration
*/
public function up()
{
if (Schema::hasTable('torrents')) {
return;
}
Schema::create('torrents', function (Blueprint $table) {
$table->mediumIncrements('id');
$table->binary('info_hash')->unique('info_hash');
@@ -13,6 +13,9 @@ class CreateUploadspeedTable extends Migration
*/
public function up()
{
if (Schema::hasTable('uploadspeed')) {
return;
}
Schema::create('uploadspeed', function (Blueprint $table) {
$table->tinyIncrements('id');
$table->string('name', 50)->nullable();
@@ -13,6 +13,9 @@ class CreateUserBanLogsTable extends Migration
*/
public function up()
{
if (Schema::hasTable('user_ban_logs')) {
return;
}
Schema::create('user_ban_logs', function (Blueprint $table) {
$table->bigInteger('id', true);
$table->integer('uid')->default(0)->index('idx_uid');
@@ -13,6 +13,9 @@ class CreateUsersTable extends Migration
*/
public function up()
{
if (Schema::hasTable('users')) {
return;
}
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('username', 40)->default('')->unique('username');
+25 -1
View File
@@ -155,11 +155,35 @@ function nexus_dd($vars)
*/
function do_log($log, $level = 'info')
{
static $uid, $passkey, $env, $sequence, $setLogLevel;
if (is_null($setLogLevel)) {
$setLogLevel = nexus_env('LOG_LEVEL', 'debug');
}
$logLevels = [
\Psr\Log\LogLevel::DEBUG,
\Psr\Log\LogLevel::INFO,
\Psr\Log\LogLevel::NOTICE,
\Psr\Log\LogLevel::WARNING,
\Psr\Log\LogLevel::ERROR,
\Psr\Log\LogLevel::CRITICAL,
\Psr\Log\LogLevel::ALERT,
\Psr\Log\LogLevel::EMERGENCY,
];
$setLogLevelKey = array_search($setLogLevel, $logLevels);
$currentLogLevelKey = array_search($level, $logLevels);
if ($currentLogLevelKey === false) {
$level = \Psr\log\LogLevel::ERROR;
$log = "[ERROR_LOG_LEVEL] $log";
$currentLogLevelKey = array_search($level, $logLevels);
}
if ($currentLogLevelKey < $setLogLevelKey) {
return;
}
$logFile = getLogFile();
if (($fd = fopen($logFile, 'a')) === false) {
$fd = fopen(sys_get_temp_dir() . '/nexus.log', 'a');
}
static $uid, $passkey, $env, $sequence;
if (is_null($uid)) {
$sequence = 0;
if (IN_NEXUS) {
+1 -1
View File
@@ -106,7 +106,7 @@ class Install
$filename = basename($path);
$count = preg_match('/create_(.*)_table.php/', $filename, $matches);
if ($count) {
$tables[$matches[1]] = '';
$tables[$matches[1]] = $filename;
}
}
return $tables;
+1 -1
View File
@@ -62,7 +62,7 @@ if ($currentStep == 3) {
try {
// $install->createTable($shouldCreateTable);
if (!WITH_LARAVEL) {
throw new \RuntimeException('Larvel is not avaliable.');
throw new \RuntimeException('Laravel is not avaliable.');
}
$command = "php " . ROOT_PATH . "artisan install:migrate";
$result = exec($command, $output, $result_code);
+4 -4
View File
@@ -81,7 +81,7 @@ $seeder = ($left == 0) ? "yes" : "no";
if (!$az = $Cache->get_value('user_passkey_'.$passkey.'_content')){
$res = sql_query("SELECT id, downloadpos, enabled, uploaded, downloaded, class, parked, clientselect, showclienterror,passkey FROM users WHERE passkey=". sqlesc($passkey)." LIMIT 1");
$az = $currentUser = mysql_fetch_array($res);
do_log("[check passkey], currentUser: " . nexus_json_encode($currentUser));
do_log("[check passkey], currentUser: " . nexus_json_encode($currentUser), 'error');
$Cache->cache_value('user_passkey_'.$passkey.'_content', $az, 950);
}
if (!$az) err("Invalid passkey! Re-download the .torrent from $BASEURL");
@@ -117,8 +117,8 @@ if (!$torrent) {
$start = strpos($queryString, $firstNeedle) + strlen($firstNeedle);
$end = strpos($queryString, "&", $start);
$infoHashUrlEncode = substr($queryString, $start, $end - $start);
do_log("[TORRENT NOT EXISTS] $checkTorrentSql, params: $queryString");
do_log("[TORRENT NOT EXISTS] infoHashUrlEncode: $infoHashUrlEncode");
do_log("[TORRENT NOT EXISTS] $checkTorrentSql, params: $queryString", 'error');
do_log("[TORRENT NOT EXISTS] infoHashUrlEncode: $infoHashUrlEncode", 'error');
err("torrent not registered with this tracker");
}
@@ -471,7 +471,7 @@ $examRep = new \App\Repositories\ExamRepository();
try {
$examRep->addProgress($userid, $torrentid, $examIndexData);
} catch (\Exception $exception) {
do_log("add exam progress fail: " . $exception->getMessage());
do_log("add exam progress fail: " . $exception->getMessage(), 'critical');
}
benc_resp($rep_dict);