Skip to content

Commit

Permalink
fix: add default value to node_speedlimit
Browse files Browse the repository at this point in the history
  • Loading branch information
Cat committed Dec 12, 2022
1 parent e82d004 commit 25611f5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion db/migrations/20000101000000_init_database.php.new
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ final class InitDatabase extends AbstractMigration
->addColumn('sort', 'integer', [])
->addColumn('traffic_rate', 'float', [ 'default' => 1 ])
->addColumn('node_class', 'integer', [ 'default' => 0 ])
->addColumn('node_speedlimit', 'double', [ 'comment' => '节点限速', 'null' => false ])
->addColumn('node_speedlimit', 'double', [ 'comment' => '节点限速', 'default' => 0, 'null' => false ])
->addColumn('node_connector', 'integer', [ 'default' => 0 ])
->addColumn('node_bandwidth', 'biginteger', [ 'default' => 0 ])
->addColumn('node_bandwidth_limit', 'biginteger', [ 'default' => 0 ])
Expand Down
2 changes: 1 addition & 1 deletion db/migrations/20221205162200_change_number_type.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function up(): void
->changeColumn('uuid', 'uuid', [ 'comment' => 'UUID', 'null' => false ])
->save();
$this->table('node')
->changeColumn('node_speedlimit', 'double', [ 'comment' => '节点限速', 'null' => false ])
->changeColumn('node_speedlimit', 'double', [ 'comment' => '节点限速', 'default' => 0, 'null' => false ])
->save();
}

Expand Down
19 changes: 19 additions & 0 deletions db/migrations/20221212141700_fix_node_default_value.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class FixNodeDefaultValue extends AbstractMigration
{
public function up(): void
{
$this->table('node')
->changeColumn('node_speedlimit', 'double', [ 'comment' => '节点限速', 'default' => 0, 'null' => false ])
->save();
}

public function down(): void
{
}
}
8 changes: 7 additions & 1 deletion src/Controllers/Admin/NodeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,13 @@ public function add(Request $request, Response $response, array $args): Response
}

$node->node_class = $request->getParam('node_class');
$node->node_bandwidth_limit = $request->getParam('node_bandwidth_limit') * 1024 * 1024 * 1024;

if ($request->getParam('node_bandwidth_limit') === null || $request->getParam('node_bandwidth_limit') === '') {
$node->node_bandwidth_limit = 0;
} else {
$node->node_bandwidth_limit = $request->getParam('node_bandwidth_limit') * 1024 * 1024 * 1024;
}

$node->bandwidthlimit_resetday = $request->getParam('bandwidthlimit_resetday');
$node->password = Tools::genRandomChar(32);

Expand Down

0 comments on commit 25611f5

Please sign in to comment.