70 lines
1.5 KiB
PHP
70 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\Config;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
/**
|
|
* Class HRCCommand
|
|
*
|
|
* @property object data
|
|
*/
|
|
class HRCCommand extends Command
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->signature = $this->signature . ' {source} {result} {--unn=}';
|
|
parent::__construct();
|
|
}
|
|
|
|
public function __get($get)
|
|
{
|
|
if ($get == 'data') {
|
|
return $this->prepareRaw();
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
private function prepareRaw()
|
|
{
|
|
$source_file = base_path() . '/../temp/' . $this->argument('source');
|
|
return parse_ini_file($source_file);
|
|
}
|
|
|
|
public function save($result)
|
|
{
|
|
$result_file = base_path() . '/../temp/' . $this->argument('result');
|
|
file_put_contents($result_file, json_encode($result));
|
|
}
|
|
|
|
public function initDB()
|
|
{
|
|
$code = $this->option('unn');
|
|
|
|
DB::disconnect('mysql');
|
|
Config::set('database.connections.mysql.database', $code);
|
|
DB::reconnect();
|
|
}
|
|
|
|
public function handle()
|
|
{
|
|
$data = $this->prepareRaw();
|
|
|
|
try {
|
|
$this->initDB();
|
|
$result = $this->command($data);
|
|
}
|
|
catch (\Exception $e) {
|
|
$result = [
|
|
'status' => 'error',
|
|
'message' => $e->getMessage()
|
|
];
|
|
}
|
|
|
|
$this->save($result);
|
|
}
|
|
}
|