/** * 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; }
/** * 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->findBySlug($name))) { $folder = $this->folders->create(['name' => $name, 'disk_id' => $disk->getId(), 'parent_id' => $parent ? $parent->getId() : null]); } $parent = $folder; } return $folder; }
/** * Find a folder by it's name and parent folder. * * @param $name * @param DiskInterface $disk * @param FolderInterface $parent * @return null|FolderInterface */ public function findByName($name, DiskInterface $disk, FolderInterface $parent = null) { return $this->model->where('name', $name)->where('disk_id', $disk->getId())->where('parent_id', $parent ? $parent->getId() : null)->first(); }
/** * Return the view link. * * @return string */ public function viewLink() { return app('html')->link(implode('/', array_filter(['admin', 'files', 'browser', $this->object->getSlug()])), $this->object->getName()); }
/** * Find a file by it's name. * * @param $name * @param DiskInterface $disk * @param FolderInterface $folder * @return null|FileInterface */ public function findByName($name, DiskInterface $disk, FolderInterface $folder = null) { return $this->model->where('name', $name)->where('disk_id', $disk->getId())->where('folder_id', $folder ? $folder->getId() : null)->first(); }
/** * Handle the command. * * @param BreadcrumbCollection $breadcrumbs */ public function handle(BreadcrumbCollection $breadcrumbs) { $breadcrumbs->add($this->disk->getName(), 'admin/files/browser/' . $this->disk->getSlug()); }
/** * Register the disk. * * @param DiskInterface $disk */ public function register(DiskInterface $disk) { if ($adapter = $disk->getAdapter()) { $this->container->call(substr(get_class($adapter), 0, -9) . 'Loader@load', compact('disk', 'adapter')); } }
/** * Handle the command. * * @param FolderRepositoryInterface $folders */ public function handle(FolderRepositoryInterface $folders) { foreach ($this->disk->getFolders() as $folder) { $folders->forceDelete($folder); } }