metadataテーブルにexpires_atカラムを追加

メタデータの有効期限が現在より過去の場合、メタデータを再取得する
This commit is contained in:
eai04191 2019-01-15 15:31:15 +09:00
parent a3813f19cf
commit 938a4d6957
3 changed files with 37 additions and 4 deletions

View File

@ -10,6 +10,6 @@ class Metadata extends Model
protected $primaryKey = 'url';
protected $keyType = 'string';
protected $fillable = ['url', 'title', 'description', 'image'];
protected $visible = ['url', 'title', 'description', 'image'];
protected $fillable = ['url', 'title', 'description', 'image', 'expires_at'];
protected $visible = ['url', 'title', 'description', 'image', 'expires_at'];
}

View File

@ -0,0 +1,32 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddExpiresOnMetadata extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('metadata', function (Blueprint $table) {
$table->timestamp('expires_at')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('metadata', function (Blueprint $table) {
$table->removeColumn('expires_at');
});
}
}

View File

@ -26,13 +26,14 @@ Route::get('/checkin/card', function (Request $request, MetadataResolver $resolv
$url = $formatter->normalizeUrl($request->input('url'));
$metadata = App\Metadata::find($url);
if ($metadata == null) {
if ($metadata == null || new DateTime($metadata->expires_at) < new DateTime("now")) {
$resolved = $resolver->resolve($url);
$metadata = App\Metadata::create([
'url' => $url,
'title' => $resolved->title,
'description' => $resolved->description,
'image' => $resolved->image
'image' => $resolved->image,
'expires_at' => $resolved->expires_at
]);
}