Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / drush / drush / examples / Commands / PolicyCommands.php
1 <?php
2 namespace Drush\Commands;
3
4 use Consolidation\AnnotatedCommand\CommandData;
5 use Drush\Commands\DrushCommands;
6 use Symfony\Component\Console\Input\InputOption;
7
8 /**
9  * Load this commandfile using the --include option - e.g. `drush --include=/path/to/drush/examples`
10  */
11
12 class PolicyCommands extends DrushCommands
13 {
14
15     /**
16      * Prevent catastrophic braino. Note that this file has to be local to the
17      * machine that initiates the sql:sync command.
18      *
19      * hook validate sql:sync
20      * @throws \Exception
21      */
22     public function sqlSyncValidate(CommandData $commandData)
23     {
24         if ($commandData->input()->getArgument('destination') == '@prod') {
25             throw new \Exception(dt('Per !file, you may never overwrite the production database.', ['!file' => __FILE__]));
26         }
27     }
28
29     /**
30     * Limit rsync operations to production site.
31     *
32     * hook validate core:rsync
33     */
34     public function rsyncValidate(CommandData $commandData)
35     {
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__]));
38         }
39     }
40
41     /**
42     * Unauthorized may not execute updates.
43     *
44     * @hook validate updatedb
45     */
46     public function validateUpdateDb(CommandData $commandData)
47     {
48         if (!$commandData->input()->getOption('secret') == 'mysecret') {
49             throw new \Exception(dt('UpdateDb command requires a secret token per site policy.'));
50         }
51     }
52
53     /**
54     * @hook option updatedb
55     * @option secret A required token else user may not run updatedb command.
56     */
57     public function optionsetUpdateDb($options = ['secret' => self::REQ])
58     {
59     }
60 }