Skip to content

Commit

Permalink
8.1.1
Browse files Browse the repository at this point in the history
- D8CORE-000: Fix cron job creator (#6)
  • Loading branch information
pookmish authored Jul 13, 2020
2 parents 3148850 + 5e6a3f1 commit 704b5ee
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 22 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Stanford Migrate

8.x-1.1
--------------------------------------------------------------------------------
_Release Date: 2020-07-13_

- D8CORE-000: Fix cron job creator (#6) (01c8767)

8.x-1.0
--------------------------------------------------------------------------------
_Release Date: 2020-06-17_
Expand Down
32 changes: 12 additions & 20 deletions src/Form/StanfordMigrateUltimateCronForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\migrate\Plugin\MigrationPluginManager;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
Expand All @@ -15,13 +14,6 @@
*/
class StanfordMigrateUltimateCronForm extends FormBase {

/**
* Migration plugin manager service.
*
* @var \Drupal\migrate\Plugin\MigrationPluginManager
*/
protected $migrationManager;

/**
* Entity type manager service.
*
Expand All @@ -34,21 +26,17 @@ class StanfordMigrateUltimateCronForm extends FormBase {
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('plugin.manager.migration'),
$container->get('entity_type.manager')
);
}

/**
* StanfordMigrateUltimateCronForm constructor.
*
* @param \Drupal\migrate\Plugin\MigrationPluginManager $migration_manager
* Migration plugin manager service.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* Entity type manager service.
*/
public function __construct(MigrationPluginManager $migration_manager, EntityTypeManagerInterface $entity_type_manager) {
$this->migrationManager = $migration_manager;
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}

Expand All @@ -68,12 +56,16 @@ public function buildForm(array $form, FormStateInterface $form_state) {

$existing_migration_jobs = [];
$missing_migration_jobs = [];
foreach ($this->migrationManager->getDefinitions() as $migration_id => $definition) {
if (in_array("ultimate_cron.job.stanford_migrate_$migration_id", $existing_configs)) {
$existing_migration_jobs[$migration_id] = $definition['label'];

$migration_group_configs = $this->configFactory->listAll('migrate_plus.migration_group.');
foreach ($migration_group_configs as $config_name) {
$group_config = $this->config($config_name);
$migration_group = $group_config->get('id');
if (in_array("ultimate_cron.job.stanford_migrate_$migration_group", $existing_configs)) {
$existing_migration_jobs[$migration_group] = $group_config->get('label');
continue;
}
$missing_migration_jobs[$migration_id] = $definition['label'];
$missing_migration_jobs[$migration_group] = $group_config->get('label');
}
$form_state->set('missing_cron_jobs', $missing_migration_jobs);

Expand Down Expand Up @@ -101,9 +93,9 @@ public function buildForm(array $form, FormStateInterface $form_state) {
* {@inheritDoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
foreach ($form_state->get('missing_cron_jobs') as $migration_id => $label) {
foreach ($form_state->get('missing_cron_jobs') as $group_id => $label) {
$values = [
'id' => "stanford_migrate_$migration_id",
'id' => "stanford_migrate_$group_id",
'title' => 'Importer: ' . $label,
'callback' => 'stanford_migrate_ultimate_cron_task',
'module' => 'stanford_migrate',
Expand All @@ -112,7 +104,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
->create($values)->save();
}
$this->messenger()
->addStatus($this->t('Created cron jobs for the following migration entities: %labels', ['%labels' => implode(',', $form_state->get('missing_cron_jobs'))]));
->addStatus($this->t('Created cron jobs for the following migration entities: %labels', ['%labels' => implode(', ', $form_state->get('missing_cron_jobs'))]));
}

}
2 changes: 1 addition & 1 deletion stanford_migrate.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: 'Adds more functionality to migrate and migrate plus modules'
type: module
core_version_requirement: ^8.8 || ^9
package: 'Stanford'
version: 8.x-1.0
version: 8.x-1.1
dependencies:
- drupal:migrate
- migrate_plus:migrate_plus
Expand Down
4 changes: 4 additions & 0 deletions stanford_migrate.links.task.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
stanford_migrate.ultimate_cron:
title: 'Migrations'
route_name: stanford_migrate.ultimate_cron
base_route: entity.ultimate_cron_job.collection
2 changes: 1 addition & 1 deletion stanford_migrate.routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ stanford_migrate.list:
_custom_access: '\Drupal\stanford_migrate\Form\StanfordMigrateImportForm::access'

stanford_migrate.ultimate_cron:
path: '/admin/config/importers/ultimate-cron'
path: '/admin/config/system/cron/migrate-jobs'
defaults:
_form: '\Drupal\stanford_migrate\Form\StanfordMigrateUltimateCronForm'
_title: 'Importer Cron Jobs'
Expand Down

0 comments on commit 704b5ee

Please sign in to comment.