/** * {@inheritdoc} */ public function saveIdMapping(Row $row, array $destination_id_values, $source_row_status = MigrateIdMapInterface::STATUS_IMPORTED, $rollback_action = MigrateIdMapInterface::ROLLBACK_DELETE) { // Construct the source key. $source_id_values = $row->getSourceIdValues(); // Construct the source key and initialize to empty variable keys. $keys = array(); foreach ($this->sourceIdFields() as $field_name => $key_name) { // A NULL key value will fail. if (!isset($source_id_values[$field_name])) { $this->message->display(t('Could not save to map table due to NULL value for key field @field', array('@field' => $field_name)), 'error'); return; } $keys[$key_name] = $source_id_values[$field_name]; } $fields = array('source_row_status' => (int) $source_row_status, 'rollback_action' => (int) $rollback_action, 'hash' => $row->getHash()); $count = 0; foreach ($destination_id_values as $dest_id) { $fields['destid' . ++$count] = $dest_id; } if ($count && $count != count($this->destinationIdFields())) { $this->message->display(t('Could not save to map table due to missing destination id values'), 'error'); return; } if ($this->migration->get('trackLastImported')) { $fields['last_imported'] = time(); } if ($keys) { // Notify anyone listening of the map row we're about to save. $this->eventDispatcher->dispatch(MigrateEvents::MAP_SAVE, new MigrateMapSaveEvent($this, $keys + $fields)); $this->getDatabase()->merge($this->mapTableName())->key($keys)->fields($fields)->execute(); } }
/** * 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.9 * $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; } }
/** * Logs a message using the Migrate message service. * * @param string $message * The message to log. * @param string $type * The type of message, for example: status or warning. */ public function logMessage($message, $type = 'status') { $this->message->display($message, $type); }