예제 #1
0
 /**
  * Handles an incoming import request. Takes the uploaded file, creates
  * a new entry in the database for it with its contents, and relies on the fact that the
  * Editor will create a new file in Firebase out of the contents of the entry.
  *
  * @param ImportRequest $request
  * @return mixed
  */
 public function import(ImportRequest $request)
 {
     $project = $request->project();
     $path = $this->makeTempDirectory('tmp', $request->project()->title);
     $fileName = $request->input('fileName');
     $import = $request->file('fileImport');
     $import->move($path, $fileName);
     $contents = str_replace("\r\n", '\\n', file_get_contents($path . '/' . $fileName));
     $newEntry = File::create(['project_id' => $project->id, 'projectname' => $project->title, 'filename' => $request->input('fileName'), 'type' => 'File', 'description' => $request->input('description'), 'contents' => $contents, 'user_id' => $request->user()->id, 'parent' => 0]);
     return redirect('/editor/edit/' . $newEntry->projectname . '/' . $newEntry->filename);
 }
 public function PerformImport(Requests\ImportRequest $request)
 {
     $json_string = Storage::get('uploads/' . $request->input('fileName'));
     $json_object = json_decode($json_string);
     foreach ($json_object->categories as $category) {
         //Check if a category exists with the same name
         if (StoreCategory::where('require_plugin', $category->require_plugin)->count() > 0) {
             $ex_cats = StoreCategory::where('require_plugin', $category->require_plugin)->get();
             foreach ($ex_cats as $ex_cat) {
                 $ex_cat->delete();
             }
         }
     }
     //TODO: Handle Import Depending on JSON Versions
     //dd($json_object);
     foreach ($json_object->categories as $category) {
         //Delete the existing category
         // Save a new Category
         $cat = new StoreCategory((array) $category);
         $cat->save();
         //Save the Items
         foreach ($category->items as $item) {
             //Convert the attrs into the json sting
             $item->attrs = json_encode($item->attrs);
             $item->category_id = $cat->id;
             //Create the item
             $itm = new StoreItem((array) $item);
             $itm->save();
         }
     }
     Storage::delete('uploads/' . $request->input('fileName'));
     return redirect()->route('webpanel.store.tools.index');
 }