Skip to content

Commit

Permalink
Update /drush dir for Drush9
Browse files Browse the repository at this point in the history
Shows how the benefits of a policyfile and also illustrates where to store site aliases and druh config.
  • Loading branch information
weitzman committed Feb 9, 2018
1 parent ffbdbf1 commit 902fa86
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 38 deletions.
55 changes: 55 additions & 0 deletions drush/Commands/PolicyCommands.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
namespace Drush\Commands;

use Consolidation\AnnotatedCommand\CommandData;
use Drush\Commands\DrushCommands;
use Symfony\Component\Console\Input\InputOption;

/**
* Edit this file to reflect your organization's needs.
*/

class PolicyCommands extends DrushCommands {

/**
* Prevent catastrophic braino. Note that this file has to be local to the
* machine that initiates the sql:sync command.
*
* hook validate sql:sync
*
* @throws \Exception
*/
public function sqlSyncValidate(CommandData $commandData) {
if ($commandData->input()->getArgument('destination') == '@prod') {
throw new \Exception(dt('Per !file, you may never overwrite the production database.', ['!file' => __FILE__]));
}
}

/**
* Limit rsync operations to production site.
*
* hook validate core:rsync
*/
public function rsyncValidate(CommandData $commandData) {
if (preg_match("/^@prod/", $commandData->input()->getArgument('destination'))) {
throw new \Exception(dt('Per !file, you may never rsync to the production site.', ['!file' => __FILE__]));
}
}

/**
* Unauthorized may not execute updates.
*
* @hook validate updatedb
*/
public function validateUpdateDb(CommandData $commandData) {
if (!$commandData->input()->getOption('secret') == 'mysecret') {
throw new \Exception(dt('UpdateDb command requires a secret token per site policy.'));
}
}

/**
* @hook option updatedb
* @option secret A required token else user may not run updatedb command.
*/
public function optionsetUpdateDb($options = ['secret' => self::REQ]) {}
}
14 changes: 14 additions & 0 deletions drush/Sites/self.site.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Edit or remove this file as needed.
# Docs at https://github.com/drush-ops/drush/blob/master/examples/example.site.yml

#live:
# host: live.domain.com
# user: www-admin
# root: /path/to/drupal
# uri: http://www.example.com
#
#stage:
# host: stage.domain.com
# user: www-admin
# root: /path/to/drupal
# uri: http://stage.example.com
2 changes: 2 additions & 0 deletions drush/drush.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# A Drush configuration file.
# Details at https://github.com/drush-ops/drush/blob/master/examples/example.drush.yml
38 changes: 0 additions & 38 deletions drush/policy.drush.inc

This file was deleted.

0 comments on commit 902fa86

Please sign in to comment.