Commit 43ad83fb authored by APolitsin's avatar APolitsin
Browse files

config import

parent 94b76de8
<?php
namespace Drupal\synhelper\Drush;
use Drush\Commands\DrushCommands;
use Symfony\Component\Yaml\Yaml;
use Drupal\Core\Config\FileStorage;
/**
* A Drush commandfile.
*/
class DrushConfigImport extends DrushCommands {
/**
* Synhrlper config import.
*
* @param string $directory
* Config directory.
*
* @command synhelper:cim
* @aliases scim
* @options arr An option that takes multiple values.
* @usage synhelper:cim /var/www/config
* Import config from /var/www/config.
*/
public function import($directory) {
$this->output()->writeln("Import config from: $directory");
$storage = \Drupal::entityTypeManager()->getStorage('node');
$source = new FileStorage($directory);
\Drupal::service('config.installer')->installOptionalConfig($source);
foreach (scandir($directory) as $file) {
$cfg = substr($file, 0, -4);
if ($cfg) {
$this->output()->writeln("Config: $file");
$data = $source->read($cfg);
if (!is_array($data)) {
$yaml = file_get_contents("$directory/$file");
// $this->output()->writeln("Skip: $yaml");
$data = Yaml::parse($yaml);
}
$config = \Drupal::service('config.factory')->getEditable($cfg);
$config->setData($data)->save();
}
}
}
}
......@@ -6,3 +6,8 @@ services:
synhelper.content_importer:
class: Drupal\synhelper\Service\ContentImporter
arguments: ['@entity_type.manager']
synhelper.drush:
class: \Drupal\synhelper\Drush\DrushConfigImport
tags:
- { name: drush.command }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment