Skip to content

Commit

Permalink
lasteditor => user_id to match Spacialist
Browse files Browse the repository at this point in the history
Signed-off-by: Vinzenz Rosenkranz <vinzenz.rosenkranz@uni-tuebingen.de>
  • Loading branch information
v1r0x committed Jul 21, 2021
1 parent dc8c7a4 commit d223671
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 31 deletions.
4 changes: 2 additions & 2 deletions app/Http/Controllers/LanguageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function addLanguage(Request $request) {
$language = new ThLanguage();
$language->display_name = $request->get('display_name');
$language->short_name = $request->get('short_name');
$language->lasteditor = $user->name;
$language->user_id = $user->id;
$language->save();

return response()->json($language);
Expand Down Expand Up @@ -81,7 +81,7 @@ public function patchLanguage(Request $request, $id) {
if($request->has('short_name')) {
$language->short_name = $request->get('short_name');
}
$language->lasteditor = $user->name;
$language->user_id = $user->id;
$language->save();

return response()->json($language);
Expand Down
36 changes: 18 additions & 18 deletions app/Http/Controllers/TreeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ public function addConcept(Request $request) {
$thConcept->concept_url = $url;
$thConcept->concept_scheme = $scheme;
$thConcept->is_top_concept = $isTop;
$thConcept->lasteditor = $user->name;
$thConcept->user_id = $user->id;
$thConcept->save();

if(!$isTop) {
Expand All @@ -305,7 +305,7 @@ public function addConcept(Request $request) {
$thConceptLabel->label = $label;
$thConceptLabel->concept_id = $thConcept->id;
$thConceptLabel->language_id = $labelLangId;
$thConceptLabel->lasteditor = $user->name;
$thConceptLabel->user_id = $user->id;
$thConceptLabel->save();

$thConcept->loadMissing('labels.language');
Expand Down Expand Up @@ -501,7 +501,7 @@ public function addLabel(Request $request) {
$thLabel->concept_id = $cid;
$thLabel->language_id = $langId;
$thLabel->concept_label_type = $type;
$thLabel->lasteditor = $user->name;
$thLabel->user_id = $user->id;
$thLabel->save();

$thLabel->language;
Expand Down Expand Up @@ -876,18 +876,18 @@ public function import(Request $request) {
count($r->allResources('skos:broaderTransitive')) === 0;
}
$scheme = '';
$lasteditor = $user->name;
$user_id = $user->id;

$needsUpdate = $type == 'update-extend' && $conceptExists;
if($needsUpdate) {
$cid = $concept->id;
} else {
$cid = DB::table($thConcept)
->insertGetId([
'concept_url' => $url,
'concept_scheme' => $scheme,
'is_top_concept' => $isTopConcept,
'lasteditor' => $lasteditor
'concept_url' => $url,
'concept_scheme' => $scheme,
'is_top_concept' => $isTopConcept,
'user_id' => $user_id
]);
}

Expand All @@ -914,12 +914,12 @@ public function import(Request $request) {
->where($where)
->update([
'label' => $label,
'lasteditor' => $lasteditor
'user_id' => $user_id
]);
} else {
DB::table($thLabel)
->insert([
'lasteditor' => $lasteditor,
'user_id' => $user_id,
'label' => $label,
'concept_id' => $cid,
'language_id' => $lid,
Expand All @@ -929,7 +929,7 @@ public function import(Request $request) {
} else {
DB::table($thLabel)
->insert([
'lasteditor' => $lasteditor,
'user_id' => $user_id,
'label' => $label,
'concept_id' => $cid,
'language_id' => $lid,
Expand Down Expand Up @@ -959,7 +959,7 @@ public function import(Request $request) {
if($cnt === 0) {
DB::table($thLabel)
->insert([
'lasteditor' => $lasteditor,
'user_id' => $user_id,
'label' => $label,
'concept_id' => $cid,
'language_id' => $lid,
Expand All @@ -969,7 +969,7 @@ public function import(Request $request) {
} else {
DB::table($thLabel)
->insert([
'lasteditor' => $lasteditor,
'user_id' => $user_id,
'label' => $label,
'concept_id' => $cid,
'language_id' => $lid,
Expand Down Expand Up @@ -1141,7 +1141,7 @@ public function copy(Request $request) {

$rows = DB::select("
WITH RECURSIVE
q(id, concept_url, concept_scheme, lasteditor, is_top_concept, created_at, updated_at, broader_id, lvl) AS
q(id, concept_url, concept_scheme, user_id, is_top_concept, created_at, updated_at, broader_id, lvl) AS
(
SELECT conc.*, -1, 0
FROM $thConceptSrc conc
Expand Down Expand Up @@ -1174,7 +1174,7 @@ public function copy(Request $request) {
else $currentConcept = new ThConceptProject();
$currentConcept->concept_url = $row->concept_url;
$currentConcept->concept_scheme = $row->concept_scheme;
$currentConcept->lasteditor = 'postgres';
$currentConcept->user_id = $user->id;
$currentConcept->is_top_concept = $row->is_top_concept;
$currentConcept->save();
} else {
Expand Down Expand Up @@ -1213,7 +1213,7 @@ public function copy(Request $request) {
if($conceptAlreadyExists) $l->concept_label_type = 2;
if($src == 'project') $currentLabel = new ThConceptLabel();
else $currentLabel = new ThConceptLabelSandbox();
$currentLabel->lasteditor = 'postgres';
$currentLabel->user_id = $user->id;
$currentLabel->label = $l->label;
$currentLabel->concept_id = $l->concept_id;
$currentLabel->language_id = $l->language_id;
Expand Down Expand Up @@ -1250,7 +1250,7 @@ public function copy(Request $request) {
//get new elements
$elements = DB::select("
WITH RECURSIVE
q(id, concept_url, concept_scheme, lasteditor, is_top_concept, created_at, updated_at, label, broader_id, reclevel) AS
q(id, concept_url, concept_scheme, user_id, is_top_concept, created_at, updated_at, label, broader_id, reclevel) AS
(
SELECT conc.*, f.label, $newBroader, 0
FROM $thConcept conc
Expand Down Expand Up @@ -1412,7 +1412,7 @@ private static function cloneConceptTree($srcId, $tgtBroaderId, $srcTree, $tgtTr
'language_id' => $label->language_id
];
$newAttrs = [
'lasteditor' => $user->name
'user_id' => $user->id
];
if($srcTree === 'sandbox') {
ThConceptLabel::firstOrCreate($attrs, $newAttrs);
Expand Down
2 changes: 1 addition & 1 deletion app/ThConcept.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ThConcept extends Model
protected $fillable = [
'concept_url',
'concept_scheme',
'lasteditor',
'user_id',
];

// protected $appends = ['parents', 'path'];
Expand Down
2 changes: 1 addition & 1 deletion app/ThConceptLabel.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ThConceptLabel extends Model
protected $fillable = [
'concept_id',
'language_id',
'lasteditor',
'user_id',
'label',
'concept_label_type',
];
Expand Down
2 changes: 1 addition & 1 deletion app/ThConceptLabelSandbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ThConceptLabelSandbox extends Model
protected $fillable = [
'concept_id',
'language_id',
'lasteditor',
'user_id',
'label',
'concept_label_type',
];
Expand Down
2 changes: 1 addition & 1 deletion app/ThConceptSandbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ThConceptSandbox extends Model
protected $fillable = [
'concept_url',
'concept_scheme',
'lasteditor',
'user_id',
];

// protected $appends = ['parents', 'path'];
Expand Down
2 changes: 1 addition & 1 deletion app/ThLanguage.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ThLanguage extends Model
* @var array
*/
protected $fillable = [
'lasteditor',
'user_id',
'display_name',
'short_name',
];
Expand Down
74 changes: 74 additions & 0 deletions database/migrations/2021_07_21_070235_replace_lasteditor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

use App\User;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class ReplaceLasteditor extends Migration
{
private $withLasteditor = [
'th_concept_master',
'th_concept_label_master',
'th_language',
];

/**
* Run the migrations.
*
* @return void
*/
public function up()
{
foreach ($this->withLasteditor as $le) {
// Skip tables which already updated by Spacialist
if(Schema::hasColumn($le, 'user_id')) continue;

$entries = $this->getElements($le);

Schema::table($le, function (Blueprint $table) {
$table->dropColumn('lasteditor');
$table->integer('user_id')->nullable();
});

foreach ($entries as $e) {
try {
$user = User::where('name', $e->lasteditor)->firstOrFail();
} catch (ModelNotFoundException $exc) {
$user = User::orderBy('id')->first();
}
$e->user_id = $user->id;
$e->save();
}

Schema::table($le, function (Blueprint $table) {
$table->integer('user_id')->nullable(false)->change();

$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
});
}
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}

private function getElements($tableName)
{
switch ($tableName) {
case 'th_concept_master':
return \App\ThConceptSandbox::all();
case 'th_concept_label_master':
return \App\ThConceptLabelSandbox::all();
case 'th_language':
return \App\ThLanguage::all();
}
}
}
12 changes: 7 additions & 5 deletions database/seeds/LanguageTableSeeder.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use App\User;
use Illuminate\Database\Seeder;

class LanguageTableSeeder extends Seeder
Expand All @@ -11,29 +12,30 @@ class LanguageTableSeeder extends Seeder
*/
public function run()
{
$admin = User::where('name', 'Admin')->first();
DB::table('th_language')->delete();
DB::table('th_language')->insert(array(
'lasteditor' => 'postgres',
'user_id' => $admin->id,
'display_name' => 'Deutsch',
'short_name' => 'de'
));
DB::table('th_language')->insert(array(
'lasteditor' => 'postgres',
'user_id' => $admin->id,
'display_name' => 'English',
'short_name' => 'en'
));
DB::table('th_language')->insert(array(
'lasteditor' => 'postgres',
'user_id' => $admin->id,
'display_name' => 'Español',
'short_name' => 'es'
));
DB::table('th_language')->insert(array(
'lasteditor' => 'postgres',
'user_id' => $admin->id,
'display_name' => 'Français',
'short_name' => 'fr'
));
DB::table('th_language')->insert(array(
'lasteditor' => 'postgres',
'user_id' => $admin->id,
'display_name' => 'Italiano',
'short_name' => 'it'
));
Expand Down
2 changes: 1 addition & 1 deletion database/seeds/StandaloneSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class StandaloneSeeder extends Seeder
*/
public function run()
{
$this->call('AdminUserSeeder');
$this->call('LanguageTableSeeder');
$this->call('RolesPermissionsSeeder');
$this->call('AdminUserSeeder');
}
}

0 comments on commit d223671

Please sign in to comment.