-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopeny_session_cleaner.module
More file actions
51 lines (45 loc) · 1.5 KB
/
openy_session_cleaner.module
File metadata and controls
51 lines (45 loc) · 1.5 KB
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
<?php
declare(strict_types=1);
/**
* @file
* Open Y session cleaner.
*/
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function openy_session_cleaner_help($route_name, RouteMatchInterface $route_match) {
if ($route_name == 'help.page.openy_session_cleaner') {
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The module removes the classes without upcoming sessions.') . '</p>';
return $output;
}
}
/**
* Implements hook_cron().
*/
function openy_session_cleaner_cron(): void {
/** @var \Drupal\Core\Lock\LockBackendInterface $lock */
$lock = \Drupal::service('lock');
if ($lock->lockMayBeAvailable('openy_session_cleaner')) {
/** @var Drupal\openy_session_cleaner\SessionCleaner $cleaner */
$cleaner = \Drupal::service('openy_session_cleaner.cleaner');
$cleaner->clean();
}
}
/**
* Implements hook_ENTITY_TYPE_delete().
*/
function openy_session_cleaner_node_delete(EntityInterface $entity): void {
// Clean up migrate mapping after removing of any session or class.
// So node can be imported one more time if needed.
if ($entity->bundle() == 'class' || $entity->bundle() == 'session') {
$map_table = ($entity->bundle() == 'class') ? 'migrate_map_activenet_classes_import' : 'migrate_map_activenet_sessions_import';
$connection = \Drupal::database();
$connection->delete($map_table)
->condition("$map_table.destid1", $entity->id())
->execute();
}
}