2 namespace Drush\Commands;
4 use Consolidation\AnnotatedCommand\CommandData;
5 use Drush\Commands\DrushCommands;
6 use Symfony\Component\Console\Input\InputOption;
9 * Load this commandfile using the --include option - e.g. `drush --include=/path/to/drush/examples`
12 class PolicyCommands extends DrushCommands
16 * Prevent catastrophic braino. Note that this file has to be local to the
17 * machine that initiates the sql:sync command.
19 * hook validate sql:sync
22 public function sqlSyncValidate(CommandData $commandData)
24 if ($commandData->input()->getArgument('destination') == '@prod') {
25 throw new \Exception(dt('Per !file, you may never overwrite the production database.', ['!file' => __FILE__]));
30 * Limit rsync operations to production site.
32 * hook validate core:rsync
34 public function rsyncValidate(CommandData $commandData)
36 if (preg_match("/^@prod/", $commandData->input()->getArgument('destination'))) {
37 throw new \Exception(dt('Per !file, you may never rsync to the production site.', ['!file' => __FILE__]));
42 * Unauthorized may not execute updates.
44 * @hook validate updatedb
46 public function validateUpdateDb(CommandData $commandData)
48 if (!$commandData->input()->getOption('secret') == 'mysecret') {
49 throw new \Exception(dt('UpdateDb command requires a secret token per site policy.'));
54 * @hook option updatedb
55 * @option secret A required token else user may not run updatedb command.
57 public function optionsetUpdateDb($options = ['secret' => self::REQ])