public function _migrateData(\b2db\Table $old_table) { switch ($old_table->getVersion()) { case 1: if ($res = $old_table->doSelectAll()) { $customdatatypes_table = TBGCustomDatatype::getB2DBTable(); $crit = $customdatatypes_table->getCriteria(); $crit->indexBy(TBGCustomFieldsTable::FIELD_KEY); $customfields = $customdatatypes_table->select($crit); while ($row = $res->getNextRow()) { $key = $row->get('customfieldoptions.customfield_key'); $customfield = array_key_exists($key, $customfields) ? $customfields[$key] : null; if ($customfield instanceof TBGCustomDatatype) { $crit = $this->getCriteria(); $crit->addUpdate(self::CUSTOMFIELD_ID, $customfield->getID()); $this->doUpdateById($crit, $row->get(self::ID)); } else { $this->doDeleteById($row->get(self::ID)); } } } break; } }
public function _migrateData(\b2db\Table $old_table) { switch ($old_table->getVersion()) { case 1: if ($res = $old_table->doSelectAll()) { $customfields = TBGCustomDatatype::getB2DBTable()->selectAll(); while ($row = $res->getNextRow()) { $customfield_id = $row->get(self::CUSTOMFIELDS_ID); $customfield = array_key_exists($customfield_id, $customfields) ? $customfields[$customfield_id] : null; if ($customfield instanceof TBGCustomDatatype && $customfield->hasCustomOptions()) { $customfieldoption = TBGCustomFieldOptionsTable::getTable()->getByValueAndCustomfieldID((int) $row->get(self::OPTION_VALUE), $customfield->getID()); if ($customfieldoption instanceof TBGCustomDatatypeOption) { $crit = $this->getCriteria(); $crit->addUpdate(self::CUSTOMFIELDOPTION_ID, $customfieldoption->getID()); $crit->addUpdate(self::OPTION_VALUE, null); $this->doUpdateById($crit, $row->get(self::ID)); } elseif ($row->get(self::ID)) { $this->doDeleteById($row->get(self::ID)); } } } } break; } }