metadataテーブルにexpires_atカラムを追加
メタデータの有効期限が現在より過去の場合、メタデータを再取得する
This commit is contained in:
parent
a3813f19cf
commit
938a4d6957
@ -10,6 +10,6 @@ class Metadata extends Model
|
|||||||
protected $primaryKey = 'url';
|
protected $primaryKey = 'url';
|
||||||
protected $keyType = 'string';
|
protected $keyType = 'string';
|
||||||
|
|
||||||
protected $fillable = ['url', 'title', 'description', 'image'];
|
protected $fillable = ['url', 'title', 'description', 'image', 'expires_at'];
|
||||||
protected $visible = ['url', 'title', 'description', 'image'];
|
protected $visible = ['url', 'title', 'description', 'image', 'expires_at'];
|
||||||
}
|
}
|
||||||
|
@ -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');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -26,13 +26,14 @@ Route::get('/checkin/card', function (Request $request, MetadataResolver $resolv
|
|||||||
$url = $formatter->normalizeUrl($request->input('url'));
|
$url = $formatter->normalizeUrl($request->input('url'));
|
||||||
|
|
||||||
$metadata = App\Metadata::find($url);
|
$metadata = App\Metadata::find($url);
|
||||||
if ($metadata == null) {
|
if ($metadata == null || new DateTime($metadata->expires_at) < new DateTime("now")) {
|
||||||
$resolved = $resolver->resolve($url);
|
$resolved = $resolver->resolve($url);
|
||||||
$metadata = App\Metadata::create([
|
$metadata = App\Metadata::create([
|
||||||
'url' => $url,
|
'url' => $url,
|
||||||
'title' => $resolved->title,
|
'title' => $resolved->title,
|
||||||
'description' => $resolved->description,
|
'description' => $resolved->description,
|
||||||
'image' => $resolved->image
|
'image' => $resolved->image,
|
||||||
|
'expires_at' => $resolved->expires_at
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user