protected function importRemainingDocuments()
 {
     $initDocuments = Document::count();
     $lostDocuments = [];
     $documentsForExtendedIssues = [];
     $pathToFiles = sprintf('%s/var/www/andr_v2/uploads/reldocs/propid_/stepid_', storage_path());
     $dbPathToFile = '/var/www/andr_v2/uploads/reldocs/propid_/stepid_/';
     $oldDocuments = DB::connection('oldissue')->select('select * from relateddoc
         where propid > 120 and stepid <> 0
     ');
     $getFileNamesFromFolder = array_diff(scandir($pathToFiles), ['.', '..']);
     foreach ($oldDocuments as $document) {
         if (!$document->filepaths) {
             continue;
         }
         if (strpos($document->filepaths, $dbPathToFile) === 0) {
             $lostDocuments[] = $document;
         }
     }
     foreach ($lostDocuments as $document) {
         $fullPathToFile = $document->filepaths;
         $file = str_replace($dbPathToFile, '', $fullPathToFile);
         if (!in_array($file, $getFileNamesFromFolder)) {
             continue;
         }
         do {
             $randomName = str_random(40);
         } while (UploadedFile::where('file_name', $randomName)->count() > 0);
         do {
             $codPublic = str_random(40);
         } while (Document::where('public_code', $codPublic)->count() > 0);
         $uploadedFileData = ['file_name' => $randomName, 'folder' => '/documents/', 'original_file_name' => $file];
         $this->moveFile(storage_path() . $fullPathToFile, $uploadedFileData['file_name']);
         $doc = factory(Document::class)->create(['public' => 1, 'uploaded_file_id' => factory(UploadedFile::class)->create($uploadedFileData)->id, 'public_code' => $codPublic, 'init_at' => $document->initat]);
         $translatableData = ['ro' => ['title' => $document->content ? $document->content : ''], 'en' => ['title' => $document->encontent ? $document->encontent : '']];
         $doc->fill($translatableData);
         $doc->save();
         try {
             $doc->steps()->attach($document->stepid);
         } catch (\Exception $e) {
             print_r("Shiit! O relatie Document - FlowStep nu s-a putut importa.\n");
         }
     }
     echo sprintf("Au fost recuperate %s documente salvate la comun intr-un folder.\n", $count = Document::count() - $initDocuments);
     return true;
 }