-
Notifications
You must be signed in to change notification settings - Fork 1
/
file_checker.drush.inc
92 lines (83 loc) · 2.97 KB
/
file_checker.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
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
<?php
/**
* @file
* File Checker drush commands.
*/
/**
* Implements hook_drush_command().
*/
function file_checker_drush_command() {
$commands['file-checking-start'] = [
'description' => 'Start file checking.',
'aliases' => ['fcheck-start'],
'examples' => [
'drush file-checking-start' => 'Starts file checking.',
],
];
$commands['file-checking-cancel'] = [
'description' => 'Start file checking.',
'aliases' => ['fcheck-cancel'],
'examples' => [
'drush file-checking-start' => 'Cancels file checking.',
],
];
$commands['file-checking-execute'] = [
'description' => 'Execute file checking for a period of time.',
'aliases' => ['fcheck-exec'],
'arguments' => [
'seconds' => 'Number of seconds to execute for.',
],
'options' => [
'log' => 'Log this execution.',
],
'examples' => [
'drush file-checking-execute --log' => 'Check files for 50 seconds, and logs it.',
'drush fcheck-exec 110' => 'Check files for 110 seconds".',
],
];
return $commands;
}
/**
* Drush logic for command file-checking-start.
*/
function drush_file_checker_file_checking_start() {
$success = \Drupal::service('file_checker.bulk_file_checking')->start();
if ($success) {
drush_print(dt("Bulk file checking requested. To actually check files, next run 'drush file-checking-execute'."));
}
else {
drush_print(dt("Bulk file checking has already been requested. To actually check files, instead run 'drush file-checking-execute'."));
}
}
/**
* Drush logic for command file-checking-cancel.
*/
function drush_file_checker_file_checking_cancel() {
\Drupal::service('file_checker.bulk_file_checking')->cancel();
drush_print(dt("Bulk file checking cancelled."));
}
/**
* Drush logic for command file-checking-execute.
*/
function drush_file_checker_file_checking_execute($seconds = 50) {
drush_print(dt('Files will be checked for up to @seconds seconds. Checking now ...', array('@seconds' => $seconds)));
$runState = \Drupal::service('file_checker.bulk_file_checking')->executeInBackground($seconds, drush_get_option('log',FALSE));
if ($runState['aborted']) {
drush_print(dt("File checking has not been previously started, checking aborted."));
drush_print(dt("To start checking, first run 'drush file-checking-start'."));
}
else {
drush_print(dt("@files_just_checked files just checked.", ['@files_just_checked' => $runState['files_just_checked']]));
drush_print(dt("So far in this run @files_checked_count out of @files_to_check files checked, with @files_missing_count missing files detected.", [
'@files_checked_count' => $runState['files_checked_count'],
'@files_to_check' => $runState['files_to_check'],
'@files_missing_count' => $runState['files_missing_count'],
]));
if ($runState['finished']) {
drush_print(dt("File checking completed."));
}
else {
drush_print(dt("To check more files, run 'drush file-checking-execute' again."));
}
}
}