Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.6] Export improvements. #7812

Merged
merged 1 commit into from
Oct 21, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/Storage/Migration/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

use Bolt\Collection\Bag;
use Bolt\Collection\MutableBag;
use Bolt\Exception\StorageException;
use Bolt\Storage\Entity\Content;
use Bolt\Storage\Entity\Entity;
use Bolt\Storage\Entity\Users;
use Bolt\Storage\EntityManager;
use Bolt\Storage\Field\Type\RelationType;
use Bolt\Storage\Mapping\ClassMetadata;
use Bolt\Storage\Query\Query;
use Bolt\Storage\Repository\ContentRepository;
Expand Down Expand Up @@ -126,6 +128,10 @@ private function getRecords($contentTypeName, MutableBag $exportData, MutableBag
$contentTypeBag = $exportData->get($contentTypeName);

foreach ($entities as $key => $entity) {
if (!$entity->getSlug()) {
throw new StorageException("Cannot export an entity that does not have a slug. Check contenttype/id {$contentTypeName}/{$entity->id} to make sure it has a slug!");
}

$this->addRecord($contentTypeBag, $metadata, $entity);
}

Expand All @@ -150,6 +156,19 @@ private function addRecord(MutableBag $contentTypeBag, ClassMetadata $metadata,
if (in_array($field['type'], ['date', 'datetime'])) {
$val = (string) $entity->$fieldName;
}
if ($fieldName === 'incomingrelation') {
// There's no need to store the incoming end of a relation.
continue;
}
if ($field['fieldtype'] === RelationType::class) {
$val = $entity->getRelation($fieldName)
->map(
function ($item) use ($fieldName) {
return "$fieldName/{$item->slug}";
}
)
->getValues();
}
if (is_callable([$val, 'serialize'])) {
/** @var Entity $val */
$val = $val->serialize();
Expand Down