mirror of
https://github.com/devfake/flox.git
synced 2024-11-15 14:42:31 +01:00
Fetch timestamp (#23)
* remove migration comments * update timestamp by fetch parser * remote empty line
This commit is contained in:
parent
7d7553088c
commit
dbd6e99eee
@ -9,7 +9,11 @@
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = ['title', 'tmdb_id', 'country'];
|
||||
protected $fillable = [
|
||||
'title',
|
||||
'tmdb_id',
|
||||
'country'
|
||||
];
|
||||
|
||||
/**
|
||||
* Store all alternative titles for tv shows and movies.
|
||||
|
@ -17,7 +17,7 @@
|
||||
'episode_tmdb_id',
|
||||
'seen',
|
||||
'season_tmdb_id',
|
||||
'created_at'
|
||||
'created_at',
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -17,7 +17,7 @@
|
||||
private $storage;
|
||||
|
||||
/**
|
||||
* Get the amout of loading items and create an instance for 'item'.
|
||||
* Get the amount of loading items and create an instance for 'item'.
|
||||
*
|
||||
* @param Item $item
|
||||
* @param Storage $storage
|
||||
@ -99,7 +99,7 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new movie to database and create the poster image file.
|
||||
* Create a new movie / tv show.
|
||||
*
|
||||
* @param TMDB $tmdb
|
||||
* @return Item
|
||||
|
@ -5,6 +5,8 @@
|
||||
use App\AlternativeTitle;
|
||||
use App\Episode;
|
||||
use App\Item;
|
||||
use App\Setting;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
class FileParser {
|
||||
@ -32,6 +34,8 @@
|
||||
*/
|
||||
public function fetch()
|
||||
{
|
||||
$this->updateTimestamp();
|
||||
|
||||
return json_decode(
|
||||
file_get_contents(base_path('tests/fixtures/Files/all.json'))
|
||||
);
|
||||
@ -153,4 +157,14 @@
|
||||
'src' => $item->src,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update last time we fetched flox-file-parser.
|
||||
*/
|
||||
private function updateTimestamp()
|
||||
{
|
||||
Setting::first()->update([
|
||||
'last_fetch_to_file_parser' => Carbon::now(),
|
||||
]);
|
||||
}
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
@ -8,5 +7,14 @@
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = ['show_date', 'show_genre', 'episode_spoiler_protection'];
|
||||
protected $dates = [
|
||||
'last_fetch_to_file_parser',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'show_date',
|
||||
'show_genre',
|
||||
'episode_spoiler_protection',
|
||||
'last_fetch_to_file_parser',
|
||||
];
|
||||
}
|
@ -7,10 +7,12 @@
|
||||
class User extends Authenticatable {
|
||||
|
||||
protected $fillable = [
|
||||
'username', 'password',
|
||||
'username',
|
||||
'password',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'password', 'remember_token',
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
}
|
||||
|
@ -10,6 +10,15 @@
|
||||
];
|
||||
});
|
||||
|
||||
$factory->define(App\Setting::class, function(Faker\Generator $faker) {
|
||||
return [
|
||||
'show_date' => 1,
|
||||
'show_genre' => 1,
|
||||
'episode_spoiler_protection' => '',
|
||||
'last_fetch_to_file_parser' => null,
|
||||
];
|
||||
});
|
||||
|
||||
$factory->define(App\Item::class, function(Faker\Generator $faker) {
|
||||
return [
|
||||
'poster' => '',
|
||||
|
@ -5,11 +5,6 @@ use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateItemsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('items', function(Blueprint $table) {
|
||||
@ -26,11 +21,6 @@ class CreateItemsTable extends Migration
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('items');
|
||||
|
@ -5,11 +5,6 @@ use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateUsersTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('users', function (Blueprint $table) {
|
||||
@ -21,11 +16,6 @@ class CreateUsersTable extends Migration
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('users');
|
||||
|
@ -6,11 +6,6 @@ use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateSettingsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('settings', function (Blueprint $table) {
|
||||
@ -20,11 +15,6 @@ class CreateSettingsTable extends Migration
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('settings');
|
||||
|
@ -6,11 +6,6 @@ use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateEpisodesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('episodes', function (Blueprint $table) {
|
||||
@ -25,11 +20,6 @@ class CreateEpisodesTable extends Migration
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('episodes');
|
||||
|
@ -6,11 +6,6 @@ use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddCreatedAtField extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('episodes', function (Blueprint $table) {
|
||||
@ -18,11 +13,6 @@ class AddCreatedAtField extends Migration
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('episodes', function (Blueprint $table) {
|
||||
|
@ -6,11 +6,6 @@ use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddEpisodeSpoilerProtectionField extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('settings', function (Blueprint $table) {
|
||||
@ -18,11 +13,6 @@ class AddEpisodeSpoilerProtectionField extends Migration
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('settings', function (Blueprint $table) {
|
||||
|
@ -6,11 +6,6 @@ use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class ChangeOriginalTitleField extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('items', function (Blueprint $table) {
|
||||
@ -18,11 +13,6 @@ class ChangeOriginalTitleField extends Migration
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('items', function (Blueprint $table) {
|
||||
|
@ -6,11 +6,6 @@ use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddSrcFieldForEpisodes extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('episodes', function (Blueprint $table) {
|
||||
@ -18,11 +13,6 @@ class AddSrcFieldForEpisodes extends Migration
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('episodes', function (Blueprint $table) {
|
||||
|
@ -6,11 +6,6 @@ use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddSrcFieldForItems extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('items', function (Blueprint $table) {
|
||||
@ -18,11 +13,6 @@ class AddSrcFieldForItems extends Migration
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('items', function (Blueprint $table) {
|
||||
|
@ -6,11 +6,6 @@ use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateAlternativeTitlesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('alternative_titles', function (Blueprint $table) {
|
||||
@ -21,11 +16,6 @@ class CreateAlternativeTitlesTable extends Migration
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('alternative_titles');
|
||||
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddLastFetchToFileParserField extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
Schema::table('settings', function (Blueprint $table) {
|
||||
$table->timestamp('last_fetch_to_file_parser')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
Schema::table('settings', function (Blueprint $table) {
|
||||
$table->dropColumn('last_fetch_to_file_parser');
|
||||
});
|
||||
}
|
||||
}
|
@ -18,6 +18,8 @@
|
||||
$this->assertTrue(Schema::hasColumn('episodes', 'src'));
|
||||
$this->assertTrue(Schema::hasColumn('items', 'src'));
|
||||
$this->assertTrue(Schema::hasTable('alternative_titles'));
|
||||
$this->assertTrue(Schema::hasTable('alternative_titles'));
|
||||
$this->assertTrue(Schema::hasColumn('settings', 'last_fetch_to_file_parser'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
|
@ -5,6 +5,7 @@
|
||||
use App\Item;
|
||||
use App\Services\Storage;
|
||||
use App\Services\TMDB;
|
||||
use App\Setting;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Handler\MockHandler;
|
||||
use GuzzleHttp\HandlerStack;
|
||||
@ -135,6 +136,24 @@
|
||||
}
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_can_update_last_fetch_to_file_parser_timestamp()
|
||||
{
|
||||
$this->createSetting();
|
||||
$this->createMovie();
|
||||
|
||||
$setting1 = Setting::first();
|
||||
$this->parser->fetch();
|
||||
$setting2 = Setting::first();
|
||||
sleep(1);
|
||||
$this->parser->fetch();
|
||||
$setting3 = Setting::first();
|
||||
|
||||
$this->assertNull($setting1->last_fetch_to_file_parser);
|
||||
$this->assertNotNull($setting2->last_fetch_to_file_parser);
|
||||
$this->assertNotEquals($setting2->last_fetch_to_file_parser, $setting3->last_fetch_to_file_parser);
|
||||
}
|
||||
|
||||
private function createTmdbMock($fixture, $alternativeTitles)
|
||||
{
|
||||
$mock = new MockHandler([
|
||||
|
@ -40,6 +40,11 @@
|
||||
$this->fixtureTmdbEpisodes = json_decode(file_get_contents(__DIR__ . '/fixtures/Tmdb/episodes.json'));
|
||||
}
|
||||
|
||||
protected function createSetting()
|
||||
{
|
||||
factory(App\Setting::class)->create();
|
||||
}
|
||||
|
||||
protected function createMovie()
|
||||
{
|
||||
factory(App\Item::class)->create([
|
||||
|
Loading…
Reference in New Issue
Block a user