codefog / contao-haste

Haste is a collection of tools and classes to ease working with Contao
http://codefog.pl/extension/haste.html
MIT License
43 stars 24 forks source link

[v5] Relation tables are deleted while contao:migrate #187

Closed rabauss closed 1 year ago

rabauss commented 1 year ago

In a project we have defined some custom entities with many-to-many relations like this:

// contao/dca/tl_taxonomy.php
'relation' => [
    'type' => 'haste-ManyToMany',
    'load' => 'lazy',
    'table' => 'tl_content_teaser',
],

After upgrading to Haste v5 the command contao:migrate deletes all relation tables (e.g. DROP TABLE tl_content_teaser_taxonomy). In the contao install tool the deletions are not listed/executed only via console command! Our app bundle is loaded after CodefogHasteBundle!

What's the reason for this misbehavior? Is there a framework init missing?

rabauss commented 1 year ago

Okay the problem is that the $request object is not set while running contao:migrate so the hook sqlGetFromFile is not executed: https://github.com/codefog/contao-haste/blob/dc3cea999909e2b81fd03f13c0da27ed1fc19536/src/DcaRelationsManager.php#L359

How do we solve this correctly?

aschempp commented 1 year ago

that looks very weird, why would relations be tied to the request? 🤔

rabauss commented 1 year ago

Well, this was migrated from this logic: https://github.com/codefog/contao-haste/blob/f5de7fd1b13fa9afce41dc466860918dc40eb13b/config/config.php#L39

I'm not sure if the hook sqlGetFromFile even needs this restriction on backend

fritzmg commented 1 year ago

Yeah, this needs to be changed to:

if (null === $request || !$this->scopeMatcher->isFrontendRequest($request)) { 

The intention was (likely) to only execute it in the back end and on the CLI (or conversely: execute it anywhere but the front end).

rabauss commented 1 year ago

Ok, I'll add a PR

qzminski commented 1 year ago

I think we should not check for request at all. This was legacy stuff in Contao 3.