Browse Source

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

Timothy J. Warren 3 years ago
parent
commit
38a2b470c5

+ 4
- 1
.gitignore View File

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

+ 10
- 2
README.md View File

@@ -6,7 +6,7 @@ A self-hosted client that allows custom formatting of data from the hummingbird
6 6
 
7 7
 ## Features
8 8
 
9
-* Anime List views:
9
+* Anime List views (Each with list and cover views):
10 10
 	* Watching
11 11
 	* Plan to Watch
12 12
 	* On Hold
@@ -14,7 +14,7 @@ A self-hosted client that allows custom formatting of data from the hummingbird
14 14
 	* Completed 
15 15
 	* All of the above
16 16
 	
17
-* Manga List views:
17
+* Manga List views (Each with list and cover views):
18 18
 	* Reading
19 19
 	* Plan to Read
20 20
 	* On Hold
@@ -36,4 +36,12 @@ A self-hosted client that allows custom formatting of data from the hummingbird
36 36
 1. Install dependencies via composer: `composer install`
37 37
 2. Change the `WHOSE` constant declaration in `index.php` to your name
38 38
 3. Configure settings in `app/config/config.php` to your liking
39
+
40
+#### Anime Collection Additional Installation
41
+* Run `php /vendor/bin/phinx migrate -e development` to create the database tables
42
+* For importing anime:
43
+	1. Find the anime you are looking for on the hummingbird search api page: `https://hummingbird.me/api/v1/search/anime?query=`
44
+	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
45
+	3. Go to the anime collection tab, and the import will be run
46
+
39 47
  

BIN
anime_collection.sqlite View File


+ 1
- 1
app/config/config.php View File

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

+ 15
- 0
app/models/AnimeCollectionModel.php View File

@@ -14,6 +14,12 @@ class AnimeCollectionModel extends BaseDBModel {
14 14
 	 */
15 15
 	private $anime_model;
16 16
 
17
+	/**
18
+	 * Whether the database is valid for querying
19
+	 * @var bool
20
+	 */
21
+	private $valid_database = FALSE;
22
+
17 23
 	/**
18 24
 	 * Constructor
19 25
 	 */
@@ -24,6 +30,12 @@ class AnimeCollectionModel extends BaseDBModel {
24 30
 		$this->db = Query($this->db_config['collection']);
25 31
 		$this->anime_model = new AnimeModel();
26 32
 
33
+		// Is database valid? If not, set a flag so the
34
+		// app can be run without a valid database
35
+		$db_file = file_get_contents($this->db_config['collection']['file']);
36
+		$this->valid_database = (strpos($db_file, 'SQLite format 3') === 0);
37
+
38
+
27 39
 		// Do an import if an import file exists
28 40
 		$this->json_import();
29 41
 	}
@@ -61,6 +73,8 @@ class AnimeCollectionModel extends BaseDBModel {
61 73
 	 */
62 74
 	private function _get_collection()
63 75
 	{
76
+		if ( ! $this->valid_database) return [];
77
+
64 78
 		$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')
65 79
 			->from('anime_set a')
66 80
 			->join('media', 'media.id=a.media_id', 'inner')
@@ -79,6 +93,7 @@ class AnimeCollectionModel extends BaseDBModel {
79 93
 	private function json_import()
80 94
 	{
81 95
 		if ( ! file_exists('import.json')) return;
96
+		if ( ! $this->valid_database) return;
82 97
 
83 98
 		$anime = json_decode(file_get_contents("import.json"));
84 99
 

+ 2
- 1
composer.json View File

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

+ 56
- 0
migrations/20150616181750_first_migration.php View File

@@ -0,0 +1,56 @@
1
+<?php
2
+
3
+use Phinx\Migration\AbstractMigration;
4
+
5
+class FirstMigration extends AbstractMigration
6
+{
7
+	/**
8
+	 * Migrate up
9
+	 */
10
+	public function change()
11
+	{
12
+		// Create media table
13
+		$this->table('media')
14
+			->addColumn('type', 'string')
15
+			->create();
16
+
17
+		// Add items to media table
18
+		if ($this->hasTable('media'))
19
+		{
20
+			foreach(['DVD & Blu-ray', 'Blu-ray', 'DVD', 'Bootleg DVD'] as $type)
21
+			{
22
+				$this->execute('INSERT INTO "media" ("type") VALUES (\'' . $type . '\')');
23
+			}
24
+		}
25
+
26
+		// Create anime_set table
27
+		$anime_set = $this->table('anime_set', ['id' => FALSE, 'primary_key' => ['hummingbird_id']]);
28
+		$anime_set->addColumn('hummingbird_id', 'biginteger')
29
+			->addColumn('slug', 'string', ['comment' => "URL slug used for image caching and generating links"])
30
+			->addColumn('title', 'string')
31
+			->addColumn('alternate_title', 'string', ['null' => TRUE])
32
+			->addColumn('media_id', 'integer', ['default' => 3, 'null' => TRUE])
33
+			->addColumn('show_type', 'string', ['default' => 'TV', 'null' => TRUE, 'comment' => "TV Series/OVA/etc"])
34
+			->addColumn('age_rating', 'string', ['default' => 'PG13', 'null' => TRUE])
35
+			->addColumn('cover_image', 'string', ['null' => TRUE])
36
+			->addColumn('episode_count', 'integer', ['null' => TRUE])
37
+			->addColumn('episode_length', 'integer', ['null' => TRUE])
38
+			->addColumn('notes', 'text')
39
+			->addForeignKey('media_id', 'media', 'id')
40
+			->create();
41
+
42
+		// Create genres table
43
+		$this->table('genres')
44
+			->addColumn('genre', 'string')
45
+			->addIndex('genre', ['unique' => TRUE])
46
+			->create();
47
+
48
+		// Create genre_anime_set_link table
49
+		$genre_anime_set_link = $this->table('genre_anime_set_link', ['id' => FALSE, 'primary_key' => ['hummingbird_id', 'genre_id']]);
50
+		$genre_anime_set_link->addColumn('hummingbird_id', 'biginteger')
51
+			->addColumn('genre_id', 'integer')
52
+			->addForeignKey('hummingbird_id', 'anime_set', 'hummingbird_id')
53
+			->addForeignKey('genre_id', 'genres', 'id')
54
+			->create();
55
+	}
56
+}

+ 9
- 0
phinx.yml View File

@@ -0,0 +1,9 @@
1
+paths:
2
+    migrations: %%PHINX_CONFIG_DIR%%/migrations
3
+
4
+environments:
5
+    default_migration_table: phinxlog
6
+    default_database: development
7
+    development:
8
+        adapter: sqlite
9
+        name: ./anime_collection.sqlite