public function getMediaToBeRegenerated()
 {
     if ($this->argument('modelType') == '') {
         return $this->mediaRepository->all();
     }
     return $this->mediaRepository->getByModelType($this->argument('modelType'));
 }
 public function getMediaItems() : Collection
 {
     $modelType = $this->argument('modelType');
     $collectionName = $this->argument('collectionName');
     if (!is_null($modelType) && !is_null($collectionName)) {
         return $this->mediaRepository->getByModelTypeAndCollectionName($modelType, $collectionName);
     }
     if (!is_null($modelType)) {
         return $this->mediaRepository->getByModelType($modelType);
     }
     if (!is_null($collectionName)) {
         return $this->mediaRepository->getByCollectionName($collectionName);
     }
     return $this->mediaRepository->all();
 }
 public function getMediaToBeRegenerated() : Collection
 {
     $modelType = $this->argument('modelType') ?? '';
     $mediaIds = $this->option('ids');
     if ($modelType === '' && !$mediaIds) {
         return $this->mediaRepository->all();
     }
     if ($mediaIds) {
         if (!is_array($mediaIds)) {
             $mediaIds = explode(',', $mediaIds);
         }
         return $this->mediaRepository->getByIds($mediaIds);
     }
     return $this->mediaRepository->getByModelType($modelType);
 }
 protected function deleteOrphanedFiles()
 {
     $diskName = $this->argument('disk') ?: config('laravel-medialibrary.defaultFilesystem');
     if (is_null(config("filesystems.disks.{$diskName}"))) {
         throw FileCannotBeAdded::diskDoesNotExist($diskName);
     }
     $mediaIds = collect($this->mediaRepository->all()->pluck('id')->toArray());
     collect($this->fileSystem->disk($diskName)->directories())->filter(function (string $directory) use($mediaIds) {
         return is_numeric($directory) ? !$mediaIds->contains((int) $directory) : false;
     })->each(function (string $directory) use($diskName) {
         if (!$this->isDryRun) {
             $this->fileSystem->disk($diskName)->deleteDirectory($directory);
         }
         $this->info("Orphaned media directory `{$directory}` " . ($this->isDryRun ? 'found' : 'has been removed'));
     });
 }