diff --git a/drush.services.yml b/drush.services.yml deleted file mode 100644 index 6cfe7ab..0000000 --- a/drush.services.yml +++ /dev/null @@ -1,6 +0,0 @@ -services: - path_redirect_import.commands: - class: \Drupal\path_redirect_import\Drush\Commands\PathRedirectImportCommands - arguments: [ '@plugin.manager.migration', '@date.formatter', '@entity_type.manager', '@keyvalue', '@file_system', '@path_redirect_import.redirect_export' ] - tags: - - { name: drush.command } diff --git a/src/Drush/Commands/PathRedirectImportCommands.php b/src/Drush/Commands/PathRedirectImportCommands.php deleted file mode 100644 index 47d9c6c..0000000 --- a/src/Drush/Commands/PathRedirectImportCommands.php +++ /dev/null @@ -1,152 +0,0 @@ -fileSystem = $fileSystem; - $this->redirectExport = $redirectExport; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container): MigrateToolsCommands { - return new static( - $container->get('plugin.manager.migration'), - $container->get('date.formatter'), - $container->get('entity_type.manager'), - $container->get('keyvalue'), - $container->get('file_system'), - $container->get('path_redirect_import.redirect_export'), - ); - } - - /** - * Imports the redirects defined in the CSV file passed as argument. - * - * @param string $file - * The CSV file to import. - * - * @command path_redirect_import:import - * @aliases prii - */ - #[CLI\Command(name: 'path_redirect_import:import', aliases: ['prii'])] - #[CLI\Argument(name: 'file', description: 'The CSV file to import.')] - #[CLI\Topics(topics: ['path_redirect_import'])] - #[CLI\ValidateModulesEnabled(modules: ['migrate_tools'])] - public function importRedirects($file) { - if (!file_exists($file)) { - $this->logger()->error("File $file doesn't exist \n"); - exit; - } - - $directory = dirname(MigrateRedirectForm::MIGRATE_FILE_PATH); - $this->fileSystem->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS); - $this->fileSystem->copy($file, MigrateRedirectForm::MIGRATE_FILE_PATH, FileSystemInterface::EXISTS_REPLACE); - - $this->resetStatus('path_redirect_import'); - - $this->import('path_redirect_import', [ - 'limit' => 0, - 'update' => TRUE, - 'force' => FALSE, - 'all' => FALSE, - 'group' => NULL, - 'tag' => NULL, - 'execute-dependencies' => FALSE, - 'sync' => FALSE, - 'skip-progress-bar' => FALSE, - 'continue-on-failure' => FALSE, - 'idlist' => NULL, - ]); - - $this->logger()->success($this->t('Redirects imported.')); - } - - /** - * Exports the redirects. - * - * @command path_redirect_import:export - * @aliases prie - */ - #[CLI\Command(name: 'path_redirect_import:export', aliases: ['prie'])] - #[CLI\Topics(topics: ['path_redirect_import'])] - #[CLI\ValidateModulesEnabled(modules: ['migrate_tools'])] - public function exportRedirects() { - $operations = $this->redirectExport->getBatchOperations(); - - $batchBuilder = new BatchBuilder(); - array_walk($operations, fn($operation) => $batchBuilder->addOperation($operation[0], $operation[1])); - - $batchBuilder - ->setTitle($this->t('Exporting redirect entities to file')) - ->setFinishCallback(RedirectExport::class . '::batchFinishedExport') - ->setErrorMessage($this->t('An error occurred while exporting redirect entities.')); - // 5. Add batch operations as new batch sets. - batch_set($batchBuilder->toArray()); - // 6. Process the batch sets. - drush_backend_batch_process(); - } - -}