BatchManager.php in Workbench Moderation to Content Moderation 8
File
src/BatchManager.php
View source
<?php
namespace Drupal\wbm2cm;
use Drupal\Core\KeyValueStore\KeyValueFactoryInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
class BatchManager {
protected $isProcessingStopped = FALSE;
protected $manager;
protected $keyValueStore;
protected $logger;
public function __construct(MigrateManager $manager, KeyValueFactoryInterface $key_value_factory, LoggerInterface $logger) {
$this->manager = $manager;
$this->batchStore = $key_value_factory
->get('wbm2cm_batch');
$this->logger = $logger;
}
public function isStepComplete($step) {
if ($this->batchStore
->has($step)) {
return 'complete' == $this->batchStore
->get($step);
}
return FALSE;
}
public function setStepComplete($step) {
$this->batchStore
->set($step, 'complete');
}
public function setStepIncomplete($step) {
$this->batchStore
->set($step, 'incomplete');
}
protected function stopProcessing() {
$this->isProcessingStopped = TRUE;
}
protected function isProcessingStopped() {
return $this->isProcessingStopped;
}
public function isStepSkipped($step) {
if ($this
->isProcessingStopped()) {
$this->logger
->info('Step %step is skipped because: %reason', [
'%step' => $step,
'%reason' => 'Processing is stopped',
]);
return TRUE;
}
if ($this
->isStepComplete($step)) {
$this->logger
->info('Step %step is skipped because: %reason', [
'%step' => $step,
'%reason' => 'Step is complete',
]);
return TRUE;
}
$this->logger
->info('Step %step is NOT skipped', [
'%step' => $step,
]);
return FALSE;
}
public function step1(&$context) {
if ($this
->isStepSkipped('step1')) {
return;
}
$this->manager
->saveWorkbenchModerationStatesAndTransitions();
$this
->setStepComplete('step1');
$context['message'] = 'Saving Workbench Moderation states and transitions to key value storage.';
}
public function step2(&$context) {
if ($this
->isStepSkipped('step2')) {
return;
}
$this->manager
->saveWorkbenchModerationSateMap();
$context['message'] = 'Saving Workbench Moderation entity states to key value storage.';
}
public function step3(&$context) {
if ($this
->isStepSkipped('step3')) {
return;
}
$this->manager
->uninstallWorkbenchModeration();
$this
->setStepComplete('step3');
$context['message'] = 'Uninstalling Workbench Moderation.';
}
public function step4(&$context) {
if ($this
->isStepSkipped('step4')) {
return;
}
$this->manager
->installWorkflows();
$this
->setStepComplete('step4');
$context['message'] = 'Installing Workflows module.';
}
public function step5(&$context) {
if ($this
->isStepSkipped('step5')) {
return;
}
$this->manager
->installContentModeration();
$this
->setStepComplete('step5');
$context['message'] = 'Installing Content Moderation module.';
}
public function step6(&$context) {
if ($this
->isStepSkipped('step6')) {
return;
}
$this->manager
->recreateWorkbenchModerationWorkflow();
$this
->setStepComplete('step6');
$context['message'] = 'Importing states and transitions from key value storage to Workflows.';
}
public function step7(&$context) {
if ($this
->isStepSkipped('step7')) {
return;
}
$this->manager
->recreateModerationStatesOnEntities();
$this
->setStepComplete('step7');
$context['message'] = 'Importing entity moderation states from key value storage to Content Moderation.';
}
public function step8(&$context) {
if ($this
->isStepSkipped('step8')) {
return;
}
$this->manager
->cleanupKeyValue();
$this
->setStepComplete('step8');
$this->manager
->setFinished();
$context['message'] = 'Clean up key value storage.';
}
public function finished($success, $results, $operations) {
if ($success) {
$message = t('Migration complete. You can now uninstall this module.');
}
else {
$message = t('Finished with an error.');
}
drupal_set_message($message);
return new RedirectResponse(\Drupal::url('wbm2cm.overview', [], [
'absolute' => TRUE,
]));
}
public function purgeAllKeyValueStores() {
$this->batchStore
->deleteAll();
}
}
Classes
Name |
Description |
BatchManager |
Manages communication between Batch API and the migration manager. |