Skip to content

Commit 3296668

Browse files
Merge branch 'feature/entity'
2 parents 33e1492 + 93fb1e3 commit 3296668

File tree

20 files changed

+459
-8
lines changed

20 files changed

+459
-8
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ composer.phar
55
*.iml
66
/.idea
77

8-
tests/app/cache
9-
tests/app/logs
8+
/tests/app/cache/
9+
/tests/app/logs/
10+
/tests/app/data/

.scrutinizer.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
tools:
2-
external_code_coverage: true
2+
external_code_coverage:
3+
timeout: 300
4+
runs: 6

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,17 @@ php:
88

99
env:
1010
- STORAGE=array
11+
- STORAGE=doctrine
1112

1213
install:
1314
- composer self-update
1415
- composer update
1516
- wget https://scrutinizer-ci.com/ocular.phar
1617

18+
before_script:
19+
- STORAGE=doctrine tests/app/console doctrine:database:create
20+
- STORAGE=doctrine tests/app/console doctrine:schema:create
21+
1722
script:
1823
- phpunit -c phpunit.xml.dist --coverage-clover=coverage.clover
1924

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
"symfony/http-kernel": "^2.6",
1616
"symfony/dependency-injection": "^2.6",
1717
"symfony/config": "^2.6",
18-
"symfony/console": "^2.6"
18+
"symfony/console": "^2.6",
19+
"doctrine/orm": "^2.5"
1920
},
2021
"require-dev": {
2122
"phpunit/phpunit": "^4.8",
2223
"symfony/framework-bundle": "^2.6",
23-
"symfony/finder": "^2.6"
24+
"symfony/finder": "^2.6",
25+
"doctrine/doctrine-bundle": "^1.5"
2426
},
2527
"autoload": {
2628
"psr-4": {

src/DependencyInjection/TaskExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public function load(array $configs, ContainerBuilder $container)
2424

2525
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
2626
$loader->load(sprintf('storage/%s.xml', $config['storage']));
27+
$loader->load('task_event_listener.xml');
2728
$loader->load('scheduler.xml');
2829
$loader->load('command.xml');
2930

src/Entity/Task.php

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?php
2+
3+
namespace Task\TaskBundle\Entity;
4+
5+
use Task\TaskInterface;
6+
7+
class Task
8+
{
9+
/**
10+
* @var int
11+
*/
12+
private $id;
13+
14+
/**
15+
* @var string
16+
*/
17+
private $uuid;
18+
19+
/**
20+
* @var TaskInterface
21+
*/
22+
private $task;
23+
24+
/**
25+
* @var \DateTime
26+
*/
27+
private $executionDate;
28+
29+
/**
30+
* @var bool
31+
*/
32+
private $completed;
33+
34+
/**
35+
* @return int
36+
*/
37+
public function getId()
38+
{
39+
return $this->id;
40+
}
41+
42+
/**
43+
* @return string
44+
*/
45+
public function getUuid()
46+
{
47+
return $this->uuid;
48+
}
49+
50+
/**
51+
* @param string $uuid
52+
*/
53+
public function setUuid($uuid)
54+
{
55+
$this->uuid = $uuid;
56+
}
57+
58+
/**
59+
* @return TaskInterface
60+
*/
61+
public function getTask()
62+
{
63+
return $this->task;
64+
}
65+
66+
/**
67+
* @param TaskInterface $task
68+
*/
69+
public function setTask($task)
70+
{
71+
$this->task = $task;
72+
}
73+
74+
/**
75+
* @return \DateTime
76+
*/
77+
public function getExecutionDate()
78+
{
79+
return $this->executionDate;
80+
}
81+
82+
/**
83+
* @param \DateTime $executionDate
84+
*/
85+
public function setExecutionDate($executionDate)
86+
{
87+
$this->executionDate = $executionDate;
88+
}
89+
90+
/**
91+
* @return bool
92+
*/
93+
public function isCompleted()
94+
{
95+
return $this->completed;
96+
}
97+
98+
/**
99+
* @param bool $completed
100+
*/
101+
public function setCompleted($completed)
102+
{
103+
$this->completed = $completed;
104+
}
105+
}

src/Entity/TaskRepository.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace Task\TaskBundle\Entity;
4+
5+
use Doctrine\ORM\EntityRepository;
6+
7+
class TaskRepository extends EntityRepository
8+
{
9+
public function findScheduled()
10+
{
11+
$query = $this->createQueryBuilder('task')
12+
->where('task.completed = :completed')
13+
->andWhere('task.executionDate <= :date')
14+
->setParameter('completed', false)
15+
->setParameter('date', new \DateTime())
16+
->getQuery();
17+
18+
return $query->getResult();
19+
}
20+
21+
/**
22+
* @param string $uuid
23+
*
24+
* @return Task
25+
*/
26+
public function findByUuid($uuid)
27+
{
28+
$query = $this->createQueryBuilder('task')
29+
->where('task.uuid = :uuid')
30+
->setParameter('uuid', $uuid)
31+
->getQuery();
32+
33+
return $query->getSingleResult();
34+
}
35+
36+
public function deleteAll()
37+
{
38+
$query = $this->_em->createQueryBuilder()
39+
->delete($this->_entityName, 'task')
40+
->getQuery();
41+
42+
$query->execute();
43+
}
44+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
5+
<entity name="Task\TaskBundle\Entity\Task"
6+
repository-class="Task\TaskBundle\Entity\TaskRepository"
7+
table="tasks">
8+
9+
<id name="id" type="integer">
10+
<generator strategy="AUTO"/>
11+
</id>
12+
13+
<field name="task" type="object"/>
14+
<field name="uuid" type="string" length="100"/>
15+
<field name="executionDate" type="datetime"/>
16+
<field name="completed" type="boolean"/>
17+
18+
</entity>
19+
</doctrine-mapping>

src/Resources/config/scheduler.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<argument type="service" id="task.storage"/>
1111
<argument type="service" id="task.handler_registry"/>
1212
<argument type="service" id="task.builder_factory"/>
13+
<argument type="service" id="event_dispatcher"/>
1314
<argument type="service" id="logger" on-invalid="ignore"/>
1415
</service>
1516
</services>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
5+
<services>
6+
<service id="task.storage.repository"
7+
class="Task\TaskBundle\Entity\TaskRepository"
8+
factory-service="doctrine.orm.entity_manager"
9+
factory-method="getRepository"
10+
public="false">
11+
<argument type="string">TaskBundle:Task</argument>
12+
</service>
13+
14+
<service id="task.storage" class="Task\TaskBundle\Storage\DoctrineStorage">
15+
<argument type="service" id="doctrine.orm.entity_manager"/>
16+
<argument type="service" id="task.storage.repository"/>
17+
</service>
18+
</services>
19+
</container>

0 commit comments

Comments
 (0)