Create Import namespace and move classes
This commit is contained in:
parent
0d03c525a1
commit
c083822806
|
|
@ -21,6 +21,8 @@ use Symfony\Component\Console\Command\Command;
|
|||
* @property \Kanboard\Model\TaskExport $taskExport
|
||||
* @property \Kanboard\Model\TaskFinder $taskFinder
|
||||
* @property \Kanboard\Model\Transition $transition
|
||||
* @property \Kanboard\Model\UserNotification $userNotification
|
||||
* @property \Kanboard\Model\UserNotificationFilter $userNotificationFilter
|
||||
* @property \Symfony\Component\EventDispatcher\EventDispatcher $dispatcher
|
||||
*/
|
||||
abstract class Base extends Command
|
||||
|
|
|
|||
|
|
@ -99,7 +99,6 @@ use Pimple\Container;
|
|||
* @property \Kanboard\Model\TaskDuplication $taskDuplication
|
||||
* @property \Kanboard\Model\TaskExport $taskExport
|
||||
* @property \Kanboard\Model\TaskExternalLink $taskExternalLink
|
||||
* @property \Kanboard\Model\TaskImport $taskImport
|
||||
* @property \Kanboard\Model\TaskFinder $taskFinder
|
||||
* @property \Kanboard\Model\TaskFilter $taskFilter
|
||||
* @property \Kanboard\Model\TaskLink $taskLink
|
||||
|
|
@ -111,7 +110,6 @@ use Pimple\Container;
|
|||
* @property \Kanboard\Model\Transition $transition
|
||||
* @property \Kanboard\Model\TransitionExport $transitionExport
|
||||
* @property \Kanboard\Model\User $user
|
||||
* @property \Kanboard\Model\UserImport $userImport
|
||||
* @property \Kanboard\Model\UserLocking $userLocking
|
||||
* @property \Kanboard\Model\UserMention $userMention
|
||||
* @property \Kanboard\Model\UserNotification $userNotification
|
||||
|
|
@ -137,6 +135,8 @@ use Pimple\Container;
|
|||
* @property \Kanboard\Validator\ExternalLinkValidator $externalLinkValidator
|
||||
* @property \Kanboard\Validator\TaskValidator $taskValidator
|
||||
* @property \Kanboard\Validator\UserValidator $userValidator
|
||||
* @property \Kanboard\Import\TaskImport $taskImport
|
||||
* @property \Kanboard\Import\UserImport $userImport
|
||||
* @property \Psr\Log\LoggerInterface $logger
|
||||
* @property \PicoDb\Database $db
|
||||
* @property \Symfony\Component\EventDispatcher\EventDispatcher $dispatcher
|
||||
|
|
|
|||
|
|
@ -10,17 +10,18 @@ use Pimple\Container;
|
|||
* @package core
|
||||
* @author Frederic Guillot
|
||||
*
|
||||
* @property \Helper\App $app
|
||||
* @property \Helper\Asset $asset
|
||||
* @property \Helper\Dt $dt
|
||||
* @property \Helper\File $file
|
||||
* @property \Helper\Form $form
|
||||
* @property \Helper\Subtask $subtask
|
||||
* @property \Helper\Task $task
|
||||
* @property \Helper\Text $text
|
||||
* @property \Helper\Url $url
|
||||
* @property \Helper\User $user
|
||||
* @property \Helper\Layout $layout
|
||||
* @property \Kanboard\Helper\App $app
|
||||
* @property \Kanboard\Helper\Asset $asset
|
||||
* @property \Kanboard\Helper\Dt $dt
|
||||
* @property \Kanboard\Helper\File $file
|
||||
* @property \Kanboard\Helper\Form $form
|
||||
* @property \Kanboard\Helper\Subtask $subtask
|
||||
* @property \Kanboard\Helper\Task $task
|
||||
* @property \Kanboard\Helper\Text $text
|
||||
* @property \Kanboard\Helper\Url $url
|
||||
* @property \Kanboard\Helper\User $user
|
||||
* @property \Kanboard\Helper\Layout $layout
|
||||
* @property \Kanboard\Helper\Model $model
|
||||
*/
|
||||
class Helper
|
||||
{
|
||||
|
|
|
|||
|
|
@ -0,0 +1,94 @@
|
|||
<?php
|
||||
|
||||
namespace Kanboard\Helper;
|
||||
|
||||
use Kanboard\Core\Base;
|
||||
|
||||
/**
|
||||
* Model Helper
|
||||
*
|
||||
* @package helper
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class Model extends Base
|
||||
{
|
||||
/**
|
||||
* Remove keys from an array
|
||||
*
|
||||
* @access public
|
||||
* @param array $values Input array
|
||||
* @param string[] $keys List of keys to remove
|
||||
*/
|
||||
public function removeFields(array &$values, array $keys)
|
||||
{
|
||||
foreach ($keys as $key) {
|
||||
if (array_key_exists($key, $values)) {
|
||||
unset($values[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove keys from an array if empty
|
||||
*
|
||||
* @access public
|
||||
* @param array $values Input array
|
||||
* @param string[] $keys List of keys to remove
|
||||
*/
|
||||
public function removeEmptyFields(array &$values, array $keys)
|
||||
{
|
||||
foreach ($keys as $key) {
|
||||
if (array_key_exists($key, $values) && empty($values[$key])) {
|
||||
unset($values[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Force fields to be at 0 if empty
|
||||
*
|
||||
* @access public
|
||||
* @param array $values Input array
|
||||
* @param string[] $keys List of keys
|
||||
*/
|
||||
public function resetFields(array &$values, array $keys)
|
||||
{
|
||||
foreach ($keys as $key) {
|
||||
if (isset($values[$key]) && empty($values[$key])) {
|
||||
$values[$key] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Force some fields to be integer
|
||||
*
|
||||
* @access public
|
||||
* @param array $values Input array
|
||||
* @param string[] $keys List of keys
|
||||
*/
|
||||
public function convertIntegerFields(array &$values, array $keys)
|
||||
{
|
||||
foreach ($keys as $key) {
|
||||
if (isset($values[$key])) {
|
||||
$values[$key] = (int) $values[$key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Force some fields to be null if empty
|
||||
*
|
||||
* @access public
|
||||
* @param array $values Input array
|
||||
* @param string[] $keys List of keys
|
||||
*/
|
||||
public function convertNullFields(array &$values, array $keys)
|
||||
{
|
||||
foreach ($keys as $key) {
|
||||
if (array_key_exists($key, $values) && empty($values[$key])) {
|
||||
$values[$key] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Kanboard\Model;
|
||||
namespace Kanboard\Import;
|
||||
|
||||
use Kanboard\Core\Base;
|
||||
use Kanboard\Core\Csv;
|
||||
use SimpleValidator\Validator;
|
||||
use SimpleValidator\Validators;
|
||||
|
|
@ -9,7 +10,7 @@ use SimpleValidator\Validators;
|
|||
/**
|
||||
* Task Import
|
||||
*
|
||||
* @package model
|
||||
* @package import
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class TaskImport extends Base
|
||||
|
|
@ -126,7 +127,7 @@ class TaskImport extends Base
|
|||
$values['date_due'] = $this->dateParser->getTimestampFromIsoFormat($row['date_due']);
|
||||
}
|
||||
|
||||
$this->removeEmptyFields(
|
||||
$this->helper->model->removeEmptyFields(
|
||||
$values,
|
||||
array('owner_id', 'creator_id', 'color_id', 'column_id', 'category_id', 'swimlane_id', 'date_due')
|
||||
);
|
||||
|
|
@ -1,16 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Kanboard\Model;
|
||||
namespace Kanboard\Import;
|
||||
|
||||
use Kanboard\Model\User;
|
||||
use SimpleValidator\Validator;
|
||||
use SimpleValidator\Validators;
|
||||
use Kanboard\Core\Security\Role;
|
||||
use Kanboard\Core\Base;
|
||||
use Kanboard\Core\Csv;
|
||||
|
||||
/**
|
||||
* User Import
|
||||
*
|
||||
* @package model
|
||||
* @package import
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class UserImport extends Base
|
||||
|
|
@ -91,7 +93,7 @@ class UserImport extends Base
|
|||
unset($row['is_admin']);
|
||||
unset($row['is_manager']);
|
||||
|
||||
$this->removeEmptyFields($row, array('password', 'email', 'name'));
|
||||
$this->helper->model->removeEmptyFields($row, array('password', 'email', 'name'));
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
|
@ -32,86 +32,6 @@ abstract class Base extends \Kanboard\Core\Base
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove keys from an array
|
||||
*
|
||||
* @access public
|
||||
* @param array $values Input array
|
||||
* @param string[] $keys List of keys to remove
|
||||
*/
|
||||
public function removeFields(array &$values, array $keys)
|
||||
{
|
||||
foreach ($keys as $key) {
|
||||
if (array_key_exists($key, $values)) {
|
||||
unset($values[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove keys from an array if empty
|
||||
*
|
||||
* @access public
|
||||
* @param array $values Input array
|
||||
* @param string[] $keys List of keys to remove
|
||||
*/
|
||||
public function removeEmptyFields(array &$values, array $keys)
|
||||
{
|
||||
foreach ($keys as $key) {
|
||||
if (array_key_exists($key, $values) && empty($values[$key])) {
|
||||
unset($values[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Force fields to be at 0 if empty
|
||||
*
|
||||
* @access public
|
||||
* @param array $values Input array
|
||||
* @param string[] $keys List of keys
|
||||
*/
|
||||
public function resetFields(array &$values, array $keys)
|
||||
{
|
||||
foreach ($keys as $key) {
|
||||
if (isset($values[$key]) && empty($values[$key])) {
|
||||
$values[$key] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Force some fields to be integer
|
||||
*
|
||||
* @access public
|
||||
* @param array $values Input array
|
||||
* @param string[] $keys List of keys
|
||||
*/
|
||||
public function convertIntegerFields(array &$values, array $keys)
|
||||
{
|
||||
foreach ($keys as $key) {
|
||||
if (isset($values[$key])) {
|
||||
$values[$key] = (int) $values[$key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Force some fields to be null if empty
|
||||
*
|
||||
* @access public
|
||||
* @param array $values Input array
|
||||
* @param string[] $keys List of keys
|
||||
*/
|
||||
public function convertNullFields(array &$values, array $keys)
|
||||
{
|
||||
foreach ($keys as $key) {
|
||||
if (array_key_exists($key, $values) && empty($values[$key])) {
|
||||
$values[$key] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build SQL condition for a given time range
|
||||
*
|
||||
|
|
|
|||
|
|
@ -334,7 +334,7 @@ class Project extends Base
|
|||
$values['identifier'] = strtoupper($values['identifier']);
|
||||
}
|
||||
|
||||
$this->convertIntegerFields($values, array('priority_default', 'priority_start', 'priority_end'));
|
||||
$this->helper->model->convertIntegerFields($values, array('priority_default', 'priority_start', 'priority_end'));
|
||||
|
||||
if (! $this->db->table(self::TABLE)->save($values)) {
|
||||
$this->db->cancelTransaction();
|
||||
|
|
@ -402,7 +402,7 @@ class Project extends Base
|
|||
$values['identifier'] = strtoupper($values['identifier']);
|
||||
}
|
||||
|
||||
$this->convertIntegerFields($values, array('priority_default', 'priority_start', 'priority_end'));
|
||||
$this->helper->model->convertIntegerFields($values, array('priority_default', 'priority_start', 'priority_end'));
|
||||
|
||||
return $this->exists($values['id']) &&
|
||||
$this->db->table(self::TABLE)->eq('id', $values['id'])->save($values);
|
||||
|
|
|
|||
|
|
@ -168,8 +168,8 @@ class Subtask extends Base
|
|||
*/
|
||||
public function prepare(array &$values)
|
||||
{
|
||||
$this->removeFields($values, array('another_subtask'));
|
||||
$this->resetFields($values, array('time_estimated', 'time_spent'));
|
||||
$this->helper->model->removeFields($values, array('another_subtask'));
|
||||
$this->helper->model->resetFields($values, array('time_estimated', 'time_spent'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -52,8 +52,8 @@ class TaskCreation extends Base
|
|||
$values = $this->dateParser->convert($values, array('date_due'));
|
||||
$values = $this->dateParser->convert($values, array('date_started'), true);
|
||||
|
||||
$this->removeFields($values, array('another_task'));
|
||||
$this->resetFields($values, array('date_started', 'creator_id', 'owner_id', 'swimlane_id', 'date_due', 'score', 'category_id', 'time_estimated'));
|
||||
$this->helper->model->removeFields($values, array('another_task'));
|
||||
$this->helper->model->resetFields($values, array('date_started', 'creator_id', 'owner_id', 'swimlane_id', 'date_due', 'score', 'category_id', 'time_estimated'));
|
||||
|
||||
if (empty($values['column_id'])) {
|
||||
$values['column_id'] = $this->column->getFirstColumnId($values['project_id']);
|
||||
|
|
|
|||
|
|
@ -87,9 +87,9 @@ class TaskModification extends Base
|
|||
$values = $this->dateParser->convert($values, array('date_due'));
|
||||
$values = $this->dateParser->convert($values, array('date_started'), true);
|
||||
|
||||
$this->removeFields($values, array('another_task', 'id'));
|
||||
$this->resetFields($values, array('date_due', 'date_started', 'score', 'category_id', 'time_estimated', 'time_spent'));
|
||||
$this->convertIntegerFields($values, array('priority', 'is_active', 'recurrence_status', 'recurrence_trigger', 'recurrence_factor', 'recurrence_timeframe', 'recurrence_basedate'));
|
||||
$this->helper->model->removeFields($values, array('another_task', 'id'));
|
||||
$this->helper->model->resetFields($values, array('date_due', 'date_started', 'score', 'category_id', 'time_estimated', 'time_spent'));
|
||||
$this->helper->model->convertIntegerFields($values, array('priority', 'is_active', 'recurrence_status', 'recurrence_trigger', 'recurrence_factor', 'recurrence_timeframe', 'recurrence_basedate'));
|
||||
|
||||
$values['date_modification'] = time();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -253,10 +253,10 @@ class User extends Base
|
|||
}
|
||||
}
|
||||
|
||||
$this->removeFields($values, array('confirmation', 'current_password'));
|
||||
$this->resetFields($values, array('is_ldap_user', 'disable_login_form'));
|
||||
$this->convertNullFields($values, array('gitlab_id'));
|
||||
$this->convertIntegerFields($values, array('gitlab_id'));
|
||||
$this->helper->model->removeFields($values, array('confirmation', 'current_password'));
|
||||
$this->helper->model->resetFields($values, array('is_ldap_user', 'disable_login_form'));
|
||||
$this->helper->model->convertNullFields($values, array('gitlab_id'));
|
||||
$this->helper->model->convertIntegerFields($values, array('gitlab_id'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -70,12 +70,10 @@ class ClassProvider implements ServiceProviderInterface
|
|||
'TaskPermission',
|
||||
'TaskPosition',
|
||||
'TaskStatus',
|
||||
'TaskImport',
|
||||
'TaskMetadata',
|
||||
'Transition',
|
||||
'TransitionExport',
|
||||
'User',
|
||||
'UserImport',
|
||||
'UserLocking',
|
||||
'UserMention',
|
||||
'UserNotification',
|
||||
|
|
@ -111,6 +109,10 @@ class ClassProvider implements ServiceProviderInterface
|
|||
'TaskLinkValidator',
|
||||
'UserValidator',
|
||||
),
|
||||
'Import' => array(
|
||||
'TaskImport',
|
||||
'UserImport',
|
||||
),
|
||||
'Core' => array(
|
||||
'DateParser',
|
||||
'Helper',
|
||||
|
|
|
|||
Loading…
Reference in New Issue