-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathUserWrappingAlterer.php
59 lines (51 loc) · 1.42 KB
/
UserWrappingAlterer.php
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
<?php
namespace Drupal\islandora_drush_utils\Drush\CommandInfoAlterers;
use Consolidation\AnnotatedCommand\CommandInfoAltererInterface;
use Consolidation\AnnotatedCommand\Parser\CommandInfo;
use Psr\Log\LoggerInterface;
/**
* Re-create the global --user option.
*
* XXX: Drush 9 dropped it; however, we require this option for various
* commands.
*/
class UserWrappingAlterer implements CommandInfoAltererInterface {
/**
* The annotation we use to handle user swapping.
*/
const ANNO = 'islandora-drush-utils-user-wrap';
/**
* The set of commands we wish to alter.
*/
const COMMANDS = [
'content-sync:import',
'content-sync:export',
'batch:process',
'migrate:rollback',
];
/**
* Constructor.
*/
public function __construct(
protected LoggerInterface $logger,
protected $debug = FALSE,
) {
// No-op.
}
/**
* {@inheritdoc}
*/
public function alterCommandInfo(CommandInfo $commandInfo, $commandFileInstance) : void {
if (!$commandInfo->hasAnnotation(static::ANNO) && in_array($commandInfo->getName(), static::COMMANDS)) {
if ($this->debug) {
$this->logger->debug(
'Adding annotation "@annotation" to @command.', [
'@annotation' => static::ANNO,
'@command' => $commandInfo->getName(),
]
);
}
$commandInfo->addAnnotation(static::ANNO, 'User swapping fun.');
}
}
}