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

Add support for importing page aliases and external links #50

Open
wants to merge 40 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
6067f7b
Use ResponseFactory to view/download export XML
mlocati Jan 17, 2025
37c4622
Add missing "use" statement
mlocati Jan 17, 2025
4f15b80
Fix importing stacks with styled blocks
mlocati Jan 17, 2025
b653d17
Remove unused stuff
mlocati Jan 17, 2025
1ed3099
Add some phpdoc and missing properties
mlocati Jan 17, 2025
5c4fbd7
Fix (re) building element in ContentMapper\Exporter
mlocati Jan 17, 2025
ba1ecb7
Fix (re) building element in Exporter
mlocati Jan 17, 2025
689e267
Improve PagePathSanitizer
mlocati Jan 17, 2025
8f439f7
Remove unused "use" statements
mlocati Jan 17, 2025
42dcb21
Simplify "use" statements
mlocati Jan 17, 2025
101e87e
Add to Import\Page entity stuff for aliases/external links
mlocati Jan 17, 2025
570cbf1
Add LocaleID to GlobalArea & Stack import entities
mlocati Jan 17, 2025
014042e
Increase package version
mlocati Jan 17, 2025
758e73f
Parse external links and page aliases
mlocati Jan 17, 2025
43c939d
Import localization state of stacks and global areas
mlocati Jan 17, 2025
e9a9df0
Skip some validations for page aliases/external links
mlocati Jan 17, 2025
16e4de5
Add validators for pages/external links
mlocati Jan 17, 2025
fdc83ef
Display localization stuff for page aliases/external links
mlocati Jan 17, 2025
1a53234
Display localization stuff for stacka and global areas
mlocati Jan 17, 2025
3f25388
Add missing "use" statement in NormalizePagePathsCommandHandler
mlocati Jan 20, 2025
58329a1
Remove references to unused and non-existing classes
mlocati Jan 20, 2025
0db7ee7
Fix 'Attempt to read property "block" on null'
mlocati Jan 20, 2025
e743e82
Display additional paths with leading slash
mlocati Jan 20, 2025
d18eb6b
Use DI to retrieve the current User object
mlocati Jan 20, 2025
df4bfed
First import stack folders, then stacks/global areas
mlocati Jan 22, 2025
a48e779
Fix importing stack structure and localized stacks
mlocati Jan 22, 2025
5b5ef42
Add some phpdoc
mlocati Jan 24, 2025
887252d
Start working on importing pages
mlocati Jan 24, 2025
7ee8f07
Simplify and modernize view_batch view
mlocati Jan 24, 2025
4bc2981
Add some phpdoc
mlocati Jan 24, 2025
c792224
Simplify DashboardPageController
mlocati Jan 24, 2025
8809fed
Add some phpdoc
mlocati Jan 24, 2025
38842ae
Make StackValidator a bit faster
mlocati Jan 24, 2025
9a7d96b
Allow publishing to the actual sitemap, continue importing pages
mlocati Jan 24, 2025
a272515
Continue importing pages
mlocati Jan 24, 2025
e095264
Improve UI
mlocati Jan 28, 2025
1bcafb4
Continue pages import
mlocati Jan 28, 2025
885b6b2
Continue pages import
mlocati Jan 28, 2025
5e2ccf2
Simplify "resetting" multilingual detector
mlocati Jan 29, 2025
8b0d0eb
Build the export SimpleXMLElement only once
mlocati Feb 5, 2025
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
59 changes: 20 additions & 39 deletions controller.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,14 @@
<?php
namespace Concrete\Package\MigrationTool;

use Concrete\Core\Application\Application;
use Concrete\Core\Asset\AssetList;
use Concrete\Core\Command\Process\Command\HandleProcessMessageCommandHandler;
use Concrete\Core\Console\Command;
use Concrete\Core\Messenger\MessageBusManager;
use Concrete\Core\Messenger\Registry\CommandBus;
use Concrete\Core\Messenger\Registry\SynchronousCommandBus;
use Concrete\Core\Package\Package;
use Concrete\Core\Page\Type\Type;
use Page;
use PortlandLabs\Concrete5\MigrationTool\Batch\Command\PublishBatchCommandHandler;
use PortlandLabs\Concrete5\MigrationTool\Batch\ContentMapper\Manager;
use PortlandLabs\Concrete5\MigrationTool\Batch\Validator\BatchValidator;
use PortlandLabs\Concrete5\MigrationTool\Batch\Validator\Pipeline\Stage\ValidateAreasStage;
use PortlandLabs\Concrete5\MigrationTool\Batch\Validator\Pipeline\Stage\ValidateAttributesStage;
use PortlandLabs\Concrete5\MigrationTool\Batch\Validator\Pipeline\Stage\ValidateBatchRecordsStage;
use PortlandLabs\Concrete5\MigrationTool\Batch\Validator\Pipeline\Stage\ValidateBlocksStage;
use PortlandLabs\Concrete5\MigrationTool\Batch\Validator\Pipeline\Stage\ValidateBlockTypesStage;
use PortlandLabs\Concrete5\MigrationTool\Batch\Validator\Pipeline\Stage\ValidateBlockValuesStage;
use PortlandLabs\Concrete5\MigrationTool\Batch\Validator\Pipeline\Stage\ValidateExpressAttributesStage;
use PortlandLabs\Concrete5\MigrationTool\Batch\Validator\Pipeline\Stage\ValidatePagePathStage;
use PortlandLabs\Concrete5\MigrationTool\Batch\Validator\Pipeline\Stage\ValidatePageTemplatesStage;
use PortlandLabs\Concrete5\MigrationTool\Batch\Validator\Pipeline\Stage\ValidatePageTypesStage;
use PortlandLabs\Concrete5\MigrationTool\Batch\Validator\Pipeline\Stage\ValidateReferencedContentItemsStage;
use PortlandLabs\Concrete5\MigrationTool\Batch\Validator\Pipeline\Stage\ValidateReferencedStacksStage;
use PortlandLabs\Concrete5\MigrationTool\Batch\Validator\Pipeline\Stage\ValidateUsersStage;
use PortlandLabs\Concrete5\MigrationTool\Batch\Validator\Pipeline\Stage\ValidateUserGroupsStage;
use PortlandLabs\Concrete5\MigrationTool\Batch\Validator\Pipeline\Stage;
use PortlandLabs\Concrete5\MigrationTool\Batch\Validator\StandardValidator;
use PortlandLabs\Concrete5\MigrationTool\Event\EventSubscriber;
use PortlandLabs\Concrete5\MigrationTool\Exporter\Item\Type\Manager as ExporterItemTypeManager;
Expand All @@ -44,17 +25,15 @@
use PortlandLabs\Concrete5\MigrationTool\Importer\Wordpress\Manager as WordpressImportManager;
use PortlandLabs\Concrete5\MigrationTool\Messenger\Middleware\PublisherExceptionHandlingMiddleware;
use PortlandLabs\Concrete5\MigrationTool\Publisher\Block\Manager as BlockPublisherManager;
use PortlandLabs\Concrete5\MigrationTool\Publisher\Command\PublisherCommand;
use PortlandLabs\Concrete5\MigrationTool\Publisher\ContentImporter\ValueInspector\InspectionRoutine\BatchPageRoutine;
use PortlandLabs\Concrete5\MigrationTool\Publisher\Routine\Manager as PublisherManager;
use SinglePage;
use Symfony\Component\Messenger\MessageBusInterface;

class Controller extends Package
{
protected $pkgHandle = 'migration_tool';
protected $appVersionRequired = '9.0.0';
protected $pkgVersion = '9.0.0';
protected $pkgVersion = '9.1.0';
protected $pkgAutoloaderMapCoreExtensions = true;
protected $pkgAutoloaderRegistries = array(
'src/PortlandLabs/Concrete5/MigrationTool' => '\PortlandLabs\Concrete5\MigrationTool',
Expand Down Expand Up @@ -137,54 +116,56 @@ public function on_start()
\Core::bind('migration/batch/page/validator', function ($app, $batch) {
if (isset($batch[0])) {
$validator = new StandardValidator($batch[0]);
$validator->addPipelineStage(new ValidateAttributesStage());
$validator->addPipelineStage(new ValidatePageTemplatesStage());
$validator->addPipelineStage(new ValidateAreasStage());
$validator->addPipelineStage(new ValidateBlocksStage());
$validator->addPipelineStage(new ValidatePageTypesStage());
$validator->addPipelineStage(new ValidatePagePathStage());
$validator->addPipelineStage(new ValidateUsersStage());
$validator->addPipelineStage(new Stage\ValidateAttributesStage());
$validator->addPipelineStage(new Stage\ValidatePageTemplatesStage());
$validator->addPipelineStage(new Stage\ValidateAreasStage());
$validator->addPipelineStage(new Stage\ValidateBlocksStage());
$validator->addPipelineStage(new Stage\ValidatePageTypesStage());
$validator->addPipelineStage(new Stage\ValidatePagePathStage());
$validator->addPipelineStage(new Stage\ValidateExternalLinkStage());
$validator->addPipelineStage(new Stage\ValidateAliasPage());
$validator->addPipelineStage(new Stage\ValidateUsersStage());
return $validator;
}
});

\Core::bind('migration/batch/site/validator', function ($app, $batch) {
if (isset($batch[0])) {
$validator = new StandardValidator();
$validator->addPipelineStage(new ValidateAttributesStage());
$validator->addPipelineStage(new Stage\ValidateAttributesStage());
return $validator;
}
});

\Core::bind('migration/batch/user/validator', function ($app, $batch) {
if (isset($batch[0])) {
$validator = new StandardValidator();
$validator->addPipelineStage(new ValidateAttributesStage());
$validator->addPipelineStage(new ValidateUserGroupsStage());
$validator->addPipelineStage(new Stage\ValidateAttributesStage());
$validator->addPipelineStage(new Stage\ValidateUserGroupsStage());
return $validator;
}
});

\Core::bind('migration/batch/express/entry/validator', function ($app, $batch) {
if (isset($batch[0])) {
$validator = new StandardValidator();
$validator->addPipelineStage(new ValidateExpressAttributesStage());
$validator->addPipelineStage(new Stage\ValidateExpressAttributesStage());
return $validator;
}
});

\Core::bindShared('migration/batch/validator', function ($app, $batch) {
$validator = new BatchValidator();
$validator->addPipelineStage(new ValidateBatchRecordsStage());
$validator->addPipelineStage(new Stage\ValidateBatchRecordsStage());
return $validator;
});

\Core::bind('migration/batch/block/validator', function ($app, $batch) {
$validator = new StandardValidator();
$validator->addPipelineStage(new ValidateBlockTypesStage());
$validator->addPipelineStage(new ValidateReferencedStacksStage());
$validator->addPipelineStage(new ValidateReferencedContentItemsStage());
$validator->addPipelineStage(new ValidateBlockValuesStage());
$validator->addPipelineStage(new Stage\ValidateBlockTypesStage());
$validator->addPipelineStage(new Stage\ValidateReferencedStacksStage());
$validator->addPipelineStage(new Stage\ValidateReferencedContentItemsStage());
$validator->addPipelineStage(new Stage\ValidateBlockValuesStage());
return $validator;
});

Expand Down
62 changes: 30 additions & 32 deletions controllers/single_page/dashboard/system/migration/export.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use Concrete\Core\Application\EditResponse;
use Concrete\Core\File\File;
use Concrete\Core\Http\ResponseFactory;
use Concrete\Core\Page\Controller\DashboardSitePageController;
use Concrete\Package\MigrationTool\Page\Controller\DashboardPageController;
use Doctrine\Common\Collections\ArrayCollection;
Expand Down Expand Up @@ -54,12 +55,11 @@ public function delete_batch()

public function view()
{
$r = $this->entityManager->getRepository('\PortlandLabs\Concrete5\MigrationTool\Entity\Export\Batch');
$batches = $r->findAll(array(), array('date' => 'desc'));
$this->set('batches', $batches);
$this->set('batchType', 'export');
$r = $this->entityManager->getRepository(\PortlandLabs\Concrete5\MigrationTool\Entity\Export\Batch::class);
$this->set('batches', $r->findAll([], ['date' => 'desc']));
$this->set('sites', $this->app->make('site')->getList());
$this->set('batchEmptyMessage', t('You have not created any export batches.'));
$this->set('dh', $this->app->make('helper/date'));
$this->render('/dashboard/system/migration/view_batches');
}

Expand All @@ -80,16 +80,33 @@ public function export_batch($id = null)
{
$r = $this->entityManager->getRepository('\PortlandLabs\Concrete5\MigrationTool\Entity\Export\Batch');
$batch = $r->findOneById($id);
if (is_object($batch)) {
$exporter = new Exporter($batch);
$files = $exporter->getReferencedFiles();
$this->set('files', $files);
$this->set('batch', $batch);
$this->set('pageTitle', t('Export Batch'));
$this->render('/dashboard/system/migration/finalize_export_batch');
} else {
$this->view();
if ($batch === null) {
return $this->view();
}
$this->set('batch', $batch);
$exporter = new Exporter($batch);
$files = $exporter->getReferencedFiles();
$this->set('files', $files);
$sx = $exporter->getElement();
$xml = $sx->saveXML();
try {
$doc = new \DOMDocument();
$doc->preserveWhiteSpace = false;
$doc->formatOutput = true;
$flags = 0 | (defined('LIBXML_BIGLINES') ? LIBXML_BIGLINES : 0);
$restore = libxml_use_internal_errors(true);
try {
if ($doc->loadXML($xml, $flags) !== false && !libxml_get_errors()) {
$xml = $doc->saveXML();
}
} finally {
libxml_use_internal_errors($restore);
}
} catch (\Throwable $_) {
}
$this->set('xml', $xml);
$this->set('pageTitle', t('Export Batch'));
$this->render('/dashboard/system/migration/finalize_export_batch');
}

public function download_files()
Expand Down Expand Up @@ -151,25 +168,6 @@ public function download_files()
exit;
}

public function export_batch_xml($id = null)
{
$r = $this->entityManager->getRepository('\PortlandLabs\Concrete5\MigrationTool\Entity\Export\Batch');
$batch = $r->findOneById($id);
if (is_object($batch)) {
$exporter = new Exporter($batch);
if ($this->request->request->get('download')) {
header('Content-disposition: attachment; filename="export.xml"');
header('Content-type: "text/xml"; charset="utf8"');
} else {
header('Content-type: text/xml');
}
echo $exporter->getElement()->asXML();
exit;
} else {
$this->view();
}
}

public function add_items_to_batch()
{
if (!$this->token->validate('add_items_to_batch')) {
Expand Down
20 changes: 8 additions & 12 deletions controllers/single_page/dashboard/system/migration/import.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,13 @@
use Concrete\Core\File\Filesystem;
use Concrete\Core\File\Importer;
use Concrete\Core\File\Set\Set;
use Concrete\Core\Command\Batch\Batch as BatchBuilder;
use Concrete\Core\Filesystem\ElementManager;
use Concrete\Core\Page\PageList;
use Concrete\Package\MigrationTool\Page\Controller\DashboardPageController;
use Doctrine\Common\Collections\ArrayCollection;
use PortlandLabs\Concrete5\MigrationTool\Batch\BatchService;
use PortlandLabs\Concrete5\MigrationTool\Batch\Command\DeleteBatchProcessesCommand;
use PortlandLabs\Concrete5\MigrationTool\Batch\Command\MapContentTypesBatchProcessFactory;
use PortlandLabs\Concrete5\MigrationTool\Batch\Command\MapContentTypesCommand;
use PortlandLabs\Concrete5\MigrationTool\Batch\Command\NormalizePagePathsCommand;
use PortlandLabs\Concrete5\MigrationTool\Batch\Command\PublishBatchCommand;
use PortlandLabs\Concrete5\MigrationTool\Batch\Command\ScanContentTypesCommand;
use PortlandLabs\Concrete5\MigrationTool\Batch\Command\TransformContentTypesBatchProcessFactory;
use PortlandLabs\Concrete5\MigrationTool\Batch\ContentMapper\PresetManager;
use PortlandLabs\Concrete5\MigrationTool\Batch\Formatter\ExpressEntry\TreeEntryJsonFormatter;
use PortlandLabs\Concrete5\MigrationTool\Batch\Formatter\Page\TreePageJsonFormatter;
Expand Down Expand Up @@ -45,7 +39,11 @@ public function add_batch()
if ($this->request->request->has('siteID')) {
$site = $this->app->make('site')->getByID($this->request->request->get('siteID'));
}
$batch = $service->addBatch($this->request->request->get('name'), $site);
$batch = $service->addBatch(
$this->request->request->get('name'),
$site,
$this->request->request->getBoolean('publishToSitemap', false)
);
if ($_FILES['mappingFile']['tmp_name']) {
$importer = new \PortlandLabs\Concrete5\MigrationTool\Batch\ContentMapper\Importer();
$mappings = $importer->getMappings($_FILES['mappingFile']['tmp_name']);
Expand Down Expand Up @@ -297,12 +295,11 @@ public function create_content_from_batch()

public function view()
{
$r = $this->entityManager->getRepository('\PortlandLabs\Concrete5\MigrationTool\Entity\Import\Batch');
$batches = $r->findAll(array(), array('date' => 'desc'));
$this->set('batches', $batches);
$this->set('batchType', 'import');
$r = $this->entityManager->getRepository(\PortlandLabs\Concrete5\MigrationTool\Entity\Import\Batch::class);
$this->set('batches', $r->findAll([], ['date' => 'desc']));
$this->set('sites', $this->app->make('site')->getList());
$this->set('batchEmptyMessage', t('You have not created any import batches. Create a batch and add content records to it.'));
$this->set('dh', $this->app->make('helper/date'));
$this->render('/dashboard/system/migration/view_batches');
}

Expand Down Expand Up @@ -337,7 +334,6 @@ public function view_batch($id = null)
$settings[] = $setting;
}
}
$service = $this->app->make(BatchService::class);
if ($batch->getBatchProcesses()->count()) {
$processes = [];
foreach($batch->getBatchProcesses() as $batchProcess) {
Expand Down
Loading