FIX: Added check if json has all required values
This commit is contained in:
parent
1151d30f75
commit
b87b5a1f42
|
@ -5,6 +5,7 @@ namespace App\Console\Commands;
|
|||
use App\Http\Controllers\PreloadDBController;
|
||||
use Illuminate\Console\Command;
|
||||
use League\Flysystem\Config;
|
||||
use phpDocumentor\Reflection\Types\Boolean;
|
||||
|
||||
class PreloadDBAll extends Command
|
||||
{
|
||||
|
@ -45,8 +46,39 @@ class PreloadDBAll extends Command
|
|||
$preloadDBController = new PreloadDBController();
|
||||
if (file_exists(env('JSON_FILE_PATH'))) {
|
||||
$config = json_decode(file_get_contents(env('JSON_FILE_PATH')), true);
|
||||
$preloadDBController->setInitialUserData($config['username'], $config['theme']);
|
||||
$preloadDBController->setInitialLinks($config['links']);
|
||||
if (
|
||||
array_key_exists('username', $config) &&
|
||||
array_key_exists('links', $config) &&
|
||||
array_key_exists('theme', $config)
|
||||
) {
|
||||
$preloadDBController->setInitialUserData($config['username'], $config['theme']);
|
||||
$arrayHasAllKeys = true;
|
||||
foreach ($config['links'] as $link)
|
||||
{
|
||||
if (
|
||||
!array_key_exists('platform', $link) ||
|
||||
!array_key_exists('link', $link) ||
|
||||
!array_key_exists('linktext', $link) ||
|
||||
!array_key_exists('brandcolors', $link)
|
||||
)
|
||||
{
|
||||
$arrayHasAllKeys = false;
|
||||
}
|
||||
}
|
||||
if ($arrayHasAllKeys == true)
|
||||
{
|
||||
$preloadDBController->setInitialLinks($config['links']);
|
||||
} else
|
||||
{
|
||||
print('Error: Not all required values are in the file'."\n");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
} else
|
||||
{
|
||||
print('Error: Not all required values are in the file'."\n");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
return Command::SUCCESS;
|
||||
} else {
|
||||
print('Error: JSON File does not exist at given location'."\n");
|
||||
|
|
Reference in a new issue