-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.php
98 lines (79 loc) · 2.64 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
namespace Concrete\Package\Centry;
use A3020\Centry\Provider\CentryServiceProvider;
use Concrete\Core\Config\Repository\Repository;
use Concrete\Core\Job\Job;
use Concrete\Core\Package\Package;
use Concrete\Core\Page\Page;
use Concrete\Core\Page\Single;
use Concrete\Core\Support\Facade\Package as PackageFacade;
final class Controller extends Package
{
protected $pkgHandle = 'centry';
protected $appVersionRequired = '8.0';
protected $pkgVersion = '2.3.1';
protected $pkgAutoloaderRegistries = [
'src/Centry' => '\A3020\Centry',
];
/** @var Repository */
protected $config;
// Needs to be a class constant, as on_start is not loaded during install.
const CENTRY_PORTAL_DEFAULT_ENDPOINT = 'https://centry.nl/api/v1';
public function getPackageName()
{
return t('Centry');
}
public function getPackageDescription()
{
return t('Allows communication to a remote Centry endpoint.');
}
public function on_start()
{
// The version of the API on this C5 installation.
define('CENTRY_INSTANCE_API_VERSION', 1);
// Default endpoint of where the data is communicated to.
// Can be overridden via the settings page.
define('CENTRY_PORTAL_DEFAULT_ENDPOINT', self::CENTRY_PORTAL_DEFAULT_ENDPOINT);
$provider = $this->app->make(CentryServiceProvider::class);
$provider->register();
}
public function install()
{
$this->config = $this->app->make(Repository::class);
$pkg = parent::install();
$this->installEverything($pkg);
$this->config->save('centry.enabled', true);
$this->config->save('centry.endpoint', self::CENTRY_PORTAL_DEFAULT_ENDPOINT);
}
public function upgrade()
{
$this->config = $this->app->make(Repository::class);
$pkg = PackageFacade::getByHandle($this->pkgHandle);
$this->installEverything($pkg);
}
public function installEverything($pkg)
{
$this->installJob($pkg);
$this->installDashboardPage($pkg);
}
private function installJob($pkg)
{
/** @var Job $job */
$job = Job::getByHandle('centry');
if (!$job) {
$job = Job::installByPackage('centry', $pkg);
}
$job->setSchedule(true, 'days', 1);
}
private function installDashboardPage($pkg)
{
$path = '/dashboard/system/centry';
/** @var Page $page */
$page = Page::getByPath($path);
if ($page && !$page->isError()) {
return;
}
$singlePage = Single::add($path, $pkg);
$singlePage->update($this->getPackageName());
}
}