diff --git a/app/Console/Commands/UpdateDOI.php b/app/Console/Commands/UpdateDOI.php new file mode 100644 index 00000000..807aedc8 --- /dev/null +++ b/app/Console/Commands/UpdateDOI.php @@ -0,0 +1,82 @@ +doiService = $doiService; + } + + /** + * Execute the console command. + */ + public function handle() + { + // $operator takes values from + // {'>' : after a certain update date, + // '<' : before a certain update date, + // '=' : at a certain update date} + $operator = $this->argument('operator'); + $date = $this->argument('update-date'); + $date = $date ? Carbon::parse($date) : null; + + // Fetch the projects and samples (studies) based on the date + $projects = $date ? Project::where('updated_at', $operator, $date)->get() : Project::all(); + $studies = $date ? Study::where('updated_at', $operator, $date)->get() : Study::all(); + + // Cover all studies within or without projects + foreach ($studies as $study) { + echo $study->identifier."\r\n"; + foreach ($study->datasets as $dataset) { + echo $dataset->identifier."\r\n"; + $dataset->updateDOIMetadata($this->doiService); + $dataset->addRelatedIdentifiers($this->doiService); + } + $study->updateDOIMetadata($this->doiService); + $study->addRelatedIdentifiers($this->doiService); + } + + foreach ($projects as $project) { + echo $project->identifier."\r\n"; + $project->updateDOIMetadata($this->doiService); + $project->addRelatedIdentifiers($this->doiService); + } + } +}