Skip to content
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

Use chains to replace site:mode command #3541

Open
marcelovani opened this issue Oct 4, 2017 · 3 comments
Open

Use chains to replace site:mode command #3541

marcelovani opened this issue Oct 4, 2017 · 3 comments

Comments

@marcelovani
Copy link
Member

marcelovani commented Oct 4, 2017

Issue title

[site:mode] Use chains to replace site:mode command

Problem/Motivation

Since chains are getting more powerful, I figured we could replace the code found in https://github.com/hechoendrupal/drupal-console/blob/master/src/Command/Site/ModeCommand.php with a chain

Details to include:
We can simply have less code to maintain and add more flexibility to users

Solution

This is how the site:mode:dev chain would look

command:
  name: site:mode:dev
  description: 'Switch system performance configuration'
commands:
  # system.performance
  - command: config:override
    arguments:
      name: system.performance
        - cache.page.use_internal: false
        - css.preprocess: false
        - css.gzip: false
        - js.preprocess: false
        - js.gzip: false
        - response.gzip: false
  # views.settings
  - command: config:override
    arguments:
      name: views.settings
        - ui.show.sql_query.enabled: true
        - ui.show.performance_statistics: true
  # system.logging
  - command: config:override
    arguments:
      name: system.logging
        - error_level: all

The prod chain would be the inverse of the chain above

This chain should appear only when there is a site installed, that would automatically happen when we implement hechoendrupal/drupal-console-core#240

@marcelovani
Copy link
Member Author

marcelovani commented Feb 6, 2018

Another proof of concept: Use twig + a new command to override services.

File: chain-site-mode.yml

# How to use
# site:mode --mode="dev"
command:
  name: site:mode
  description: 'Changes the site mode'
vars:
  mode:
    - dev
    - prod
commands:
  # System Performance
  {% set keys = ['cache.page.use_internal', 'css.preprocess', 'css.gzip', 'js.preprocess', 'js.gzip', 'response.gzip'] %}
  {% for key in keys %}
  - command: config:override
    arguments:
      name: system.performance
      key: {{ key }}
      value: {% if mode == "dev" %} false {% else %} true {% endif %}
  {% endfor %}

  # Views settings
  {% set keys = ['ui.show.sql_query.enabled', 'ui.show.performance_statistics'] %}
  {% for key in keys %}
  - command: config:override
    arguments:
      name: views.settings
      key: {{ key }}
      value: {% if mode == "dev" %} false {% else %} true {% endif %}
  {% endfor %}

  # System Logging
  - command: config:override
    arguments:
      name: system.logging
      key: error_level
      value: {% if mode == "dev" %} all {% else %} none {% endif %}

  # Services http.response.debug_cacheability_headers
  - command: service:override
    arguments:
      name: http.response.debug_cacheability_headers
      key: error_level
      value: {% if mode == "dev" %} true {% else %} false {% endif %}

  # Services Twig config
  {% set keys = ['debug', 'auto_reload', 'cache'] %}
  {% for key in keys %}
  - command: service:override
    arguments:
      name: twig.config
      key: {{ key }}
      value: {% if mode == "dev" %} true {% else %} false {% endif %}
  {% endfor %}

The if/else is not working, I think I am using an invalid syntax

@jmolivas
Copy link
Member

jmolivas commented Feb 7, 2018

@marcelovani could you try using as :

{{ mode === 'dev' }}

or

{{ mode === 'dev' ?? false }}

marcelovani added a commit to marcelovani/drupal-console that referenced this issue Feb 8, 2018
@marcelovani
Copy link
Member Author

marcelovani commented Feb 8, 2018

Ok, try this
https://github.com/hechoendrupal/drupal-console-core/pull/306/files
with
https://github.com/hechoendrupal/drupal-console/pull/3771/files

It works fine but the chain looks cluttered with all the twig stuff, I think its neater if we do the chain as per #3540

Testing:
Install a drupal site and run
drupal site:mode --mode="dev"
drupal site:mode --mode="prod"

Todo:

  • Translation strings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants