This repository has been archived on 2022-11-29. You can view files and clone it, but cannot push or open issues or pull requests.
socialtree-laravel/src/app/Console/Commands/PreloadDBAll.php

90 lines
2.6 KiB
PHP

<?php
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
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'preloadDB:all';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Loads all the config from the json into the DB';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
/*@todo
error if keys are not in json
*/
$preloadDBController = new PreloadDBController();
if (file_exists(env('JSON_FILE_PATH'))) {
$config = json_decode(file_get_contents(env('JSON_FILE_PATH')), true);
if (
array_key_exists('username', $config) &&
array_key_exists('links', $config) &&
array_key_exists('profilepicture', $config) &&
array_key_exists('theme', $config)
) {
$preloadDBController->setInitialUserData($config['username'], $config['theme'], $config['profilepicture']);
$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");
return Command::FAILURE;
}
}
}