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 2d54736b..00000000 Binary files a/anime_collection.sqlite and /dev/null differ diff --git a/app/config/config.php b/app/config/config.php index 65e9a7a7..931be018 100644 --- a/app/config/config.php +++ b/app/config/config.php @@ -10,7 +10,7 @@ return (object)[ // ---------------------------------------------------------------------------- // do you wish to show the anime collection tab? - 'show_anime_collection' => 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