summaryrefslogtreecommitdiff
path: root/app/Controller
diff options
context:
space:
mode:
Diffstat (limited to 'app/Controller')
-rw-r--r--app/Controller/Config.php2
-rw-r--r--app/Controller/Export.php2
-rw-r--r--app/Controller/FileViewer.php2
-rw-r--r--app/Controller/TaskImport.php2
-rw-r--r--app/Controller/UserImportController.php (renamed from app/Controller/UserImport.php)51
5 files changed, 35 insertions, 24 deletions
diff --git a/app/Controller/Config.php b/app/Controller/Config.php
index ebb541d2..deafd05b 100644
--- a/app/Controller/Config.php
+++ b/app/Controller/Config.php
@@ -176,7 +176,7 @@ class Config extends BaseController
public function downloadDb()
{
$this->checkCSRFParam();
- $this->response->withDownload('db.sqlite.gz');
+ $this->response->withFileDownload('db.sqlite.gz');
$this->response->binary($this->config->downloadDatabase());
}
diff --git a/app/Controller/Export.php b/app/Controller/Export.php
index f5783b72..7e1d2fdc 100644
--- a/app/Controller/Export.php
+++ b/app/Controller/Export.php
@@ -29,7 +29,7 @@ class Export extends BaseController
if ($from && $to) {
$data = $this->$model->$method($project['id'], $from, $to);
- $this->response->withDownload($filename.'.csv');
+ $this->response->withFileDownload($filename.'.csv');
$this->response->csv($data);
}
diff --git a/app/Controller/FileViewer.php b/app/Controller/FileViewer.php
index a990e12a..52ff0d0e 100644
--- a/app/Controller/FileViewer.php
+++ b/app/Controller/FileViewer.php
@@ -123,7 +123,7 @@ class FileViewer extends BaseController
{
try {
$file = $this->getFile();
- $this->response->withDownload($file['name']);
+ $this->response->withFileDownload($file['name']);
$this->objectStorage->output($file['path']);
} catch (ObjectStorageException $e) {
$this->logger->error($e->getMessage());
diff --git a/app/Controller/TaskImport.php b/app/Controller/TaskImport.php
index 5dbf8678..5e37fb2f 100644
--- a/app/Controller/TaskImport.php
+++ b/app/Controller/TaskImport.php
@@ -69,7 +69,7 @@ class TaskImport extends BaseController
*/
public function template()
{
- $this->response->withDownload('tasks.csv');
+ $this->response->withFileDownload('tasks.csv');
$this->response->csv(array($this->taskImport->getColumnMapping()));
}
}
diff --git a/app/Controller/UserImport.php b/app/Controller/UserImportController.php
index b99e56a0..b3cb52d1 100644
--- a/app/Controller/UserImport.php
+++ b/app/Controller/UserImportController.php
@@ -7,51 +7,43 @@ use Kanboard\Core\Csv;
/**
* User Import controller
*
- * @package controller
+ * @package Kanboard\Controller
* @author Frederic Guillot
*/
-class UserImport extends BaseController
+class UserImportController extends BaseController
{
/**
* Upload the file and ask settings
*
+ * @param array $values
+ * @param array $errors
*/
- public function step1(array $values = array(), array $errors = array())
+ public function show(array $values = array(), array $errors = array())
{
- $this->response->html($this->helper->layout->app('user_import/step1', array(
+ $this->response->html($this->template->render('user_import/show', array(
'values' => $values,
'errors' => $errors,
'max_size' => ini_get('upload_max_filesize'),
'delimiters' => Csv::getDelimiters(),
'enclosures' => Csv::getEnclosures(),
- 'title' => t('Import users from CSV file'),
)));
}
/**
- * Process CSV file
- *
+ * Submit form
*/
- public function step2()
+ public function save()
{
$values = $this->request->getValues();
$filename = $this->request->getFilePath('file');
if (! file_exists($filename)) {
- $this->step1($values, array('file' => array(t('Unable to read your file'))));
- }
-
- $csv = new Csv($values['delimiter'], $values['enclosure']);
- $csv->setColumnMapping($this->userImport->getColumnMapping());
- $csv->read($filename, array($this->userImport, 'import'));
-
- if ($this->userImport->counter > 0) {
- $this->flash->success(t('%d user(s) have been imported successfully.', $this->userImport->counter));
+ $this->flash->failure(t('Unable to read your file'));
} else {
- $this->flash->failure(t('Nothing have been imported!'));
+ $this->importFile($values, $filename);
}
- $this->response->redirect($this->helper->url->to('userImport', 'step1'));
+ $this->response->redirect($this->helper->url->to('user', 'index'));
}
/**
@@ -60,7 +52,26 @@ class UserImport extends BaseController
*/
public function template()
{
- $this->response->withDownload('users.csv');
+ $this->response->withFileDownload('users.csv');
$this->response->csv(array($this->userImport->getColumnMapping()));
}
+
+ /**
+ * Process file
+ *
+ * @param array $values
+ * @param $filename
+ */
+ private function importFile(array $values, $filename)
+ {
+ $csv = new Csv($values['delimiter'], $values['enclosure']);
+ $csv->setColumnMapping($this->userImport->getColumnMapping());
+ $csv->read($filename, array($this->userImport, 'import'));
+
+ if ($this->userImport->counter > 0) {
+ $this->flash->success(t('%d user(s) have been imported successfully.', $this->userImport->counter));
+ } else {
+ $this->flash->failure(t('Nothing have been imported!'));
+ }
+ }
}