public function migrate(Request $request, MessageBag $bag, FolderRepositoryInterface $folders)
 {
     $input = $request->input();
     if (!$input['table'] || !$input['column']) {
         $bag->error("Table and column are both required");
         return redirect('/admin/migrator/migrate_column');
     }
     $data = DB::select('select `id`, ' . $input['column'] . ' from ' . $input['table']);
     echo "<table><thead><tr><th>Row</th><th>Original ID</th><th>New Id</th></tr></thead><tbody>";
     foreach ($data as $row) {
         $remoteFile = json_decode($this->getData($this->baseUrl . '/migrator/get_file/' . $row->{$input['column']}));
         $folder = $folders->findByPath($remoteFile->path, $this->disk);
         $foundFile = false;
         if ($folder) {
             foreach ($folder->getFiles() as $file) {
                 if ($file->getName() == $remoteFile->file) {
                     $foundFile = true;
                     // return 'found file ID: ' . $file->getId();
                     echo "<tr><td>" . $row->id . "</td><td>" . $row->{$input['column']} . "</td><td>" . $file->getId() . "</td>";
                 }
             }
         }
         if (!$foundFile) {
             echo "<tr><td>" . $row->id . "</td><td>" . $row->{$input['column']} . "</td><td>Could not find file to migrate to.<br>";
             echo "<b>Path:</b> " . $remoteFile->path . "<br>";
             echo "<b>File:</b> " . $remoteFile->file . "<br>";
             echo "<b>Filename:</b> " . $remoteFile->filename;
             echo "</td></tr>";
         }
     }
     echo "</tbody></table>";
     var_dump($input['table']);
     var_dump($input['column']);
 }
示例#2
0
 /**
  * Run the seeder.
  */
 public function run()
 {
     $disk = $this->disks->findBySlug('local');
     $this->folders->truncate();
     $this->folders->create(['en' => ['name' => 'Images', 'description' => 'A folder for images.'], 'slug' => 'images', 'disk' => $disk, 'allowed_types' => ['png', 'jpeg', 'jpg']]);
     $this->folders->create(['en' => ['name' => 'Documents', 'description' => 'A folder for documents.'], 'slug' => 'documents', 'disk' => $disk, 'allowed_types' => ['pdf', 'docx']]);
 }
 /**
  * Upload a file.
  *
  * @param  FileUploader                  $uploader
  * @param  FolderRepositoryInterface     $folders
  * @return \Illuminate\Http\JsonResponse
  */
 public function upload(FileUploader $uploader, FolderRepositoryInterface $folders)
 {
     if ($file = $uploader->upload($this->request->file('upload'), $folders->find($this->request->get('folder')))) {
         return $this->response->json($file->getAttributes());
     }
     return $this->response->json(['error' => 'There was a problem uploading the file.'], 500);
 }
示例#4
0
 /**
  * Locate a file by disk and path.
  *
  * @param $folder
  * @param $path
  * @return FileInterface|null
  */
 public function locate($folder, $name)
 {
     $folder = $this->folders->findBySlug($folder);
     if (!($file = $this->files->findByNameAndFolder($name, $folder))) {
         return null;
     }
     return $file;
 }
 /**
  * Return the form to upload files.
  *
  * @param FolderRepositoryInterface $folders
  * @param DiskRepositoryInterface   $disks
  * @param FileFormBuilder           $form
  * @param                           $disk
  * @param null                      $path
  * @return Response
  */
 public function upload(FolderRepositoryInterface $folders, DiskRepositoryInterface $disks, FileFormBuilder $form, $disk, $path = null)
 {
     $form->setDisk($disk = $disks->findBySlug($disk));
     if ($path && ($folder = $folders->findByPath($path, $disk))) {
         $form->setFolder($folder);
     }
     return $form->render();
 }
 /**
  * Return a form to create a new folder.
  *
  * @param FolderFormBuilder $form
  * @param                   $path
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function create(FolderFormBuilder $form, DiskRepositoryInterface $disks, FolderRepositoryInterface $folders, $disk, $path = null)
 {
     $form->setDisk($disk = $disks->findBySlug($disk));
     if ($path && ($parent = $folders->findByPath($path, $disk))) {
         $form->setParent($parent);
     }
     return $form->render();
 }
示例#7
0
 /**
  * Handle the command.
  *
  * @param FileRepositoryInterface   $files
  * @param FolderRepositoryInterface $folders
  */
 public function handle(FileRepositoryInterface $files, FolderRepositoryInterface $folders)
 {
     $folder = $folders->findBySlug(dirname($this->file->getPath()));
     $file = $files->findByNameAndFolder(basename($this->file->getPath()), $folder);
     if ($file) {
         $files->delete($file);
     }
 }
示例#8
0
 /**
  * Handle the command.
  *
  * @param FolderRepositoryInterface $folders
  * @return FolderInterface|bool
  */
 public function handle(FolderRepositoryInterface $folders)
 {
     $folder = $folders->findBySlug($this->directory->getPath(), $this->getFilesystemDisk());
     if ($folder && $folders->delete($folder)) {
         return $folder;
     }
     return true;
 }
示例#9
0
 /**
  * Handle the command.
  *
  * @param FileRepositoryInterface   $files
  * @param FolderRepositoryInterface $folders
  * @param Decorator                 $decorator
  * @return \Anomaly\FilesModule\Folder\Contract\FolderInterface|\Anomaly\Streams\Platform\Model\EloquentModel|null
  */
 public function handle(FolderRepositoryInterface $folders)
 {
     if (is_numeric($this->identifier)) {
         return $folders->find($this->identifier);
     }
     if (!is_numeric($this->identifier)) {
         return $folders->findBySlug($this->identifier);
     }
     return null;
 }
示例#10
0
 /**
  * Handle the command.
  *
  * @param FolderRepositoryInterface $folders
  * @param Decorator                 $decorator
  * @return null|FolderPresenter
  */
 public function handle(FolderRepositoryInterface $folders, Decorator $decorator)
 {
     if (is_numeric($this->identifier)) {
         return $decorator->decorate($folders->find($this->identifier));
     }
     if (is_string($this->identifier)) {
         return $decorator->decorate($folders->findBySlug($this->identifier));
     }
     return null;
 }
示例#11
0
 /**
  * Sync a file.
  *
  * @param Directory     $resource
  * @param DiskInterface $disk
  * @return null|FolderInterface
  */
 public function sync(Directory $resource, DiskInterface $disk)
 {
     $path = $resource->getPath();
     if ($path === '.') {
         return null;
     }
     if (!($folder = $this->folders->findBySlug($path))) {
         $folder = $this->folders->create(['name' => $path, 'disk_id' => $disk->getId()]);
     }
     return $folder;
 }
示例#12
0
 /**
  * Locate a file by disk and path.
  *
  * @param $disk
  * @param $path
  * @return FileInterface|null
  */
 public function locate($disk, $path)
 {
     if (!($disk = $this->disks->findBySlug($disk))) {
         return null;
     }
     $folder = dirname($path) !== '.' ? $this->folders->findByPath(dirname($path), $disk) : null;
     if (!($file = $this->files->findByName(basename($path), $disk, $folder))) {
         return null;
     }
     return $file;
 }
示例#13
0
 /**
  * Handle the upload.
  *
  * @param FileUploader $uploader
  * @param FolderRepositoryInterface $folders
  * @return \Illuminate\Http\JsonResponse
  */
 public function upload(FileUploader $uploader, FolderRepositoryInterface $folders)
 {
     $error = trans('anomaly.module.files::error.generic');
     try {
         if ($file = $uploader->upload($this->request->file('upload'), $folders->find($this->request->get('folder')))) {
             return $this->response->json($file->getAttributes());
         }
     } catch (\Exception $e) {
         $error = $e->getMessage();
     }
     return $this->response->json(['error' => $error], 500);
 }
示例#14
0
 /**
  * Handle the command.
  *
  * @param FileRepositoryInterface   $files
  * @param FolderRepositoryInterface $folders
  * @param Decorator                 $decorator
  * @return \Anomaly\FilesModule\File\Contract\FileInterface|\Anomaly\Streams\Platform\Model\EloquentModel|null
  */
 public function handle(FileRepositoryInterface $files, FolderRepositoryInterface $folders)
 {
     if (is_numeric($this->identifier)) {
         return $files->find($this->identifier);
     }
     if (!is_numeric($this->identifier)) {
         list($folder, $name) = explode('/', $this->identifier);
         if (!($folder = $folders->findBySlug($folder))) {
             return null;
         }
         return $files->findByNameAndFolder($name, $folder);
     }
     return null;
 }
示例#15
0
 /**
  * Return a list of folders to choose from.
  *
  * @param FolderRepositoryInterface $folders
  * @param Repository                $cache
  * @param Request                   $request
  * @return \Illuminate\View\View
  */
 public function choose(FolderRepositoryInterface $folders, Repository $cache, Request $request)
 {
     $allowed = [];
     $config = $cache->get('file-field_type::' . $request->route('key'), []);
     foreach (array_get($config, 'folders', []) as $identifier) {
         /* @var FolderInterface $folder */
         if ($folder = $this->dispatch(new GetFolder($identifier))) {
             $allowed[] = $folder;
         }
     }
     if (!$allowed) {
         $allowed = $folders->all();
     }
     return $this->view->make('anomaly.field_type.file::choose', ['folders' => $allowed]);
 }
 /**
  * Handle the filters.
  *
  * @param FileTableBuilder          $builder
  * @param FolderRepositoryInterface $folders
  * @param Repository                $cache
  * @param Request                   $request
  */
 public function handle(FileTableBuilder $builder, FolderRepositoryInterface $folders, Repository $cache, Request $request)
 {
     $allowed = [];
     $config = $cache->get('files-field_type::' . $request->route('key'), []);
     foreach (array_get($config, 'folders', []) as $identifier) {
         /* @var FolderInterface $folder */
         if ($folder = $this->dispatch(new GetFolder($identifier))) {
             $allowed[$folder->getId()] = $folder->getName();
         }
     }
     if (!$allowed) {
         $allowed = $folders->all()->pluck('name', 'id')->all();
     }
     $builder->setFolders($allowed)->setFilters(['search' => ['columns' => ['name', 'keywords', 'mime_type']], 'folder' => ['exact' => true, 'filter' => 'select', 'options' => $allowed, 'enabled' => count($allowed) !== 1]]);
 }
示例#17
0
 /**
  * Sync the files folder.
  *
  * @param File          $resource
  * @param DiskInterface $disk
  * @return null|FolderInterface
  */
 protected function syncFolder(File $resource, DiskInterface $disk)
 {
     $path = dirname($resource->getPath());
     if ($path === '.') {
         return null;
     }
     /* @var FolderInterface|null $parent */
     $parent = null;
     $folder = null;
     foreach (explode('/', $path) as $name) {
         if (!($folder = $this->folders->findByName($name, $disk, $parent))) {
             $folder = $this->folders->create(['name' => $name, 'disk_id' => $disk->getId(), 'parent_id' => $parent ? $parent->getId() : null]);
         }
         $parent = $folder;
     }
     return $folder;
 }
示例#18
0
 /**
  * Fire just before saving a folder.
  *
  * @param EntryInterface|FolderInterface $entry
  */
 public function deleting(EntryInterface $entry)
 {
     $this->manager->deleteDir($entry->diskPath());
     // Delete contained files.
     foreach ($entry->getFiles() as $file) {
         $this->files->delete($file);
     }
     // Delete contained folders.
     foreach ($entry->getChildren() as $folder) {
         $this->folders->delete($folder);
     }
 }
 /**
  * Return the details of a file or folder.
  *
  * @param $disk
  * @param $path
  * @return string
  */
 public function view($disk, $path)
 {
     $disk = $this->disks->findBySlug($disk);
     $folder = $this->folders->findByPath(dirname($path), $disk);
     $file = $this->files->findByName(basename($path), $disk, $folder);
     if (!$disk || !$folder && !$file) {
         abort(404);
     }
     if ($file) {
         return json_encode($file);
     }
     if ($folder) {
         return json_encode($folder);
     }
 }
 /**
  * Return a form for an existing file type field and assignment.
  *
  * @param AssignmentFormBuilder       $form
  * @param FolderRepositoryInterface   $folders
  * @param                             $id
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function assignment(AssignmentFormBuilder $form, FolderRepositoryInterface $folders, $id, $assignment)
 {
     $folder = $folders->find($id);
     $this->breadcrumbs->put('streams::breadcrumb.assignments', 'admin/files/types/assignments/' . $folder->getId());
     return $form->render($assignment);
 }
示例#21
0
 /**
  * Handle the command.
  *
  * @param FolderRepositoryInterface $folders
  */
 public function handle(FolderRepositoryInterface $folders)
 {
     foreach ($this->disk->getFolders() as $folder) {
         $folders->forceDelete($folder);
     }
 }
示例#22
0
 /**
  * Return a list of folders to choose from.
  *
  * @param FolderRepositoryInterface $folders
  * @return \Illuminate\View\View
  */
 public function choose(FolderRepositoryInterface $folders)
 {
     return $this->view->make('anomaly.field_type.wysiwyg::choose', ['folders' => $folders->all()]);
 }
示例#23
0
 /**
  * Return an ajax modal to choose the folder
  * to use for uploading files.
  *
  * @param FolderRepositoryInterface
  * @return \Illuminate\View\View
  */
 public function choose(FolderRepositoryInterface $folders)
 {
     return view('module::ajax/choose_folder', ['folders' => $folders->all()]);
 }