You are here

function drush_content_synchronizer_create_import in Content Synchronizer 8

Same name and namespace in other branches
  1. 8.2 content_synchronizer.drush.inc \drush_content_synchronizer_create_import()

Create an import entity from a zip file.

Parameters

string $path: The path to the file to import.

File

./content_synchronizer.drush.inc, line 64
Drush commands for content_synchronizer module.

Code

function drush_content_synchronizer_create_import($path) {
  if (file_exists($path)) {
    $extensionData = explode('.', $path);
    if (end($extensionData) == 'zip') {
      if ($file = file_save_data(file_get_contents($path))) {
        $name = strip_tags(t('Drush import - %date', [
          '%date' => \Drupal::service('date.formatter')
            ->format(time()),
        ]));
        $ie = ImportEntity::create([
          'name' => $name,
          ImportEntity::FIELD_ARCHIVE => $file,
        ]);
        $ie
          ->save();
        drush_log(t('The import has been created'), 'status');
      }
    }
    else {
      drush_log(t('The file is not a .zip archive'), 'error');
    }
  }
  else {
    drush_log(t('No file found'), 'error');
  }
}