/** * {@inheritdoc} */ protected function processStubRow(Row $row) { // We stub the uri value ourselves so we can create a real stub file for it. if (!$row->getDestinationProperty('uri')) { $field_definitions = $this->entityManager->getFieldDefinitions($this->storage->getEntityTypeId(), $this->getKey('bundle')); $value = UriItem::generateSampleValue($field_definitions['uri']); if (empty($value)) { throw new MigrateException('Stubbing failed, unable to generate value for field uri'); } // generateSampleValue() wraps the value in an array. $value = reset($value); // Make it into a proper public file uri, stripping off the existing // scheme if present. $value = 'public://' . preg_replace('|^[a-z]+://|i', '', $value); $value = Unicode::substr($value, 0, $field_definitions['uri']->getSetting('max_length')); // Create a real file, so File::preSave() can do filesize() on it. touch($value); $row->setDestinationProperty('uri', $value); } parent::processStubRow($row); }
/** * {@inheritdoc} */ protected function processStubRow(Row $row) { parent::processStubRow($row); $stub_commented_entity_type = $row->getDestinationProperty('entity_type'); // While parent::getEntity() fills the bundle property for stub entities // if it's still empty, here we must also make sure entity_id/entity_type // are filled (so $comment->getCommentedEntity() always returns a value). if (empty($this->stubCommentedEntityIds[$stub_commented_entity_type])) { // Fill stub entity id. Any id will do, as long as it exists. $entity_type = $this->entityManager->getDefinition($stub_commented_entity_type); $id_key = $entity_type->getKey('id'); $result = $this->entityQuery->get($stub_commented_entity_type)->range(0, 1)->execute(); if ($result) { $this->stubCommentedEntityIds[$stub_commented_entity_type] = array_pop($result); $row->setSourceProperty($id_key, $this->stubCommentedEntityIds[$stub_commented_entity_type]); } else { throw new MigrateException(t('Could not find parent entity to use for comment %id', ['%id' => implode(':', $row->getSourceIdValues())]), MigrationInterface::MESSAGE_ERROR); } } $row->setDestinationProperty('entity_id', $this->stubCommentedEntityIds[$stub_commented_entity_type]); $row->setDestinationProperty('entity_type', $stub_commented_entity_type); $row->setDestinationProperty('created', REQUEST_TIME); $row->setDestinationProperty('changed', REQUEST_TIME); }
/** * {@inheritdoc} */ protected function processStubRow(Row $row) { parent::processStubRow($row); // Neither uid nor name is required in itself, but it is required to set one // of them. $row->setDestinationProperty('name', 'anonymous_stub'); }
/** * {@inheritdoc} */ protected function processStubRow(Row $row) { parent::processStubRow($row); // Email address is not defined as required in the base field definition but // is effectively required by the UserMailRequired constraint. This means // that Entity::processStubRow() did not populate it - we do it here. $field_definitions = $this->entityManager->getFieldDefinitions($this->storage->getEntityTypeId(), $this->getKey('bundle')); $mail = EmailItem::generateSampleValue($field_definitions['mail']); $row->setDestinationProperty('mail', reset($mail)); // @todo Work-around for https://www.drupal.org/node/2602066. $name = $row->getDestinationProperty('name'); if (is_array($name)) { $name = reset($name); } if (Unicode::strlen($name) > USERNAME_MAX_LENGTH) { $row->setDestinationProperty('name', Unicode::substr($name, 0, USERNAME_MAX_LENGTH)); } }