1 | <?php |
||||||
2 | |||||||
3 | namespace Apps\Controller\Admin\Main; |
||||||
4 | |||||||
5 | use Apps\Model\Install\Main\EntityCheck; |
||||||
6 | use Extend\Version; |
||||||
7 | use Ffcms\Core\App; |
||||||
8 | use Ffcms\Core\Arch\View; |
||||||
9 | use Ffcms\Core\Helper\Environment; |
||||||
10 | use Ffcms\Core\Helper\FileSystem\Directory; |
||||||
11 | use Ffcms\Core\Network\Request; |
||||||
12 | use Ffcms\Core\Network\Response; |
||||||
13 | use Ffcms\Yandex\Metrika\Client; |
||||||
14 | |||||||
15 | /** |
||||||
16 | * Trait ActionIndex |
||||||
17 | * @package Apps\Controller\Admin\Main |
||||||
18 | * @property Request $request |
||||||
19 | * @property Response $response |
||||||
20 | * @property View $view |
||||||
21 | */ |
||||||
22 | trait ActionIndex |
||||||
23 | { |
||||||
24 | /** |
||||||
25 | * Index page of admin dashboard |
||||||
26 | * @return string|null |
||||||
27 | * @throws \Psr\Cache\InvalidArgumentException |
||||||
28 | */ |
||||||
29 | public function index(): ?string |
||||||
30 | { |
||||||
31 | // get cached statistics |
||||||
32 | $rootSize = App::$Cache->getItem('root.size'); |
||||||
33 | $loadAvg = App::$Cache->getItem('load.avarage'); |
||||||
34 | if (!$rootSize->isHit()) { |
||||||
35 | $calcSize = round(Directory::size('/') / (1024*1000), 2) . ' mb'; |
||||||
36 | $rootSize->set($calcSize); |
||||||
37 | $rootSize->expiresAfter(86400); |
||||||
38 | App::$Cache->save($rootSize); |
||||||
39 | } |
||||||
40 | if (!$loadAvg->isHit()) { |
||||||
41 | $loadAvg->set(Environment::loadAverage()); |
||||||
42 | $loadAvg->expiresAfter(300); |
||||||
43 | App::$Cache->save($loadAvg); |
||||||
44 | } |
||||||
45 | |||||||
46 | // prepare system statistic |
||||||
47 | $stats = [ |
||||||
48 | 'ff_version' => Version::VERSION . ' (' . Version::DATE . ')', |
||||||
49 | 'php_version' => Environment::phpVersion() . ' (' . Environment::phpSAPI() . ')', |
||||||
50 | 'os_name' => Environment::osName(), |
||||||
51 | 'database_name' => App::$Database->connection()->getDatabaseName() . ' (' . App::$Database->connection()->getDriverName() . ')', |
||||||
52 | 'file_size' => $rootSize->get(), |
||||||
53 | 'load_avg' => $loadAvg->get() |
||||||
54 | ]; |
||||||
55 | // check directory chmods and other environment features |
||||||
56 | $model = new EntityCheck(); |
||||||
57 | |||||||
58 | // work with yandex statistics |
||||||
59 | $yandexCfg = App::$Properties->getAll('Yandex'); |
||||||
60 | $tokenLifetime = $yandexCfg['oauth']['expires']; |
||||||
61 | $tokenActive = ($tokenLifetime && time() < $tokenLifetime); |
||||||
62 | |||||||
63 | $visits = null; |
||||||
64 | $sources = null; |
||||||
65 | if ($tokenActive) { |
||||||
66 | // initialize yandex.api client |
||||||
67 | $client = new Client($yandexCfg['oauth']['token'], $yandexCfg['metrika']['id']); |
||||||
68 | |||||||
69 | // get visit statistics |
||||||
70 | $visits = App::$Cache->getItem('metrika.visits'); |
||||||
71 | if (!$visits->isHit()) { |
||||||
72 | $calcVisit = $client->getVisits30days(); |
||||||
0 ignored issues
–
show
|
|||||||
73 | $visits->set($calcVisit) |
||||||
74 | ->expiresAfter(3600); // update 1 times at hour |
||||||
75 | App::$Cache->save($visits); |
||||||
76 | } |
||||||
77 | $visits = $visits->get(); |
||||||
78 | |||||||
79 | // get source distribution statistics |
||||||
80 | $sources = App::$Cache->getItem('metrika.sources'); |
||||||
81 | if (!$sources->isHit()) { |
||||||
82 | $calcSources = $client->getSourcesSummary30days(); |
||||||
0 ignored issues
–
show
The method
getSourcesSummary30days() does not exist on Ffcms\Yandex\Metrika\Client .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||||||
83 | $sources->set($calcSources) |
||||||
84 | ->expiresAfter(3600); |
||||||
85 | App::$Cache->save($sources); |
||||||
86 | } |
||||||
87 | $sources = array_slice($sources->get(), 0, 5); |
||||||
88 | } |
||||||
89 | |||||||
90 | // render view output |
||||||
91 | return $this->view->render('main/index', [ |
||||||
92 | 'stats' => $stats, |
||||||
93 | 'check' => $model, |
||||||
94 | 'tokenActive' => $tokenActive, |
||||||
95 | 'yandexCfg' => $yandexCfg, |
||||||
96 | 'visits' => $visits, |
||||||
97 | 'sources' => $sources |
||||||
98 | ]); |
||||||
99 | } |
||||||
100 | } |
||||||
101 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.