2018-01-30 03:16:39 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
2019-07-16 03:44:31 +08:00
|
|
|
use App\Contracts\Service;
|
2019-10-30 01:07:53 +08:00
|
|
|
use Exception;
|
2019-09-17 01:08:26 +08:00
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
2018-01-30 03:16:39 +08:00
|
|
|
use PDO;
|
2020-06-04 22:36:55 +08:00
|
|
|
use VaCentral\Models\Stat;
|
|
|
|
use VaCentral\VaCentral;
|
2018-01-30 03:16:39 +08:00
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
class AnalyticsService extends Service
|
2018-01-30 03:16:39 +08:00
|
|
|
{
|
2019-10-30 01:07:53 +08:00
|
|
|
/**
|
|
|
|
* Send out some stats about the install, like the PHP and DB versions
|
2018-01-30 03:16:39 +08:00
|
|
|
*/
|
|
|
|
public function sendInstall()
|
|
|
|
{
|
2019-10-30 01:07:53 +08:00
|
|
|
if (setting('general.telemetry') === false) {
|
2018-01-30 03:16:39 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-04 22:36:55 +08:00
|
|
|
$versionSvc = app(VersionService::class);
|
|
|
|
$pdo = DB::connection()->getPdo();
|
2019-10-30 01:07:53 +08:00
|
|
|
|
2020-06-04 22:36:55 +08:00
|
|
|
$props = [
|
|
|
|
'php' => PHP_VERSION,
|
|
|
|
'db' => strtolower($pdo->getAttribute(PDO::ATTR_SERVER_VERSION)),
|
|
|
|
'version' => $versionSvc->getCurrentVersion(false),
|
|
|
|
];
|
2018-01-30 03:16:39 +08:00
|
|
|
|
2020-06-04 22:36:55 +08:00
|
|
|
try {
|
|
|
|
$stat = Stat::new('event', 'install', $props);
|
|
|
|
$client = new VaCentral();
|
|
|
|
$client->postStat($stat);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
Log::error($e->getMessage());
|
|
|
|
}
|
|
|
|
}
|
2018-01-30 03:16:39 +08:00
|
|
|
|
2020-06-04 22:36:55 +08:00
|
|
|
public function sendUpdate()
|
|
|
|
{
|
|
|
|
if (setting('general.telemetry') === false) {
|
|
|
|
return;
|
|
|
|
}
|
2018-01-30 03:16:39 +08:00
|
|
|
|
2019-10-30 01:07:53 +08:00
|
|
|
$versionSvc = app(VersionService::class);
|
2020-06-04 22:36:55 +08:00
|
|
|
$props = [
|
|
|
|
'version' => $versionSvc->getCurrentVersion(false),
|
|
|
|
];
|
2019-10-30 01:07:53 +08:00
|
|
|
|
2018-02-12 23:47:12 +08:00
|
|
|
try {
|
2020-06-04 22:36:55 +08:00
|
|
|
$stat = Stat::new('event', 'update', $props);
|
|
|
|
$client = new VaCentral();
|
|
|
|
$client->postStat($stat);
|
2019-10-30 01:07:53 +08:00
|
|
|
} catch (Exception $e) {
|
2018-02-12 23:47:12 +08:00
|
|
|
Log::error($e->getMessage());
|
|
|
|
}
|
2018-01-30 03:16:39 +08:00
|
|
|
}
|
|
|
|
}
|