Completed
Branch master (288a42)
by Benjamin
04:20
created
src/Alpixel/Bundle/CronBundle/Command/CronEnableJobCommand.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -24,15 +24,15 @@
 block discarded – undo
24 24
         $jobRepo = $em->getRepository('CronBundle:CronJob');
25 25
 
26 26
         $job = $jobRepo->findOneByCommand($jobName);
27
-        if(!$job)
27
+        if (!$job)
28 28
         {
29
-            $output->writeln("Couldn't find a job by the name of " . $jobName);
29
+            $output->writeln("Couldn't find a job by the name of ".$jobName);
30 30
             return CronJobResult::FAILED;
31 31
         }
32 32
 
33 33
         $job->setEnabled(true);
34 34
         $em->flush();
35 35
 
36
-        $output->writeln("Enabled cron job by the name of " . $jobName);
36
+        $output->writeln("Enabled cron job by the name of ".$jobName);
37 37
     }
38 38
 }
Please login to merge, or discard this patch.
src/Alpixel/Bundle/CronBundle/Command/CronStatusCommand.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -27,13 +27,13 @@  discard block
 block discarded – undo
27 27
         $output->writeln("Cron job statuses:");
28 28
 
29 29
         $cronJobs = array();
30
-        if($jobName = $input->getArgument('job'))
30
+        if ($jobName = $input->getArgument('job'))
31 31
         {
32 32
             try
33 33
             {
34 34
                 $cronJobs = array($jobRepo->findOneByCommand($jobName));
35 35
             }
36
-            catch(\Exception $e)
36
+            catch (\Exception $e)
37 37
             {
38 38
                 $output->writeln("Couldn't find a job by the name of $jobName");
39 39
                 return CronJobResult::FAILED;
@@ -44,16 +44,16 @@  discard block
 block discarded – undo
44 44
             $cronJobs = $em->getRepository('CronBundle:CronJob')->findAll();
45 45
         }
46 46
 
47
-        foreach($cronJobs as $cronJob)
47
+        foreach ($cronJobs as $cronJob)
48 48
         {
49
-            $output->write(" - " . $cronJob->getCommand());
50
-            if(!$cronJob->getEnabled())
49
+            $output->write(" - ".$cronJob->getCommand());
50
+            if (!$cronJob->getEnabled())
51 51
             {
52 52
                 $output->write(" (disabled)");
53 53
             }
54 54
             $output->writeln("");
55
-            $output->writeln("   Description: " . $cronJob->getDescription());
56
-            if(!$cronJob->getEnabled())
55
+            $output->writeln("   Description: ".$cronJob->getDescription());
56
+            if (!$cronJob->getEnabled())
57 57
             {
58 58
                 $output->writeln("   Not scheduled");
59 59
             }
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
             {
62 62
                 $output->write("   Scheduled for: ");
63 63
                 $now = new \DateTime();
64
-                if($cronJob->getNextRun() <= $now)
64
+                if ($cronJob->getNextRun() <= $now)
65 65
                 {
66 66
                     $output->writeln("Next run");
67 67
                 }
@@ -70,10 +70,10 @@  discard block
 block discarded – undo
70 70
                     $output->writeln(strftime("%c", $cronJob->getNextRun()->getTimestamp()));
71 71
                 }
72 72
             }
73
-            if($cronJob->getMostRecentRun())
73
+            if ($cronJob->getMostRecentRun())
74 74
             {
75 75
                 $status = "Unknown";
76
-                switch($cronJob->getMostRecentRun()->getResult())
76
+                switch ($cronJob->getMostRecentRun()->getResult())
77 77
                 {
78 78
                     case CronJobResult::SUCCEEDED:
79 79
                         $status = "Successful";
Please login to merge, or discard this patch.
src/Alpixel/Bundle/CronBundle/Command/CronScanCommand.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -42,16 +42,16 @@  discard block
 block discarded – undo
42 42
         // Enumerate all the jobs currently loaded
43 43
         $reader = $this->getContainer()->get("annotation_reader");
44 44
 
45
-        foreach($this->getApplication()->all() as $command)
45
+        foreach ($this->getApplication()->all() as $command)
46 46
         {
47 47
             // Check for an @CronJob annotation
48 48
             $reflClass = new \ReflectionClass($command);
49
-            foreach($reader->getClassAnnotations($reflClass) as $anno)
49
+            foreach ($reader->getClassAnnotations($reflClass) as $anno)
50 50
             {
51
-                if($anno instanceof CronJobAnno)
51
+                if ($anno instanceof CronJobAnno)
52 52
                 {
53 53
                     $job = $command->getName();
54
-                    if(array_key_exists($job, $knownJobs))
54
+                    if (array_key_exists($job, $knownJobs))
55 55
                     {
56 56
                         // Clear it from the known jobs so that we don't try to delete it
57 57
                         unset($knownJobs[$job]);
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
                         // Update the job if necessary
60 60
                         $currentJob = $jobRepo->findOneByCommand($job);
61 61
                         $currentJob->setDescription($command->getDescription());
62
-                        if($currentJob->getInterval() != $anno->value)
62
+                        if ($currentJob->getInterval() != $anno->value)
63 63
                         {
64 64
                             $newTime = new \DateTime();
65 65
                             $newTime = $newTime->add(new \DateInterval($anno->value));
@@ -78,9 +78,9 @@  discard block
 block discarded – undo
78 78
         }
79 79
 
80 80
         // Clear any jobs that weren't found
81
-        if(!$keepDeleted)
81
+        if (!$keepDeleted)
82 82
         {
83
-            foreach(array_keys($knownJobs) as $deletedJob)
83
+            foreach (array_keys($knownJobs) as $deletedJob)
84 84
             {
85 85
                 $output->writeln("Deleting job: $deletedJob");
86 86
                 $jobToDelete = $jobRepo->findOneByCommand($deletedJob);
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
         $newJob->setNextRun(new \DateTime());
102 102
         $newJob->setEnabled(!$defaultDisabled);
103 103
 
104
-        $output->writeln("Added the job " . $newJob->getCommand() . " with interval " . $newJob->getInterval());
104
+        $output->writeln("Added the job ".$newJob->getCommand()." with interval ".$newJob->getInterval());
105 105
         $em->persist($newJob);
106 106
     }
107 107
 }
Please login to merge, or discard this patch.
src/Alpixel/Bundle/CronBundle/Command/MemoryWriter.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@
 block discarded – undo
15 15
 
16 16
     public function doWrite($message, $newline) {
17 17
         $this->backingStore .= $message;
18
-        if($newline) {
18
+        if ($newline) {
19 19
             $this->backingStore .= "\n";
20 20
         }
21 21
     }
Please login to merge, or discard this patch.
src/Alpixel/Bundle/CronBundle/Command/CronPruneLogsCommand.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
         $em = $this->getContainer()->get("doctrine.orm.entity_manager");
26 26
         $job = $input->getArgument('job');
27 27
 
28
-        if($job)
28
+        if ($job)
29 29
         {
30 30
             $output->writeln("Pruning logs for cron job $job");
31 31
         }
@@ -34,12 +34,12 @@  discard block
 block discarded – undo
34 34
             $output->writeln("Pruning logs for all cron jobs");
35 35
         }
36 36
 
37
-        if($job)
37
+        if ($job)
38 38
         {
39 39
             $jobObj = $em->getRepository('CronBundle:CronJob')->findOneByCommand($job);
40
-            if(!$jobObj)
40
+            if (!$jobObj)
41 41
             {
42
-                $output->writeln("Couldn't find a job by the name of " . $job);
42
+                $output->writeln("Couldn't find a job by the name of ".$job);
43 43
                 return CronJobResult::FAILED;
44 44
             }
45 45
 
Please login to merge, or discard this patch.
src/Alpixel/Bundle/CronBundle/Command/CronRunCommand.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -32,17 +32,17 @@  discard block
 block discarded – undo
32 32
         $jobRepo = $em->getRepository('CronBundle:CronJob');
33 33
 
34 34
         $jobsToRun = array();
35
-        if($jobName = $input->getArgument('job'))
35
+        if ($jobName = $input->getArgument('job'))
36 36
         {
37 37
             try
38 38
             {
39 39
                 $jobObj = $jobRepo->findOneByCommand($jobName);
40
-                if($jobObj->getEnabled())
40
+                if ($jobObj->getEnabled())
41 41
                 {
42 42
                     $jobsToRun = array($jobObj);
43 43
                 }
44 44
             }
45
-            catch(\Exception $e)
45
+            catch (\Exception $e)
46 46
             {
47 47
                 $output->writeln("Couldn't find a job by the name of $jobName");
48 48
                 return CronJobResult::FAILED;
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
         $jobCount = count($jobsToRun);
57 57
         $output->writeln("Running $jobCount jobs:");
58 58
 
59
-        foreach($jobsToRun as $job)
59
+        foreach ($jobsToRun as $job)
60 60
         {
61 61
             $this->runJob($job, $output, $em);
62 62
         }
@@ -71,13 +71,13 @@  discard block
 block discarded – undo
71 71
 
72 72
     protected function runJob(CronJob $job, OutputInterface $output, EntityManager $em)
73 73
     {
74
-        $output->write("Running " . $job->getCommand() . ": ");
74
+        $output->write("Running ".$job->getCommand().": ");
75 75
 
76 76
         try
77 77
         {
78 78
             $commandToRun = $this->getApplication()->get($job->getCommand());
79 79
         }
80
-        catch(InvalidArgumentException $ex)
80
+        catch (InvalidArgumentException $ex)
81 81
         {
82 82
             $output->writeln(" skipped (command no longer exists)");
83 83
             $this->recordJobResult($em, $job, 0, "Command no longer exists", CronJobResult::SKIPPED);
@@ -94,32 +94,32 @@  discard block
 block discarded – undo
94 94
         {
95 95
             $returnCode = $commandToRun->execute($emptyInput, $jobOutput);
96 96
         }
97
-        catch(\Exception $ex)
97
+        catch (\Exception $ex)
98 98
         {
99 99
             $returnCode = CronJobResult::FAILED;
100 100
             $jobOutput->writeln("");
101
-            $jobOutput->writeln("Job execution failed with exception " . get_class($ex) . ":");
101
+            $jobOutput->writeln("Job execution failed with exception ".get_class($ex).":");
102 102
             $jobOutput->writeln($ex->__toString());
103 103
         }
104 104
         $jobEnd = microtime(true);
105 105
 
106 106
         // Clamp the result to accepted values
107
-        if($returnCode < CronJobResult::RESULT_MIN || $returnCode > CronJobResult::RESULT_MAX)
107
+        if ($returnCode < CronJobResult::RESULT_MIN || $returnCode > CronJobResult::RESULT_MAX)
108 108
         {
109 109
             $returnCode = CronJobResult::FAILED;
110 110
         }
111 111
 
112 112
         // Output the result
113 113
         $statusStr = "unknown";
114
-        if($returnCode == CronJobResult::SKIPPED)
114
+        if ($returnCode == CronJobResult::SKIPPED)
115 115
         {
116 116
             $statusStr = "skipped";
117 117
         }
118
-        elseif($returnCode == CronJobResult::SUCCEEDED)
118
+        elseif ($returnCode == CronJobResult::SUCCEEDED)
119 119
         {
120 120
             $statusStr = "succeeded";
121 121
         }
122
-        elseif($returnCode == CronJobResult::FAILED)
122
+        elseif ($returnCode == CronJobResult::FAILED)
123 123
         {
124 124
             $statusStr = "failed";
125 125
         }
Please login to merge, or discard this patch.
src/Alpixel/Bundle/CronBundle/Command/CronDisableJobCommand.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -26,15 +26,15 @@
 block discarded – undo
26 26
         $jobRepo = $em->getRepository('CronBundle:CronJob');
27 27
 
28 28
         $job = $jobRepo->findOneByCommand($jobName);
29
-        if(!$job)
29
+        if (!$job)
30 30
         {
31
-            $output->writeln("Couldn't find a job by the name of " . $jobName);
31
+            $output->writeln("Couldn't find a job by the name of ".$jobName);
32 32
             return CronJobResult::FAILED;
33 33
         }
34 34
 
35 35
         $job->setEnabled(false);
36 36
         $em->flush();
37 37
 
38
-        $output->writeln("Disabled cron job by the name of " . $jobName);
38
+        $output->writeln("Disabled cron job by the name of ".$jobName);
39 39
     }
40 40
 }
Please login to merge, or discard this patch.
src/Alpixel/Bundle/CronBundle/Entity/Repository/CronJobRepository.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@
 block discarded – undo
10 10
                      ->createQuery("SELECT job.command FROM CronBundle:CronJob job")
11 11
                      ->getScalarResult();
12 12
         $toRet = array();
13
-        foreach($data as $datum)
13
+        foreach ($data as $datum)
14 14
         {
15 15
             $toRet[] = $datum['command'];
16 16
         }
Please login to merge, or discard this patch.