protected function initPhpcr()
{
/** @var SessionInterface $session */
$session = $this->getContainer()->get('sulu_document_manager.default_session');
$liveSession = $this->getContainer()->get('sulu_document_manager.live_session');
if ($session->nodeExists('/cmf')) {
NodeHelper::purgeWorkspace($session);
$session->save();
}
if ($liveSession->nodeExists('/cmf')) {
NodeHelper::purgeWorkspace($liveSession);
$liveSession->save();
}
if (!$this->importer) {
$this->importer = new PHPCRImporter($session, $liveSession);
}
// initialize the content repository. in order to speed things up, for
// each process, we dump the initial state to an XML file and restore
// it thereafter.
$initializerDump = __DIR__ . '/../Resources/app/cache/initial.xml';
$initializerDumpLive = __DIR__ . '/../Resources/app/cache/initial_live.xml';
if (true === self::$workspaceInitialized) {
$session->importXml('/', $initializerDump, ImportUUIDBehaviorInterface::IMPORT_UUID_COLLISION_THROW);
$session->save();
$liveSession->importXml('/', $initializerDumpLive, ImportUUIDBehaviorInterface::IMPORT_UUID_COLLISION_THROW);
$liveSession->save();
return;
}
$filesystem = new Filesystem();
if (!$filesystem->exists(dirname($initializerDump))) {
$filesystem->mkdir(dirname($initializerDump));
}
$this->getContainer()->get('sulu_document_manager.initializer')->initialize();
$handle = fopen($initializerDump, 'w');
$liveHandle = fopen($initializerDumpLive, 'w');
$session->exportSystemView('/cmf', $handle, false, false);
$liveSession->exportSystemView('/cmf', $liveHandle, false, false);
fclose($handle);
self::$workspaceInitialized = true;
}