-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Issue Tracker] Redirect and error warning fixes #7323
Conversation
@maltheism I addressed your comments :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @laemtl, can you change the ajax/EditIssue.php to be the following:
// Attachment for new issue.
if (isset($_FILES['file'])) {
$attachment = new \LORIS\issue_tracker\UploadHelper();
$success = $attachment->setupUploading(
$user,
$_FILES,
[
'fileDescription' => '',
'issueID' => $issueID,
]
);
if (!$success) {
showError($attachment->errorMessage);
}
}
the uploadhelper.class.inc
/**
* The error message if something fails.
*/
public $errorMessage;
/**
* Setup uploading configurations.
*
* @param \User $user The user uploading.
* @param array $files The $_FILES array content.
* @param array $values The post message array content.
* @return boolean success/fail
*
*/
function setupUploading(\User $user, array $files, array $values) : bool
{
// Check if post.ini max_post configured for the file_size.
if (!isset($files['file']['tmp_name'])
|| empty($files['file']['tmp_name'])
) {
$this->errorMessage = 'The server is not configured to receive a file this large.';
return false;
}
$this->_user = $user;
$this->_bytes = $files['file']['size'];
$this->_values = $values;
$this->_fileToUpload
= (object) [
'file' => $files['file']['name'],
'file_hash' => $this->generateHash($files['file']['tmp_name']),
'mime_type' => $this->getFileMimeType($files['file']['name']),
'tmp_name' => $files['file']['tmp_name'],
'size' => $this->_bytes,
'inserted_by' => $this->_user->getData('UserID'),
'description' => $this->_values['fileDescription'] ?? '',
];
if(!$this->setFullPath($this->_fileToUpload)) {
$this->errorMessage = 'The server is not configured for attachments';
return false;
}
$DB = \NDB_Factory::singleton()->database();
$DB->beginTransaction();
$this->registerFile($this->_fileToUpload);
$this->endWithSuccess();
return true;
}
...
/**
* Sets $fileToUpload->full_path to be the full path
* of where the attachment file will be stored.
*
* @param object $fileToUpload The file to upload
*
* @return boolean success/fail
*/
function setFullPath(Object &$fileToUpload) : bool
{
$factory = \NDB_Factory::singleton();
$config = $factory->config();
$attachment_data_dir = trim(
rtrim(
$config->getSetting('IssueTrackerDataPath'),
'/'
)
);
if (is_writable($attachment_data_dir)) {
$fileToUpload->full_path = $attachment_data_dir .
'/attachments';
if (!is_dir($fileToUpload->full_path)) {
mkdir($fileToUpload->full_path, 0770, true);
}
return true;
}
return false;
}
I wanted to push the above changes but I think I don't have permission. The above gets the error message to display when the attachment fails for your swal. Everything else passed. :)
Fixes to address the comments on #7315