Update information on anime collection, and remove sqlite file, which can be created by a database migration

This commit is contained in:
Timothy Warren 2015-06-16 15:54:10 -04:00
parent d4d8b5d9c7
commit 38a2b470c5
8 changed files with 97 additions and 5 deletions

5
.gitignore vendored
View File

@ -1,4 +1,7 @@
vendor vendor
app/cache/* app/cache/*
public/images/* public/images/*
composer.lock composer.lock
*.sqlite
*.db
*.sqlite3

View File

@ -6,7 +6,7 @@ A self-hosted client that allows custom formatting of data from the hummingbird
## Features ## Features
* Anime List views: * Anime List views (Each with list and cover views):
* Watching * Watching
* Plan to Watch * Plan to Watch
* On Hold * On Hold
@ -14,7 +14,7 @@ A self-hosted client that allows custom formatting of data from the hummingbird
* Completed * Completed
* All of the above * All of the above
* Manga List views: * Manga List views (Each with list and cover views):
* Reading * Reading
* Plan to Read * Plan to Read
* On Hold * On Hold
@ -36,4 +36,12 @@ A self-hosted client that allows custom formatting of data from the hummingbird
1. Install dependencies via composer: `composer install` 1. Install dependencies via composer: `composer install`
2. Change the `WHOSE` constant declaration in `index.php` to your name 2. Change the `WHOSE` constant declaration in `index.php` to your name
3. Configure settings in `app/config/config.php` to your liking 3. Configure settings in `app/config/config.php` to your liking
#### Anime Collection Additional Installation
* Run `php /vendor/bin/phinx migrate -e development` to create the database tables
* For importing anime:
1. Find the anime you are looking for on the hummingbird search api page: `https://hummingbird.me/api/v1/search/anime?query=`
2. Create an `import.json` file in the root of the app, with an array of objects from the search page that you want to import
3. Go to the anime collection tab, and the import will be run

Binary file not shown.

View File

@ -10,7 +10,7 @@ return (object)[
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// do you wish to show the anime collection tab? // do you wish to show the anime collection tab?
'show_anime_collection' => FALSE, 'show_anime_collection' => TRUE,
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Routing // Routing

View File

@ -14,6 +14,12 @@ class AnimeCollectionModel extends BaseDBModel {
*/ */
private $anime_model; private $anime_model;
/**
* Whether the database is valid for querying
* @var bool
*/
private $valid_database = FALSE;
/** /**
* Constructor * Constructor
*/ */
@ -24,6 +30,12 @@ class AnimeCollectionModel extends BaseDBModel {
$this->db = Query($this->db_config['collection']); $this->db = Query($this->db_config['collection']);
$this->anime_model = new AnimeModel(); $this->anime_model = new AnimeModel();
// Is database valid? If not, set a flag so the
// app can be run without a valid database
$db_file = file_get_contents($this->db_config['collection']['file']);
$this->valid_database = (strpos($db_file, 'SQLite format 3') === 0);
// Do an import if an import file exists // Do an import if an import file exists
$this->json_import(); $this->json_import();
} }
@ -61,6 +73,8 @@ class AnimeCollectionModel extends BaseDBModel {
*/ */
private function _get_collection() private function _get_collection()
{ {
if ( ! $this->valid_database) return [];
$query = $this->db->select('hummingbird_id, slug, title, alternate_title, show_type, age_rating, episode_count, episode_length, cover_image, notes, media.type as media') $query = $this->db->select('hummingbird_id, slug, title, alternate_title, show_type, age_rating, episode_count, episode_length, cover_image, notes, media.type as media')
->from('anime_set a') ->from('anime_set a')
->join('media', 'media.id=a.media_id', 'inner') ->join('media', 'media.id=a.media_id', 'inner')
@ -79,6 +93,7 @@ class AnimeCollectionModel extends BaseDBModel {
private function json_import() private function json_import()
{ {
if ( ! file_exists('import.json')) return; if ( ! file_exists('import.json')) return;
if ( ! $this->valid_database) return;
$anime = json_decode(file_get_contents("import.json")); $anime = json_decode(file_get_contents("import.json"));

View File

@ -3,6 +3,7 @@
"guzzlehttp/guzzle": "5.3.*", "guzzlehttp/guzzle": "5.3.*",
"filp/whoops": "1.1.*", "filp/whoops": "1.1.*",
"aura/router": "2.2.*", "aura/router": "2.2.*",
"aviat4ion/query": "2.0.*" "aviat4ion/query": "2.0.*",
"robmorgan/phinx": "*"
} }
} }

View File

@ -0,0 +1,56 @@
<?php
use Phinx\Migration\AbstractMigration;
class FirstMigration extends AbstractMigration
{
/**
* Migrate up
*/
public function change()
{
// Create media table
$this->table('media')
->addColumn('type', 'string')
->create();
// Add items to media table
if ($this->hasTable('media'))
{
foreach(['DVD & Blu-ray', 'Blu-ray', 'DVD', 'Bootleg DVD'] as $type)
{
$this->execute('INSERT INTO "media" ("type") VALUES (\'' . $type . '\')');
}
}
// Create anime_set table
$anime_set = $this->table('anime_set', ['id' => FALSE, 'primary_key' => ['hummingbird_id']]);
$anime_set->addColumn('hummingbird_id', 'biginteger')
->addColumn('slug', 'string', ['comment' => "URL slug used for image caching and generating links"])
->addColumn('title', 'string')
->addColumn('alternate_title', 'string', ['null' => TRUE])
->addColumn('media_id', 'integer', ['default' => 3, 'null' => TRUE])
->addColumn('show_type', 'string', ['default' => 'TV', 'null' => TRUE, 'comment' => "TV Series/OVA/etc"])
->addColumn('age_rating', 'string', ['default' => 'PG13', 'null' => TRUE])
->addColumn('cover_image', 'string', ['null' => TRUE])
->addColumn('episode_count', 'integer', ['null' => TRUE])
->addColumn('episode_length', 'integer', ['null' => TRUE])
->addColumn('notes', 'text')
->addForeignKey('media_id', 'media', 'id')
->create();
// Create genres table
$this->table('genres')
->addColumn('genre', 'string')
->addIndex('genre', ['unique' => TRUE])
->create();
// Create genre_anime_set_link table
$genre_anime_set_link = $this->table('genre_anime_set_link', ['id' => FALSE, 'primary_key' => ['hummingbird_id', 'genre_id']]);
$genre_anime_set_link->addColumn('hummingbird_id', 'biginteger')
->addColumn('genre_id', 'integer')
->addForeignKey('hummingbird_id', 'anime_set', 'hummingbird_id')
->addForeignKey('genre_id', 'genres', 'id')
->create();
}
}

9
phinx.yml Normal file
View File

@ -0,0 +1,9 @@
paths:
migrations: %%PHINX_CONFIG_DIR%%/migrations
environments:
default_migration_table: phinxlog
default_database: development
development:
adapter: sqlite
name: ./anime_collection.sqlite