/
controller.php
50 lines (44 loc) · 1.6 KB
/
controller.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
namespace Concrete\Block\DesktopAppStatus;
use Concrete\Core\Block\BlockController;
use Concrete\Core\Package\PackageService;
use Concrete\Core\Permission\Checker;
use Concrete\Core\Updater\Update;
class Controller extends BlockController
{
protected $btCacheBlockRecord = true;
protected $btCacheBlockOutput = true;
protected $btCacheBlockOutputOnPost = true;
protected $btCacheBlockOutputForRegisteredUsers = true;
protected $btCacheBlockOutputLifetime = 86400; // check every day
public function getBlockTypeDescription()
{
return t("Displays alerts about your Concrete site and package updates.");
}
public function getBlockTypeName()
{
return t("Concrete Status Messages");
}
public function view()
{
$config = $this->app->make('config');
$this->set('current_version', $config->get('concrete.version'));
$this->set('latest_version', Update::getLatestAvailableVersionNumber());
$updates = 0;
$p = new Checker();
if ($p->canInstallPackages()) {
$packageService = $this->app->make(PackageService::class);
$localHandles = [];
foreach ($packageService->getLocalUpgradeablePackages() as $pkg) {
++$updates;
$localHandles[] = $pkg->getPackageHandle();
}
foreach ($packageService->getRemotelyUpgradeablePackages() as $pkg) {
if (!in_array($pkg->getPackageHandle(), $localHandles)) {
++$updates;
}
}
}
$this->set('updates', $updates);
}
}