/** * add_file_from_multi * * @access public * @param $file_data * @param $uploaded_file * @param $member_ids * @return file id */ function add_file_from_multi($file_data, $uploaded_file, $member_ids, $upload_option) { try { if ($upload_option != -1) { $file = ProjectFiles::findById($upload_option); } else { $file = new ProjectFile(); } $type = array_var($file_data, 'type'); $file->setType($type); $file->setFilename(array_var($file_data, 'name')); $file->setFromAttributes($file_data); $file->setIsVisible(true); $file->setAttachToNotification(array_var($file_data, 'attach_to_notification')); if (array_var($file_data, 'default_subject_sel') == 'subject') { $file->setDefaultSubject(array_var($file_data, 'default_subject_text')); } else { $file->setDefaultSubject(''); } DB::beginWork(); $file->save(); if ($file->getType() == ProjectFiles::TYPE_DOCUMENT) { // handle uploaded file $revision_comment = array_var($file_data, 'revision_comment'); $revision = $file->handleUploadedFile($uploaded_file, true, $revision_comment); // handle uploaded file @unlink($uploaded_file['tmp_name']); } $object_controller = new ObjectController(); //$member_ids = json_decode(array_var($_POST, 'members')); if (count($member_ids) > 0 || !array_var($file_data, 'composing_mail')) { $object_controller->add_to_members($file, $member_ids); } $object_controller->add_subscribers($file, array('user_' . logged_user()->getId() => '1')); //If New file if ($upload_option == -1) { //Add links $object_controller->link_to_new_object($file); $object_controller->add_subscribers($file); if (!array_Var($file_data, 'composing_mail')) { $object_controller->add_custom_properties($file); } } DB::commit(); set_user_config_option('notify_myself_too', array_var($file_data, 'notify_myself_too')); if (array_var($file_data, 'notify_myself_too')) { logged_user()->notify_myself = true; } ApplicationLogs::createLog($file, ApplicationLogs::ACTION_ADD); if (array_var($file_data, 'notify_myself_too')) { logged_user()->notify_myself = false; } return $file->getId(); } catch (Exception $e) { DB::rollback(); Logger::log("Error when uploading file: " . $e->getMessage() . "\n" . $e->getTraceAsString()); // If we uploaded the file remove it from repository if (isset($revision) && $revision instanceof ProjectFileRevision && FileRepository::isInRepository($revision->getRepositoryId())) { FileRepository::deleteFile($revision->getRepositoryId()); } // if flash_error($e->getMessage()); } // try }