/** * Execute the console command. * * @return void */ public function fire() { // Get the file option from the command line $filename = $this->option('file'); if (empty($filename)) { $filename = self::getExportFile(); } // Get the jobid, if none is provided, return all of the jobs by default $jobid = $this->argument('jobid'); $content = null; if (empty($jobid)) { $jobs = \Job::all(); $content = array(); foreach ($jobs as $job) { $content[$job->collection_uri . '/' . $job->name] = $job->getAllProperties(); } $content = json_encode($content); } else { $job = InputController::get($jobid); if (empty($job)) { $this->error("No input job has been found with the given identifer ({$jobid})."); die; } $content[$job->collection_uri . '/' . $job->name] = $job->getAllProperties(); $content = json_encode($content); } try { // Write to file $fs = new Filesystem(); if ($fs->exists($filename)) { $fs->put($filename, $content); } else { $handle = fopen($filename, "w"); if (!$handle) { \App::abort('Could not open/create the file ' . $filename); } fwrite($handle, $content); } $this->info("The export has been written to the file '{$filename}'."); } catch (Exception $e) { $this->error("The contents could not be written to the file '{$filename}'."); die; } }
/** * Execute the console command. * * @return void */ public function fire() { // Get the file option from the command line $filename = $this->option('file'); if (empty($file)) { $file = self::getExportFile(); } // Get the jobid, if none is provided, return all of the jobs by default $jobid = $this->argument('jobid'); $content = null; if (empty($jobid)) { $jobs = \Job::all(); $content = array(); foreach ($jobs as $job) { $content[$job->collection_uri . '/' . $job->name] = $job->getAllProperties(); } $content = json_encode($content); } else { $job = InputController::get($jobid); if (empty($job)) { $this->error("No input job has been found with the given identifer ({$jobid})."); die; } $content[$job->collection_uri . '/' . $job->name] = $job->getAllProperties(); $content = json_encode($content); } // Output if (empty($filename)) { // Print to console echo $content; } else { try { // Write to file file_put_contents($filename, $content); $this->info("The export has been written to the file '{$filename}'."); } catch (Exception $e) { $this->error("The contents could not be written to the file '{$filename}'."); die; } } }