Commit 1c60878c authored by Darron Park's avatar Darron Park

Fix Setting Media type test error

parent 6beaaad8
......@@ -13,4 +13,10 @@ class Setting extends Model
public $translatedAttributes = ['value', 'description'];
protected $fillable = ['name', 'value', 'description', 'isTranslatable', 'plainValue'];
protected $table = 'setting__settings';
public function hasMedia(): boolean
{
$value = json_decode($this->plainValue, true);
return is_array($value) && isset($value['media_single']) && $setting->files->count();
}
}
......@@ -50,10 +50,10 @@ class EloquentSettingRepository extends EloquentBaseRepository implements Settin
foreach ($settings as $settingName => $settingValues) {
// Check if media exists
if(in_array($settingName, ['medias_single', 'medias_multiple'])) {
if($settingName == 'medias_single') {
// Get first key of values (Original settingName)
foreach ($settingValues as $key => $value) {
$normalisedValue = [ $settingName => [$key => $value] ];
foreach ($settingValues as $key => $mediaId) {
$normalisedValue = [ 'media_single' => $mediaId ];
$settingName = $key;
break;
}
......
......@@ -36,7 +36,7 @@ class Settings implements Setting
return is_null($default) ? $defaultFromConfig : $default;
}
if($media = $setting->files()->first()) {
if($setting->hasMedia() && $media = $setting->files->first()) {
return $media->path;
}
......
......@@ -78,5 +78,9 @@ abstract class BaseSettingTest extends TestCase
$this->artisan('migrate', [
'--database' => 'sqlite',
]);
$this->artisan('migrate', [
'--database' => 'sqlite',
'--path' => 'Modules/Media/Database/Migrations',
]);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment