From 38a2b470c5a0fcd14393bb9bc979ce95ad176bf7 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Tue, 16 Jun 2015 15:54:10 -0400 Subject: [PATCH] Update information on anime collection, and remove sqlite file, which can be created by a database migration --- .gitignore | 5 +- README.md | 12 +++- anime_collection.sqlite | Bin 12288 -> 0 bytes app/config/config.php | 2 +- app/models/AnimeCollectionModel.php | 15 +++++ composer.json | 3 +- migrations/20150616181750_first_migration.php | 56 ++++++++++++++++++ phinx.yml | 9 +++ 8 files changed, 97 insertions(+), 5 deletions(-) delete mode 100755 anime_collection.sqlite create mode 100644 migrations/20150616181750_first_migration.php create mode 100644 phinx.yml diff --git a/.gitignore b/.gitignore index d8e76b2e..6c3fe56e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ vendor app/cache/* public/images/* -composer.lock \ No newline at end of file +composer.lock +*.sqlite +*.db +*.sqlite3 \ No newline at end of file diff --git a/README.md b/README.md index b4a9004a..44e77a0e 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ A self-hosted client that allows custom formatting of data from the hummingbird ## Features -* Anime List views: +* Anime List views (Each with list and cover views): * Watching * Plan to Watch * On Hold @@ -14,7 +14,7 @@ A self-hosted client that allows custom formatting of data from the hummingbird * Completed * All of the above -* Manga List views: +* Manga List views (Each with list and cover views): * Reading * Plan to Read * 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` 2. Change the `WHOSE` constant declaration in `index.php` to your name 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 + \ No newline at end of file diff --git a/anime_collection.sqlite b/anime_collection.sqlite deleted file mode 100755 index 2d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?+o=o<6Y!RPf;Y@3u81znwAeO^0EQw5YK$7h+N) z<@Cr9m8$~M6@B|3-VliGoI!oXje2LSBf3-Hx zGw-R@|DhxA`}Kc*{a>wSaf-Fn|G`5t>(~GBOWD@?Kfw6&zW;Se_X*sBS7DmYBI&nX ziNI4!v|AU$A?3&s>B?ZU(z>HW+xyPk!IRs{T(^_hsnWS#$IM#FkQ;@%ot@&fQtj6A g FALSE, + 'show_anime_collection' => TRUE, // ---------------------------------------------------------------------------- // Routing diff --git a/app/models/AnimeCollectionModel.php b/app/models/AnimeCollectionModel.php index 061ac8d9..9d7a5cbc 100644 --- a/app/models/AnimeCollectionModel.php +++ b/app/models/AnimeCollectionModel.php @@ -14,6 +14,12 @@ class AnimeCollectionModel extends BaseDBModel { */ private $anime_model; + /** + * Whether the database is valid for querying + * @var bool + */ + private $valid_database = FALSE; + /** * Constructor */ @@ -24,6 +30,12 @@ class AnimeCollectionModel extends BaseDBModel { $this->db = Query($this->db_config['collection']); $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 $this->json_import(); } @@ -61,6 +73,8 @@ class AnimeCollectionModel extends BaseDBModel { */ 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') ->from('anime_set a') ->join('media', 'media.id=a.media_id', 'inner') @@ -79,6 +93,7 @@ class AnimeCollectionModel extends BaseDBModel { private function json_import() { if ( ! file_exists('import.json')) return; + if ( ! $this->valid_database) return; $anime = json_decode(file_get_contents("import.json")); diff --git a/composer.json b/composer.json index c126b95a..cbf24110 100644 --- a/composer.json +++ b/composer.json @@ -3,6 +3,7 @@ "guzzlehttp/guzzle": "5.3.*", "filp/whoops": "1.1.*", "aura/router": "2.2.*", - "aviat4ion/query": "2.0.*" + "aviat4ion/query": "2.0.*", + "robmorgan/phinx": "*" } } \ No newline at end of file diff --git a/migrations/20150616181750_first_migration.php b/migrations/20150616181750_first_migration.php new file mode 100644 index 00000000..080a70e8 --- /dev/null +++ b/migrations/20150616181750_first_migration.php @@ -0,0 +1,56 @@ +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(); + } +} diff --git a/phinx.yml b/phinx.yml new file mode 100644 index 00000000..23cc4bae --- /dev/null +++ b/phinx.yml @@ -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