class TranslationConverter (View source)

Migrate a field that has become translated or changed its translation strategy.

To avoid problems with large repositories, the converter is operating in a batched mode. Call it repeatedly and call flush and clear between calls.

You need to call save() on the PHPCR session, rather than flush() on the document maanger. To avoid unexpected results, it is recommended to clear() the document manager before starting to convert and after having saved the PHPCR session.

Methods

__construct(DocumentManagerInterface $dm, int $batchSize = 200)

No description

bool
convert(string $class, array $locales, array $fields = [], string $previousStrategyName = NonTranslatedStrategy::NAME)

Migrate content into the new translation format and remove the old properties.

array
getLastNotices()

Get list of child documents that had to be skipped because their class was not an exact match with the class being converted.

Details

__construct(DocumentManagerInterface $dm, int $batchSize = 200)

Parameters

DocumentManagerInterface $dm
int $batchSize

bool convert(string $class, array $locales, array $fields = [], string $previousStrategyName = NonTranslatedStrategy::NAME)

Migrate content into the new translation format and remove the old properties.

This does not commit the changes to the repository. Call save on the PHPCR session after each batch. Calling flush on the document manager is not enough.

When translating, the new properties are copied into the languages specified in $locales. When un-translating, the current locale and language fallback is used, and $locales is ignored.

To convert all fields into a translation, you can pass an empty array for $fields and the information is read from the metadata. The fields are mandatory when converting fields back to non-translated.

To convert a single field from translated to non-translated, simply specify that field.

If you convert an existing translation, you need to specify the name of the strategy that was previously used. The name is the one you would use for DocumentManagerInterface::getTranslationStrategy, so "attribute" or "child".

The current strategy is read from the document metadata.

Only documents that match $class exactly are converted, but not descendants. You can query whether there where documents encountered that could not be converted by calling getLastNotices() after each call to convert().

Parameters

string $class FQN of the document class
array $locales Locales to copy previously untranslated fields into. Ignored when untranslating a document.
array $fields List of fields to convert. Required when making a field not translated anymore
string $previousStrategyName Name of previous strategy or "none" if field was not previously translated

Return Value

bool true if there are more documents to convert and this method needs to be called again.

Exceptions

PHPCRExceptionInterface if the document can not be found.

See also

getLastNotices()

array getLastNotices()

Get list of child documents that had to be skipped because their class was not an exact match with the class being converted.

Return Value

array Map of path => class