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');
 }
예제 #2
0
 public function import(Excel $excel, ImportRequest $request)
 {
     $file = $request->file('excel');
     //Input::file('excel');
     //dd($file);
     if (!$file) {
         Flash('Seleccione un archivo!!');
         return Redirect()->route('clients');
     }
     $excel->load($file, function ($reader) {
         foreach ($reader->get() as $client) {
             // para evitar en los campos que no se permiten null poner en blanco
             $data = array_map(function ($v) {
                 return is_null($v) ? "" : $v;
             }, $client->toArray());
             /* $data = [
                    'name' => $client->title,
                    'author' =>$client->author,
                    'year' =>$client->publication_year
                ];*/
             $this->clientRepo->store($data);
         }
     });
     //return Book::all();
     Flash('Imported !!');
     return Redirect()->route('clients');
 }
예제 #3
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);
 }