-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Drupal 8 policy.drush.inc for site not being read #2497
Comments
In order for the file to get read, you must be in the PROJECT/web dir, or specify a --root or a site alias. If you are in the top level dir without specifying any of those, I dont think /drush gets read. In order to help more, please paste output of your command with --debug. Its helpful to see your prompt so we can see what the command is and what dir it launches from. |
Hi weitzman! These test have all been done from the PROJECT/web dir (webroot is docroot in my case). With the policy.drush.inc in the PROJECT folder:
Let me know if I should have placed the policy.drush.inc in a different folder. |
Your setup looks right to me. Not sure whats going on. |
I'm thinking this is the same bug that we are hitting. Basically, we've defined policy_drush_sitealias_alter but it's not taking effect as expected. Our project structure is something like:
If I run drush from the myproject directory, it correctly picks up the alter hook in policy.drush.inc. If I run drush from myproject/docroot, it does not pick up the alter hook in policy.drush.inc, despite the documentation indicating that drush should detect a policy file "in the /drush folder in the directory above the Drupal root": https://github.com/drush-ops/drush/blob/master/examples/policy.drush.inc#L15 |
@weitzman I think I have figured something out on this issue. Maybe you can confirm that this is the way it should work. If so then a change to the documentation at the top of the example policy.drush.inc file is what is needed. Currently this reads: /** * @file * Drush Policy command file. Currently only helps prevents the user from doing * things they use to use drush for but should now use Composer for. * * An example Drush Policy File can be found at: * https://raw.githubusercontent.com/drush-ops/drush/master/examples/policy.drush.inc * * Validates commands as they are issued and returns an error * or changes options when policy is violated. * * You can copy this file to any of the following * 1. A .drush folder in your HOME folder. * 2. Anywhere in a folder tree below an active module on your site. * 3. /usr/share/drush/commands (configurable) * 4. In an arbitrary folder specified with the --include option. * 5. Drupal's /drush or sites/all/drush folder, or in the /drush * folder in the directory above the Drupal root (note: sql-sync * validation won't work in any of these locations). */ I believe that in addition to being able to put a policy file in these different locations this also makes a difference to what the policy gets applied to. The closer to the top of the location list (see above) the more it gets applied and the closer to the bottom of the same list it only gets applied to the realms or scopes below it. Let me try and explain. I tried to test with the make-your-own-sandwich example policy in the Drupal sites drush folder (5.). This did not work because the sandwich command was not installed at the Drupal site level (5.) but on the Drush user level (1.) I believe that this is working as it should. It allows for a hierarchy of policy files and this needs to be explained in the policy.drush.inc example file. As an example I added the the example policy that Encourage folks to use If I wanted this for all websites that I work with I could instead add this to my .drush/policy.drush.inc in my HOME folder. Is this sounding correct @weitzman according to what the code that handles policy.drush.inc files? If so an explanation of this hierarchy should be added to the comments in the example policy.drush.inc. |
@danepowell The folder you should place your site specific policy.drush.inc, in your case would be: @weitzman I have to wonder if the "directory above Drupal root" is best way to say this. If people visualise the Linux file structure as a tree with the base being root / and everything goes up from there into the branches so to speak, then the drush folder would be in the directory below the Drupal docroot folder. Maybe would should change this to say that the policy.drush.inc for a Composer managed site should be place in the in the drush folder in the Composer project root beside the docroot folder. |
Yes, your understanding of where we look for policy files is correct ... Sure, I'm open to rewording the "directory above drupal root" part. |
I think I understand how it's supposed to work, that's why I organized our project folders the way I did. What I'm saying is that it doesn't work in practice. I have to manually include the policy file. See acquia/blt#1076 |
@danepowell does your policy.drush.inc file work if you move it to, |
@weitzman Is my understanding of the context of the policy.drush.inc files also correct? In other word putting policy in 5. (site specific policy file) for the make a sandwich command that is installed not in the Drupal site but in the users' ~/.drush folder would have no effect on the make a sandwich command? |
@frederickjh that's where my policy file is. See my original comment: #2497 (comment) Am I missing something? There's a small chance that this is due to caching... I can't recall if I attempted clearing the Drush cache before or after noticing this, since I was dealing with a lot of quirks at the same time. |
@danepowell Sorry, you are correct. That is where you said you put the policy.drush.inc However, I would not expect it to work there. You are trying to modify a site alias that you most likely have in your I am not sure how to explain this better but it is like the policy.drush.inc files only work in the context of where they are placed. If a policy file is defined at the site level. It only affects things for that site. The policy file for a site would not be loaded for a site alias for that site when the alias is in the user's In your case try putting the site alias in the same folder on the site with the drush.policy.inc file and see if it works. However placing an alias file there removes a lot of the benefits of drush sites aliases. IMHO it would be better to use either a user (1.) or server (3.) policy.drush.inc file for policy_drush_sitealias_alter. This is my policy_drush_sitealias_alter that is in
|
Actually my site aliases are also with my site (so siblings of the policy file). They are all part of a Git repo containing the project, which I think is pretty typical for enterprise deployments. I'll update my previous post to reflect this.
|
I'm running into this too, and I imagine I have the same setup as @danepowell since he and I are both using BLT. Heres the file structure:
The
Inside the
And in my policy file I have:
Running This is strange that sql-sync hook is not working but the other is? |
OK, nevermind, things are working as expected for me. I was confused by the fact that I was being prompted to confirm the sql-sync action even though my policy denied it. That's because that prompt is included in drush's own implementation of the sql_sync_validate and was invoked before mine. After responding to the prompt, my validation is run. |
@danepowell I just reread your last comment due to the recent posts on this thread. Is there a reason you have your
I have never seen it done this way before. @weitzman Could this have any effect on the policy file not working? Or is it OK to organize your |
subdirs are fine and should not affect whether drush find a policy or not. |
No activity |
Hi!
I have a fresh install of the Drupal 8 Lightning distribution using composer. I want to add a policy.drush.inc that will be used for the site. Lightning comes with drush folder with a README.md file in it that is on the same level as the docroot (inside the Composer project file). The README.md file says:
To test I added the make your own sandwich policy from the example policy.drush.inc. into my policy.drush.inc In the drush folder supplied by Lightning it is not read. I check this by adding the
--show-invoke
option when runningdrush mmas
(short for make me a sandwich).When I place the same policy.drush.inc file in ~/.drush/policy.drush.inc I get told to make my own sandwich, as I should.
Placing the same policy.drush.inc file in
/drush
or/sites/all/drush or /sites/all/default
and runningdrush mmas
results in me getting a sandwich even though policy should tell me to make my own.I am using Drush Version : 8.1.8. This is not install with composer in the Lightning website project. It is installed with composer on my computer at
~/.composer/vendor/bin/drush
.So, I am not sure with folders moving around in Drupal 8 as to where is the correct place. Not sure if I am not doing this the correct way or if it is a Lightning or Drush issue.
So, where on a Drupal 8 site built with Composer should I be placing policy.drush.inc files that I want to apply to only that website?
Thanks in advance for any help you can provide!
Frederick
The text was updated successfully, but these errors were encountered: