/** * Extract Field data from XML input * * @param Tracker_FormElement_Field $field * @param SimpleXMLElement $field_change * * @return mixed */ public function getFieldData(Tracker_FormElement_Field $field, SimpleXMLElement $field_change) { $values = $field_change->value; $files_infos = array(); if ($this->isFieldChangeEmpty($values)) { $this->logger->warn('Skipped attachment field ' . $field->getLabel() . ': field value is empty.'); return $files_infos; } foreach ($values as $value) { try { $attributes = $value->attributes(); $file_id = (string) $attributes['ref']; $file = $this->files_importer->getFileXML($file_id); if (!$this->files_importer->fileIsAlreadyImported($file_id)) { $files_infos[] = $this->getFileInfoForAttachment($file); $this->files_importer->markAsImported($file_id); } } catch (Tracker_Artifact_XMLImport_Exception_FileNotFoundException $exception) { $this->logger->warn('Skipped attachment field ' . $field->getLabel() . ': ' . $exception->getMessage()); } } if ($this->itCannotImportAnyFiles($values, $files_infos)) { throw new Tracker_Artifact_XMLImport_Exception_NoValidAttachementsException(); } return $files_infos; }
protected function getFullRESTRepresentation($value) { $classname_with_namespace = 'Tuleap\\Tracker\\REST\\Artifact\\ArtifactFieldValueFullRepresentation'; $artifact_field_value_full_representation = new $classname_with_namespace(); $artifact_field_value_full_representation->build($this->field->getId(), Tracker_FormElementFactory::instance()->getType($this->field), $this->field->getLabel(), $value); return $artifact_field_value_full_representation; }
function testValidateSubmitFieldRequiredNotSubmittedNoDefaultValue() { stub($this->field1)->isValid()->returns(false); stub($this->field1)->userCanSubmit()->returns(true); stub($this->field1)->isRequired()->returns(true); stub($this->field1)->hasDefaultValue()->returns(false); stub($this->field2)->isValid()->returns(true); stub($this->field3)->isValid()->returns(true); stub($this->workflow)->validate()->returns(true); $GLOBALS['Language']->expectOnce('getText', array('plugin_tracker_common_artifact', 'err_required', $this->field1->getLabel() . ' (' . $this->field1->getName() . ')')); $fields_data = array(); $this->assertFalse($this->initial_changeset_fields_validator->validate($this->artifact, $fields_data)); }