private function getUserValue(Tracker_FormElement_Field $field, $value)
 {
     if (isset($value['format']) && (string) $value['format'] === self::FORMAT_ID) {
         return (string) $value;
     }
     if ($this->doesValueConcernUser($value)) {
         $user = $this->user_finder->getUser($value);
         if ($user->isAnonymous()) {
             return '';
         }
         return Tracker_FormElement_Field_OpenList::BIND_PREFIX . $user->getId();
     }
     return $field->getFieldData((string) $value);
 }
 /**
  * @param SimpleXMLElement $ugroup
  *
  * @return PFUser[]
  */
 private function getListOfUgroupMember(SimpleXMLElement $ugroup)
 {
     $ugroup_members = array();
     foreach ($ugroup->members->member as $xml_member) {
         $ugroup_members[] = $this->user_finder->getUser($xml_member);
     }
     return $ugroup_members;
 }
 /**
  * Extract Field data from XML input
  *
  * @param Tracker_FormElement_Field $field
  * @param SimpleXMLElement $field_change
  *
  * @return array
  */
 public function getFieldData(Tracker_FormElement_Field $field, SimpleXMLElement $field_change, PFUser $submitted_by)
 {
     $bind = (string) $field_change['bind'];
     $data = array();
     if ($bind === self::BIND_STATIC) {
         foreach ($field_change as $value) {
             $data[] = $this->getStaticListDataValue($field, $value);
         }
     } elseif ($bind === self::BIND_UGROUPS) {
         foreach ($field_change as $value) {
             $data[] = $this->getUgroupListDataValue($value);
         }
     } else {
         foreach ($field_change as $value) {
             $user = $this->user_finder->getUser($value);
             $data[] = $user->getId();
         }
     }
     return $data;
 }
Example #4
0
 private function importFile(Project $project, FRSRelease $release, PFUser $user, SimpleXMLElement $xml_file, $extraction_path)
 {
     $user = empty($xml_file->user) ? $user : $this->user_finder->getUser($xml_file->user);
     $attrs = $xml_file->attributes();
     $src = $extraction_path . '/' . $attrs['src'];
     $name = isset($attrs['name']) ? (string) $attrs['name'] : basename($src);
     $md5 = strtolower(md5_file($src));
     $time = strtotime($attrs['release-time']);
     $date = strtotime($attrs['post-date']);
     $desc = "";
     $type_id = $this->getFileTypeDao()->searchTypeId($attrs['filetype']);
     if (is_null($type_id)) {
         throw new Exception("Invalid filetype '{$attrs['filetype']}'");
     }
     $proc_id = $this->getProcessorDao()->searchProcessorId($project->getID(), $attrs['arch']);
     if (is_null($proc_id)) {
         throw new Exception("Invalid architecture '{$attrs['arch']}'");
     }
     foreach ($xml_file->children() as $elem) {
         if ($elem->getName() != "description") {
             continue;
         }
         $desc .= (string) $elem;
     }
     if (isset($attrs['md5sum'])) {
         $expected_md5 = strtolower($attrs['md5sum']);
         if ($expected_md5 != $md5) {
             throw new Exception("Import of file {$src} failed because the file is corrupted " . "(expected MD5 {$expected_md5}, got {$md5})");
         }
     }
     $dirPath = $this->file_factory->getSrcDir($project);
     $dest = "{$dirPath}/{$name}";
     if (!copy($src, $dest)) {
         throw new Exception("Could not copy {$src} to {$dest}");
     }
     $newFile = new FRSFile();
     $newFile->setGroup($project);
     $newFile->setRelease($release);
     $newFile->setFileName($name);
     $newFile->setProcessorID($proc_id);
     $newFile->setTypeID($type_id);
     $newFile->setReferenceMd5($md5);
     $newFile->setComputedMd5($md5);
     $newFile->setUserId($user->getId());
     $newFile->setComment($desc);
     $newFile->setReleaseTime($time);
     $newFile->setPostDate($date);
     $this->file_factory->createFile($newFile);
 }
Example #5
0
 private function getSubmittedBy(SimpleXMLElement $xml_changeset)
 {
     return $this->user_finder->getUser($xml_changeset->submitted_by);
 }
 /**
  * Creates a Field_List_Bind Object
  *
  * @param SimpleXMLElement          $xml         containing the structure of the imported bind
  * @param Tracker_FormElement_Field $field       to which the bind is attached
  * @param array                     &$xmlMapping where the newly created formElements indexed by their XML IDs are stored
  *
  * @return Tooltip Object
  */
 public function getInstanceFromXML($xml, $field, &$xmlMapping, User\XML\Import\IFindUserFromXMLReference $user_finder)
 {
     $row = array('type' => (string) $xml['type'], 'field' => $field, 'default_values' => null, 'decorators' => null);
     if (isset($xml->decorators)) {
         $row['decorators'] = array();
         foreach ($xml->decorators->decorator as $deco) {
             $ID = (string) $deco['REF'];
             $row['decorators'][$ID] = $this->getDecoratorInstance($field, $ID, (int) $deco['r'], (int) $deco['g'], (int) $deco['b']);
         }
     }
     $type = (string) $xml['type'];
     switch ($type) {
         case self::STATIK:
             $row['is_rank_alpha'] = (int) $xml['is_rank_alpha'];
             $values = array();
             if ($xml->items->item) {
                 $i = 0;
                 foreach ($xml->items->item as $item) {
                     $ID = (string) $item['ID'];
                     $description = '';
                     if (isset($item->description)) {
                         $description = (string) $item->description;
                     }
                     $is_hidden = isset($item['is_hidden']) && (int) $item['is_hidden'] ? 1 : 0;
                     $values[$ID] = $this->getStaticValueInstance($ID, (string) $item['label'], $description, $i++, $is_hidden);
                     $xmlMapping[$ID] = $values[$ID];
                 }
             }
             $row['values'] = $values;
             break;
         case self::USERS:
             $values = array();
             if ($xml->items->item) {
                 foreach ($xml->items->item as $item) {
                     $values[] = (string) $item['label'];
                 }
             }
             $row['value_function'] = implode(',', $values);
             break;
         case self::UGROUPS:
             $values = array();
             if ($xml->items->item) {
                 foreach ($xml->items->item as $item) {
                     $ugroup = $this->ugroup_manager->getUGroupByName($field->getTracker()->getProject(), (string) $item['label']);
                     if ($ugroup) {
                         $ID = (string) $item['ID'];
                         $is_hidden = isset($item['is_hidden']) && (int) $item['is_hidden'] ? 1 : 0;
                         $values[$ID] = new Tracker_FormElement_Field_List_Bind_UgroupsValue($ID, $ugroup, $is_hidden);
                         $xmlMapping[$ID] = $values[$ID];
                     }
                 }
             }
             $row['values'] = array_filter($values);
             break;
         default:
             break;
     }
     if (isset($xml->default_values)) {
         $row['default_values'] = array();
         foreach ($xml->default_values->value as $default_value) {
             if (isset($default_value['REF'])) {
                 $ID = (string) $default_value['REF'];
                 if (isset($xmlMapping[$ID])) {
                     $row['default_values'][$ID] = $xmlMapping[$ID];
                 }
             } else {
                 $user = $user_finder->getUser($default_value);
                 $row['default_values'][$user->getId()] = new Tracker_FormElement_Field_List_Bind_UsersValue($user->getId());
             }
         }
     }
     return $this->getInstanceFromRow($row);
 }