ScheduleApiJobsCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 4
dl 0
loc 39
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 4 1
B execute() 0 25 4
1
<?php
2
namespace Tarioch\EveapiFetcherBundle\Command;
3
4
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
5
use Symfony\Component\Console\Input\InputInterface;
6
use Symfony\Component\Console\Output\OutputInterface;
7
use Tarioch\EveapiFetcherBundle\Entity\ApiCall;
8
9
class ScheduleApiJobsCommand extends ContainerAwareCommand
10
{
11
    /**
12
     * @inheritdoc
13
     */
14
    protected function configure()
15
    {
16
        $this->setName('eve:api:schedule')->setDescription('Schedule needed api fetches');
17
    }
18
19
    /**
20
     * @inheritdoc
21
     */
22
    protected function execute(InputInterface $input, OutputInterface $output)
23
    {
24
        $gearman = $this->getContainer()->get('gearman');
25
        $entityManager = $this->getContainer()->get('doctrine.orm.eveapi_entity_manager');
26
27
        $newKeys = $entityManager->getRepository('TariochEveapiFetcherBundle:ApiKey')->loadKeysWithoutApiCall();
28
        if (!empty($newKeys)) {
29
            $api = $entityManager->getRepository('TariochEveapiFetcherBundle:Api')->loadApiKeyInfoApi();
30
            foreach ($newKeys as $key) {
31
                $entityManager->persist(new ApiCall($api, null, $key));
32
            }
33
            $entityManager->flush();
34
        }
35
36
        $calls = $entityManager->getRepository('TariochEveapiFetcherBundle:ApiCall')->loadReadyCalls();
37
        foreach ($calls as $call) {
38
            $api = $call->getApi();
39
40
            $worker = $api->getWorker();
41
            $job = $worker . '~apiUpdate';
42
            $callId = $call->getApiCallId();
43
44
            $gearman->doBackgroundJob($job, $callId, $callId);
45
        }
46
    }
47
}
48