Loading core/modules/migrate/src/MigrateExecutable.php +0 −286 Original line number Diff line number Diff line Loading @@ -31,20 +31,6 @@ class MigrateExecutable implements MigrateExecutableInterface { */ protected $migration; /** * The number of successfully imported rows since feedback was given. * * @var int */ protected $successesSinceFeedback; /** * The number of rows that were successfully processed. * * @var int */ protected $totalSuccesses; /** * Status of one row. * Loading @@ -55,15 +41,6 @@ class MigrateExecutable implements MigrateExecutableInterface { */ protected $sourceRowStatus; /** * The number of rows processed. * * The total attempted, whether or not they were successful. * * @var int */ protected $totalProcessed; /** * The queued messages not yet saved. * Loading @@ -75,44 +52,6 @@ class MigrateExecutable implements MigrateExecutableInterface { */ protected $queuedMessages = array(); /** * The options that can be set when executing the migration. * * Values can be set for: * - 'limit': Sets a time limit. * * @var array */ protected $options; /** * The PHP max_execution_time. * * @var int */ protected $maxExecTime; /** * The ratio of the memory limit at which an operation will be interrupted. * * @var float */ protected $memoryThreshold = 0.85; /** * The ratio of the time limit at which an operation will be interrupted. * * @var float */ public $timeThreshold = 0.90; /** * The time limit when executing the migration. * * @var array */ public $limit = array(); /** * The configuration values of the source. * Loading @@ -120,20 +59,6 @@ class MigrateExecutable implements MigrateExecutableInterface { */ protected $sourceIdValues; /** * The number of rows processed since feedback was given. * * @var int */ protected $processedSinceFeedback = 0; /** * The PHP memory_limit expressed in bytes. * * @var int */ protected $memoryLimit; /** * The rollback action to be saved for the current row. * Loading Loading @@ -202,31 +127,6 @@ public function __construct(MigrationInterface $migration, MigrateMessageInterfa $this->message = $message; $this->migration->getIdMap()->setMessage($message); $this->eventDispatcher = $event_dispatcher; // Record the memory limit in bytes $limit = trim(ini_get('memory_limit')); if ($limit == '-1') { $this->memoryLimit = PHP_INT_MAX; } else { if (!is_numeric($limit)) { $last = strtolower(substr($limit, -1)); switch ($last) { case 'g': $limit *= 1024; case 'm': $limit *= 1024; case 'k': $limit *= 1024; break; default: throw new MigrateException($this->t('Invalid PHP memory_limit !limit', array('!limit' => $limit))); } } $this->memoryLimit = $limit; } // Record the maximum execution time limit. $this->maxExecTime = ini_get('max_execution_time'); } /** Loading Loading @@ -321,8 +221,6 @@ public function import() { if ($destination_id_values !== TRUE) { $id_map->saveIdMapping($row, $destination_id_values, $this->sourceRowStatus, $this->rollbackAction); } $this->successesSinceFeedback++; $this->totalSuccesses++; } else { $id_map->saveIdMapping($row, array(), MigrateIdMapInterface::STATUS_FAILED, $this->rollbackAction); Loading @@ -343,8 +241,6 @@ public function import() { $this->handleException($e); } } $this->totalProcessed++; $this->processedSinceFeedback++; if ($high_water_property = $this->migration->get('highWaterProperty')) { $this->migration->saveHighWater($row->getSourceProperty($high_water_property['name'])); } Loading @@ -353,12 +249,6 @@ public function import() { unset($sourceValues, $destinationValues); $this->sourceRowStatus = MigrateIdMapInterface::STATUS_IMPORTED; if (($return = $this->checkStatus()) != MigrationInterface::RESULT_COMPLETED) { break; } if ($this->timeOptionExceeded()) { break; } try { $source->next(); } Loading @@ -370,11 +260,6 @@ public function import() { } } /** * @TODO uncomment this */ #$this->progressMessage($return); $this->migration->setMigrationResult($return); $this->getEventDispatcher()->dispatch(MigrateEvents::POST_IMPORT, new MigrateImportEvent($this->migration)); return $return; Loading Loading @@ -441,40 +326,6 @@ protected function currentSourceIds() { return $this->getSource()->getCurrentIds(); } /** * Tests whether we've exceeded the designated time limit. * * @return bool * TRUE if the threshold is exceeded, FALSE if not. */ protected function timeOptionExceeded() { // If there is no time limit, then it is not exceeded. if (!$time_limit = $this->getTimeLimit()) { return FALSE; } // Calculate if the time limit is exceeded. $time_elapsed = $this->getTimeElapsed(); if ($time_elapsed >= $time_limit) { return TRUE; } else { return FALSE; } } /** * {@inheritdoc} */ public function getTimeLimit() { $limit = $this->limit; if (isset($limit['unit']) && isset($limit['value']) && ($limit['unit'] == 'seconds' || $limit['unit'] == 'second')) { return $limit['value']; } else { return NULL; } } /** * {@inheritdoc} */ Loading @@ -499,143 +350,6 @@ public function saveQueuedMessages() { $this->queuedMessages = array(); } /** * Checks for exceptional conditions, and display feedback. * * Standard top-of-loop stuff, common between rollback and import. */ protected function checkStatus() { if ($this->memoryExceeded()) { return MigrationInterface::RESULT_INCOMPLETE; } if ($this->maxExecTimeExceeded()) { return MigrationInterface::RESULT_INCOMPLETE; } /* * @TODO uncomment this if ($this->getStatus() == MigrationInterface::STATUS_STOPPING) { return MigrationBase::RESULT_STOPPED; } */ // If feedback is requested, produce a progress message at the proper time /* * @TODO uncomment this if (isset($this->feedback)) { if (($this->feedback_unit == 'seconds' && time() - $this->lastfeedback >= $this->feedback) || ($this->feedback_unit == 'items' && $this->processed_since_feedback >= $this->feedback)) { $this->progressMessage(MigrationInterface::RESULT_INCOMPLETE); } } */ return MigrationInterface::RESULT_COMPLETED; } /** * Tests whether we've exceeded the desired memory threshold. * * If so, output a message. * * @return bool * TRUE if the threshold is exceeded, otherwise FALSE. */ protected function memoryExceeded() { $usage = $this->getMemoryUsage(); $pct_memory = $usage / $this->memoryLimit; if (!$threshold = $this->memoryThreshold) { return FALSE; } if ($pct_memory > $threshold) { $this->message->display( $this->t('Memory usage is !usage (!pct% of limit !limit), reclaiming memory.', array('!pct' => round($pct_memory*100), '!usage' => $this->formatSize($usage), '!limit' => $this->formatSize($this->memoryLimit))), 'warning'); $usage = $this->attemptMemoryReclaim(); $pct_memory = $usage / $this->memoryLimit; // Use a lower threshold - we don't want to be in a situation where we keep // coming back here and trimming a tiny amount if ($pct_memory > (0.90 * $threshold)) { $this->message->display( $this->t('Memory usage is now !usage (!pct% of limit !limit), not enough reclaimed, starting new batch', array('!pct' => round($pct_memory*100), '!usage' => $this->formatSize($usage), '!limit' => $this->formatSize($this->memoryLimit))), 'warning'); return TRUE; } else { $this->message->display( $this->t('Memory usage is now !usage (!pct% of limit !limit), reclaimed enough, continuing', array('!pct' => round($pct_memory*100), '!usage' => $this->formatSize($usage), '!limit' => $this->formatSize($this->memoryLimit))), 'warning'); return FALSE; } } else { return FALSE; } } /** * Returns the memory usage so far. * * @return int * The memory usage. */ protected function getMemoryUsage() { return memory_get_usage(); } /** * Tries to reclaim memory. * * @return int * The memory usage after reclaim. */ protected function attemptMemoryReclaim() { // First, try resetting Drupal's static storage - this frequently releases // plenty of memory to continue. drupal_static_reset(); // @TODO: explore resetting the container. return memory_get_usage(); } /** * Generates a string representation for the given byte count. * * @param int $size * A size in bytes. * * @return string * A translated string representation of the size. */ protected function formatSize($size) { return format_size($size); } /** * Tests whether we're approaching the PHP maximum execution time limit. * * @return bool * TRUE if the threshold is exceeded, FALSE if not. */ protected function maxExecTimeExceeded() { return $this->maxExecTime && (($this->getTimeElapsed() / $this->maxExecTime) > $this->timeThreshold); } /** * Returns the time elapsed. * * This allows a test to set a fake elapsed time. */ protected function getTimeElapsed() { return time() - REQUEST_TIME; } /** * Takes an Exception object and both saves and displays it. * Loading core/modules/migrate/src/MigrateExecutableInterface.php +0 −8 Original line number Diff line number Diff line Loading @@ -36,14 +36,6 @@ public function import(); */ public function processRow(Row $row, array $process = NULL, $value = NULL); /** * Returns the time limit. * * @return null|int * The time limit, NULL if no limit or if the units were not in seconds. */ public function getTimeLimit(); /** * Passes messages through to the map class. * Loading core/modules/migrate/src/Plugin/MigrateDestinationInterface.php +0 −27 Original line number Diff line number Diff line Loading @@ -55,33 +55,6 @@ public function getIds(); */ public function fields(MigrationInterface $migration = NULL); /** * Allows pre-processing of an import. * * Derived classes may implement preImport() to do any processing they need * done before over all source rows. */ public function preImport(); /** * Allows pre-processing of a rollback. */ public function preRollback(); /** * Allows post-processing of an import. * * Derived classes may implement postImport(), to do any processing they need * done after looping over all source rows. */ public function postImport(); /** * Allows post-processing of a rollback. */ public function postRollback(); /** * Import the row. * Loading core/modules/migrate/src/Plugin/migrate/destination/DestinationBase.php +0 −49 Original line number Diff line number Diff line Loading @@ -59,34 +59,6 @@ public function checkRequirements() { } } /** * Modify the Row before it is imported. */ public function preImport() { // By default we do nothing. } /** * Modify the Row before it is rolled back. */ public function preRollback() { // By default we do nothing. } /** * {@inheritdoc} */ public function postImport() { // By default we do nothing. } /** * {@inheritdoc} */ public function postRollback() { // By default we do nothing. } /** * {@inheritdoc} */ Loading @@ -94,25 +66,4 @@ public function rollbackMultiple(array $destination_identifiers) { // By default we do nothing. } /** * {@inheritdoc} */ public function getCreated() { // TODO: Implement getCreated() method. } /** * {@inheritdoc} */ public function getUpdated() { // TODO: Implement getUpdated() method. } /** * {@inheritdoc} */ public function resetStats() { // TODO: Implement resetStats() method. } } core/modules/migrate/src/Plugin/migrate/source/SourcePluginBase.php +0 −39 Original line number Diff line number Diff line Loading @@ -59,20 +59,6 @@ abstract class SourcePluginBase extends PluginBase implements MigrateSourceInter */ protected $currentSourceIds; /** * Number of rows intentionally ignored (prepareRow() returned FALSE) * * @var int */ protected $numIgnored = 0; /** * Number of rows we've at least looked at. * * @var int */ protected $numProcessed = 0; /** * The high water mark at the beginning of the import operation. * Loading Loading @@ -214,7 +200,6 @@ public function prepareRow(Row $row) { $id_map->delete($this->currentSourceIds, TRUE); $this->migrateExecutable->saveQueuedMessages(); $id_map->saveIdMapping($row, array(), MigrateIdMapInterface::STATUS_IGNORED, $this->migrateExecutable->rollbackAction); $this->numIgnored++; $this->currentRow = NULL; $this->currentSourceIds = NULL; $result = FALSE; Loading @@ -226,7 +211,6 @@ public function prepareRow(Row $row) { // after hashes). $row->rehash(); } $this->numProcessed++; return $result; } Loading Loading @@ -280,8 +264,6 @@ public function valid() { */ public function rewind() { $this->idMap = $this->migration->getIdMap(); $this->numProcessed = 0; $this->numIgnored = 0; $this->getIterator()->rewind(); $this->next(); } Loading Loading @@ -377,27 +359,6 @@ public function getCurrentIds() { return $this->currentSourceIds; } /** * Getter for numIgnored data member. */ public function getIgnored() { return $this->numIgnored; } /** * Getter for numProcessed data member. */ public function getProcessed() { return $this->numProcessed; } /** * Reset numIgnored back to 0. */ public function resetStats() { $this->numIgnored = 0; } /** * Get the source count. * Loading Loading
core/modules/migrate/src/MigrateExecutable.php +0 −286 Original line number Diff line number Diff line Loading @@ -31,20 +31,6 @@ class MigrateExecutable implements MigrateExecutableInterface { */ protected $migration; /** * The number of successfully imported rows since feedback was given. * * @var int */ protected $successesSinceFeedback; /** * The number of rows that were successfully processed. * * @var int */ protected $totalSuccesses; /** * Status of one row. * Loading @@ -55,15 +41,6 @@ class MigrateExecutable implements MigrateExecutableInterface { */ protected $sourceRowStatus; /** * The number of rows processed. * * The total attempted, whether or not they were successful. * * @var int */ protected $totalProcessed; /** * The queued messages not yet saved. * Loading @@ -75,44 +52,6 @@ class MigrateExecutable implements MigrateExecutableInterface { */ protected $queuedMessages = array(); /** * The options that can be set when executing the migration. * * Values can be set for: * - 'limit': Sets a time limit. * * @var array */ protected $options; /** * The PHP max_execution_time. * * @var int */ protected $maxExecTime; /** * The ratio of the memory limit at which an operation will be interrupted. * * @var float */ protected $memoryThreshold = 0.85; /** * The ratio of the time limit at which an operation will be interrupted. * * @var float */ public $timeThreshold = 0.90; /** * The time limit when executing the migration. * * @var array */ public $limit = array(); /** * The configuration values of the source. * Loading @@ -120,20 +59,6 @@ class MigrateExecutable implements MigrateExecutableInterface { */ protected $sourceIdValues; /** * The number of rows processed since feedback was given. * * @var int */ protected $processedSinceFeedback = 0; /** * The PHP memory_limit expressed in bytes. * * @var int */ protected $memoryLimit; /** * The rollback action to be saved for the current row. * Loading Loading @@ -202,31 +127,6 @@ public function __construct(MigrationInterface $migration, MigrateMessageInterfa $this->message = $message; $this->migration->getIdMap()->setMessage($message); $this->eventDispatcher = $event_dispatcher; // Record the memory limit in bytes $limit = trim(ini_get('memory_limit')); if ($limit == '-1') { $this->memoryLimit = PHP_INT_MAX; } else { if (!is_numeric($limit)) { $last = strtolower(substr($limit, -1)); switch ($last) { case 'g': $limit *= 1024; case 'm': $limit *= 1024; case 'k': $limit *= 1024; break; default: throw new MigrateException($this->t('Invalid PHP memory_limit !limit', array('!limit' => $limit))); } } $this->memoryLimit = $limit; } // Record the maximum execution time limit. $this->maxExecTime = ini_get('max_execution_time'); } /** Loading Loading @@ -321,8 +221,6 @@ public function import() { if ($destination_id_values !== TRUE) { $id_map->saveIdMapping($row, $destination_id_values, $this->sourceRowStatus, $this->rollbackAction); } $this->successesSinceFeedback++; $this->totalSuccesses++; } else { $id_map->saveIdMapping($row, array(), MigrateIdMapInterface::STATUS_FAILED, $this->rollbackAction); Loading @@ -343,8 +241,6 @@ public function import() { $this->handleException($e); } } $this->totalProcessed++; $this->processedSinceFeedback++; if ($high_water_property = $this->migration->get('highWaterProperty')) { $this->migration->saveHighWater($row->getSourceProperty($high_water_property['name'])); } Loading @@ -353,12 +249,6 @@ public function import() { unset($sourceValues, $destinationValues); $this->sourceRowStatus = MigrateIdMapInterface::STATUS_IMPORTED; if (($return = $this->checkStatus()) != MigrationInterface::RESULT_COMPLETED) { break; } if ($this->timeOptionExceeded()) { break; } try { $source->next(); } Loading @@ -370,11 +260,6 @@ public function import() { } } /** * @TODO uncomment this */ #$this->progressMessage($return); $this->migration->setMigrationResult($return); $this->getEventDispatcher()->dispatch(MigrateEvents::POST_IMPORT, new MigrateImportEvent($this->migration)); return $return; Loading Loading @@ -441,40 +326,6 @@ protected function currentSourceIds() { return $this->getSource()->getCurrentIds(); } /** * Tests whether we've exceeded the designated time limit. * * @return bool * TRUE if the threshold is exceeded, FALSE if not. */ protected function timeOptionExceeded() { // If there is no time limit, then it is not exceeded. if (!$time_limit = $this->getTimeLimit()) { return FALSE; } // Calculate if the time limit is exceeded. $time_elapsed = $this->getTimeElapsed(); if ($time_elapsed >= $time_limit) { return TRUE; } else { return FALSE; } } /** * {@inheritdoc} */ public function getTimeLimit() { $limit = $this->limit; if (isset($limit['unit']) && isset($limit['value']) && ($limit['unit'] == 'seconds' || $limit['unit'] == 'second')) { return $limit['value']; } else { return NULL; } } /** * {@inheritdoc} */ Loading @@ -499,143 +350,6 @@ public function saveQueuedMessages() { $this->queuedMessages = array(); } /** * Checks for exceptional conditions, and display feedback. * * Standard top-of-loop stuff, common between rollback and import. */ protected function checkStatus() { if ($this->memoryExceeded()) { return MigrationInterface::RESULT_INCOMPLETE; } if ($this->maxExecTimeExceeded()) { return MigrationInterface::RESULT_INCOMPLETE; } /* * @TODO uncomment this if ($this->getStatus() == MigrationInterface::STATUS_STOPPING) { return MigrationBase::RESULT_STOPPED; } */ // If feedback is requested, produce a progress message at the proper time /* * @TODO uncomment this if (isset($this->feedback)) { if (($this->feedback_unit == 'seconds' && time() - $this->lastfeedback >= $this->feedback) || ($this->feedback_unit == 'items' && $this->processed_since_feedback >= $this->feedback)) { $this->progressMessage(MigrationInterface::RESULT_INCOMPLETE); } } */ return MigrationInterface::RESULT_COMPLETED; } /** * Tests whether we've exceeded the desired memory threshold. * * If so, output a message. * * @return bool * TRUE if the threshold is exceeded, otherwise FALSE. */ protected function memoryExceeded() { $usage = $this->getMemoryUsage(); $pct_memory = $usage / $this->memoryLimit; if (!$threshold = $this->memoryThreshold) { return FALSE; } if ($pct_memory > $threshold) { $this->message->display( $this->t('Memory usage is !usage (!pct% of limit !limit), reclaiming memory.', array('!pct' => round($pct_memory*100), '!usage' => $this->formatSize($usage), '!limit' => $this->formatSize($this->memoryLimit))), 'warning'); $usage = $this->attemptMemoryReclaim(); $pct_memory = $usage / $this->memoryLimit; // Use a lower threshold - we don't want to be in a situation where we keep // coming back here and trimming a tiny amount if ($pct_memory > (0.90 * $threshold)) { $this->message->display( $this->t('Memory usage is now !usage (!pct% of limit !limit), not enough reclaimed, starting new batch', array('!pct' => round($pct_memory*100), '!usage' => $this->formatSize($usage), '!limit' => $this->formatSize($this->memoryLimit))), 'warning'); return TRUE; } else { $this->message->display( $this->t('Memory usage is now !usage (!pct% of limit !limit), reclaimed enough, continuing', array('!pct' => round($pct_memory*100), '!usage' => $this->formatSize($usage), '!limit' => $this->formatSize($this->memoryLimit))), 'warning'); return FALSE; } } else { return FALSE; } } /** * Returns the memory usage so far. * * @return int * The memory usage. */ protected function getMemoryUsage() { return memory_get_usage(); } /** * Tries to reclaim memory. * * @return int * The memory usage after reclaim. */ protected function attemptMemoryReclaim() { // First, try resetting Drupal's static storage - this frequently releases // plenty of memory to continue. drupal_static_reset(); // @TODO: explore resetting the container. return memory_get_usage(); } /** * Generates a string representation for the given byte count. * * @param int $size * A size in bytes. * * @return string * A translated string representation of the size. */ protected function formatSize($size) { return format_size($size); } /** * Tests whether we're approaching the PHP maximum execution time limit. * * @return bool * TRUE if the threshold is exceeded, FALSE if not. */ protected function maxExecTimeExceeded() { return $this->maxExecTime && (($this->getTimeElapsed() / $this->maxExecTime) > $this->timeThreshold); } /** * Returns the time elapsed. * * This allows a test to set a fake elapsed time. */ protected function getTimeElapsed() { return time() - REQUEST_TIME; } /** * Takes an Exception object and both saves and displays it. * Loading
core/modules/migrate/src/MigrateExecutableInterface.php +0 −8 Original line number Diff line number Diff line Loading @@ -36,14 +36,6 @@ public function import(); */ public function processRow(Row $row, array $process = NULL, $value = NULL); /** * Returns the time limit. * * @return null|int * The time limit, NULL if no limit or if the units were not in seconds. */ public function getTimeLimit(); /** * Passes messages through to the map class. * Loading
core/modules/migrate/src/Plugin/MigrateDestinationInterface.php +0 −27 Original line number Diff line number Diff line Loading @@ -55,33 +55,6 @@ public function getIds(); */ public function fields(MigrationInterface $migration = NULL); /** * Allows pre-processing of an import. * * Derived classes may implement preImport() to do any processing they need * done before over all source rows. */ public function preImport(); /** * Allows pre-processing of a rollback. */ public function preRollback(); /** * Allows post-processing of an import. * * Derived classes may implement postImport(), to do any processing they need * done after looping over all source rows. */ public function postImport(); /** * Allows post-processing of a rollback. */ public function postRollback(); /** * Import the row. * Loading
core/modules/migrate/src/Plugin/migrate/destination/DestinationBase.php +0 −49 Original line number Diff line number Diff line Loading @@ -59,34 +59,6 @@ public function checkRequirements() { } } /** * Modify the Row before it is imported. */ public function preImport() { // By default we do nothing. } /** * Modify the Row before it is rolled back. */ public function preRollback() { // By default we do nothing. } /** * {@inheritdoc} */ public function postImport() { // By default we do nothing. } /** * {@inheritdoc} */ public function postRollback() { // By default we do nothing. } /** * {@inheritdoc} */ Loading @@ -94,25 +66,4 @@ public function rollbackMultiple(array $destination_identifiers) { // By default we do nothing. } /** * {@inheritdoc} */ public function getCreated() { // TODO: Implement getCreated() method. } /** * {@inheritdoc} */ public function getUpdated() { // TODO: Implement getUpdated() method. } /** * {@inheritdoc} */ public function resetStats() { // TODO: Implement resetStats() method. } }
core/modules/migrate/src/Plugin/migrate/source/SourcePluginBase.php +0 −39 Original line number Diff line number Diff line Loading @@ -59,20 +59,6 @@ abstract class SourcePluginBase extends PluginBase implements MigrateSourceInter */ protected $currentSourceIds; /** * Number of rows intentionally ignored (prepareRow() returned FALSE) * * @var int */ protected $numIgnored = 0; /** * Number of rows we've at least looked at. * * @var int */ protected $numProcessed = 0; /** * The high water mark at the beginning of the import operation. * Loading Loading @@ -214,7 +200,6 @@ public function prepareRow(Row $row) { $id_map->delete($this->currentSourceIds, TRUE); $this->migrateExecutable->saveQueuedMessages(); $id_map->saveIdMapping($row, array(), MigrateIdMapInterface::STATUS_IGNORED, $this->migrateExecutable->rollbackAction); $this->numIgnored++; $this->currentRow = NULL; $this->currentSourceIds = NULL; $result = FALSE; Loading @@ -226,7 +211,6 @@ public function prepareRow(Row $row) { // after hashes). $row->rehash(); } $this->numProcessed++; return $result; } Loading Loading @@ -280,8 +264,6 @@ public function valid() { */ public function rewind() { $this->idMap = $this->migration->getIdMap(); $this->numProcessed = 0; $this->numIgnored = 0; $this->getIterator()->rewind(); $this->next(); } Loading Loading @@ -377,27 +359,6 @@ public function getCurrentIds() { return $this->currentSourceIds; } /** * Getter for numIgnored data member. */ public function getIgnored() { return $this->numIgnored; } /** * Getter for numProcessed data member. */ public function getProcessed() { return $this->numProcessed; } /** * Reset numIgnored back to 0. */ public function resetStats() { $this->numIgnored = 0; } /** * Get the source count. * Loading