/**
  * Shows the changes that are going to happen to the user
  *
  * @param Requests\ImportRequest $request
  * @return Response
  */
 public function verifyImport(Requests\ImportRequest $request)
 {
     //TODO: Support the upload of zip files
     //Check if the uploaded file is a zip file
     // -> if yes then unpack and extract the json file
     // **Get the File**
     $file = $request->file('import');
     $json_valid = false;
     $json_version = 0;
     $json_type = false;
     $categories_collection = false;
     $fileName = "";
     // **Perform some validation**
     //Check if the file is valid
     if (Input::file('import')->isValid()) {
         $json_string = File::get($file);
         $json_object = json_decode($json_string);
         $extension = Input::file('import')->getClientOriginalExtension();
         $fileName = $this->getUploadString($extension);
         Storage::put('uploads/' . $fileName, $json_string);
         //Check if the JSON is valid
         if ($json_object !== null) {
             $json_valid = true;
         }
         //Check if JSON Version is set
         if (isset($json_object->version)) {
             $json_version = $json_object->version;
         }
         //Check if the Type is set
         if (isset($json_object->type)) {
             $json_type = $json_object->type;
         }
         if (isset($json_object->categories)) {
             $categories_collection = Collection::make($json_object->categories);
         }
         // TODO: Check if anything gets deleted when importing this category
         // TODO: Check if there are categories with the same type
         // **Send the output to the user**
         return view('templates.' . \Config::get('webpanel.template') . 'webpanel.store.tools.verify_import', compact('json_valid', 'json_version', 'json_type', 'categories_collection', 'fileName'));
     } else {
         return view('templates.' . \Config::get('webpanel.template') . 'webpanel.store.tools.index');
     }
 }
Exemplo n.º 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');
 }
Exemplo n.º 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);
 }