Skip to content

Commit

Permalink
Prevent errors when try to download Trello Attachments (401 Response)
Browse files Browse the repository at this point in the history
  • Loading branch information
wiltonsr committed Nov 8, 2021
1 parent 2e55a31 commit 24bf9fc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
19 changes: 16 additions & 3 deletions Controller/TrelloJSON2KanboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function save()
$comment_id = $this->commentModel->create($values);
}

if (sizeof($task->attachments) > 0 and $this->is_trello_connected()) {
if (sizeof($task->attachments) > 0 && $this->is_trello_connected()) {
foreach ($task->attachments as $attachment) {
$values = array(
'task_id' => $task_id,
Expand All @@ -119,10 +119,21 @@ public function save()
//return file in variable
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
$data = curl_exec($ch); //get curl response
if ($data !== false) {
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); //get curl response http status code
/*
*TODO: add support for download attachments from Trello
* currently file download requests return 401
*/
if ($data !== false && ($status_code>=200 && $status_code<300)) {
//creating attachment
$attachment_id = $this->taskFileModel->uploadContent($task_id, $attachment->filename, base64_encode($data));
} else {
// cant upload attachment, add a comment with infos
$values += array('comment' => t('Cant Download Attachment: %s Link: %s Http Response Status Code: %d', $attachment->filename, $attachment->url, $status_code));
//creating comment
$comment_id = $this->commentModel->create($values);
}
curl_close($ch);
} else {
Expand Down Expand Up @@ -198,7 +209,9 @@ private function is_trello_connected()

curl_close($curlInit);

if ($response) return true;
if ($response) {
return true;
}

return false;
}
Expand Down
1 change: 1 addition & 0 deletions Locale/pt_BR/translations.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
'Please select a JSON file.' => 'Por favor, selecione o arquivo JSON.',
'Unable to parse JSON file. Error: %s' => 'Incapaz de analisar o arquivo json. Erro: %s',
'Attachment exceeds the upload limit: %s' => 'O anexo excede o limite de upload: %s',
'Cant Download Attachment: %s Link: %s Http Response Status Code: %d Reason: %s' => 'Não foi possível realizar o Download do Anexo: %s Link: %s Código de Resposta Http: %d Motivo: %s',
'Attachment is just a link: %s' => 'O anexo é apenas um link: %s',
'Your project have been imported successfully.' => 'Seu projeto foi importado com sucesso.',
'Unable to import your project.', 'Não é possível importar seu projeto.',
Expand Down
2 changes: 1 addition & 1 deletion Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function getPluginAuthor()

public function getPluginVersion()
{
return '1.2.2';
return '1.3.0';
}

public function getPluginHomepage()
Expand Down
2 changes: 1 addition & 1 deletion Template/json_import/create.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<ul>
<li><?= t('Your file must use the JSON format') ?></li>
<li><?= t('The JSON file must contain the keys: name, lists, cards, checklists and actions') ?></li>
<li><?= $trello_connection ? t('Internet connection detected. Attachments will be downloaded automatically') : t('Internet connection not detected. Attachments will not be downloaded automatically') ?></li>
<li><?= $trello_connection ? t('Internet connection detected. An attempt to download the attachments automatically will be made') : t('Internet connection not detected. Attachments will not be downloaded automatically') ?></li>
<li><?= t('If the attachment exceeds the upload limit, a comment with its link will be created') ?></li>
<li><?= t('Your user will be the author of the imported comments') ?></li>
<li><?= t('Your attachments that are links will be imported as comments') ?></li>
Expand Down

0 comments on commit 24bf9fc

Please sign in to comment.