-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #533 from BitBagCommerce/feature/OP-525
OP-525: Content migration script
- Loading branch information
Showing
30 changed files
with
493 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
code,type,name_en_US,content_en_US,sections,channels,products,image_en_US,slug_en_US | ||
test4,image,Test,test,"blog, general",US_WEB,"010ba66b-adee-3d6e-9d63-67c44d686db1, 01d35db9-247d-3834-b300-20483d5e34e8",https://bitbag.shop/assets/web/images/header-logo.png,https://bitbag.shop/assets/web/images/header-logo.png |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Legacy data migration | ||
|
||
## Introduction | ||
|
||
You can migrate your blocks & pages from the 4.x version to the 5.x version of the plugin. | ||
To do so, you need to follow the steps below. | ||
|
||
## Steps | ||
|
||
1. Create new CSV files with blocks & pages data in the 4.x format. | ||
See an example in [block_legacy.csv](block_legacy.csv) or [page_legacy.csv](page_legacy.csv). | ||
2. Install the 5.x version of the plugin. | ||
3. Go to the console and run the following command: | ||
```bash | ||
bin/console cms:import:csv page_legacy {file_path}.csv | ||
bin/console cms:import:csv block_legacy {file_path}.csv | ||
``` | ||
|
||
## Info about legacy CSV files columns | ||
|
||
### Blocks | ||
|
||
- **code** - block code. | ||
- **type** - it will be ignored. | ||
- **name_LOCALE** - block name. First occurrence of its column is the default name for the block. | ||
For each locale, there will be created a Heading content element. | ||
- **content_LOCALE** - block content. For each locale, there will be created a Textarea content element. | ||
- **sections** - it will be converted to the block's collections. | ||
- **channels** - block channels. | ||
- **products** - block products. There will be created Products grid content element. | ||
- **image_LOCALE** - block image. For each locale, there will be created a Single media content element. | ||
- **slug_LOCALE** - it will be ignored. | ||
|
||
### Pages | ||
|
||
- **code** - page code. | ||
- **sections** - it will be converted to the page's collections. | ||
- **channels** - page channels. | ||
- **products** - page products. There will be created Products grid content element. | ||
- **slug_LOCALE** - page slug. | ||
- **name_LOCALE** - page name. First occurrence of its column is the default name for the page. | ||
For each locale, there will be created a Heading content element. | ||
- **image_LOCALE** - page image. For each locale, there will be created a Single media content element. | ||
- **meta_keywords_LOCALE** - page meta keywords. | ||
- **meta_description_LOCALE** - page meta description. | ||
- **content_LOCALE** - page content. For each locale, there will be created a Textarea content element. | ||
- **breadcrumb_LOCALE** - it will be ignored. | ||
- **name_when_linked_LOCALE** - for each locale, there will be created a teaser title. | ||
- **description_when_linked_LOCALE** - for each locale, there will be created a teaser content. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
code,sections,channels,products,slug_en_US,name_en_US,image_en_US,meta_keywords_en_US,meta_description_en_US,content_en_US,breadcrumb_en_US,name_when_linked_en_US,description_when_linked_en_US | ||
aboutUS,,US_WEB,,about_us,About US,,About US,About US,"",,, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\CmsPlugin\Factory; | ||
|
||
use Sylius\CmsPlugin\Entity\ContentConfiguration; | ||
|
||
final class ContentElementFactory | ||
{ | ||
public static function createHeadingContentElement( | ||
?string $locale, | ||
?string $headingType, | ||
?string $headingContent, | ||
): ?ContentConfiguration { | ||
if (null === $headingContent) { | ||
return null; | ||
} | ||
|
||
$contentConfiguration = new ContentConfiguration(); | ||
$contentConfiguration->setLocale($locale ?? 'en_US'); | ||
$contentConfiguration->setType('heading'); | ||
$contentConfiguration->setConfiguration([ | ||
'heading_type' => $headingType ?? 'h1', | ||
'heading' => $headingContent, | ||
]); | ||
|
||
return $contentConfiguration; | ||
} | ||
|
||
public static function createTextareaContentElement(?string $locale, ?string $content): ?ContentConfiguration | ||
{ | ||
if (null === $content) { | ||
return null; | ||
} | ||
|
||
$contentConfiguration = new ContentConfiguration(); | ||
$contentConfiguration->setLocale($locale ?? 'en_US'); | ||
$contentConfiguration->setType('textarea'); | ||
$contentConfiguration->setConfiguration([ | ||
'textarea' => $content, | ||
]); | ||
|
||
return $contentConfiguration; | ||
} | ||
|
||
public static function createProductsGridContentElement(?string $locale, ?string $codes): ?ContentConfiguration | ||
{ | ||
if (null === $codes) { | ||
return null; | ||
} | ||
|
||
$productsCodes = explode(',', $codes); | ||
$productsCodes = array_map(static function (string $element): string { | ||
return trim($element); | ||
}, $productsCodes); | ||
|
||
$contentConfiguration = new ContentConfiguration(); | ||
$contentConfiguration->setLocale($locale ?? 'en_US'); | ||
$contentConfiguration->setType('products_grid'); | ||
$contentConfiguration->setConfiguration([ | ||
'products_grid' => [ | ||
'products' => $productsCodes, | ||
], | ||
]); | ||
|
||
return $contentConfiguration; | ||
} | ||
|
||
public static function createSingleMediaContentElement(?string $locale, ?string $code): ?ContentConfiguration | ||
{ | ||
if (null === $code) { | ||
return null; | ||
} | ||
|
||
$contentConfiguration = new ContentConfiguration(); | ||
$contentConfiguration->setLocale($locale ?? 'en_US'); | ||
$contentConfiguration->setType('single_media'); | ||
$contentConfiguration->setConfiguration([ | ||
'single_media' => $code, | ||
]); | ||
|
||
return $contentConfiguration; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.