-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredis_watchdog.drush.inc
61 lines (53 loc) · 1.5 KB
/
redis_watchdog.drush.inc
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
<?php
/**
* @file
* Provide drush integration for Redis Watchdog.
*/
use Drupal\redis_watchdog\RedisWatchdog;
/**
* Implementation of hook_drush_command().
*/
function redis_watchdog_drush_command() {
$items = [];
$items['redis-watchdog-export'] = [
'description' => t('Export the Redis Watchdog logs to CSV'),
'drupal dependencies' => ['redis_watchdog'],
'aliases' => ['rwe'],
'arguements' => [
'filepath' => 'File path for the export.',
],
];
$items['redis-watchdog-clear'] = [
'description' => t('Clear the Redis memory'),
'drupal dependencies' => ['redis_watchdog'],
'aliases' => ['rwc'],
];
return $items;
}
/**
* Implements hook_drush_help().
*/
function redis_watchdog_drush_help($section) {
switch ($section) {
case 'drush:redis-watchdog-export':
return t('Export the logs in Redis to a CSV file. You must pass an argument to specify the path to the CSV to be created. Depending on the size of your logs, this operation could require a lot of time.');
case 'drush:redis-watchdog-clear':
return t('Clear all of the Redis memory of watchdog logs.');
}
}
/**
* Callback from the redis-watchdog-export command.
*/
function drush_redis_watchdog_export($filepath) {
$redis = new RedisWatchdog();
$data = $redis->exportCSV();
$df = fopen($filepath, 'w');
fwrite($df, $data);
fclose($df);
}
/**
* Callback from the redis-watchdog-clear command.
*/
function drush_redis_watchdog_clear() {
RedisWatchdog::redis_watchdog_redis_destroy();
}