bytic /
MediaLibrary
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace ByTIC\MediaLibrary\Loaders; |
||||
| 4 | |||||
| 5 | use ByTIC\MediaLibrary\Support\MediaModels; |
||||
| 6 | use Nip\Filesystem\File; |
||||
| 7 | |||||
| 8 | /** |
||||
| 9 | * Class Database |
||||
| 10 | */ |
||||
| 11 | class Database extends AbstractLoader |
||||
| 12 | { |
||||
| 13 | /** |
||||
| 14 | * @return File[] |
||||
| 15 | */ |
||||
| 16 | public function getMediaFiles() |
||||
| 17 | { |
||||
| 18 | $files = $this->tryDatabase(); |
||||
| 19 | if (is_array($files)) { |
||||
| 20 | return $files; |
||||
| 21 | } |
||||
| 22 | $files = $this->tryFilesystem(); |
||||
| 23 | |||||
| 24 | $model = $this->getCollection()->getRecord(); |
||||
| 25 | |||||
| 26 | foreach ($files as $file) { |
||||
| 27 | MediaModels::records()->createFor( |
||||
| 28 | $file, |
||||
| 29 | $model, |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 30 | $this->getCollection() |
||||
| 31 | ); |
||||
| 32 | } |
||||
| 33 | |||||
| 34 | $model->mediaProperties($this->getCollection())->saveDbLoaded(true); |
||||
|
0 ignored issues
–
show
The method
saveDbLoaded() does not exist on Nip\Records\Collections\Collection.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||
| 35 | |||||
| 36 | return $files; |
||||
| 37 | } |
||||
| 38 | |||||
| 39 | /** |
||||
| 40 | * @return array|false |
||||
| 41 | */ |
||||
| 42 | protected function tryDatabase() |
||||
| 43 | { |
||||
| 44 | $propertiesRecord = MediaModels::properties()->forCollection($this->getCollection()); |
||||
| 45 | |||||
| 46 | if (!is_object($propertiesRecord) || $propertiesRecord->dbLoaded() === false) { |
||||
| 47 | return false; |
||||
| 48 | } |
||||
| 49 | |||||
| 50 | $mediaRecords = MediaModels::records()->for( |
||||
| 51 | $this->getCollection()->getRecord(), |
||||
|
0 ignored issues
–
show
It seems like
$this->getCollection()->getRecord() can also be of type ByTIC\MediaLibrary\HasMedia\HasMediaTrait; however, parameter $model of ByTIC\MediaLibrary\Model...rds\MediaRecords::for() does only seem to accept Nip\Records\AbstractModels\Record, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 52 | $this->getCollection()->getName() |
||||
| 53 | ); |
||||
| 54 | $files = []; |
||||
| 55 | foreach ($mediaRecords as $mediaRecord) { |
||||
| 56 | $files[] = new File($this->getFilesystem(), $mediaRecord->path); |
||||
|
0 ignored issues
–
show
The property
path does not exist on ByTIC\MediaLibrary\Model...roperties\MediaProperty. Since you implemented __get, consider adding a @property annotation.
Loading history...
|
|||||
| 57 | } |
||||
| 58 | return $files; |
||||
| 59 | } |
||||
| 60 | |||||
| 61 | /** |
||||
| 62 | * @return array|false |
||||
| 63 | */ |
||||
| 64 | protected function tryFilesystem() |
||||
| 65 | { |
||||
| 66 | $loader = $this->initFromSibling(Filesystem::class); |
||||
| 67 | return $loader->getMediaFiles(); |
||||
| 68 | } |
||||
| 69 | } |
||||
| 70 |