61 lines
1.7 KiB
PHP
61 lines
1.7 KiB
PHP
|
<?php
|
||
|
namespace ProVM\Crypto\Common\Service;
|
||
|
|
||
|
use Carbon\Carbon;
|
||
|
use ProVM\Common\Factory\Model as Factory;
|
||
|
use ProVM\Crypto\Coin;
|
||
|
|
||
|
class Update {
|
||
|
protected $factory;
|
||
|
protected $execs;
|
||
|
public function __construct(Factory $factory, array $executables) {
|
||
|
$this->factory = $factory;
|
||
|
$this->execs = $executables;
|
||
|
$this->load();
|
||
|
}
|
||
|
public function load() {
|
||
|
$this->coins = [[], []];
|
||
|
$results = \ORM::for_table('coin_registers')->find_many();
|
||
|
foreach ($results as $result) {
|
||
|
$this->coins[$result->type] []= $result->coin_id;
|
||
|
}
|
||
|
}
|
||
|
protected $coins;
|
||
|
public function register(int $coin_id, int $type = 0) {
|
||
|
/*if (array_search($coin_id, $this->coins[$type]) !== false) {
|
||
|
return;
|
||
|
}*/
|
||
|
$this->coins[$type] []= $coin_id;
|
||
|
$this->getHistorical($coin_id, $type);
|
||
|
$check = \ORM::for_table('coin_registers')->where('coin_id', $coin_id)->find_one();
|
||
|
if (!$check) {
|
||
|
\ORM::raw_execute("INSERT INTO coin_registers (coin_id, type) VALUES (?, ?)", [$coin_id, $type]);
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
protected function getHistorical(int $coin_id, int $type) {
|
||
|
$coin = $this->factory->find(Coin::class)->one($coin_id);
|
||
|
$f = Carbon::now();
|
||
|
$exe = [$this->execs[$type]];
|
||
|
switch ($type) {
|
||
|
case 0:
|
||
|
$exe []= '-i ' . $coin->identifier;
|
||
|
$exe []= '-c usd,clp';
|
||
|
$exe []= 'hist -hi';
|
||
|
$exe []= '-f ' . $f->copy()->subYears(10)->timestamp;
|
||
|
$exe []= '-t ' . $f->timestamp();
|
||
|
break;
|
||
|
case 1:
|
||
|
$exe []= '-i ' . $coin->identifier;
|
||
|
$exe []= 'hist -hi';
|
||
|
$exe []= '-s ' . $f->copy()->subYears(10)->year;
|
||
|
break;
|
||
|
}
|
||
|
!d(implode(' ', $exe));
|
||
|
$output = shell_exec(implode(' ', $exe));
|
||
|
!d($output);
|
||
|
}
|
||
|
public function run() {
|
||
|
}
|
||
|
}
|