Skip to content

Commit

Permalink
Merge pull request #534 from NFDI4Chem/development
Browse files Browse the repository at this point in the history
fix: removing duplicate dataset types
  • Loading branch information
NishaSharma14 authored Oct 25, 2022
2 parents 292ad92 + a85044c commit 1b2ef55
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 55 deletions.
104 changes: 50 additions & 54 deletions app/Console/Commands/SanitizeProjects.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,19 @@ public function cleanDrafts()
foreach ($privateProjects as $project) {
DB::transaction(function () use ($project) {
if (! $project->draft) {
echo($project->id);
$project->draft_id = null;
$project->save();
}
});
}

$projects = Project::where([
$privateProjectsWithOutDrafts = Project::where([
['is_public', false],
['draft_id', null],
])->get();

foreach ($projects as $project) {
foreach ($privateProjectsWithOutDrafts as $project) {
DB::transaction(function () use ($project) {
$user_id = $project->owner->id;
$team_id = $project->team_id;
Expand Down Expand Up @@ -201,9 +202,11 @@ public function cleanDrafts()
$parent = $FSObject->parent;
$parent->project_id = $project->id;
$parent->save();
$FSObject->project_id = 0;
$FSObject->save();
$this->updateDraftId($parent->fresh(), $project);
}
} else {
}else {
foreach ($projectFSObjects as $FSObject) {
$this->updateDraftId($FSObject, $project);
}
Expand All @@ -212,68 +215,61 @@ public function cleanDrafts()

foreach ($privateProjects as $project) {
$projectFSObjects = FileSystemObject::with('children')
->where([
['project_id', $project->id],
['level', 0],
])
->get();
->where([
['project_id', $project->id],
['level', 0],
])
->get();

foreach ($projectFSObjects as $FSObject) {
if ($FSObject->draft) {
if (! str_contains($FSObject->path, $FSObject->draft->path)) {
echo($FSObject->path . ' <-> ' . $FSObject->draft->path);
echo "\n";
$this->moveFolder($FSObject, $FSObject->project, $FSObject->draft);
}
} else {
echo $FSObject->id;
echo "\n";
}
}
}

$projectFSObjects = FileSystemObject::with('children')
->where([
['level', 0],
['project_id', 0],
['study_id', 0],
['dataset_id', 0],
])
->get();
$environment = env('APP_ENV', 'local');
foreach ($projectFSObjects as $FSObject) {
if (! $FSObject->draft) {
$projectUUID = str_replace(['/'.$environment.'/', '/'.$FSObject->key], '', $FSObject->path);
$project = Project::where('uuid', $projectUUID)->first();
if ($project) {
$FSObject->project_id = $project->id;
$FSObject->save();
$this->updateDraftId($FSObject->fresh(), $project);
}
}
}

$projectFSObjects = FileSystemObject::with('children')
->where([
['project_id', $project->id],
['level', 0],
])
->get();

foreach ($projectFSObjects as $FSObject) {
if ($FSObject->draft) {
if (! str_contains($FSObject->path, $FSObject->draft->path)) {
$this->moveFolder($FSObject, $FSObject->project, $FSObject->draft);
}
}
}

$projectFSObjects = FileSystemObject::all();
// $projectFSObjects = FileSystemObject::with('children')
// ->where([
// ['level', 0],
// ['project_id', 0],
// ['study_id', 0],
// ['dataset_id', 0],
// ])
// ->get();
// $environment = env('APP_ENV', 'local');
// foreach ($projectFSObjects as $FSObject) {
// echo($FSObject->path);
// echo("\n");
// if (! $FSObject->draft) {
// $projectUUID = str_replace(['/'.$environment.'/', '/'.$FSObject->key], '', $FSObject->path);
// $project = Project::where('uuid', $projectUUID)->first();
// if ($project) {
// $FSObject->project_id = $project->id;
// $FSObject->save();
// $this->updateDraftId($FSObject->fresh(), $project);
// }
// }
// }

// $projectFSObjects = FileSystemObject::with('children')
// ->where([
// ['project_id', $project->id],
// ['level', 0],
// ])
// ->get();

// foreach ($projectFSObjects as $FSObject) {
// if ($FSObject->draft) {
// if (! str_contains($FSObject->path, $FSObject->draft->path)) {
// $this->moveFolder($FSObject, $FSObject->project, $FSObject->draft);
// }
// }
// }

foreach ($projectFSObjects as $FSObject) {
if (str_contains($FSObject->path, 'Isopropanol-neat')) {
echo $FSObject->path.' -- '.$FSObject->id;
echo "\n";
}
}
}

public function versionProjects()
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/DatasetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function nmriumInfo(Request $request, Dataset $dataset)
if (is_array($nucleus)) {
$nucleus = implode('-', $nucleus);
}
$dataset->type = $nucleus.', '.$dataset->type;
$dataset->type = implode(array_unique(explode(",", $nucleus.', '.$dataset->type)), ',');
}

$dataset->save();
Expand Down
2 changes: 2 additions & 0 deletions app/Models/NMRium.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class NMRium extends Model

protected $table = 'nmrium';

protected $keepOldVersions = 10;

protected $fillable = [
'nmrium_info',
'dataset_id',
Expand Down

0 comments on commit 1b2ef55

Please sign in to comment.