Skip to content

Commit

Permalink
MERGE: Merge branch '2.3' into 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kdambekalns committed May 24, 2017
2 parents e22ecf3 + 1141b01 commit f90d29f
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,15 @@ class NodeImportService
public function import(\XMLReader $xmlReader, $targetPath, $resourceLoadPath = null)
{
$this->propertyMappingConfiguration = new ImportExportPropertyMappingConfiguration($resourceLoadPath);
$this->nodeNameStack = ($targetPath === '/') ? array() : array_map(function ($pathSegment) {
return Utility::renderValidNodeName($pathSegment);
}, explode('/', $targetPath));
$this->nodeNameStack = [];

if ($targetPath !== '/') {
$pathSegments = explode('/', $targetPath);
array_shift($pathSegments);
$this->nodeNameStack = array_map(function ($pathSegment) {
return Utility::renderValidNodeName($pathSegment);
}, $pathSegments);
}

$formatVersion = $this->determineFormatVersion($xmlReader);
switch ($formatVersion) {
Expand Down Expand Up @@ -267,7 +273,7 @@ protected function parseElement(\XMLReader $xmlReader)
$this->nodeIdentifierStack[] = $xmlReader->getAttribute('identifier');
// update current path
$nodeName = $xmlReader->getAttribute('nodeName');
if ($nodeName !== '/') {
if ($nodeName !== '/' && $nodeName !== '') {
$this->nodeNameStack[] = Utility::renderValidNodeName($nodeName);
}
break;
Expand Down Expand Up @@ -583,7 +589,7 @@ protected function parseEndElement(\XMLReader $reader)
protected function getCurrentPath()
{
$path = implode('/', $this->nodeNameStack);
return ($path === '') ? '/' : $path;
return '/' . $path;
}

/**
Expand Down
7 changes: 7 additions & 0 deletions Neos.ContentRepository/Classes/Utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public static function renderValidNodeName($name)
return $name;
}

$originalName = $name;

// Transliterate (transform 北京 to 'Bei Jing')
$name = Transliterator::transliterate($name);

Expand All @@ -44,6 +46,11 @@ public static function renderValidNodeName($name)
// Ensure only allowed characters are left
$name = preg_replace('/[^a-z0-9\-]/', '', $name);

// Make sure we don't have an empty string left.
if ($name === '') {
$name = 'node-' . strtolower(md5($originalName));
}

return $name;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Neos\Flow\Property\PropertyMapper;
use Neos\Flow\Security\Context;
use Neos\Flow\Tests\UnitTestCase;
use Neos\Flow\Utility\Now;
use Neos\ContentRepository\Domain\Service\ImportExport\NodeImportService;

class NodeImportServiceTest extends UnitTestCase
Expand Down Expand Up @@ -63,8 +62,8 @@ public function importSingleNode()
'removed' => false,
'hidden' => false,
'hiddenInIndex' => false,
'path' => 'neosdemoio',
'pathHash' => '0423106850d41d93150a4e8e3ecd68b3',
'path' => '/neosdemoio',
'pathHash' => '9204ab1d1079b1d950fffecf874955c3',
'parentPath' => '/',
'parentPathHash' => '6666cd76f96956469e7be39d750cc7d9',
'properties' => array(
Expand Down Expand Up @@ -129,8 +128,8 @@ public function importSingleNodeWithoutIdentifier()
'removed' => false,
'hidden' => false,
'hiddenInIndex' => false,
'path' => 'neosdemoio',
'pathHash' => '0423106850d41d93150a4e8e3ecd68b3',
'path' => '/neosdemoio',
'pathHash' => '9204ab1d1079b1d950fffecf874955c3',
'parentPath' => '/',
'parentPathHash' => '6666cd76f96956469e7be39d750cc7d9',
'properties' => array(
Expand Down Expand Up @@ -184,8 +183,8 @@ public function importWithEmptyPropertyImportsAllProperties()
'removed' => false,
'hidden' => false,
'hiddenInIndex' => false,
'path' => 'neosdemoio',
'pathHash' => '0423106850d41d93150a4e8e3ecd68b3',
'path' => '/neosdemoio',
'pathHash' => '9204ab1d1079b1d950fffecf874955c3',
'parentPath' => '/',
'parentPathHash' => '6666cd76f96956469e7be39d750cc7d9',
'properties' => array(
Expand Down Expand Up @@ -259,8 +258,8 @@ public function importWithEmptyPropertyImportsAllProperties()
'removed' => false,
'hidden' => false,
'hiddenInIndex' => false,
'path' => 'node53a18fb53bdf2',
'pathHash' => '3f1d4fea7c0b21d21098960149de9c80',
'path' => '/node53a18fb53bdf2',
'pathHash' => 'adb885c51ef09d0d4beec84adff97355',
'parentPath' => '/',
'parentPathHash' => '6666cd76f96956469e7be39d750cc7d9',
'properties' => array(
Expand Down Expand Up @@ -352,8 +351,8 @@ public function importWithArrayPropertiesImportsCorrectly()
'removed' => false,
'hidden' => false,
'hiddenInIndex' => false,
'path' => 'node53a18fb53bdf2',
'pathHash' => '3f1d4fea7c0b21d21098960149de9c80',
'path' => '/node53a18fb53bdf2',
'pathHash' => 'adb885c51ef09d0d4beec84adff97355',
'parentPath' => '/',
'parentPathHash' => '6666cd76f96956469e7be39d750cc7d9',
'properties' => array(
Expand Down
4 changes: 3 additions & 1 deletion Neos.ContentRepository/Tests/Unit/UtilityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ public function sourcesAndNodeNames()
['ελληνικά', 'ellenika'],
['မြန်မာဘာသာ', 'm-n-maabhaasaa'],
[' हिन्दी', 'hindii'],
[' x- ', 'x']
[' x- ', 'x'],
['', 'node-' . md5('')],
[',.~', 'node-' . md5(',.~')]
];
}

Expand Down
12 changes: 6 additions & 6 deletions Neos.Media/Classes/Domain/Service/AssetService.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,9 @@ public function replaceAssetResource(AssetInterface $asset, PersistentResource $
$uriMapping = [];
$redirectHandlerEnabled = isset($options['generateRedirects']) && (boolean)$options['generateRedirects'] === true && $this->packageManager->isPackageAvailable('Neos.RedirectHandler');
if ($redirectHandlerEnabled) {
$uriMapping[
$this->resourceManager->getPublicPersistentResourceUri($originalAssetResource)
] = $this->resourceManager->getPublicPersistentResourceUri($asset->getResource());
$originalAssetResourceUri = new Uri($this->resourceManager->getPublicPersistentResourceUri($originalAssetResource));
$newAssetResourceUri = new Uri($this->resourceManager->getPublicPersistentResourceUri($asset->getResource()));
$uriMapping[$originalAssetResourceUri->getPath()] = $newAssetResourceUri->getPath();
}

if (method_exists($asset, 'getVariants')) {
Expand All @@ -272,9 +272,9 @@ public function replaceAssetResource(AssetInterface $asset, PersistentResource $
}

if ($redirectHandlerEnabled) {
$uriMapping[
$this->resourceManager->getPublicPersistentResourceUri($originalVariantResource)
] = $this->resourceManager->getPublicPersistentResourceUri($variant->getResource());
$originalVariantResourceUri = new Uri($this->resourceManager->getPublicPersistentResourceUri($originalVariantResource));
$newVariantResourceUri = new Uri($this->resourceManager->getPublicPersistentResourceUri($variant->getResource()));
$uriMapping[$originalVariantResourceUri->getPath()] = $newVariantResourceUri->getPath();
}

$this->getRepository($variant)->update($variant);
Expand Down

0 comments on commit f90d29f

Please sign in to comment.