/** * Save the value and return the id * * @param Tracker_Artifact $artifact The artifact * @param int $changeset_value_id The id of the changeset_value * @param mixed $value The value submitted by the user * @param Tracker_Artifact_ChangesetValue $previous_changesetvalue The data previously stored in the db * * @return boolean */ protected function saveValue($artifact, $changeset_value_id, $value, Tracker_Artifact_ChangesetValue $previous_changesetvalue = null) { $save_ok = true; $success = array(); $dao = $this->getValueDao(); //first save the previous files if ($previous_changesetvalue) { $previous_fileinfo_ids = array(); foreach ($previous_changesetvalue as $previous_attachment) { if (empty($value['delete']) || !in_array($previous_attachment->getId(), $value['delete'])) { $previous_fileinfo_ids[] = $previous_attachment->getId(); } } if (count($previous_fileinfo_ids)) { $save_ok = $save_ok && $dao->create($changeset_value_id, $previous_fileinfo_ids); } } //Now save the new submitted files $current_user = UserManager::instance()->getCurrentUser(); $r = new Rule_File(); foreach ($value as $i => $file_info) { if ("{$i}" != 'delete' && $r->isValid($file_info)) { $temporary = new Tracker_Artifact_Attachment_TemporaryFileManager($this->getCurrentUser(), $this->getTemporaryFileManagerDao(), $this->getFileInfoFactory()); if (isset($file_info['id'])) { $temporary_file = $temporary->getFileByTemporaryName($file_info['id']); } if (isset($temporary_file)) { $attachment = new Tracker_FileInfo($temporary_file->getId(), $this, $current_user->getId(), trim($temporary_file->getDescription()), $temporary_file->getName(), $temporary_file->getSize(), $temporary_file->getType()); if ($this->createAttachmentForRest($attachment, $file_info)) { $success[] = $attachment->getId(); } } else { $attachment = new Tracker_FileInfo(null, $this, $current_user->getId(), trim($file_info['description']), $file_info['name'], $file_info['size'], $file_info['type']); if ($this->createAttachment($attachment, $file_info)) { $success[] = $attachment->getId(); } } } } if (count($success)) { $save_ok = $save_ok && $dao->create($changeset_value_id, $success); } return $save_ok; }
/** * Save the value and return the id * * @param Tracker_Artifact $artifact The artifact * @param int $changeset_value_id The id of the changeset_value * @param mixed $value The value submitted by the user * @param Tracker_Artifact_ChangesetValue $previous_changesetvalue The data previously stored in the db * * @return int or array of int */ protected function saveValue($artifact, $changeset_value_id, $value, Tracker_Artifact_ChangesetValue $previous_changesetvalue = null) { $success = array(); $dao = $this->getValueDao(); //first save the previous files if ($previous_changesetvalue) { $previous_fileinfo_ids = array(); foreach ($previous_changesetvalue as $previous_attachment) { if (empty($value['delete']) || !in_array($previous_attachment->getId(), $value['delete'])) { $previous_fileinfo_ids[] = $previous_attachment->getId(); } } if (count($previous_fileinfo_ids)) { $dao->create($changeset_value_id, $previous_fileinfo_ids); } } //Now save the new submitted files $current_user = UserManager::instance()->getCurrentUser(); $r = new Rule_File(); foreach ($value as $i => $file_info) { if ("{$i}" != 'delete' && $r->isValid($file_info)) { if ($attachment = Tracker_FileInfo::create($this, $current_user->getId(), trim($file_info['description']), $file_info['name'], $file_info['size'], $file_info['type'])) { $path = $this->getRootPath(); if (!is_dir($path . '/thumbnails')) { mkdir($path . '/thumbnails', 0777, true); } $filename = $path . '/' . $attachment->getId(); if (move_uploaded_file($file_info['tmp_name'], $filename)) { $success[] = $attachment->getId(); //If image, store thumbnails if ($attachment->isImage()) { $this->createThumbnail($attachment->getId(), $path, $filename); } } else { //Something goes wrong //delete the attachment Tracker_FileInfo::delete($attachment); } } } } if (count($success)) { $dao->create($changeset_value_id, $success); } return $success; }