diff --git a/app/Http/Controllers/Publish/IndexController.php b/app/Http/Controllers/Publish/IndexController.php index c1dded3..2639dbf 100644 --- a/app/Http/Controllers/Publish/IndexController.php +++ b/app/Http/Controllers/Publish/IndexController.php @@ -479,8 +479,13 @@ class IndexController extends Controller //save keywords if (isset($data['keywords'])) { foreach ($request->get('keywords') as $key => $keyword) { - $dataKeyword = new Subject($keyword); - $dataset->subjects()->save($dataKeyword); + // $dataKeyword = new Subject($keyword); + // $dataset->subjects()->save($dataKeyword); + $keyword = Subject::firstOrCreate( + ['value' => $keyword['value']], + $keyword + ); + $dataset->subjects()->attach($keyword); } } diff --git a/app/Library/Xml/DatasetExtension.php b/app/Library/Xml/DatasetExtension.php index 317e151..e17c423 100644 --- a/app/Library/Xml/DatasetExtension.php +++ b/app/Library/Xml/DatasetExtension.php @@ -78,6 +78,7 @@ trait DatasetExtension ), 'Subject' => array( 'model' => Subject::class, + 'through' => 'link_dataset_subjects', 'relation' => 'subjects', 'fetch' => 'eager' ), diff --git a/app/Models/Dataset.php b/app/Models/Dataset.php index e465884..16efd2f 100644 --- a/app/Models/Dataset.php +++ b/app/Models/Dataset.php @@ -260,9 +260,13 @@ class Dataset extends Model return $this->hasMany(\App\Models\DatasetReference::class, 'document_id', 'id'); } + // public function subjects() + // { + // return $this->hasMany(\App\Models\Subject::class, 'document_id', 'id'); + // } public function subjects() { - return $this->hasMany(\App\Models\Subject::class, 'document_id', 'id'); + return $this->belongsToMany(\App\Models\Subject::class, 'link_dataset_subjects', 'document_id', 'subject_id'); } /** diff --git a/app/Models/Subject.php b/app/Models/Subject.php index c992e2c..7223ec7 100644 --- a/app/Models/Subject.php +++ b/app/Models/Subject.php @@ -7,13 +7,18 @@ use App\Models\Dataset; class Subject extends Model { - protected $table = 'document_subjects'; + // protected $table = 'document_subjects'; + protected $table = 'dataset_subjects'; public $timestamps = false; protected $fillable = ['value', 'type', 'language']; - public function dataset() + // public function dataset() + // { + // return $this->belongsTo(Dataset::class, 'document_id', 'id'); + // } + public function datasets() { - return $this->belongsTo(Dataset::class, 'document_id', 'id'); + return $this->belongsToMany(Dataset::class, 'link_dataset_subjects', 'subject_id', 'document_id'); } } diff --git a/composer.lock b/composer.lock index 0536396..d75b9a4 100755 --- a/composer.lock +++ b/composer.lock @@ -3870,16 +3870,16 @@ }, { "name": "symfony/http-foundation", - "version": "v5.3.0", + "version": "v5.3.1", "source": { "type": "git", "url": "https://github.com/symfony/http-foundation.git", - "reference": "31f25d99b329a1461f42bcef8505b54926a30be6" + "reference": "8827b90cf8806e467124ad476acd15216c2fceb6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-foundation/zipball/31f25d99b329a1461f42bcef8505b54926a30be6", - "reference": "31f25d99b329a1461f42bcef8505b54926a30be6", + "url": "https://api.github.com/repos/symfony/http-foundation/zipball/8827b90cf8806e467124ad476acd15216c2fceb6", + "reference": "8827b90cf8806e467124ad476acd15216c2fceb6", "shasum": "" }, "require": { @@ -3923,7 +3923,7 @@ "description": "Defines an object-oriented layer for the HTTP specification", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/http-foundation/tree/v5.3.0" + "source": "https://github.com/symfony/http-foundation/tree/v5.3.1" }, "funding": [ { @@ -3939,20 +3939,20 @@ "type": "tidelift" } ], - "time": "2021-05-26T17:43:10+00:00" + "time": "2021-06-02T09:32:00+00:00" }, { "name": "symfony/http-kernel", - "version": "v5.3.0", + "version": "v5.3.1", "source": { "type": "git", "url": "https://github.com/symfony/http-kernel.git", - "reference": "f8e8f5391b6909e2f0ba8c12220ab7af3050eb4f" + "reference": "74eb022e3bac36b3d3a897951a98759f2b32b864" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-kernel/zipball/f8e8f5391b6909e2f0ba8c12220ab7af3050eb4f", - "reference": "f8e8f5391b6909e2f0ba8c12220ab7af3050eb4f", + "url": "https://api.github.com/repos/symfony/http-kernel/zipball/74eb022e3bac36b3d3a897951a98759f2b32b864", + "reference": "74eb022e3bac36b3d3a897951a98759f2b32b864", "shasum": "" }, "require": { @@ -4035,7 +4035,7 @@ "description": "Provides a structured process for converting a Request into a Response", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/http-kernel/tree/v5.3.0" + "source": "https://github.com/symfony/http-kernel/tree/v5.3.1" }, "funding": [ { @@ -4051,7 +4051,7 @@ "type": "tidelift" } ], - "time": "2021-05-31T10:44:03+00:00" + "time": "2021-06-02T10:07:12+00:00" }, { "name": "symfony/mime", @@ -6515,16 +6515,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.5.4", + "version": "9.5.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "c73c6737305e779771147af66c96ca6a7ed8a741" + "reference": "89ff45ea9d70e35522fb6654a2ebc221158de276" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c73c6737305e779771147af66c96ca6a7ed8a741", - "reference": "c73c6737305e779771147af66c96ca6a7ed8a741", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/89ff45ea9d70e35522fb6654a2ebc221158de276", + "reference": "89ff45ea9d70e35522fb6654a2ebc221158de276", "shasum": "" }, "require": { @@ -6554,7 +6554,7 @@ "sebastian/global-state": "^5.0.1", "sebastian/object-enumerator": "^4.0.3", "sebastian/resource-operations": "^3.0.3", - "sebastian/type": "^2.3", + "sebastian/type": "^2.3.2", "sebastian/version": "^3.0.2" }, "require-dev": { @@ -6602,7 +6602,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.4" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.5" }, "funding": [ { @@ -6614,7 +6614,7 @@ "type": "github" } ], - "time": "2021-03-23T07:16:29+00:00" + "time": "2021-06-05T04:49:07+00:00" }, { "name": "sebastian/cli-parser", @@ -7473,16 +7473,16 @@ }, { "name": "sebastian/type", - "version": "2.3.1", + "version": "2.3.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/type.git", - "reference": "81cd61ab7bbf2de744aba0ea61fae32f721df3d2" + "reference": "0d1c587401514d17e8f9258a27e23527cb1b06c1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/81cd61ab7bbf2de744aba0ea61fae32f721df3d2", - "reference": "81cd61ab7bbf2de744aba0ea61fae32f721df3d2", + "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/0d1c587401514d17e8f9258a27e23527cb1b06c1", + "reference": "0d1c587401514d17e8f9258a27e23527cb1b06c1", "shasum": "" }, "require": { @@ -7517,7 +7517,7 @@ "homepage": "https://github.com/sebastianbergmann/type", "support": { "issues": "https://github.com/sebastianbergmann/type/issues", - "source": "https://github.com/sebastianbergmann/type/tree/2.3.1" + "source": "https://github.com/sebastianbergmann/type/tree/2.3.2" }, "funding": [ { @@ -7525,7 +7525,7 @@ "type": "github" } ], - "time": "2020-10-26T13:18:59+00:00" + "time": "2021-06-04T13:02:07+00:00" }, { "name": "sebastian/version", @@ -7701,5 +7701,5 @@ "platform-overrides": { "php": "7.3" }, - "plugin-api-version": "2.0.0" + "plugin-api-version": "2.1.0" } diff --git a/database/migrations/2021_06_07_135923_create_dataset_subjects_table.php b/database/migrations/2021_06_07_135923_create_dataset_subjects_table.php new file mode 100644 index 0000000..232afa3 --- /dev/null +++ b/database/migrations/2021_06_07_135923_create_dataset_subjects_table.php @@ -0,0 +1,58 @@ +id(); + $table->string('language', 3)->nullable(); + $table->enum( + 'type', + ['uncontrolled'] + ); + $table->string('value', 255); + $table->string('external_key', 255)->nullable(); + $table->nullableTimestamps(); + }); + + Schema::create('link_dataset_subjects', function (Blueprint $table) { + // $table->increments('id'); + + $table->unsignedInteger('subject_id')->index(); + $table->foreign('subject_id') + ->references('id')->on('dataset_subjects') + ->onDelete('no action')->onUpdate('no action'); //detach the relation via code + + $table->unsignedInteger('document_id')->index(); + $table->foreign('document_id') + ->references('id')->on('documents') + ->onDelete('cascade')->onUpdate('cascade'); + + $table->primary(['subject_id', 'document_id']); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('link_dataset_subjects'); + Schema::dropIfExists('dataset_subjects'); + } +} diff --git a/routes/api.php b/routes/api.php index 1cb690f..15cf0b7 100644 --- a/routes/api.php +++ b/routes/api.php @@ -14,8 +14,11 @@ use App\Models\Person; | is assigned the "api" middleware group. Enjoy building your API! | */ +$base_domain = config('app.url'); +$alias_domain = config('app.alias_url'); -Route::domain('tethys.at')->group(function () { +// Route::domain('tethys.at')->group(function () { +$appRoutes = function () { Route::match(array('GET', 'POST'), '/oai', ['as' => 'oai', 'uses' => 'Oai\RequestController@index']); @@ -79,4 +82,9 @@ Route::domain('tethys.at')->group(function () { ->header('Access-Control-Allow-Origin', '*') ->header('Access-Control-Allow-Methods', 'GET'); }); -}); +}; + +Route::group(array('domain' => $base_domain), $appRoutes); +if ($alias_domain) { + Route::group(array('domain' => $alias_domain), $appRoutes); +}