Akaunting/app/Utilities/Info.php

105 lines
2.6 KiB
PHP
Raw Normal View History

2017-09-14 19:21:00 +00:00
<?php
namespace App\Utilities;
2023-10-25 09:40:52 +00:00
use Akaunting\Version\Version;
2018-06-09 23:48:51 +00:00
use App\Models\Common\Company;
2022-09-21 21:57:54 +00:00
use App\Models\Common\Contact;
use App\Models\Document\Document;
2023-10-26 20:16:08 +00:00
use App\Traits\Settings;
2021-12-24 15:44:10 +00:00
use Composer\InstalledVersions;
2022-09-21 21:57:54 +00:00
use Illuminate\Support\Facades\DB;
2017-09-14 19:21:00 +00:00
class Info
{
2019-12-18 12:29:59 +00:00
public static function all()
2017-09-14 19:21:00 +00:00
{
2023-05-05 21:24:18 +00:00
static $info = [];
2023-10-24 10:37:37 +00:00
$basic = [
2023-10-26 20:16:08 +00:00
'api_key' => static::getApiKey(),
2023-10-24 10:37:37 +00:00
'ip' => static::ip(),
];
2023-10-25 09:40:52 +00:00
if (! empty($info) || is_cloud()) {
2025-06-30 13:17:14 +00:00
if (is_cloud()) {
$basic['companies'] = 0;
}
return array_merge(static::versions(), $info, $basic);
2023-05-05 21:24:18 +00:00
}
$users_count = user_model_class()::query()->isNotCustomer()->count();
2023-10-24 10:37:37 +00:00
$info = array_merge(static::versions(), $basic, [
2020-03-03 13:09:05 +00:00
'companies' => Company::count(),
'users' => $users_count,
2023-10-03 08:06:08 +00:00
'invoices' => Document::allCompanies()->invoice()->count(),
'customers' => Contact::allCompanies()->customer()->count(),
2020-05-19 12:48:24 +00:00
'php_extensions' => static::phpExtensions(),
2019-12-18 12:29:59 +00:00
]);
2023-05-05 21:24:18 +00:00
return $info;
2017-09-14 19:21:00 +00:00
}
2019-12-18 12:29:59 +00:00
public static function versions()
2017-09-14 19:21:00 +00:00
{
2023-05-05 21:24:18 +00:00
static $versions = [];
if (! empty($versions)) {
return $versions;
}
$versions = [
2023-10-25 09:40:52 +00:00
'akaunting' => Version::short(),
2022-09-21 21:57:54 +00:00
'laravel' => InstalledVersions::getPrettyVersion('laravel/framework'),
2019-12-18 12:29:59 +00:00
'php' => static::phpVersion(),
'mysql' => static::mysqlVersion(),
2022-09-21 21:57:54 +00:00
'guzzle' => InstalledVersions::getPrettyVersion('guzzlehttp/guzzle'),
2021-12-24 15:44:10 +00:00
'livewire' => InstalledVersions::getPrettyVersion('livewire/livewire'),
2022-09-21 21:57:54 +00:00
'omnipay' => InstalledVersions::getPrettyVersion('league/omnipay'),
2019-12-18 12:29:59 +00:00
];
2023-05-05 21:24:18 +00:00
return $versions;
2017-09-14 19:21:00 +00:00
}
public static function phpVersion()
{
return phpversion();
}
2020-03-03 13:09:05 +00:00
2020-05-19 12:48:24 +00:00
public static function phpExtensions()
{
return get_loaded_extensions();
}
2017-09-14 19:21:00 +00:00
public static function mysqlVersion()
{
2020-05-19 12:48:24 +00:00
static $version;
if (empty($version) && (config('database.default') === 'mysql')) {
$version = DB::selectOne('select version() as mversion')->mversion;
}
if (isset($version)) {
return $version;
}
2017-09-14 19:21:00 +00:00
2019-12-18 12:29:59 +00:00
return 'N/A';
2017-09-14 19:21:00 +00:00
}
2022-09-21 21:57:54 +00:00
public static function ip()
{
return request()->header('CF_CONNECTING_IP')
? request()->header('CF_CONNECTING_IP')
: request()->ip();
}
2023-10-26 20:16:08 +00:00
public static function getApiKey(): string
{
$setting = new class() { use Settings; };
2023-10-26 20:59:06 +00:00
return $setting->getSettingValue('apps.api_key', '');
2023-10-26 20:16:08 +00:00
}
2020-03-03 13:09:05 +00:00
}