Skip to content

Instantly share code, notes, and snippets.

@ilyautkin
Last active May 19, 2022 14:29
Show Gist options
  • Save ilyautkin/30332948d5611bea34130b5f3347083b to your computer and use it in GitHub Desktop.
Save ilyautkin/30332948d5611bea34130b5f3347083b to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="UTF-8"?>
<data package="contentblocks" exported="2021-05-04@16:36:10" total="4">
<cbCategory>
<id>1</id>
<name><![CDATA[Content]]></name>
<description><![CDATA[]]></description>
<sortorder>0</sortorder>
</cbCategory>
<cbCategory>
<id>2</id>
<name><![CDATA[Media]]></name>
<description><![CDATA[]]></description>
<sortorder>1</sortorder>
</cbCategory>
<cbCategory>
<id>3</id>
<name><![CDATA[Forms]]></name>
<description><![CDATA[]]></description>
<sortorder>2</sortorder>
</cbCategory>
<cbCategory>
<id>4</id>
<name><![CDATA[Components]]></name>
<description><![CDATA[]]></description>
<sortorder>3</sortorder>
</cbCategory>
</data>
<?xml version="1.0" encoding="UTF-8"?>
<data package="contentblocks" exported="2021-01-01@00:00:00" total="1">
<cbField>
<id>100</id>
<parent>0</parent>
<parent_properties></parent_properties>
<input><![CDATA[repeater]]></input>
<name><![CDATA[Title]]></name>
<description><![CDATA[]]></description>
<sortorder>10</sortorder>
<category>1</category>
<icon><![CDATA[heading]]></icon>
<icon_type><![CDATA[core]]></icon_type>
<template><![CDATA[&size=`[[+size]]`
&title=`[[+title]]`
&titleTheme=`[[+titleTheme]]`
&subTitle=`[[+subTitle]]`
&subTitleTheme=`[[+subTitleTheme]]`]]></template>
<properties><![CDATA[{"wrapper_template":"[[cbRenderBlock?\n &method=`blockTitle`\n &blockIdx=`[[+layout_idx]]-[[+unique_idx]]`\n &anchorTitle=`[[+anchor_title]]`\n &anchorAlias=`[[+anchor_alias]]`\n [[+rows]]\n]]","row_separator":",","max_items":"1","min_items":"0","add_first_item":"true","manager_columns":"1","layout_style":"default"}]]></properties>
<availability><![CDATA[[]]]></availability>
<layouts><![CDATA[]]></layouts>
<times_per_layout>0</times_per_layout>
<times_per_page>0</times_per_page>
<settings><![CDATA[[{"reference":"anchor_display","title":"Display anchor","fieldtype":"select","default_value":"0","image_source":"","image_directory":"","image_file_types":"","image_thumbnail_size":"","fieldoptions":"0==Hide\n1==Show","field_is_exposed":"modal"},{"reference":"anchor_title","title":"Anchor title","fieldtype":"textfield","default_value":"","image_source":"","image_directory":"","image_file_types":"","image_thumbnail_size":"","fieldoptions":"","field_is_exposed":"modal"},{"reference":"anchor_alias","title":"Anchor alias","fieldtype":"textfield","default_value":"","image_source":"","image_directory":"","image_file_types":"","image_thumbnail_size":"","fieldoptions":"","field_is_exposed":"modal"}]]]></settings>
</cbField>
<!-- Children -->
<cbField >
<id>110</id>
<parent>100</parent>
<parent_properties><![CDATA[{"key":"size","width":"100"}]]></parent_properties>
<input><![CDATA[dropdown]]></input>
<name><![CDATA[Size]]></name>
<description><![CDATA[]]></description>
<sortorder>10</sortorder>
<category>0</category>
<icon><![CDATA[paragraph]]></icon>
<icon_type><![CDATA[core]]></icon_type>
<template><![CDATA[[[+value]]]]></template>
<properties><![CDATA[{"options":"@SNIPPET cbTitleSizeOptions","default_value":"default"}]]></properties>
<availability><![CDATA[[]]]></availability>
<layouts></layouts>
<times_per_layout>0</times_per_layout>
<times_per_page>0</times_per_page>
<settings><![CDATA[[]]]></settings>
</cbField>
<cbField >
<id>120</id>
<parent>100</parent>
<parent_properties><![CDATA[{"key":"title","width":"67"}]]></parent_properties>
<input><![CDATA[heading]]></input>
<name><![CDATA[Title]]></name>
<description><![CDATA[]]></description>
<sortorder>20</sortorder>
<category>0</category>
<icon><![CDATA[heading]]></icon>
<icon_type><![CDATA[core]]></icon_type>
<template><![CDATA[[[+value:notempty=`
<[[+level]] class="is-h1 text-color text-color--[[+titleTheme]]">[[+value]]</[[+level]]]]><![CDATA[>
`]]]]></template>
<properties><![CDATA[{"default_level":"h2","available_levels":"h1=heading_1,h2=heading_2,h3=heading_3,h4=heading_4,h5=heading_5","use_tinyrte":"0"}]]></properties>
<availability><![CDATA[[]]]></availability>
<layouts></layouts>
<times_per_layout>0</times_per_layout>
<times_per_page>0</times_per_page>
<settings><![CDATA[[]]]></settings>
</cbField>
<cbField >
<id>130</id>
<parent>100</parent>
<parent_properties><![CDATA[{"key":"titleTheme","width":"33"}]]></parent_properties>
<input><![CDATA[dropdown]]></input>
<name><![CDATA[Title color]]></name>
<description><![CDATA[]]></description>
<sortorder>30</sortorder>
<category>0</category>
<icon><![CDATA[paragraph]]></icon>
<icon_type><![CDATA[core]]></icon_type>
<template><![CDATA[[[+value]]]]></template>
<properties><![CDATA[{"options":"@SNIPPET cbTitleThemeOptions","default_value":"default"}]]></properties>
<availability><![CDATA[[]]]></availability>
<layouts></layouts>
<times_per_layout>0</times_per_layout>
<times_per_page>0</times_per_page>
<settings><![CDATA[[]]]></settings>
</cbField>
<cbField >
<id>140</id>
<parent>100</parent>
<parent_properties><![CDATA[{"key":"subTitle","width":"67"}]]></parent_properties>
<input><![CDATA[heading]]></input>
<name><![CDATA[Subtitle]]></name>
<description><![CDATA[]]></description>
<sortorder>40</sortorder>
<category>0</category>
<icon><![CDATA[heading]]></icon>
<icon_type><![CDATA[core]]></icon_type>
<template><![CDATA[[[+value:notempty=`
<[[+level]] class="is-h2 text-color text-color--[[+subTitleTheme]]">[[+value]]</[[+level]]]]><![CDATA[>
`]]]]></template>
<properties><![CDATA[{"default_level":"h3","available_levels":"h1=heading_1,h2=heading_2,h3=heading_3,h4=heading_4,h5=heading_5","use_tinyrte":"0"}]]></properties>
<availability><![CDATA[[]]]></availability>
<layouts></layouts>
<times_per_layout>0</times_per_layout>
<times_per_page>0</times_per_page>
<settings><![CDATA[[]]]></settings>
</cbField>
<cbField >
<id>150</id>
<parent>100</parent>
<parent_properties><![CDATA[{"key":"subTitleTheme","width":"33"}]]></parent_properties>
<input><![CDATA[dropdown]]></input>
<name><![CDATA[Subtitle color]]></name>
<description><![CDATA[]]></description>
<sortorder>50</sortorder>
<category>0</category>
<icon><![CDATA[paragraph]]></icon>
<icon_type><![CDATA[core]]></icon_type>
<template><![CDATA[[[+value]]]]></template>
<properties><![CDATA[{"options":"@SNIPPET cbTitleThemeOptions","default_value":"default"}]]></properties>
<availability><![CDATA[[]]]></availability>
<layouts></layouts>
<times_per_layout>0</times_per_layout>
<times_per_page>0</times_per_page>
<settings><![CDATA[[]]]></settings>
</cbField>
<!-- / Children -->
</data>
<?php
define('MODX_API_MODE', true);
include dirname(__DIR__, 7) . '/webroot/index.php';
$config_path = dirname(__DIR__) . '/cb/';
$contentBlocks = $modx->getService(
'contentblocks',
'ContentBlocks',
$modx->getOption(
'migx.core_path',
null,
$modx->getOption('core_path') . 'components/contentblocks/'
) . 'model/contentblocks/',
[]
);
$options = [
'processors_path' => $contentBlocks->config['processorsPath'],
'mode' => 'overwrite',
];
if (!$contentBlocks) {
echo 'Unable to load ContentBlocks service' . PHP_EOL;
echo '__________________________________' . PHP_EOL;
echo 'Please install ContentBlocks first' . PHP_EOL;
echo '__________________________________' . PHP_EOL;
return;
} else {
echo 'ContentBlocks service was loaded, start import' . PHP_EOL;
}
$modx->removeCollection('cbField', ['id:>' => 0]);
$configs = [
'layouts' => [
'layout.xml'
],
'templates' => [
'template.xml'
],
'categories' => [
'category.xml'
],
'fields' => []
];
$fields = scandir($config_path . 'fields/');
natsort($fields);
foreach ($fields as $file) {
if (in_array($file, ['.', '..'])) {
continue;
}
$configs['fields'][] = 'fields/' . $file;
}
foreach ($configs as $type => $files) {
foreach ($files as $file) {
if (!file_exists($config_path . $file)) {
continue;
}
/* Simulate the upload of the file (the path should be accessible from the webserver). */
$_FILES['file'] = [
'name' => basename($file),
'tmp_name' => $config_path . $file,
'size' => filesize($config_path . $file),
'error' => 0,
'type' => 'text/xml'
];
$response = $modx->runProcessor('mgr/' . $type . '/import', ['mode' => 'overwrite'], $options);
if ($response->isError()) {
echo "Error unable to import {$type}" . $response->getMessage() . PHP_EOL;
} else {
echo "{$type} {$file} imported correctly" . PHP_EOL;
}
}
}
return;
<?xml version="1.0" encoding="UTF-8"?>
<data package="contentblocks" exported="2021-05-04@16:36:19" total="1">
<cbLayout>
<id>1</id>
<name><![CDATA[Main]]></name>
<description><![CDATA[]]></description>
<sortorder>1</sortorder>
<category>0</category>
<icon><![CDATA[layout_1]]></icon>
<icon_type><![CDATA[core]]></icon_type>
<columns><![CDATA[[{"reference":"main","width":"100"}]]]></columns>
<template><![CDATA[[[+main]]]]></template>
<availability><![CDATA[[]]]></availability>
<times_per_page>0</times_per_page>
<layout_only_nested>0</layout_only_nested>
<settings><![CDATA[[]]]></settings>
<Category >
</Category>
</cbLayout>
</data>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment