/** * */ public function editAttribute($pa_values, $pa_options = null) { if (!$this->getPrimaryKey()) { return null; } $vb_already_in_transaction = $this->inTransaction(); if (!$vb_already_in_transaction) { $o_trans = new Transaction(); $this->setTransaction($o_trans); } else { $o_trans = $this->getTransaction(); } unset(ca_attributes::$s_get_attributes_cache[$this->get('table_num') . '/' . $this->get('row_id')]); $this->setMode(ACCESS_WRITE); $this->set('locale_id', $pa_values['locale_id']); $this->update(); if ($this->numErrors()) { if (!$vb_already_in_transaction) { $o_trans->rollback(); } $vs_errors = join('; ', $this->getErrors()); $this->clearErrors(); $this->postError(1971, $vs_errors, 'ca_attributes->editAttribute()'); return false; } $t_attr_val = new ca_attribute_values(); $t_attr_val->purify($this->purify()); $t_attr_val->setTransaction($o_trans); $t_attr_val->setMode(ACCESS_WRITE); $t_element = ca_attributes::getElementInstance($this->get('element_id')); $va_elements = $t_element->getElementsInSet(); $va_attr_vals = $this->getAttributeValues(); foreach ($va_attr_vals as $o_attr_val) { $vn_element_id = intval($o_attr_val->getElementID()); if ($t_attr_val->load($o_attr_val->getValueID())) { if (isset($pa_values[$vn_element_id])) { $vm_value = $pa_values[$vn_element_id]; } else { $vm_value = $pa_values[$o_attr_val->getElementCode()]; } if ($t_attr_val->editValue($vm_value, $pa_options) === false) { $this->postError(1973, join('; ', $t_attr_val->getErrors()), 'ca_attributes->editAttribute()'); } foreach ($va_elements as $vn_i => $va_element_info) { if ($va_element_info['element_id'] == $vn_element_id) { unset($va_elements[$vn_i]); } } } } $vn_attribute_id = $this->getPrimaryKey(); // Add values that don't already exist (added after the fact?) foreach ($va_elements as $vn_index => $va_element) { if ($va_element['datatype'] == 0) { continue; } // skip containers $vn_element_id = $va_element['element_id']; if (isset($pa_values[$vn_element_id])) { $vm_value = $pa_values[$vn_element_id]; } else { $vm_value = $pa_values[$va_element['element_code']]; } if ($t_attr_val->addValue($vm_value, $va_element, $vn_attribute_id, $pa_options) === false) { $this->postError(1972, join('; ', $t_attr_val->getErrors()), 'ca_attributes->editAttribute()'); break; } } if ($this->numErrors()) { if (!$vb_already_in_transaction) { $o_trans->rollback(); } return false; } if (!$vb_already_in_transaction) { $o_trans->commit(); } return true; }
public static function reload_service_values($po_opts = null) { $va_infoservice_elements = ca_metadata_elements::getElementsAsList(false, null, null, true, false, false, array(__CA_ATTRIBUTE_VALUE_INFORMATIONSERVICE__)); $o_db = new Db(); foreach ($va_infoservice_elements as $va_element) { $qr_values = $o_db->query("\n\t\t\t\t\tSELECT * FROM ca_attribute_values\n\t\t\t\t\tWHERE element_id = ?\n\t\t\t\t", $va_element['element_id']); print CLIProgressBar::start($qr_values->numRows(), "Reloading values for element code " . $va_element['element_code']); $t_value = new ca_attribute_values(); while ($qr_values->nextRow()) { $o_val = new InformationServiceAttributeValue($qr_values->getRow()); $vs_uri = $o_val->getUri(); print CLIProgressBar::next(); // inc before first continuation point if (!$vs_uri || !strlen($vs_uri)) { continue; } if (!$t_value->load($qr_values->get('value_id'))) { continue; } $t_value->editValue($vs_uri); if ($t_value->numErrors() > 0) { print _t('There were errors updating an attribute row: ') . join(' ', $t_value->getErrors()); } } print CLIProgressBar::finish(); } return true; }