121 lines
3.9 KiB
Text
Executable file
121 lines
3.9 KiB
Text
Executable file
<?php
|
|
|
|
/**
|
|
* Implements hook_cron().
|
|
*/
|
|
function wisski_cloud_account_manager_cron() {
|
|
$time_limit = \Drupal::time()->getRequestTime() - 24 * 60 * 60;
|
|
|
|
$ids = \Drupal::entityQuery('user')
|
|
->condition('status', 0)
|
|
->condition('created', $time_limit, '<')
|
|
->accessCheck(TRUE)
|
|
->execute();
|
|
|
|
// Delete rows from the wisski_cloud_account_manager table.
|
|
$connection = \Drupal::database();
|
|
|
|
$wisskiCloudUsers = $connection->select('wisski_cloud_account_manager', 'wcam')
|
|
->fields('wcam', ['uid'])
|
|
->condition('uid', $ids, 'IN')
|
|
->execute()
|
|
->fetchAll();
|
|
|
|
$ids = array_map(function($wisskiCloudUser) {
|
|
return $wisskiCloudUser->uid;
|
|
}, $wisskiCloudUsers);
|
|
|
|
if (empty($ids)) {
|
|
return;
|
|
}
|
|
|
|
\Drupal::logger('wisski_cloud_account_manager')->notice('Deleting users, who missed the validation: @ids', ['@ids' => implode(', ', $ids)]);
|
|
$connection->delete('wisski_cloud_account_manager')
|
|
->condition('uid', $ids, 'IN')
|
|
->execute();
|
|
|
|
$storage_handler = \Drupal::entityTypeManager()->getStorage('user');
|
|
$entities = $storage_handler->loadMultiple($ids);
|
|
$storage_handler->delete($entities);
|
|
|
|
}
|
|
|
|
/**
|
|
* Implements hook_help().
|
|
*/
|
|
function wisski_cloud_account_manager_help($route_name, \Drupal\Core\Routing\RouteMatchInterface $route_match) {
|
|
$output = '';
|
|
|
|
switch ($route_name) {
|
|
case 'help.page.wisski_cloud_account_manager':
|
|
$output .= '<h3>' . t('About') . '</h3>';
|
|
$output .= '<p>' . t('This module provides the functionality to create, validate and manage WissKI Cloud accounts.') . '</p>';
|
|
|
|
$output .= '<h3>' . t('Configuration') . '</h3>';
|
|
$output .= '<p>' . t('Configuration is done on the <a href="@settingsPage" targer="_blank">settings page</a>.', ['@settingsPage' => '/admin/config/wisski-cloud-account-manager/settings']) . '</p>';
|
|
|
|
$output .= '<h3>' . t('Create WissKI Cloud Account') . '</h3>';
|
|
$output .= '<p>' . t('<a href="@createPage" targer="_blank">This page</a> allows you to create a WissKI Cloud account.', ['@createPage' => '/wisski-cloud-account-manager/create']) . '</p>';
|
|
|
|
$output .= '<h3>' . t('Validate WissKI Cloud Account') . '</h3>';
|
|
$output .= '<p>' . t('<a href="@validationPage" targer="_blank">This page</a> allows you to validate your account and check the status of the provision.', ['@validationPage' => '/wisski-cloud-account-manager/validate/GsyMv5DdFhPCixL1wTLZhzFg7sVDOiHq']) . '</p>';
|
|
break;
|
|
}
|
|
return $output;
|
|
}
|
|
|
|
|
|
/**
|
|
* Implements hook_mail().
|
|
*/
|
|
function wisski_cloud_account_manager_mail($key, &$message, $params) {
|
|
$options = [
|
|
'langcode' => $message['langcode'],
|
|
];
|
|
switch ($key) {
|
|
case 'wisski_cloud_account_validation':
|
|
$message['from'] = \Drupal::config('system.site')->get('mail');
|
|
$message['subject'] = t('@subject', ['@subject' => $params['subject']], $options);
|
|
$message['body'][] = $params['message'];
|
|
|
|
$headers = [
|
|
'Content-Type' => 'text/html; charset=UTF-8; format=flowed',
|
|
'MIME-Version' => '1.0',
|
|
'Content-Transfer-Encoding' => '8Bit',
|
|
'X-Mailer' => 'Drupal',
|
|
];
|
|
|
|
$message['headers'] = $headers;
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Implements hook_theme().
|
|
*/
|
|
function wisski_cloud_account_manager_theme($existing, $type, $theme, $path) {
|
|
return [
|
|
'wisski_cloud_account_manager_terms_and_conditions_page' => [
|
|
'variables' => ['date' => NULL],
|
|
],
|
|
'wisski_cloud_account_manager_account_managing_page' => [
|
|
'variables' => [
|
|
'accounts' => NULL,
|
|
'healthCheck' => NULL,],
|
|
],
|
|
'wisski_cloud_account_manager_validation_page' => [
|
|
'variables' => ['account' => NULL],
|
|
],
|
|
'wisski_cloud_account_manager_health_check_page' => [
|
|
'variables' => ['healthCheck' => NULL],
|
|
],
|
|
'wisski_cloud_account_manager_validation_email' => [
|
|
'variables' => [
|
|
'personName' => NULL,
|
|
'validationLink' => NULL,
|
|
],
|
|
],
|
|
];
|
|
}
|
|
|