Skip to content

Commit

Permalink
Changing number of iterations in JSON file to reduce procces time
Browse files Browse the repository at this point in the history
  • Loading branch information
wiltonsr committed Apr 28, 2019
1 parent b263c19 commit a5d58c8
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 41 deletions.
35 changes: 30 additions & 5 deletions Controller/TrelloJSON2KanboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,11 @@ public function save()
$this->columnModel->remove($column['id']);
}

//getting columns from JSON file
foreach ($project->columns as $column) {
//creating column
$column_id = $this->columnModel->create($project_id, $column->name, 0, '', 0);

//getting tasks from JSON file
foreach ($column->tasks as $task) {
//only get cards that belongs to this column
$values = array(
'title' => $task->name,
'project_id' => $project_id,
Expand All @@ -84,7 +81,6 @@ public function save()
//creating task
$task_id = $this->taskCreationModel->create($values);

//getting checklists from JSON file
foreach ($task->subtasks as $subtask) {
$values = array(
'title' => $subtask->content,
Expand All @@ -96,7 +92,6 @@ public function save()
}

foreach ($task->comments as $comment) {
//only get actions from commentCard type
$values = array(
'task_id' => $task_id,
'user_id' => $this->userSession->getId(),
Expand All @@ -105,6 +100,36 @@ public function save()
//creating comment
$comment_id = $this->commentModel->create($values);
}

if (sizeof($task->attachments) > 0 and $this->is_trello_connected()) {
foreach ($task->attachments as $attachment) {
$values = array(
'task_id' => $task_id,
'user_id' => $this->userSession->getId(),
);
//only get attachments that are uploaded files
$attachment_size = $this->retrieve_remote_file_size($attachment->url);
if ($attachment_size < $max_attachment_size) {
//here is the file we are downloading, replace spaces with %20
$ch = curl_init($attachment->url);
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
//return file in variable
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$data = curl_exec($ch); //get curl response
if ($data !== false) {
//creating attachment
$attachment_id = $this->taskFileModel->uploadContent($task_id, $attachment->filename, base64_encode($data));
}
curl_close($ch);
} else {
// cant upload attachment, add a comment with attachment link
$values += array('comment' => t('Attachment exceeds the upload limit: %s', $attachment->url));
//creating comment
$comment_id = $this->commentModel->create($values);
}
}
}
}
}
}
Expand Down
135 changes: 100 additions & 35 deletions Model/TrelloJSON2KanboardModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,47 +25,99 @@ public function parserJSON($jsonObj)
//creating column
$column = new Column($list->name, $list->id);
array_push($project->columns, $column);
}

foreach ($jsonObj->cards as $card) {
if ($card->closed) {
//ignore archived lists
continue;
}
if ($card->idList == $column->trello_id) {
$due_date = $card->due !== null ? date('Y-m-d H:i', strtotime($card->due)) : null;
$task = new Task($card->name, $card->id, $card->idList, $due_date, $card->desc);
array_push($column->tasks, $task);

//getting checklists from JSON file
foreach ($jsonObj->checklists as $checklist) {
if ($checklist->idCard == $card->id) {
foreach ($checklist->checkItems as $checkitem) {
$status = $checkitem->state == 'complete' ? 2 : 0;
//creating subtask
$subtask = new Subtask($checkitem->name, $status);
array_push($task->subtasks, $subtask);
}
}
}
foreach ($jsonObj->cards as $card) {
if ($card->closed) {
//ignore archived lists
continue;
}
$due_date = $card->due !== null ? date('Y-m-d H:i', strtotime($card->due)) : null;
$task = new Task($card->name, $card->id, $due_date, $card->desc);
$column_id = $this->card_column_id($project->columns, $card->idList);
if (!is_null($column_id)) {
array_push($project->columns[$column_id]->tasks, $task);
}

//getting actions from JSON file
foreach ($jsonObj->actions as $action) {
//only get actions from commentCard type
if ($action->type == 'commentCard') {
//only get comments that belongs to this card
if ($action->data->card->id == $task->trello_id) {
$comment = new Comment($action->data->text);
array_push($task->comments, $comment);
}
}
if ($card->badges->attachments > 0) {
foreach ($card->attachments as $att) {
//only get attachments that are uploaded files
if ($att->isUpload) {
$attachment = new Attachment($att->name, $att->url);
array_push($task->attachments, $attachment);
} else {
// just an url, add a comment
$comment = new Comment(t('Attachment is just a link: %s', $att->url));
array_push($task->comments, $comment);
}
}
}
}

//getting actions from JSON file
foreach ($jsonObj->actions as $action) {
//only get actions from commentCard type
if ($action->type == 'commentCard') {
//only get comments that belongs to this card
$values = $this->comment_card_id($project->columns, $action->data->card->id);
$comment = new Comment($action->data->text);
if (!is_null($values)) {
array_push($project->columns[$values['column_key']]->tasks[$values['task_key']]->comments, $comment);
}
}
}

foreach ($jsonObj->checklists as $checklist) {
//only get checklists that belongs to this card
$values = $this->checkitem_card_id($project->columns, $checklist->idCard);
if (!is_null($values)) {
foreach ($checklist->checkItems as $checkitem) {
$status = $checkitem->state == 'complete' ? 2 : 0;
$subtask = new Subtask($checkitem->name, $status);
array_push($project->columns[$values['column_key']]->tasks[$values['task_key']]->subtasks, $subtask);
}
}
}

return $project;
}

public function card_column_id($columns, $value)
{
foreach ($columns as $task_key => $card) {
if ($card->trello_id == $value) {
return $task_key;
}
}
}

public function comment_card_id($columns, $value)
{
foreach ($columns as $column_key => $column) {
foreach ($column->tasks as $task_key => $task) {
if ($task->trello_id == $value) {
return array(
'column_key' => $column_key,
'task_key' => $task_key,
);
}
}
}
}

public function checkitem_card_id($columns, $value)
{
foreach ($columns as $column_key => $column) {
foreach ($column->tasks as $task_key => $task) {
if ($task->trello_id == $value) {
return array(
'column_key' => $column_key,
'task_key' => $task_key,
);
}
}
}
}
}

class Project
Expand All @@ -83,30 +135,31 @@ class Column
{
var $name;
var $trello_id;
var $kanboard_id;
var $tasks = array();

function __construct($name, $trello_id)
function __construct($name, $trello_id, $kanboard_id = null)
{
$this->name = $name;
$this->trello_id = $trello_id;
$this->kanboard_id = $kanboard_id;
}
}

class Task
{
var $name;
var $trello_id;
var $trello_column_id;
var $date_due;
var $desc;
var $subtasks = array();
var $comments = array();
var $attachments = array();

function __construct($name, $trello_id, $trello_column_id, $date_due, $desc)
function __construct($name, $trello_id, $date_due, $desc)
{
$this->name = $name;
$this->trello_id = $trello_id;
$this->trello_column_id = $trello_column_id;
$this->date_due = $date_due;
$this->desc = $desc;
}
Expand All @@ -133,3 +186,15 @@ function __construct($content)
$this->content = $content;
}
}

class Attachment
{
var $filename;
var $url;

function __construct($filename, $url)
{
$this->filename = $filename;
$this->url = $url;
}
}
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.1.2';
return '1.2.0';
}

public function getPluginHomepage()
Expand Down

0 comments on commit a5d58c8

Please sign in to comment.