class LockrAdminController in Lockr 8.2
Same name and namespace in other branches
- 8.4 src/Controller/LockrAdminController.php \Drupal\lockr\Controller\LockrAdminController
- 8.3 src/Controller/LockrAdminController.php \Drupal\lockr\Controller\LockrAdminController
- 4.x src/Controller/LockrAdminController.php \Drupal\lockr\Controller\LockrAdminController
Hierarchy
- class \Drupal\lockr\Controller\LockrAdminController implements ContainerInjectionInterface
Expanded class hierarchy of LockrAdminController
File
- src/
Controller/ LockrAdminController.php, line 19
Namespace
Drupal\lockr\ControllerView source
class LockrAdminController implements ContainerInjectionInterface {
/**
* Constructs a new LockrAdminForm.
*/
public function __construct(ClientFactory $client_factory, PartnerFactory $partner_factory, ConfigFactoryInterface $config_factory, FormBuilderInterface $form_builder, $drupalRoot) {
$this->clientFactory = $client_factory;
$this->partnerFactory = $partner_factory;
$this->configFactory = $config_factory;
$this->formBuilder = $form_builder;
$this->drupalRoot = $drupalRoot;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('lockr.client_factory'), $container
->get('lockr.partner_factory'), $container
->get('config.factory'), $container
->get('form_builder'), $container
->get('app.root'));
}
public function overview() {
$site_client = $this->clientFactory
->getSiteClient();
try {
$status = $site_client
->exists();
} catch (LockrServerException $e) {
watchdog_exception('lockr', $e);
drupal_set_message('The Lockr service has returned an error. Please try again.', 'error');
return $form;
}
$text_config = $this->configFactory
->get('lockr.ui_text');
$exists = $status['exists'];
$ra['header'] = [
'#prefix' => '<p>',
'#markup' => $exists ? $text_config
->get('admin_page.header.registered') : $text_config
->get('admin_page.header.not_registered'),
'#suffix' => '</p>',
];
$ra['status'] = $this
->getStatus($status);
$cert_valid = $status['cert_valid'];
$partner = $this->partnerFactory
->detectPartner();
if ($partner) {
$ra['description'] = [
'#prefix' => '<p>',
'#markup' => $partner['description'],
'#suffix' => '</p>',
];
}
elseif (!$cert_valid) {
$ra['csr'] = $this->formBuilder
->getForm(LockrCSRForm::class);
}
elseif ($exists && $status['info']['env'] === 'dev') {
$ra['migrate_info'] = array(
'#prefix' => '<p>',
'#markup' => 'Click the button below to deploy this site to production. ' . 'This should only be done in your production environment as it writes a new certificate to the file system. ',
'#suffix' => '</p>',
);
$ra['migrate'] = $this->formBuilder
->getForm(LockrMigrateForm::class);
}
if (!$exists && $cert_valid) {
$ra['register'] = $this->formBuilder
->getForm(LockrRegisterForm::class);
}
$ra['advanced'] = $this->formBuilder
->getForm(LockrAdvancedForm::class);
return $ra;
}
public function getStatus($status) {
require_once "{$this->drupalRoot}/core/includes/install.inc";
$text_config = $this->configFactory
->get('lockr.ui_text');
$cert_valid = $status['cert_valid'];
$exists = $status['exists'];
$created = isset($status['created']) ? $status['created'] : FALSE;
$reqs[] = [
'title' => 'Certificate Valid',
'value' => $cert_valid ? 'Yes' : 'No',
'description' => $cert_valid ? $text_config
->get('admin_page.status.cert.valid') : $text_config
->get('admin_page.status.cert.not_valid'),
'severity' => $cert_valid ? REQUIREMENT_OK : REQUIREMENT_ERROR,
];
if ($cert_valid) {
$reqs[] = [
'title' => 'Environment',
'value' => $status['info']['env'],
'severity' => REQUIREMENT_INFO,
];
}
else {
$private_path = PrivateStream::basepath();
$default_text = $private_path ? $text_config
->get('admin_page.status.path.invalid') : $text_config
->get('admin_page.status.path.unknown');
$is_dir = is_dir($private_path);
$req = [
'title' => 'Private Directory',
'value' => $private_path ?: 'Unknown',
'description' => $is_dir ? $text_config
->get('admin_page.status.path.exists') : $default_text,
'severity' => $is_dir ? REQUIREMENT_OK : REQUIREMENT_ERROR,
];
array_unshift($reqs, $req);
}
$reqs[] = [
'title' => 'Site Registered',
'value' => $exists ? 'Yes' : 'No',
'description' => $exists ? $text_config
->get('admin_page.status.registered') : $text_config
->get('admin_page.status.not_registered'),
'severity' => $exists ? REQUIREMENT_OK : REQUIREMENT_ERROR,
];
if ($cert_valid) {
$has_cc = $status['has_cc'];
if ($created) {
$expires = (new \DateTime())
->setTimestamp($created)
->add(new \DateInterval('P14D'));
if ($expires > new \DateTime()) {
$reqs[] = [
'title' => 'Trial Expiration Date',
'value' => $expires
->format('M jS, Y'),
'severity' => REQUIREMENT_INFO,
];
}
elseif (!$has_cc) {
$reqs[] = [
'title' => 'Trial Expiration Date',
'value' => $expires
->format('M jS, Y'),
'severity' => REQUIREMENT_ERROR,
];
}
}
$partner = $status['info']['partner'];
$is_custom = in_array($partner, [
'custom',
'lockr',
]);
$default = $is_custom ? REQUIREMENT_ERROR : REQUIREMENT_WARNING;
$default_text = $is_custom ? $text_config
->get('admin_page.status.cc.missing.required') : $text_config
->get('admin_page.status.cc.missing.partner');
$reqs[] = [
'title' => 'Credit Card on File',
'value' => $has_cc ? 'Yes' : 'No',
'description' => $has_cc ? $text_config
->get('admin_page.status.cc.has') : $default_text,
'severity' => $has_cc ? REQUIREMENT_OK : $default,
];
}
lockr_preprocess_status_report($reqs);
return [
'#theme' => 'status_report',
'#requirements' => $reqs,
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LockrAdminController:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
LockrAdminController:: |
public | function | ||
LockrAdminController:: |
public | function | ||
LockrAdminController:: |
public | function | Constructs a new LockrAdminForm. |