public function deepClean() { Simulation::where('Caption', 'LIKE', "N: %")->delete(); }
public function backup() { $store = !Input::get('html'); $path = public_path() . '/backups/' . date("Y-m-d_H-i-s"); if ($store) { mkdir($path, 0777, true); } if (Input::has('prefix')) { $simulations = Simulation::where("Caption", "LIKE", Input::get('prefix') . "%")->get(); } else { $simulations = Simulation::all(); } $couldNotStore = []; $simulations->each(function ($simulation) use(&$couldNotStore, $store, $path) { $xml = new DOMDocument('1.0'); $root = $xml->createElement('simulationDefinition'); $xml->appendChild($root); try { $simulation->xml($root, true); } catch (Exception $e) { $couldNotStore[] = $simulation; return; } $xml->preserveWhiteSpace = false; $xml->formatOutput = true; if ($store) { $xml->save($path . '/' . $simulation->Id . '.xml'); } }); if (Request::format() == 'json') { if (count($store)) { $responseArray = array_map(function ($s) { return ['id' => $s->Id, 'description' => $s->asString]; }); return json_encode($responseArray); } return true; } else { $err = "Backup<br/>\n"; foreach ($couldNotStore as $simulation) { $err .= "Error for " . $simulation->Id . ':' . $simulation->asString . "<br\\>\n"; } if ($store) { $err .= 'Complete.'; } else { $err .= 'Tested but not stored.'; } return $err; } }