1
0
mirror of https://github.com/devfake/flox.git synced 2024-11-15 06:32:34 +01:00

Fetch timestamp (#23)

* remove migration comments

* update timestamp by fetch parser

* remote empty line
This commit is contained in:
Viktor Geringer 2017-01-06 13:00:18 +01:00 committed by Tim Meier
parent 7d7553088c
commit dbd6e99eee
21 changed files with 96 additions and 111 deletions

View File

@ -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.

View File

@ -17,7 +17,7 @@
'episode_tmdb_id',
'seen',
'season_tmdb_id',
'created_at'
'created_at',
];
/**

View File

@ -17,9 +17,9 @@
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 Item $item
* @param Storage $storage
*/
public function __construct(Item $item, 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

View File

@ -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(),
]);
}
}

View File

@ -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',
];
}

View File

@ -7,10 +7,12 @@
class User extends Authenticatable {
protected $fillable = [
'username', 'password',
'username',
'password',
];
protected $hidden = [
'password', 'remember_token',
'password',
'remember_token',
];
}

View File

@ -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' => '',

View File

@ -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');

View File

@ -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');

View File

@ -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');

View File

@ -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');

View File

@ -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) {

View File

@ -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) {

View File

@ -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) {

View File

@ -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) {

View File

@ -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) {

View File

@ -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');

View File

@ -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');
});
}
}

View File

@ -17,7 +17,9 @@
$this->assertTrue(Schema::hasColumn('settings', 'episode_spoiler_protection'));
$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::hasTable('alternative_titles'));
$this->assertTrue(Schema::hasColumn('settings', 'last_fetch_to_file_parser'));
}
/** @test */

View File

@ -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([

View File

@ -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([