Created
April 20, 2017 14:12
-
-
Save weitzman/9b2f395e6bd9f266e9f9c2df1c8f287b to your computer and use it in GitHub Desktop.
Determine if a migration is running
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Drupal\ras_comments; | |
use Drupal\migrate\Event\MigrateEvents; | |
use Drupal\migrate\Event\MigrateImportEvent; | |
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | |
/** | |
* Class CommentEventSubscriber. | |
* | |
* Sets a temporary variable to identify that this process is a migration | |
* process. Used during the comment mail hook to disable emails. | |
* | |
* @package Drupal\ras_comments | |
*/ | |
class CommentEventSubscriber implements EventSubscriberInterface { | |
const DISABLE_VARIABLE = 'ras_comments_email_disable'; | |
/** | |
* The drupal_static cache. | |
* | |
* @var array | |
*/ | |
protected $staticCache; | |
/** | |
* CommentEventSubscriber constructor. | |
*/ | |
public function __construct() { | |
$this->staticCache = &drupal_static(self::DISABLE_VARIABLE); | |
} | |
/** | |
* Get subscribed events. | |
* | |
* @inheritdoc | |
*/ | |
public static function getSubscribedEvents() { | |
return [ | |
MigrateEvents::PRE_IMPORT => 'onMigratePreImport', | |
MigrateEvents::POST_IMPORT => 'onMigratePostImport', | |
]; | |
} | |
/** | |
* Listener onMigratePreImport. | |
* | |
* Set the blocking variable. | |
* | |
* @param \Drupal\migrate\Event\MigrateImportEvent $importEvent | |
* The import event object. | |
*/ | |
public function onMigratePreImport(MigrateImportEvent $importEvent) { | |
if ($importEvent->getMigration()->getBaseId() == 'typo3_comment') { | |
$this->staticCache = TRUE; | |
} | |
} | |
/** | |
* Listener onMigratePostSave. | |
* | |
* Set the blocking variable to FALSE, in case anything else needs to create | |
* a comment in this process. | |
* | |
* @param \Drupal\migrate\Event\MigrateImportEvent $importEvent | |
* The import event object. | |
*/ | |
public function onMigratePostImport(MigrateImportEvent $importEvent) { | |
if ($importEvent->getMigration()->getBaseId() == 'typo3_comment') { | |
$this->staticCache = FALSE; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment