87 lines
3.1 KiB
PHP
87 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\Commands;
|
|
|
|
use App\Component\Models\Terminal;
|
|
use App\Console\Commands\HRCCommand;
|
|
use App\Console\Commands\HRCCommandInterface;
|
|
|
|
class Import extends HRCCommand implements HRCCommandInterface {
|
|
protected $signature = 'getimport';
|
|
|
|
public function command($input, $output = null) {
|
|
$HRCPortalURL = 'https://portal.hrc.by/';
|
|
$folder = 'backup';
|
|
$terminals = Terminal::where('soft', '=', 1)->where('is_active', '=', 1)->where('work_code', '=', 1)->get();
|
|
$end_date = date('m/d/Y H:i:s', strtotime($input['end_date']) + 86399);
|
|
$start_date = date('m/d/Y H:i:s', strtotime($input['start_date']));
|
|
foreach ($terminals as $terminal) {
|
|
$url = $HRCPortalURL . 'api/cloud/list?api=2.0&project_code=hrc&code=' . $terminal['key'] . '&folder=' . $folder;
|
|
$search = curl_init();
|
|
|
|
curl_setopt_array($search, array(
|
|
CURLOPT_URL => $url,
|
|
CURLOPT_RETURNTRANSFER => true,
|
|
CURLOPT_HEADER => false,
|
|
CURLOPT_MAXREDIRS => 10,
|
|
CURLOPT_TIMEOUT => 0,
|
|
CURLOPT_FOLLOWLOCATION => true,
|
|
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
|
));
|
|
$search_response = curl_exec($search);
|
|
curl_close($search);
|
|
$responses = json_decode($search_response, TRUE)['files'];
|
|
foreach ($responses as $key => $response) {
|
|
if (array_key_exists('filename', $response)) {
|
|
$fulldate = date_parse_from_format('d-m-Y-H-i-s', $response['filename']);
|
|
$fulldate = mktime($fulldate['hour'], $fulldate['minute'], $fulldate['second'], $fulldate['month'], $fulldate['day'], $fulldate['year']);
|
|
if ($fulldate >= strtotime($start_date) && $fulldate <= strtotime($end_date)) {
|
|
$out[] = date('d-m-Y-H-i-s', $fulldate);
|
|
}
|
|
}
|
|
}
|
|
if (!isset($out)) {
|
|
return [
|
|
'status' => 'success',
|
|
'message' => 'shifts not found',
|
|
];
|
|
} else {
|
|
foreach ($out as $filename) {
|
|
$path = '/backup/' . $filename . '.xml';
|
|
$download_url = $HRCPortalURL . 'api/cloud/download?api=2.0&project_code=hrc&code=' . $terminal['key'] . '&path=' . $path;
|
|
$download = curl_init();
|
|
|
|
curl_setopt_array($download, array(
|
|
CURLOPT_URL => $download_url,
|
|
CURLOPT_RETURNTRANSFER => true,
|
|
CURLOPT_HEADER => false,
|
|
CURLOPT_MAXREDIRS => 10,
|
|
CURLOPT_TIMEOUT => 0,
|
|
CURLOPT_FOLLOWLOCATION => true,
|
|
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
|
));
|
|
$download_response = curl_exec($download);
|
|
curl_close($download);
|
|
$file = json_decode($download_response, TRUE)['content'];
|
|
$params = array('code' => $terminal['key'], 'name' => $filename . '.xml', 'folder' => 'exchange', 'content' => $file, 'project_code' => 'hrc', 'api' => '2.0');
|
|
$upload = curl_init();
|
|
curl_setopt_array($upload, array(
|
|
CURLOPT_RETURNTRANSFER => true,
|
|
CURLOPT_HEADER => true,
|
|
CURLOPT_URL => $HRCPortalURL . 'api/cloud/upload',
|
|
CURLOPT_SSL_VERIFYHOST => 0,
|
|
CURLOPT_POST => true,
|
|
CURLOPT_POSTFIELDS => $params,
|
|
));
|
|
$upload_response = curl_exec($upload);
|
|
curl_close($upload);
|
|
}
|
|
return [
|
|
'status' => 'success',
|
|
'start_date' => strtotime($start_date),
|
|
'end_date' => strtotime($end_date),
|
|
];
|
|
}
|
|
}
|
|
}
|
|
} |