@@ -21,6 +21,7 @@ use App\Importer\UnknownUserException;
|
|||||||
use App\Repository\ActivityRepository;
|
use App\Repository\ActivityRepository;
|
||||||
use App\Repository\CustomerRepository;
|
use App\Repository\CustomerRepository;
|
||||||
use App\Repository\ProjectRepository;
|
use App\Repository\ProjectRepository;
|
||||||
|
use App\Repository\TagRepository;
|
||||||
use App\Repository\TimesheetRepository;
|
use App\Repository\TimesheetRepository;
|
||||||
use App\Repository\UserRepository;
|
use App\Repository\UserRepository;
|
||||||
use App\Utils\Duration;
|
use App\Utils\Duration;
|
||||||
@@ -79,6 +80,10 @@ class ImportTimesheetCommand extends Command
|
|||||||
* @var UserRepository
|
* @var UserRepository
|
||||||
*/
|
*/
|
||||||
private $users;
|
private $users;
|
||||||
|
/**
|
||||||
|
* @var TagRepository
|
||||||
|
*/
|
||||||
|
private $tagRepository;
|
||||||
/**
|
/**
|
||||||
* @var TimesheetRepository
|
* @var TimesheetRepository
|
||||||
*/
|
*/
|
||||||
@@ -116,13 +121,14 @@ class ImportTimesheetCommand extends Command
|
|||||||
*/
|
*/
|
||||||
private $begin = self::DEFAULT_BEGIN;
|
private $begin = self::DEFAULT_BEGIN;
|
||||||
|
|
||||||
public function __construct(CustomerRepository $customers, ProjectRepository $projects, ActivityRepository $activities, UserRepository $users, TimesheetRepository $timesheets, FormConfiguration $configuration)
|
public function __construct(CustomerRepository $customers, ProjectRepository $projects, ActivityRepository $activities, UserRepository $users, TagRepository $tagRepository, TimesheetRepository $timesheets, FormConfiguration $configuration)
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->customers = $customers;
|
$this->customers = $customers;
|
||||||
$this->projects = $projects;
|
$this->projects = $projects;
|
||||||
$this->activities = $activities;
|
$this->activities = $activities;
|
||||||
$this->users = $users;
|
$this->users = $users;
|
||||||
|
$this->tagRepository = $tagRepository;
|
||||||
$this->timesheets = $timesheets;
|
$this->timesheets = $timesheets;
|
||||||
$this->configuration = $configuration;
|
$this->configuration = $configuration;
|
||||||
}
|
}
|
||||||
@@ -309,11 +315,16 @@ class ImportTimesheetCommand extends Command
|
|||||||
$timesheet->setExported((bool) $record['Exported']);
|
$timesheet->setExported((bool) $record['Exported']);
|
||||||
|
|
||||||
if (!empty($record['Tags'])) {
|
if (!empty($record['Tags'])) {
|
||||||
foreach (explode(',', $record['Tags']) as $tag) {
|
foreach (explode(',', $record['Tags']) as $tagName) {
|
||||||
if (empty($tag)) {
|
if (empty($tagName)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$timesheet->addTag((new Tag())->setName($tag));
|
|
||||||
|
if (null === ($tag = $this->tagRepository->findTagByName($tagName))) {
|
||||||
|
$tag = (new Tag())->setName($tagName);
|
||||||
|
}
|
||||||
|
|
||||||
|
$timesheet->addTag($tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ use App\Configuration\FormConfiguration;
|
|||||||
use App\Repository\ActivityRepository;
|
use App\Repository\ActivityRepository;
|
||||||
use App\Repository\CustomerRepository;
|
use App\Repository\CustomerRepository;
|
||||||
use App\Repository\ProjectRepository;
|
use App\Repository\ProjectRepository;
|
||||||
|
use App\Repository\TagRepository;
|
||||||
use App\Repository\TimesheetRepository;
|
use App\Repository\TimesheetRepository;
|
||||||
use App\Repository\UserRepository;
|
use App\Repository\UserRepository;
|
||||||
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
||||||
@@ -39,10 +40,11 @@ class ImportTimesheetCommandTest extends KernelTestCase
|
|||||||
$projects = $this->createMock(ProjectRepository::class);
|
$projects = $this->createMock(ProjectRepository::class);
|
||||||
$activities = $this->createMock(ActivityRepository::class);
|
$activities = $this->createMock(ActivityRepository::class);
|
||||||
$users = $this->createMock(UserRepository::class);
|
$users = $this->createMock(UserRepository::class);
|
||||||
|
$tagRepository = $this->createMock(TagRepository::class);
|
||||||
$timesheets = $this->createMock(TimesheetRepository::class);
|
$timesheets = $this->createMock(TimesheetRepository::class);
|
||||||
$configuration = $this->createMock(FormConfiguration::class);
|
$configuration = $this->createMock(FormConfiguration::class);
|
||||||
|
|
||||||
$this->application->add(new ImportTimesheetCommand($customers, $projects, $activities, $users, $timesheets, $configuration));
|
$this->application->add(new ImportTimesheetCommand($customers, $projects, $activities, $users, $tagRepository, $timesheets, $configuration));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCommandName()
|
public function testCommandName()
|
||||||
|
|||||||
Reference in New Issue
Block a user