protected function doSave($con = null) { parent::doSave($con); $this->getObject()->getMailingList()->invalidateCache(); $choices_db = $this->getObject()->getMailingListMetaChoice(); $choices = $this->getObject()->getKind() == MailingListMeta::KIND_CHOICE ? $this->getValue('choices') : array(); $choices_lower = array_map('strtolower', $choices); $done = array(); foreach ($choices_db as $choice_db) { $lower = mb_strtolower($choice_db['choice'], 'utf-8'); $choice_key = array_search($lower, $choices_lower, true); if ($choice_key === false) { $choice_db->delete($con); } else { $done[] = $lower; if ($choices[$choice_key] !== $choice_db['choice']) { $choice_db['choice'] = $choices[$choice_key]; $choice_db->save($con); } } } foreach ($choices as $choice) { if (!in_array(mb_strtolower($choice, 'utf-8'), $done, true)) { $choice_db = new MailingListMetaChoice(); $choice_db->setMailingListMetaId($this->getObject()->getId()); $choice_db->setChoice($choice); $choice_db->save(); } } }