Commit 53a2bf5d authored by Stephen Mulvihill's avatar Stephen Mulvihill Committed by Kevin Reynen
Browse files

Issue #3250768 by smulvih2, Willy Christian, kreynen, Matheus Macario,...

Issue #3250768 by smulvih2, Willy Christian, kreynen, Matheus Macario, Guilherme Rabelo, joachim, Rajeshreeputra: PHPCS errors
parent 2c62f65b
Loading
Loading
Loading
Loading
+21 −7
Changes for README.md: 21 added lines, 7 removed lines.
Original line number Diff line number Diff line
# Profile Switcher

This module provides a Drush command to switch between installation profiles found in the `/profiles` directory.
This module provides a Drush command to switch between installation
profiles found in the `/profiles` directory.

## Use Cases

* Moving an existing site to distribution
* Moving from an abandoned distribution back to a standard Drupal core installation profile
* Moving from an abandoned distribution back to a standard
Drupal core installation profile
* Moving from a multi-site installation profile to a new site-specific one.
* etc.

@@ -13,10 +15,20 @@ This module provides a Drush command to switch between installation profiles fou

* Switching profiles is *not* a trivial change like switching a theme.
* *Always* test before using on a live site and *Always* have a backup.
* Switching profiles does *not* run the profile's `.install` file. This will not work for all distributions.
* Modules, themes, and libraries included in a distribution are only available when using the distribution. Modules, themes, and libraries in `sites/all` are available for any profile, *but override profile versions even if the `sites/all` versions are older*.
* Because some modules register absolute paths to files in Drupal's registry table, you may run into issues when switching profiles even if the version of the module is the same. (See [Tips for fixing registry related issues](https://drupal.org/node/1974964)).
* If the Profile Switcher module was included in a `/profile/[profile_name]/modules` directory and you switch to a profile that doesn't include it, you will get a page-not-found error after the switch, and not be able to switch back until adding this module to `sites/all/modules`.
* Switching profiles does *not* run the profile's `.install` file.
This will not work for all distributions.
* Modules, themes, and libraries included in a distribution are only available
when using the distribution.Modules, themes, and libraries in `sites/all` are
available for any profile, *but override profile versions even if the
`sites/all` versions are older*.
* Because some modules register absolute paths to files in Drupal's registry
table, you may run into issues when switching profiles even if the version of
the module is the same.
(See [Tips for fixing registry related issues](https://drupal.org/node/1974964)).
* If the Profile Switcher module was included in a
`/profile/[profile_name]/modules` directory and you switch to a profile that
doesn't include it, you will get a page-not-found error after the switch,
and not be able to switch back until adding this module to `sites/all/modules`.

## Usage

@@ -26,4 +38,6 @@ drush switch:profile NEW_PROFILE_MACHINE_NAME

## References

What is the difference between an Install Profile and a Drupal Distribution/Packaged Distribution?  See [Creating distributions](https://www.drupal.org/docs/8/distributions/creating-distributions) for an explanation.
What is the difference between an Install Profile and a Drupal Distribution?
See [Creating distributions](https://www.drupal.org/docs/8/distributions/creating-distributions)
for an explanation.
+1
Changes for drush.services.yml: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
services:
  profile_switcher.commands:
    class: \Drupal\profile_switcher\Commands\ProfileSwitcherCommands
    arguments: ['@config.factory', '@profile_switcher.profile_switcher']
    tags:
      - { name: drush.command }
+5 −3
Changes for profile_switcher.drush.inc: 5 added lines, 3 removed lines.
Original line number Diff line number Diff line
<?php

/**
 * @file Contains the code for the profile_switcher drush commands.
 * @file
 * Contains the code for the profile_switcher drush commands.
 */

/**
 * Implements hook_drush_command().
 */
function profile_switcher_drush_command() {
  $items = array();
  $items = [];
  $items['switch-profile'] = [
    'description' => 'Switch Drupal profile in a installed site',
    'arguments' => [
@@ -23,7 +25,7 @@ function profile_switcher_drush_command() {
 * Call back function drush_custom_drush_command_().
 *
 * @param string $profile_to_install
 *
 *   The profile to install.
 */
function drush_profile_switcher_switch_profile($profile_to_install = '') {
  $profile_to_remove = \Drupal::installProfile();
+37 −6
Changes for src/Commands/ProfileSwitcherCommands.php: 37 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -2,6 +2,8 @@

namespace Drupal\profile_switcher\Commands;

use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\profile_switcher\ProfileSwitcher;
use Drush\Commands\DrushCommands;
use Drush\Exceptions\UserAbortException;

@@ -11,7 +13,34 @@ use Drush\Exceptions\UserAbortException;
class ProfileSwitcherCommands extends DrushCommands {

  /**
   * Switch Drupal profile in a installed site
   * The config factory service.
   *
   * @var \Drupal\Core\Config\ConfigFactory
   */
  protected $configFactory;

  /**
   * The profile switcher service.
   *
   * @var \Drupal\profile_switcher\ProfileSwitcher
   */
  protected $profileSwitcher;

  /**
   * Constructs a ProfileSwitcherCommands object.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The config factory service.
   * @param \Drupal\profile_switcher\ProfileSwitcher $profile_switcher
   *   The profile switcher service.
   */
  public function __construct(ConfigFactoryInterface $config_factory, ProfileSwitcher $profile_switcher) {
    $this->configFactory = $config_factory;
    $this->profileSwitcher = $profile_switcher;
  }

  /**
   * Switch the Drupal profile of an installed site.
   *
   * @param string $profile_to_install
   *   The profile to activate.
@@ -20,19 +49,21 @@ class ProfileSwitcherCommands extends DrushCommands {
   * @aliases sp,switch-profile
   */
  public function profile($profile_to_install) {
    $profile_to_remove = \Drupal::installProfile();
    $profile_to_remove = $this->configFactory->get('core.extension')->get('profile');

    $this->output()->writeln(dt("The site's install profile will be switched from !profile_to_remove to !profile_to_install.", [
    $this->output()->writeln(
      dt("The site's install profile will be switched from !profile_to_remove to !profile_to_install.", [
        '!profile_to_remove' => $profile_to_remove,
        '!profile_to_install' => $profile_to_install,
    ]));
      ])
    );
    if (!$this->io()->confirm(dt('Do you want to continue?'))) {
      throw new UserAbortException();
    }

    \Drupal::service('profile_switcher.profile_switcher')->switchProfile($profile_to_install);
    $this->profileSwitcher->switchProfile($profile_to_install);

    $this->output()->writeln('Profile changed to: ' . \Drupal::installProfile());
    $this->output()->writeln('Profile changed to: ' . $profile_to_install);
  }

}
+2
Changes for src/ProfileSwitcher.php: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -41,6 +41,8 @@ class ProfileSwitcher {
   *   The configuration factory.
   * @param \Drupal\Core\KeyValueStore\KeyValueFactoryInterface $keyvalue
   *   The Key Value Factory service.
   * @param \Drupal\Core\State\StateInterface $state
   *   The State service.
   */
  public function __construct(
    ConfigFactoryInterface $config_factory,