diff --git a/app/Console/Base.php b/app/Console/Base.php index 04ee8a217..b2066a636 100644 --- a/app/Console/Base.php +++ b/app/Console/Base.php @@ -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 diff --git a/app/Core/Base.php b/app/Core/Base.php index 14b06b902..c84fcbac0 100644 --- a/app/Core/Base.php +++ b/app/Core/Base.php @@ -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 diff --git a/app/Core/Helper.php b/app/Core/Helper.php index bf71769f3..759209f61 100644 --- a/app/Core/Helper.php +++ b/app/Core/Helper.php @@ -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 { diff --git a/app/Helper/Model.php b/app/Helper/Model.php new file mode 100644 index 000000000..68a525427 --- /dev/null +++ b/app/Helper/Model.php @@ -0,0 +1,94 @@ +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') ); diff --git a/app/Model/UserImport.php b/app/Import/UserImport.php similarity index 94% rename from app/Model/UserImport.php rename to app/Import/UserImport.php index 0ec4e8023..64300d774 100644 --- a/app/Model/UserImport.php +++ b/app/Import/UserImport.php @@ -1,16 +1,18 @@ removeEmptyFields($row, array('password', 'email', 'name')); + $this->helper->model->removeEmptyFields($row, array('password', 'email', 'name')); return $row; } diff --git a/app/Model/Base.php b/app/Model/Base.php index 635ed09ab..714b4308f 100644 --- a/app/Model/Base.php +++ b/app/Model/Base.php @@ -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 * diff --git a/app/Model/Project.php b/app/Model/Project.php index a79e46a1c..d2e5b7ce2 100644 --- a/app/Model/Project.php +++ b/app/Model/Project.php @@ -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); diff --git a/app/Model/Subtask.php b/app/Model/Subtask.php index b5898fcf3..3f5cfe836 100644 --- a/app/Model/Subtask.php +++ b/app/Model/Subtask.php @@ -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')); } /** diff --git a/app/Model/TaskCreation.php b/app/Model/TaskCreation.php index 576eb18c9..2d2e5504b 100644 --- a/app/Model/TaskCreation.php +++ b/app/Model/TaskCreation.php @@ -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']); diff --git a/app/Model/TaskModification.php b/app/Model/TaskModification.php index 8e59b3fe6..a77b78a47 100644 --- a/app/Model/TaskModification.php +++ b/app/Model/TaskModification.php @@ -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(); } diff --git a/app/Model/User.php b/app/Model/User.php index 2d87d35bf..0e11422b1 100644 --- a/app/Model/User.php +++ b/app/Model/User.php @@ -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')); } /** diff --git a/app/ServiceProvider/ClassProvider.php b/app/ServiceProvider/ClassProvider.php index 0ffe7099d..6612844b4 100644 --- a/app/ServiceProvider/ClassProvider.php +++ b/app/ServiceProvider/ClassProvider.php @@ -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',