Skip to content

Commit 902fa86

Browse files
committed
Update /drush dir for Drush9
Shows how the benefits of a policyfile and also illustrates where to store site aliases and druh config.
1 parent ffbdbf1 commit 902fa86

File tree

4 files changed

+71
-38
lines changed

4 files changed

+71
-38
lines changed

drush/Commands/PolicyCommands.php

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
* Edit this file to reflect your organization's needs.
10+
*/
11+
12+
class PolicyCommands extends DrushCommands {
13+
14+
/**
15+
* Prevent catastrophic braino. Note that this file has to be local to the
16+
* machine that initiates the sql:sync command.
17+
*
18+
* hook validate sql:sync
19+
*
20+
* @throws \Exception
21+
*/
22+
public function sqlSyncValidate(CommandData $commandData) {
23+
if ($commandData->input()->getArgument('destination') == '@prod') {
24+
throw new \Exception(dt('Per !file, you may never overwrite the production database.', ['!file' => __FILE__]));
25+
}
26+
}
27+
28+
/**
29+
* Limit rsync operations to production site.
30+
*
31+
* hook validate core:rsync
32+
*/
33+
public function rsyncValidate(CommandData $commandData) {
34+
if (preg_match("/^@prod/", $commandData->input()->getArgument('destination'))) {
35+
throw new \Exception(dt('Per !file, you may never rsync to the production site.', ['!file' => __FILE__]));
36+
}
37+
}
38+
39+
/**
40+
* Unauthorized may not execute updates.
41+
*
42+
* @hook validate updatedb
43+
*/
44+
public function validateUpdateDb(CommandData $commandData) {
45+
if (!$commandData->input()->getOption('secret') == 'mysecret') {
46+
throw new \Exception(dt('UpdateDb command requires a secret token per site policy.'));
47+
}
48+
}
49+
50+
/**
51+
* @hook option updatedb
52+
* @option secret A required token else user may not run updatedb command.
53+
*/
54+
public function optionsetUpdateDb($options = ['secret' => self::REQ]) {}
55+
}

drush/Sites/self.site.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Edit or remove this file as needed.
2+
# Docs at https://github.com/drush-ops/drush/blob/master/examples/example.site.yml
3+
4+
#live:
5+
# host: live.domain.com
6+
# user: www-admin
7+
# root: /path/to/drupal
8+
# uri: http://www.example.com
9+
#
10+
#stage:
11+
# host: stage.domain.com
12+
# user: www-admin
13+
# root: /path/to/drupal
14+
# uri: http://stage.example.com

drush/drush.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# A Drush configuration file.
2+
# Details at https://github.com/drush-ops/drush/blob/master/examples/example.drush.yml

drush/policy.drush.inc

-38
This file was deleted.

0 commit comments

Comments
 (0)