implement GRIDs
This commit is contained in:
@@ -39,7 +39,9 @@ class ConfirmUser extends Command
|
||||
public function handle()
|
||||
{
|
||||
$u = User::resolve($this->argument('user'));
|
||||
$u->update('confirmed', true);
|
||||
$u->update(['confirmed' => true]);
|
||||
$this->info("User #$u->id with e-mail $u->email and handle @$u->name was confirmed.");
|
||||
|
||||
dd($u);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,12 +189,19 @@ class TableController extends Controller
|
||||
// Preparing data to insert into the Rows table
|
||||
$rowsData = null;
|
||||
try {
|
||||
$rowsData = array_map(function ($row) use ($columns) {
|
||||
if (count($row) == 0 || count($row)==1&&$row[0]=='') return null;
|
||||
$grid_range = Row::allocateGRIDs(count($rowTable));
|
||||
$grid_cnt = $grid_range[0];
|
||||
|
||||
$rowsData = array_map(function ($row) use ($columns, &$grid_cnt) {
|
||||
if (count($row) == 0 || count($row) == 1 && $row[0] == '') return null;
|
||||
if (count($row) != count($columns)) {
|
||||
throw new NotApplicableException("All rows must have " . count($columns) . " fields.");
|
||||
}
|
||||
$parsed = [];
|
||||
|
||||
$parsed = [
|
||||
'_grid' => $grid_cnt++
|
||||
];
|
||||
|
||||
foreach ($row as $i => $val) {
|
||||
$key = $columns[$i]->name;
|
||||
if (strlen($val) > 255) {
|
||||
|
||||
+14
-7
@@ -2,6 +2,13 @@
|
||||
|
||||
namespace App\Http;
|
||||
|
||||
use App\Http\Middleware\ActivatedAccount;
|
||||
use App\Http\Middleware\EncryptCookies;
|
||||
use App\Http\Middleware\RedirectIfAuthenticated;
|
||||
use App\Http\Middleware\ThrottleIfNotDebug;
|
||||
use App\Http\Middleware\TrimStrings;
|
||||
use App\Http\Middleware\TrustProxies;
|
||||
use App\Http\Middleware\VerifyCsrfToken;
|
||||
use Illuminate\Foundation\Http\Kernel as HttpKernel;
|
||||
|
||||
class Kernel extends HttpKernel
|
||||
@@ -16,9 +23,9 @@ class Kernel extends HttpKernel
|
||||
protected $middleware = [
|
||||
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
|
||||
\App\Http\Middleware\TrimStrings::class,
|
||||
TrimStrings::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
|
||||
\App\Http\Middleware\TrustProxies::class,
|
||||
TrustProxies::class,
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -29,12 +36,12 @@ class Kernel extends HttpKernel
|
||||
protected $middlewareGroups = [
|
||||
'web' => [
|
||||
'throttle:120,15', // try to prevent people refresh-spamming the server to game table visit counts
|
||||
\App\Http\Middleware\EncryptCookies::class,
|
||||
EncryptCookies::class,
|
||||
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
||||
\Illuminate\Session\Middleware\StartSession::class,
|
||||
// \Illuminate\Session\Middleware\AuthenticateSession::class,
|
||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||
\App\Http\Middleware\VerifyCsrfToken::class,
|
||||
VerifyCsrfToken::class,
|
||||
'bindings',
|
||||
],
|
||||
|
||||
@@ -52,14 +59,14 @@ class Kernel extends HttpKernel
|
||||
* @var array
|
||||
*/
|
||||
protected $routeMiddleware = [
|
||||
'activated' => \App\Http\Middleware\ActivatedAccount::class,
|
||||
'activated' => ActivatedAccount::class,
|
||||
'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
|
||||
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
|
||||
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
|
||||
'can' => \Illuminate\Auth\Middleware\Authorize::class,
|
||||
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
|
||||
'guest' => RedirectIfAuthenticated::class,
|
||||
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
|
||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||
'throttle' => ThrottleIfNotDebug::class,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
|
||||
use Illuminate\Routing\Middleware\ThrottleRequests;
|
||||
|
||||
class ThrottleIfNotDebug extends ThrottleRequests
|
||||
{
|
||||
public function handle($request, \Closure $next, $maxAttempts = 60, $decayMinutes = 1)
|
||||
{
|
||||
if (config('app.debug')) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
return parent::handle($request, $next, $maxAttempts, $decayMinutes);
|
||||
}
|
||||
}
|
||||
+36
-1
@@ -6,7 +6,7 @@ namespace App\Models;
|
||||
* Row in a data table
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $data - JSONB
|
||||
* @property string $data - JSONB, always containing _grid
|
||||
*/
|
||||
class Row extends BaseModel
|
||||
{
|
||||
@@ -16,4 +16,39 @@ class Row extends BaseModel
|
||||
|
||||
protected $guarded = [];
|
||||
public $timestamps = false;
|
||||
|
||||
public function getGridAttribute() {
|
||||
return $this->data->_grid;
|
||||
}
|
||||
|
||||
public function setGridAttribute($value) {
|
||||
$this->data->_grid = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocate a single Global Row ID, application-unique.
|
||||
*
|
||||
* GRIDs are used to uniquely identify existing or proposed new rows,
|
||||
* and are preserved after row modifications, to ensure change proposals have
|
||||
* a clear target.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function allocateGRID()
|
||||
{
|
||||
return \DB::selectOne("SELECT nextval('global_row_id_seq') AS grid;")->grid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocate a block of Global Row IDs, application-unique.
|
||||
*
|
||||
* @see Row::allocateGRID()
|
||||
*
|
||||
* @return int[] first and last
|
||||
*/
|
||||
public static function allocateGRIDs($count)
|
||||
{
|
||||
$last = \DB::selectOne("SELECT multi_nextval('global_row_id_seq', ?) AS last_grid;", [$count])->last_grid;
|
||||
return [$last - $count + 1, $last];
|
||||
}
|
||||
}
|
||||
|
||||
+5
-1
@@ -62,7 +62,7 @@ class User extends BaseModel implements
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name', 'title', 'email', 'password', 'bio', 'website'
|
||||
'name', 'title', 'email', 'password', 'bio', 'website', 'confirmed'
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -183,6 +183,10 @@ class User extends BaseModel implements
|
||||
}
|
||||
else {
|
||||
$u = static::where('email', $ident)->first();
|
||||
|
||||
if (!$u) {
|
||||
$u = static::where('name', $ident)->first();
|
||||
}
|
||||
}
|
||||
|
||||
if (!$u) throw new NotExistException("No user found matching \"$ident\"");
|
||||
|
||||
@@ -57,6 +57,10 @@ class Column implements JsonSerializable
|
||||
$this->title = $b->title;
|
||||
$this->type = $b->type;
|
||||
|
||||
if ($this->name == '_grid') { // global row ID
|
||||
throw new NotApplicableException("_grid is a reserved column name.");
|
||||
}
|
||||
|
||||
if (!in_array($this->type, self::colTypes)) {
|
||||
throw new NotApplicableException("\"$this->type\" is not a valid column type.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user