How to avoid TYPO3 caching of table mapping for the whole multi website installation?

487 views Asked by At

I have one TYPO3 installation 7.6.22 with different websites, each in own page trees.

In an own extension normally a certain object is persisted in table tx_myextension_domain_model_name.

But for one website A I need to map this object on another table A. So I defined the typoscript config.tx_extbase.persistence.classes.MyVendor\Myextension\Domain\Model\Name.mapping ... in a separate extension especially for this website A.

This works but its not possible at the moment to have both mappings parallel.

If I - after clearing all caches - load the plugin in the frontend of website A, all other websites have the mapping on table A (and not on tx_myextension_domain_model_name).

If I - after clearing all caches - load the plugin in the frontend of one of the other websites, everything is ok on this website, but website A produces an error, because some processes doesn't work with the default table tx_myextension_domain_model_name.

So obviously somewhere the mapping configuration is cached for the whole installation, not on a per website base. Is that a bug or a feature? And is there a way to work around?

3

There are 3 answers

1
Artur Cichosz On BEST ANSWER

Take a look at this issue in TYPO3 forge and my comment at the very bottom.

https://forge.typo3.org/issues/75399#change-337355

Clearly: You need to disable the property mapper cache. In your AdditionalConfiguration.php file add the following.

$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['extbase_datamapfactory_datamap']['backend'] = 'TYPO3\CMS\Core\Cache\Backend\NullBackend';

This will cost you probably some performance, but I do not think it will be that much. But you will be able to configure different mappings for different sites using (local) TypoScript setup.

1
Bernd Wilke πφ On

In one installation you only can use one set of classes/ PHP sources/ extensions.
If you want different behaviour you need to insert conditions. you might split usage in your controller, and you might do some twists to split it in your repository. BUt I think that could be very complicated.

Probably the cleanest solution is to use another data domain with it's own data records.

4
René Pflamm On

Should it only another table to seperate the entries? Why not working with the pid field to define different storages for different pages?

If it should different source code, then "simple" copy this extension and rename it.

Edit:

You can also use different domain models per website, so you have different repositories and tables for each domain.

Extend you main model to an new model (Model1DomainB extends Model1()) and copy the sql in ext_tables.sql to create the new table (tx_extension_domain_model_model1domainb).

Now set an setting to your plugin to define an switchable value:

plugin.tx_extension.settings.domain = b

And in your controller you can make an switch to use the correct repository:

switch ($this->settings['domain']) {
  case 'b':
    $models = $this->model1DomainBRepository->findAll();
  case 'c':
    $models = $this->model1DomainCRepository->findAll();
  case 'd':
    $models = $this->model1DomainDRepository->findAll();
  default:
    $models = $this->model1Repository->findAll();
    break;
}