Sulu 3 runs on Symfony 7.4 and stores content with Doctrine ORM instead of PHPCR. Pages, articles and snippets have a draft row and a live row per language. Change them through messages with EnableFlushStamp, not by SQL. Admin and website are two contexts with their own cache.
Series 5: Sulu for developers Chapter 1 of 16
Sulu 3 at a glance
In short
Sulu 3 is a Symfony application in which the admin and the website live together in one project. This chapter shows what it consists of and where you step in. The details apply to Sulu 3.0.11, the version of the example website bertrams-media.
The framework
The project runs on PHP 8.2 or later and Symfony 7.4. The composer.lock of the example website lists sulu/sulu 3.0.11, symfony/framework-bundle 7.4.19 and doctrine/orm 3.7.2. Search is handled by the SEAL library (cmsig/seal 0.12.16). The former MassiveSearchBundle is gone; search lives in the package search.
The packages
The core lives in vendor/sulu/sulu/packages: content, page, article, snippet, route, search and custom-url. The package content is the common foundation. Pages, articles and snippets build on it, and route manages their addresses.
Each package has four layers: Domain, Application, Infrastructure and UserInterface. Which layer may use which other layer is defined in the package's deptrac.yaml. Media, contacts, users, categories and tags live as classic bundles under vendor/sulu/sulu/src/Sulu/Bundle.
No more PHPCR
Sulu 2 stored content in a PHPCR repository. Sulu 3 uses Doctrine ORM entities instead. The Document Manager is gone. According to the upgrade notes in UPGRADE-3.x.md, you read content through the repositories of the packages, for example with PageRepositoryInterface::getOneBy(['uuid' => $uuid]). Creating, changing, publishing and deleting all go through messages.
Draft and published
A page consists of several rows. The table pa_pages holds the page itself with its UUID and its place in the tree. The content lives in pa_page_dimension_contents, with one row per language and per stage. The stage is draft or live (DimensionContentInterface::STAGE_DRAFT and STAGE_LIVE), and the current draft has version 0 (CURRENT_VERSION). For articles the table is called ar_article_dimension_contents, and the column with the UUID is articleUuid.
This is how you see the state of a page in each language:
SELECT locale, stage, version, templateKey, workflowPlace
FROM pa_page_dimension_contents
WHERE pageUuid = 'UUID-of-the-page'
ORDER BY locale, stage, version;
Do not write to these tables by SQL. Routes, search index, cache and activity log only follow if the change goes through Sulu, that is, through messages.
Changing content by message
Each package ships its own messages. For articles these are CreateArticleMessage, ModifyArticleMessage, RemoveArticleMessage, CopyArticleMessage and ApplyWorkflowTransitionArticleMessage. Pages and snippets have matching messages with Page or Snippet in the name, and pages also have MovePageMessage and OrderPageMessage.
The bus is called sulu_message_bus. Send the message in an Envelope with an EnableFlushStamp. Only then does the DoctrineFlushMiddleware from the package sulu/messenger write the change to the database.
<?php
use Sulu\Content\Domain\Model\WorkflowInterface;
use Sulu\Messenger\Infrastructure\Symfony\Messenger\FlushMiddleware\EnableFlushStamp;
use Sulu\Page\Application\Message\ApplyWorkflowTransitionPageMessage;
use Symfony\Component\Messenger\Envelope;
// $messageBus is the service "sulu_message_bus"
$messageBus->dispatch(new Envelope(
new ApplyWorkflowTransitionPageMessage(['uuid' => $uuid], $locale, WorkflowInterface::WORKFLOW_TRANSITION_PUBLISH),
[new EnableFlushStamp()],
));
Admin and website
A project runs in two contexts. public/index.php starts SuluKernel::CONTEXT_ADMIN if the path begins with /admin, and CONTEXT_WEBSITE otherwise. On the console, the script decides: bin/adminconsole and bin/console run in the admin context, bin/websiteconsole in the website context. In the example website, bin/console also warns at startup that it runs in the admin context.
Each context has its own cache directory (SuluKernel::getCacheDir()). That is why the auto-scripts in composer.json contain both calls: cache:clear and bin/websiteconsole cache:clear.
php bin/adminconsole cache:clear
php bin/websiteconsole cache:clear