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

Feature Request: Allow saving #62

Open Defcon0 opened 4 years ago

Defcon0 commented 4 years ago

Hello,

we integrated DC_Multilingual in many projects now. It works just fine. Only one thing is quite a problem: the disallowing of saving (preventSaving) as described here.

I understand the problem (the record is merged from multiple records (the translations)).

Now I thought how we could solve this issue and one option would be to introduce a new method called saveUntranslatedRecord(). This method would work on the data retrieved from the database without taking into account the ranslations. In saveUntranslatedRecord() we would store the modified values merged with the untranslated values (retrieved from the database ignoring the translations) using an UPDATE.

I could also imagine that we wouldn't have to introduce a new saveUntranslatedRecord() but put this code into save(). Of course this would be BC breaking, but at the moment calling save() throws an error only.

What do you think? I could also write a pull request if you agree that this would be a way to deal with the limitation of not being able to save().

Thanks in advance.

Bye Defcon0

richardhj commented 4 years ago

What version are you using? preventSaving got removed in the latest major version.

Defcon0 commented 4 years ago

I have contao 4.4 and dc_multilingual 4.

The preventSaving is still in the master:

https://github.com/terminal42/contao-DC_Multilingual/blob/f43270eb857e9a8aef9ed9086ea618ab6106f1ae/src/Model/Multilingual.php#L224

Don‘t let it irritate you. $this->preventSaving(false); leads to prevent the model from save.

rabauss commented 4 years ago

We struggle with this problem on Contao 4.9 with Version 4, too :-( Is there any simple workaround? I guess we have to implement a solution like saveUntranslatedRecord

koertho commented 1 year ago

Gibt es hier schon Neuigkeiten?

Ich habe mir aktuell so in einer abstrakten Klasse beholfen (könnte man bei Mehrfachverwendung auch in einen Trait packen):

public function saveIfOriginal(): bool
{
    if (0 !== (int)$this->langPid) {
        return false;
    }

    $registry = Registry::getInstance();
    if ($this->id && !$registry->isRegistered($this)) {
        $registry->register($this);
    }

    $this->blnPreventSaving = false;
    $this->save();
    return true;
}