/**
   * {@inheritdoc}
   */
  public function prepare(array &$packages = array(), FeaturesBundleInterface $bundle = NULL) {
    // If no packages were specified, get all packages.
    if (empty($packages)) {
      $packages = $this->featuresManager->getPackages();
    }

    // If any packages exist, read in their files.
    $existing_packages = $this->featuresManager->listPackageDirectories(array_keys($packages), $bundle);

    foreach ($packages as &$package) {
      list($full_name, $path) = $this->featuresManager->getExportInfo($package, $bundle);
      $package['directory'] = $path . '/' . $full_name;
      $this->preparePackage($package, $existing_packages, $bundle);
    }
    // Clean up the $package pass by reference.
    unset($package);

    if (isset($bundle) && $bundle->isProfile()) {
      $profile_name = $bundle->getProfileName();
      $profile_package = $this->featuresManager->getPackage($profile_name);
      if (isset($profile_package)) {
        $package['directory'] = 'profiles/' . $profile_name;
        $this->preparePackage($profile_package, $existing_packages, $bundle);
      }
    }
  }
 /**
  * {@inheritdoc}
  */
 public function prepare(array &$packages = array(), FeaturesBundleInterface $bundle = NULL)
 {
     // If no packages were specified, get all packages.
     if (empty($packages)) {
         $packages = $this->featuresManager->getPackages();
     }
     // If any packages exist, read in their files.
     $existing_packages = $this->featuresManager->listPackageDirectories(array_keys($packages), $bundle);
     foreach ($packages as &$package) {
         list($full_name, $path) = $this->featuresManager->getExportInfo($package, $bundle);
         if (empty($package->getDirectory())) {
             $package->setDirectory($path);
         }
         // If this is the profile, its directory is already assigned.
         if (!isset($bundle) || !$bundle->isProfilePackage($package->getMachineName())) {
             $current_path = $package->getDirectory();
             if (strpos($current_path, $full_name) < strlen($current_path) - strlen($full_name)) {
                 // Only append package name if it isn't already there.
                 $package->setDirectory($package->getDirectory() . '/' . $full_name);
             }
         }
         $this->preparePackage($package, $existing_packages, $bundle);
     }
     // Clean up the $package pass by reference.
     unset($package);
 }
 /**
  * @covers ::getPackage
  * @covers ::getPackages
  * @covers ::reset
  * @covers ::setPackages
  */
 public function testPackages() {
   $packages = ['foo' => 'bar'];
   $this->featuresManager->setPackages($packages);
   $this->assertEquals($packages, $this->featuresManager->getPackages());
   $this->assertEquals('bar', $this->featuresManager->getPackage('foo'));
   $this->featuresManager->reset();
   $this->assertArrayEquals([], $this->featuresManager->getPackages());
   $this->assertNull($this->featuresManager->getPackage('foo'));
 }
 /**
  * Returns the configuration dependent on given items.
  *
  * @param array $item_names
  *   An array of item names.
  *
  * @return array
  *   An array of config items.
  */
 protected function getConfigDependents(array $item_names = NULL)
 {
     $result = [];
     $config_collection = $this->featuresManager->getConfigCollection();
     $packages = $this->featuresManager->getPackages();
     $settings = $this->featuresManager->getSettings();
     $allow_conflicts = $settings->get('conflicts');
     if (empty($item_names)) {
         $item_names = array_keys($config_collection);
     }
     foreach ($item_names as $item_name) {
         if ($config_collection[$item_name]->getPackage()) {
             foreach ($config_collection[$item_name]->getDependents() as $dependent_item_name) {
                 if (isset($config_collection[$dependent_item_name])) {
                     $allow = TRUE;
                     if (!$allow_conflicts && $config_collection[$dependent_item_name]->getPackage()) {
                         if ($packages[$config_collection[$dependent_item_name]->getPackage()]) {
                             $allow = $packages[$config_collection[$dependent_item_name]->getPackage()]->getStatus() == FeaturesManagerInterface::STATUS_NO_EXPORT || $config_collection[$item_name]->getPackage() == $config_collection[$dependent_item_name]->getPackage();
                         }
                     }
                     if ($allow) {
                         $result[] = $dependent_item_name;
                     }
                 }
             }
         }
     }
     return $result;
 }
 /**
  * Clean up the package list after all config has been assigned
  */
 protected function cleanup()
 {
     $packages = $this->featuresManager->getPackages();
     foreach ($packages as $index => $package) {
         if ($package->getStatus() === FeaturesManagerInterface::STATUS_NO_EXPORT && empty($package->getConfig()) && empty($package->getConfigOrig())) {
             unset($packages[$index]);
         }
     }
     $this->featuresManager->setPackages($packages);
 }
 /**
  * {@inheritdoc}
  */
 public function prepare(array &$packages = array(), FeaturesBundleInterface $bundle = NULL)
 {
     // If no packages were specified, get all packages.
     if (empty($packages)) {
         $packages = $this->featuresManager->getPackages();
     }
     // If any packages exist, read in their files.
     $existing_packages = $this->featuresManager->listPackageDirectories(array_keys($packages), $bundle);
     foreach ($packages as &$package) {
         list($full_name, $path) = $this->featuresManager->getExportInfo($package, $bundle);
         $package['directory'] = $path;
         // If this is the profile, its directory is already assigned.
         if (!isset($bundle) || !$bundle->isProfilePackage($package['machine_name'])) {
             $package['directory'] .= '/' . $full_name;
         }
         $this->preparePackage($package, $existing_packages, $bundle);
     }
     // Clean up the $package pass by reference.
     unset($package);
 }
Exemple #7
0
 /**
  * @covers ::reset
  */
 public function testReset()
 {
     $packages = ['package' => ['machine_name' => 'package', 'config' => ['example.config', 'example.config3'], 'dependencies' => [], 'bundle' => 'giraffe'], 'package2' => ['machine_name' => 'package2', 'config' => ['example.config2'], 'dependencies' => [], 'bundle' => 'giraffe']];
     $this->featuresManager->setPackages($packages);
     $config_item = new ConfigurationItem('example', [], ['package' => 'package']);
     $config_item2 = new ConfigurationItem('example2', [], ['package' => 'package2']);
     $this->featuresManager->setConfigCollection([$config_item, $config_item2]);
     $this->featuresManager->reset();
     $this->assertEmpty($this->featuresManager->getPackages());
     $config_collection = $this->featuresManager->getConfigCollection();
     $this->assertEquals('', $config_collection[0]->getPackage());
     $this->assertEquals('', $config_collection[1]->getPackage());
 }
 /**
  * Generates a file representation of configuration packages and, optionally,
  * an install profile.
  *
  * @param string $method_id
  *   The ID of the generation method to use.
  * @param string[] $package_names
  *   Names of packages to be generated. If none are specified, all
  *   available packages will be added.
  * @param \Drupal\features\FeaturesBundleInterface $bundle
  *   The optional bundle used for the generation.  Used to generate profiles.
  *
  * @return array
  *   Array of results for profile and/or packages, each result including the
  *   following keys:
  *   - 'success': boolean TRUE or FALSE for successful writing.
  *   - 'display': boolean TRUE if the message should be displayed to the
  *     user, otherwise FALSE.
  *   - 'message': a message about the result of the operation.
  *   - 'variables': an array of substitutions to be used in the message.
  */
 protected function generate($method_id, array $package_names = array(), FeaturesBundleInterface $bundle = NULL)
 {
     // Prepare the files.
     $this->featuresManager->prepareFiles();
     $packages = $this->featuresManager->getPackages();
     // Filter out the packages that weren't requested.
     if (!empty($package_names)) {
         $packages = array_intersect_key($packages, array_fill_keys($package_names, NULL));
     }
     $return = $this->applyGenerationMethod($method_id, $packages, $bundle);
     foreach ($return as $message) {
         if ($message['display']) {
             $type = $message['success'] ? 'status' : 'error';
             drupal_set_message($this->t($message['message'], $message['variables']), $type);
         }
         $type = $message['success'] ? 'notice' : 'error';
         \Drupal::logger('features')->{$type}($message['message'], $message['variables']);
     }
     return $return;
 }
 /**
  * Returns the configuration dependent on given items.
  *
  * @param array $item_names
  *   An array of item names.
  * @param string $package_name
  *   Short machine name of feature to process.
  *
  * @return array
  *   An array of config items.
  */
 protected function getConfigDependents(array $item_names, $package_name)
 {
     $result = [];
     $config_collection = $this->featuresManager->getConfigCollection();
     $packages = $this->featuresManager->getPackages();
     $settings = $this->featuresManager->getSettings();
     $allow_conflicts = $settings->get('conflicts');
     if (empty($item_names)) {
         $item_names = array_keys($config_collection);
     }
     // Add any existing auto-detected items already in the package config
     $this->package = $packages[$package_name];
     $package_config = isset($this->package) ? $this->package->getConfig() : array();
     $package_config = !empty($package_config) ? array_unique(array_merge($package_config, $item_names)) : $item_names;
     foreach ($package_config as $config_name) {
         if (!$config_collection[$config_name]->getPackageExcluded()) {
             $result[] = $config_name;
         }
     }
     // Now add dependents of the items selected
     foreach ($item_names as $item_name) {
         if ($config_collection[$item_name]->getPackage()) {
             foreach ($config_collection[$item_name]->getDependents() as $dependent_item_name) {
                 if (isset($config_collection[$dependent_item_name])) {
                     $allow = TRUE;
                     if (!$allow_conflicts && $config_collection[$dependent_item_name]->getPackage()) {
                         if ($packages[$config_collection[$dependent_item_name]->getPackage()]) {
                             $allow = $packages[$config_collection[$dependent_item_name]->getPackage()]->getStatus() == FeaturesManagerInterface::STATUS_NO_EXPORT || $config_collection[$item_name]->getPackage() == $config_collection[$dependent_item_name]->getPackage();
                         }
                     }
                     if ($allow) {
                         $result[] = $dependent_item_name;
                     }
                 }
             }
         }
     }
     return $result;
 }