Task CSV import is now able to handle more fields

Add support for the priority, start date, tags and one external link.
This commit is contained in:
Frederic Guillot 2017-11-14 15:39:43 -08:00
parent f6d7791ddc
commit 95cdeed472
35 changed files with 366 additions and 77 deletions

View File

@ -4,7 +4,7 @@ Version 1.x (unreleased)
Breaking changes:
* Remove feature "Allow everybody to access to this project" (You must define members and groups)
* Composer dependencies are now included in the repository (except development dependencies)
* Composer dependencies are now included in the repository to be able to use git-archive (except development dependencies)
New features:
@ -13,6 +13,7 @@ New features:
Improvements:
* Task CSV import is now able to handle the priority, start date, tags and one external link
* Improve iCalendar feed to include tasks with start/end date and due date with a time
* Check if the start date is before due date
* You can get an archive of Kanboard by using the download button in Github or the command git archive

View File

@ -3,6 +3,7 @@
namespace Kanboard\Controller;
use Kanboard\Core\Csv;
use Kanboard\Import\TaskImport;
/**
* Task Import controller
@ -45,14 +46,15 @@ class TaskImportController extends BaseController
if (! file_exists($filename)) {
$this->show($values, array('file' => array(t('Unable to read your file'))));
} else {
$this->taskImport->projectId = $project['id'];
$taskImport = new TaskImport($this->container);
$taskImport->setProjectId($project['id']);
$csv = new Csv($values['delimiter'], $values['enclosure']);
$csv->setColumnMapping($this->taskImport->getColumnMapping());
$csv->read($filename, array($this->taskImport, 'import'));
$csv->setColumnMapping($taskImport->getColumnMapping());
$csv->read($filename, array($taskImport, 'importTask'));
if ($this->taskImport->counter > 0) {
$this->flash->success(t('%d task(s) have been imported successfully.', $this->taskImport->counter));
if ($taskImport->getNumberOfImportedTasks() > 0) {
$this->flash->success(t('%d task(s) have been imported successfully.', $taskImport->getNumberOfImportedTasks()));
} else {
$this->flash->failure(t('Nothing have been imported!'));
}
@ -67,7 +69,8 @@ class TaskImportController extends BaseController
*/
public function template()
{
$taskImport = new TaskImport($this->container);
$this->response->withFileDownload('tasks.csv');
$this->response->csv(array($this->taskImport->getColumnMapping()));
$this->response->csv(array($taskImport->getColumnMapping()));
}
}

View File

@ -182,7 +182,6 @@ use Pimple\Container;
* @property \Kanboard\Validator\TaskValidator $taskValidator
* @property \Kanboard\Validator\UserValidator $userValidator
* @property \Kanboard\Validator\PredefinedTaskDescriptionValidator $predefinedTaskDescriptionValidator
* @property \Kanboard\Import\TaskImport $taskImport
* @property \Kanboard\Import\UserImport $userImport
* @property \Kanboard\Export\SubtaskExport $subtaskExport
* @property \Kanboard\Export\TaskExport $taskExport

View File

@ -4,90 +4,86 @@ namespace Kanboard\Import;
use Kanboard\Core\Base;
use Kanboard\Core\Csv;
use Kanboard\Core\ExternalLink\ExternalLinkManager;
use Kanboard\Core\ExternalLink\ExternalLinkProviderNotFound;
use SimpleValidator\Validator;
use SimpleValidator\Validators;
/**
* Task Import
* Task CSV Import
*
* @package import
* @package Kanboard\Import
* @author Frederic Guillot
*/
class TaskImport extends Base
{
/**
* Number of successful import
*
* @access public
* @var integer
*/
public $counter = 0;
protected $nbImportedTasks = 0;
protected $projectId = 0;
/**
* Project id to import tasks
*
* @access public
* @var integer
*/
public $projectId;
public function setProjectId($projectId)
{
$this->projectId = $projectId;
return $this;
}
public function getNumberOfImportedTasks()
{
return $this->nbImportedTasks;
}
/**
* Get mapping between CSV header and SQL columns
*
* @access public
* @return array
*/
public function getColumnMapping()
{
return array(
'reference' => 'Reference',
'title' => 'Title',
'description' => 'Description',
'assignee' => 'Assignee Username',
'creator' => 'Creator Username',
'color' => 'Color Name',
'column' => 'Column Name',
'category' => 'Category Name',
'swimlane' => 'Swimlane Name',
'score' => 'Complexity',
'time_estimated' => 'Time Estimated',
'time_spent' => 'Time Spent',
'date_due' => 'Due Date',
'is_active' => 'Closed',
'reference' => e('Reference'),
'title' => e('Title'),
'description' => e('Description'),
'assignee' => e('Assignee Username'),
'creator' => e('Creator Username'),
'color' => e('Color Name'),
'column' => e('Column Name'),
'category' => e('Category Name'),
'swimlane' => e('Swimlane Name'),
'score' => e('Complexity'),
'time_estimated' => e('Time Estimated'),
'time_spent' => e('Time Spent'),
'date_started' => e('Start Date'),
'date_due' => e('Due Date'),
'priority' => e('Priority'),
'is_active' => e('Status'),
'tags' => e('Tags'),
'external_link' => e('External Link'),
);
}
/**
* Import a single row
*
* @access public
* @param array $row
* @param integer $line_number
*/
public function import(array $row, $line_number)
public function importTask(array $row, $lineNumber)
{
$row = $this->prepare($row);
$task = $this->prepareTask($row);
if ($this->validateCreation($row)) {
if ($this->taskCreationModel->create($row) > 0) {
$this->logger->debug('TaskImport: imported successfully line '.$line_number);
$this->counter++;
if ($this->validateCreation($task)) {
$taskId = $this->taskCreationModel->create($task);
if ($taskId > 0) {
$this->logger->debug(__METHOD__.': imported successfully line '.$lineNumber);
$this->nbImportedTasks++;
if (! empty($row['tags'])) {
$tagsList = explode(',', $row['tags']);
array_walk($tagsList, function (&$value) { $value = trim($value); });
$this->taskTagModel->save($this->projectId, $taskId, $tagsList);
}
if (! empty($row['external_link'])) {
$this->createExternalLink($taskId, $row['external_link']);
}
} else {
$this->logger->error('TaskImport: creation error at line '.$line_number);
$this->logger->error(__METHOD__.': creation error at line '.$lineNumber);
}
} else {
$this->logger->error('TaskImport: validation error at line '.$line_number);
$this->logger->error(__METHOD__.': validation error at line '.$lineNumber);
}
}
/**
* Format row before validation
*
* @access public
* @param array $row
* @return array
*/
public function prepare(array $row)
public function prepareTask(array $row)
{
$values = array();
$values['project_id'] = $this->projectId;
@ -96,6 +92,7 @@ class TaskImport extends Base
$values['description'] = $row['description'];
$values['is_active'] = Csv::getBooleanValue($row['is_active']) == 1 ? 0 : 1;
$values['score'] = (int) $row['score'];
$values['priority'] = (int) $row['priority'];
$values['time_estimated'] = (float) $row['time_estimated'];
$values['time_spent'] = (float) $row['time_spent'];
@ -127,22 +124,19 @@ class TaskImport extends Base
$values['date_due'] = $this->dateParser->getTimestamp($row['date_due']);
}
if (! empty($row['date_started'])) {
$values['date_started'] = $this->dateParser->getTimestamp($row['date_started']);
}
$this->helper->model->removeEmptyFields(
$values,
array('owner_id', 'creator_id', 'color_id', 'column_id', 'category_id', 'swimlane_id', 'date_due')
array('owner_id', 'creator_id', 'color_id', 'column_id', 'category_id', 'swimlane_id', 'date_due', 'date_started', 'priority')
);
return $values;
}
/**
* Validate user creation
*
* @access public
* @param array $values
* @return boolean
*/
public function validateCreation(array $values)
protected function validateCreation(array $values)
{
$v = new Validator($values, array(
new Validators\Integer('project_id', t('This value must be an integer')),
@ -154,4 +148,34 @@ class TaskImport extends Base
return $v->execute();
}
protected function createExternalLink($taskId, $externalLink)
{
try {
$provider = $this->externalLinkManager
->setUserInputText($externalLink)
->setUserInputType(ExternalLinkManager::TYPE_AUTO)
->find();
$link = $provider->getLink();
$dependencies = $provider->getDependencies();
$values = array(
'task_id' => $taskId,
'title' => $link->getTitle(),
'url' => $link->getUrl(),
'link_type' => $provider->getType(),
'dependency' => key($dependencies),
);
list($valid, $errors) = $this->externalLinkValidator->validateCreation($values);
if ($valid) {
$this->taskExternalLinkModel->create($values);
} else {
$this->logger->error(__METHOD__.': '.var_export($errors, true));
}
} catch (ExternalLinkProviderNotFound $e) {
$this->logger->error(__METHOD__.': '.$e->getMessage());
}
}
}

View File

@ -1357,4 +1357,13 @@ return array(
// 'Unable to remove this template.' => '',
// 'Template for the task description' => '',
// 'The start date is greater than the end date' => '',
// 'Tags must be separated by a comma' => '',
// 'Only the task title is required' => '',
// 'Creator Username' => '',
// 'Color Name' => '',
// 'Column Name' => '',
// 'Swimlane Name' => '',
// 'Time Estimated' => '',
// 'Time Spent' => '',
// 'External Link' => '',
);

View File

@ -1357,4 +1357,13 @@ return array(
// 'Unable to remove this template.' => '',
// 'Template for the task description' => '',
// 'The start date is greater than the end date' => '',
// 'Tags must be separated by a comma' => '',
// 'Only the task title is required' => '',
// 'Creator Username' => '',
// 'Color Name' => '',
// 'Column Name' => '',
// 'Swimlane Name' => '',
// 'Time Estimated' => '',
// 'Time Spent' => '',
// 'External Link' => '',
);

View File

@ -1357,4 +1357,13 @@ return array(
// 'Unable to remove this template.' => '',
// 'Template for the task description' => '',
// 'The start date is greater than the end date' => '',
// 'Tags must be separated by a comma' => '',
// 'Only the task title is required' => '',
// 'Creator Username' => '',
// 'Color Name' => '',
// 'Column Name' => '',
// 'Swimlane Name' => '',
// 'Time Estimated' => '',
// 'Time Spent' => '',
// 'External Link' => '',
);

View File

@ -1357,4 +1357,13 @@ return array(
// 'Unable to remove this template.' => '',
// 'Template for the task description' => '',
// 'The start date is greater than the end date' => '',
// 'Tags must be separated by a comma' => '',
// 'Only the task title is required' => '',
// 'Creator Username' => '',
// 'Color Name' => '',
// 'Column Name' => '',
// 'Swimlane Name' => '',
// 'Time Estimated' => '',
// 'Time Spent' => '',
// 'External Link' => '',
);

View File

@ -1357,4 +1357,13 @@ return array(
// 'Unable to remove this template.' => '',
// 'Template for the task description' => '',
// 'The start date is greater than the end date' => '',
// 'Tags must be separated by a comma' => '',
// 'Only the task title is required' => '',
// 'Creator Username' => '',
// 'Color Name' => '',
// 'Column Name' => '',
// 'Swimlane Name' => '',
// 'Time Estimated' => '',
// 'Time Spent' => '',
// 'External Link' => '',
);

View File

@ -1357,4 +1357,13 @@ return array(
// 'Unable to remove this template.' => '',
// 'Template for the task description' => '',
// 'The start date is greater than the end date' => '',
// 'Tags must be separated by a comma' => '',
// 'Only the task title is required' => '',
// 'Creator Username' => '',
// 'Color Name' => '',
// 'Column Name' => '',
// 'Swimlane Name' => '',
// 'Time Estimated' => '',
// 'Time Spent' => '',
// 'External Link' => '',
);

View File

@ -1357,4 +1357,13 @@ return array(
// 'Unable to remove this template.' => '',
// 'Template for the task description' => '',
// 'The start date is greater than the end date' => '',
// 'Tags must be separated by a comma' => '',
// 'Only the task title is required' => '',
// 'Creator Username' => '',
// 'Color Name' => '',
// 'Column Name' => '',
// 'Swimlane Name' => '',
// 'Time Estimated' => '',
// 'Time Spent' => '',
// 'External Link' => '',
);

View File

@ -1357,4 +1357,13 @@ return array(
// 'Unable to remove this template.' => '',
// 'Template for the task description' => '',
// 'The start date is greater than the end date' => '',
// 'Tags must be separated by a comma' => '',
// 'Only the task title is required' => '',
// 'Creator Username' => '',
// 'Color Name' => '',
// 'Column Name' => '',
// 'Swimlane Name' => '',
// 'Time Estimated' => '',
// 'Time Spent' => '',
// 'External Link' => '',
);

View File

@ -1357,4 +1357,13 @@ return array(
'Unable to remove this template.' => 'Impossible de supprimer ce modèle.',
'Template for the task description' => 'Modèle pour la description des tâches',
'The start date is greater than the end date' => 'La date de début est plus grande que la date d\'échéance',
'Tags must be separated by a comma' => 'Les labels doivent être séparé par une virgule',
'Only the task title is required' => 'Seulement le titre est obligatoire',
'Creator Username' => 'Identifiant du créateur',
'Color Name' => 'Nom de la couleur',
'Column Name' => 'Nom de la colonne',
'Swimlane Name' => 'Nom de la swimlane',
'Time Estimated' => 'Durée estimée',
'Time Spent' => 'Temps passé',
'External Link' => 'Lien externe',
);

View File

@ -1357,4 +1357,13 @@ return array(
// 'Unable to remove this template.' => '',
// 'Template for the task description' => '',
// 'The start date is greater than the end date' => '',
// 'Tags must be separated by a comma' => '',
// 'Only the task title is required' => '',
// 'Creator Username' => '',
// 'Color Name' => '',
// 'Column Name' => '',
// 'Swimlane Name' => '',
// 'Time Estimated' => '',
// 'Time Spent' => '',
// 'External Link' => '',
);

View File

@ -1357,4 +1357,13 @@ return array(
'Unable to remove this template.' => 'Nem lehet eltávolítani a sablont.',
'Template for the task description' => 'Sablon a feladatleíráshoz',
'The start date is greater than the end date' => 'A kezdési dátum nagyobb mint a befejezési dátum',
// 'Tags must be separated by a comma' => '',
// 'Only the task title is required' => '',
// 'Creator Username' => '',
// 'Color Name' => '',
// 'Column Name' => '',
// 'Swimlane Name' => '',
// 'Time Estimated' => '',
// 'Time Spent' => '',
// 'External Link' => '',
);

View File

@ -1357,4 +1357,13 @@ return array(
// 'Unable to remove this template.' => '',
// 'Template for the task description' => '',
// 'The start date is greater than the end date' => '',
// 'Tags must be separated by a comma' => '',
// 'Only the task title is required' => '',
// 'Creator Username' => '',
// 'Color Name' => '',
// 'Column Name' => '',
// 'Swimlane Name' => '',
// 'Time Estimated' => '',
// 'Time Spent' => '',
// 'External Link' => '',
);

View File

@ -1357,4 +1357,13 @@ return array(
// 'Unable to remove this template.' => '',
// 'Template for the task description' => '',
// 'The start date is greater than the end date' => '',
// 'Tags must be separated by a comma' => '',
// 'Only the task title is required' => '',
// 'Creator Username' => '',
// 'Color Name' => '',
// 'Column Name' => '',
// 'Swimlane Name' => '',
// 'Time Estimated' => '',
// 'Time Spent' => '',
// 'External Link' => '',
);

View File

@ -1357,4 +1357,13 @@ return array(
'Unable to remove this template.' => 'テンプレートを削除できません',
'Template for the task description' => 'タスク説明のテンプレート',
'The start date is greater than the end date' => '開始日が終了日を超えています',
// 'Tags must be separated by a comma' => '',
// 'Only the task title is required' => '',
// 'Creator Username' => '',
// 'Color Name' => '',
// 'Column Name' => '',
// 'Swimlane Name' => '',
// 'Time Estimated' => '',
// 'Time Spent' => '',
// 'External Link' => '',
);

View File

@ -1357,4 +1357,13 @@ return array(
// 'Unable to remove this template.' => '',
// 'Template for the task description' => '',
// 'The start date is greater than the end date' => '',
// 'Tags must be separated by a comma' => '',
// 'Only the task title is required' => '',
// 'Creator Username' => '',
// 'Color Name' => '',
// 'Column Name' => '',
// 'Swimlane Name' => '',
// 'Time Estimated' => '',
// 'Time Spent' => '',
// 'External Link' => '',
);

View File

@ -1357,4 +1357,13 @@ return array(
// 'Unable to remove this template.' => '',
// 'Template for the task description' => '',
// 'The start date is greater than the end date' => '',
// 'Tags must be separated by a comma' => '',
// 'Only the task title is required' => '',
// 'Creator Username' => '',
// 'Color Name' => '',
// 'Column Name' => '',
// 'Swimlane Name' => '',
// 'Time Estimated' => '',
// 'Time Spent' => '',
// 'External Link' => '',
);

View File

@ -1357,4 +1357,13 @@ return array(
// 'Unable to remove this template.' => '',
// 'Template for the task description' => '',
// 'The start date is greater than the end date' => '',
// 'Tags must be separated by a comma' => '',
// 'Only the task title is required' => '',
// 'Creator Username' => '',
// 'Color Name' => '',
// 'Column Name' => '',
// 'Swimlane Name' => '',
// 'Time Estimated' => '',
// 'Time Spent' => '',
// 'External Link' => '',
);

View File

@ -1357,4 +1357,13 @@ return array(
// 'Unable to remove this template.' => '',
// 'Template for the task description' => '',
// 'The start date is greater than the end date' => '',
// 'Tags must be separated by a comma' => '',
// 'Only the task title is required' => '',
// 'Creator Username' => '',
// 'Color Name' => '',
// 'Column Name' => '',
// 'Swimlane Name' => '',
// 'Time Estimated' => '',
// 'Time Spent' => '',
// 'External Link' => '',
);

View File

@ -1357,4 +1357,13 @@ return array(
// 'Unable to remove this template.' => '',
// 'Template for the task description' => '',
// 'The start date is greater than the end date' => '',
// 'Tags must be separated by a comma' => '',
// 'Only the task title is required' => '',
// 'Creator Username' => '',
// 'Color Name' => '',
// 'Column Name' => '',
// 'Swimlane Name' => '',
// 'Time Estimated' => '',
// 'Time Spent' => '',
// 'External Link' => '',
);

View File

@ -1357,4 +1357,13 @@ return array(
// 'Unable to remove this template.' => '',
// 'Template for the task description' => '',
// 'The start date is greater than the end date' => '',
// 'Tags must be separated by a comma' => '',
// 'Only the task title is required' => '',
// 'Creator Username' => '',
// 'Color Name' => '',
// 'Column Name' => '',
// 'Swimlane Name' => '',
// 'Time Estimated' => '',
// 'Time Spent' => '',
// 'External Link' => '',
);

View File

@ -1357,4 +1357,13 @@ return array(
// 'Unable to remove this template.' => '',
// 'Template for the task description' => '',
// 'The start date is greater than the end date' => '',
// 'Tags must be separated by a comma' => '',
// 'Only the task title is required' => '',
// 'Creator Username' => '',
// 'Color Name' => '',
// 'Column Name' => '',
// 'Swimlane Name' => '',
// 'Time Estimated' => '',
// 'Time Spent' => '',
// 'External Link' => '',
);

View File

@ -1357,4 +1357,13 @@ return array(
'Unable to remove this template.' => 'Nu am putut șterge modelul.',
// 'Template for the task description' => '',
// 'The start date is greater than the end date' => '',
// 'Tags must be separated by a comma' => '',
// 'Only the task title is required' => '',
// 'Creator Username' => '',
// 'Color Name' => '',
// 'Column Name' => '',
// 'Swimlane Name' => '',
// 'Time Estimated' => '',
// 'Time Spent' => '',
// 'External Link' => '',
);

View File

@ -1357,4 +1357,13 @@ return array(
// 'Unable to remove this template.' => '',
// 'Template for the task description' => '',
// 'The start date is greater than the end date' => '',
// 'Tags must be separated by a comma' => '',
// 'Only the task title is required' => '',
// 'Creator Username' => '',
// 'Color Name' => '',
// 'Column Name' => '',
// 'Swimlane Name' => '',
// 'Time Estimated' => '',
// 'Time Spent' => '',
// 'External Link' => '',
);

View File

@ -1357,4 +1357,13 @@ return array(
// 'Unable to remove this template.' => '',
// 'Template for the task description' => '',
// 'The start date is greater than the end date' => '',
// 'Tags must be separated by a comma' => '',
// 'Only the task title is required' => '',
// 'Creator Username' => '',
// 'Color Name' => '',
// 'Column Name' => '',
// 'Swimlane Name' => '',
// 'Time Estimated' => '',
// 'Time Spent' => '',
// 'External Link' => '',
);

View File

@ -1357,4 +1357,13 @@ return array(
// 'Unable to remove this template.' => '',
// 'Template for the task description' => '',
// 'The start date is greater than the end date' => '',
// 'Tags must be separated by a comma' => '',
// 'Only the task title is required' => '',
// 'Creator Username' => '',
// 'Color Name' => '',
// 'Column Name' => '',
// 'Swimlane Name' => '',
// 'Time Estimated' => '',
// 'Time Spent' => '',
// 'External Link' => '',
);

View File

@ -1357,4 +1357,13 @@ return array(
// 'Unable to remove this template.' => '',
// 'Template for the task description' => '',
// 'The start date is greater than the end date' => '',
// 'Tags must be separated by a comma' => '',
// 'Only the task title is required' => '',
// 'Creator Username' => '',
// 'Color Name' => '',
// 'Column Name' => '',
// 'Swimlane Name' => '',
// 'Time Estimated' => '',
// 'Time Spent' => '',
// 'External Link' => '',
);

View File

@ -1357,4 +1357,13 @@ return array(
// 'Unable to remove this template.' => '',
// 'Template for the task description' => '',
// 'The start date is greater than the end date' => '',
// 'Tags must be separated by a comma' => '',
// 'Only the task title is required' => '',
// 'Creator Username' => '',
// 'Color Name' => '',
// 'Column Name' => '',
// 'Swimlane Name' => '',
// 'Time Estimated' => '',
// 'Time Spent' => '',
// 'External Link' => '',
);

View File

@ -1363,4 +1363,13 @@ return array(
// 'Unable to remove this template.' => '',
// 'Template for the task description' => '',
// 'The start date is greater than the end date' => '',
// 'Tags must be separated by a comma' => '',
// 'Only the task title is required' => '',
// 'Creator Username' => '',
// 'Color Name' => '',
// 'Column Name' => '',
// 'Swimlane Name' => '',
// 'Time Estimated' => '',
// 'Time Spent' => '',
// 'External Link' => '',
);

View File

@ -1357,4 +1357,13 @@ return array(
// 'Unable to remove this template.' => '',
// 'Template for the task description' => '',
// 'The start date is greater than the end date' => '',
// 'Tags must be separated by a comma' => '',
// 'Only the task title is required' => '',
// 'Creator Username' => '',
// 'Color Name' => '',
// 'Column Name' => '',
// 'Swimlane Name' => '',
// 'Time Estimated' => '',
// 'Time Spent' => '',
// 'External Link' => '',
);

View File

@ -122,7 +122,6 @@ class ClassProvider implements ServiceProviderInterface
'PredefinedTaskDescriptionValidator',
),
'Import' => array(
'TaskImport',
'UserImport',
),
'Export' => array(

View File

@ -26,6 +26,8 @@
<li><?= t('The first row must be the header') ?></li>
<li><?= t('Duplicates are not verified for you') ?></li>
<li><?= t('The due date must use the ISO format: YYYY-MM-DD') ?></li>
<li><?= t('Tags must be separated by a comma') ?></li>
<li><?= t('Only the task title is required') ?></li>
</ul>
<p class="margin-top">
<?= $this->url->icon('download', t('Download CSV template'), 'TaskImportController', 'template', array('project_id' => $project['id'])) ?>