terminal42 / contao-DC_Multilingual

A multilingual DC driver storing the translations in the same table for Contao Open Source CMS
17 stars 8 forks source link

preserve dynamicPtable for languageChildren #57

Closed rabauss closed 5 years ago

rabauss commented 5 years ago

We had some trouble with DC Multilingual and dynamicPtable. Unfortunately the ptable will not preserved for the languageChildren. And so the children could get deleted by DC_Table -> reviseTable, if you have an sql default for the ptable field! If I think again about it, then the following problem would not occur with empty default for ptable.

For the insert the ptable should also get loaded and set - somewhere here: https://github.com/terminal42/contao-DC_Multilingual/blob/35fe458c1b3bc1fced8461ad9f0ec36735f3ba6f/src/Driver.php#L1211

On the update of tstamp the ptable will only get set on the primary language (because $this->id is not the language ID) https://github.com/terminal42/contao-DC_Multilingual/blob/35fe458c1b3bc1fced8461ad9f0ec36735f3ba6f/src/Driver.php#L477

By the way the tstamp of the language child should always get an update there while updating the primary language, shouldn't it?

aschempp commented 5 years ago

Are you sure dynamicPtable is actually supported by DC_Multilingual?

qzminski commented 5 years ago

@rabauss can you check if 025b567 solves the problem for you?

By the way the tstamp of the language child should always get an update there while updating the primary language, shouldn't it?

I think it shouldn't be copied because tstamp reflects the last change of certain record (i.e. language record). So the language record could be edited in May and the main record in June. No need to sync that in my opinion.

rabauss commented 5 years ago

Well, our solution would look like this:

                if ($GLOBALS['TL_DCA'][$this->strTable]['config']['dynamicPtable']) {
                    $objCurrent = \Database::getInstance()->prepare(
                        "SELECT pid, ptable FROM ".$this->strTable." WHERE id=?"
                    )
                        ->limit(1)
                        ->execute($this->intId);

                    $intPid = ($objCurrent->numRows) ? $objCurrent->pid : 0;
                    $pTable = ($objCurrent->numRows) ? $objCurrent->ptable : '';
                    $intId = \Database::getInstance()->prepare(
                        "INSERT INTO ".$this->strTable." ({$this->pidColumnName},tstamp,{$this->langColumnName},pid,ptable) VALUES (?,?,?,?,?)"
                    )
                        ->execute($this->intId, time(), $language, $intPid, $pTable)
                        ->insertId;
                } else {

because the current entry has to be selected with ptable!

qzminski commented 5 years ago

Why is that if I may ask? $this->ptable should always match $objCurrent->ptable, no?

rabauss commented 5 years ago

Yes, you're right the ptable should match. But I think the variable was sometimes not set. I guess because in our DCA it's dynamic with something like that: 'ptable' => \Input::get('ptable') ?? '', and the get variable was not set on post reload of language selector. I'm not sure anymore but I had some struggle with that variable.

qzminski commented 5 years ago

If that was the case then the source of the problem must have been in a different place I think. When you have chance to find out the problem again, let me know. For now I will release my fix 👍🏻