public function update()
 {
     if (sizeof($this->confirmed_objects)) {
         // we need the "old" options for the search
         $def = $this->getADTDefinition();
         $def = clone $def;
         $def->setOptions(array_combine($this->old_options, $this->old_options));
         $search = ilADTFactory::getInstance()->getSearchBridgeForDefinitionInstance($def, false, false);
         ilADTFactory::initActiveRecordByType();
         foreach ($this->confirmed_objects as $old_option => $item_ids) {
             // get complete old values
             $old_values = array();
             foreach ($this->findBySingleValue($search, $old_option) as $item) {
                 $old_values[$item[0] . "_" . $item[1] . "_" . $item[2]] = $item[3];
             }
             foreach ($item_ids as $item => $new_option) {
                 $parts = explode("_", $item);
                 $obj_id = $parts[0];
                 $sub_type = $parts[1];
                 $sub_id = $parts[2];
                 if (!$new_option) {
                     // remove existing value
                     $primary = array("obj_id" => array("integer", $obj_id), "sub_type" => array("text", $sub_type), "sub_id" => array("integer", $sub_id), "field_id" => array("integer", $this->getFieldId()));
                     ilADTActiveRecordByType::deleteByPrimary("adv_md_values", $primary, "MultiEnum");
                 } else {
                     // update existing value (with changed option)
                     if (isset($old_values[$item])) {
                         // find changed option in old value
                         $old_value = explode(ilADTMultiEnumDBBridge::SEPARATOR, $old_values[$item]);
                         // remove separators
                         array_shift($old_value);
                         array_pop($old_value);
                         $old_idx = array_keys($old_value, $old_option);
                         if (sizeof($old_idx)) {
                             // switch option
                             $old_idx = array_pop($old_idx);
                             $old_value[$old_idx] = $new_option;
                             $new_value = array_unique($old_value);
                             // add separators
                             $new_value = ilADTMultiEnumDBBridge::SEPARATOR . implode(ilADTMultiEnumDBBridge::SEPARATOR, $new_value) . ilADTMultiEnumDBBridge::SEPARATOR;
                             $primary = array("obj_id" => array("integer", $obj_id), "sub_type" => array("text", $sub_type), "sub_id" => array("integer", $sub_id), "field_id" => array("integer", $this->getFieldId()));
                             ilADTActiveRecordByType::writeByPrimary("adv_md_values", $primary, "MultiEnum", $new_value);
                         }
                     }
                 }
                 if ($sub_type == "wpg") {
                     // #15763 - adapt advmd page lists
                     include_once "Modules/Wiki/classes/class.ilPCAMDPageList.php";
                     ilPCAMDPageList::migrateField($obj_id, $this->getFieldId(), $old_option, $new_option, true);
                 }
             }
         }
         $this->confirmed_objects = array();
     }
     parent::update();
 }
 public function update()
 {
     parent::update();
     if (sizeof($this->confirmed_objects)) {
         ilADTFactory::initActiveRecordByType();
         foreach ($this->confirmed_objects as $old_option => $item_ids) {
             foreach ($item_ids as $item => $new_option) {
                 $item = explode("_", $item);
                 $obj_id = $item[0];
                 $sub_type = $item[1];
                 $sub_id = $item[2];
                 if (!$new_option) {
                     // remove existing value
                     $primary = array("obj_id" => array("integer", $obj_id), "sub_type" => array("text", $sub_type), "sub_id" => array("integer", $sub_id), "field_id" => array("integer", $this->getFieldId()));
                     ilADTActiveRecordByType::deleteByPrimary("adv_md_values", $primary, "Enum");
                 } else {
                     // update existing value
                     $primary = array("obj_id" => array("integer", $obj_id), "sub_type" => array("text", $sub_type), "sub_id" => array("integer", $sub_id), "field_id" => array("integer", $this->getFieldId()));
                     ilADTActiveRecordByType::writeByPrimary("adv_md_values", $primary, "Enum", $new_option);
                 }
                 if ($sub_type == "wpg") {
                     // #15763 - adapt advmd page lists
                     include_once "Modules/Wiki/classes/class.ilPCAMDPageList.php";
                     ilPCAMDPageList::migrateField($obj_id, $this->getFieldId(), $old_option, $new_option);
                 }
             }
         }
     }
 }