Skip to content

Instantly share code, notes, and snippets.

@brachycera
Last active June 29, 2022 10:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brachycera/8f7ce72e4cd70c4d58fc22a839d97e0c to your computer and use it in GitHub Desktop.
Save brachycera/8f7ce72e4cd70c4d58fc22a839d97e0c to your computer and use it in GitHub Desktop.
Sulu CMS Import articles from an existing CMS
<?php
// src/Commands/ImportExternalCmsCommand.php
namespace App\Commands;
use Doctrine\ORM\EntityManagerInterface;
use Sulu\Component\DocumentManager\DocumentManagerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class ImportExternalCmsCommand extends Command
{
protected static $defaultName = 'sulu:import-external-cms';
protected static $defaultDescription = 'Import all articles from an external CMS via DBAL and create Sulu articles with the document manager.';
private $entityManager;
private $documentManager;
public function __construct(EntityManagerInterface $entityManager, DocumentManagerInterface $documentManager)
{
$this->entityManager = $entityManager;
$this->documentManager = $documentManager;
parent::__construct();
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
// TODO:
// - query old articles via entity manager
// - return Generator with articles data
// - save articles via document manager
return 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment