-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from FriendsOfAkeneo/develop
Merge develop with master
- Loading branch information
Showing
24 changed files
with
1,522 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,215 @@ | ||
<?php | ||
|
||
namespace FOA\CronBundle\Controller; | ||
|
||
use Symfony\Component\Serializer\Encoder\JsonEncoder; | ||
use Symfony\Component\Serializer\Serializer; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use FOA\CronBundle\Form\Type\CronType; | ||
use FOA\CronBundle\Manager\Cron; | ||
use FOA\CronBundle\Manager\CronManager; | ||
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
use Oro\Bundle\SecurityBundle\Annotation\AclAncestor; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
|
||
/** | ||
* Display dashboard and manage CRUD operations | ||
*/ | ||
class DashboardController extends Controller | ||
{ | ||
/** | ||
* Displays the current crontab and a form to add a new one. | ||
* | ||
* @AclAncestor("foa_cron_management_index") | ||
* | ||
* @return \Symfony\Component\HttpFoundation\Response | ||
*/ | ||
public function indexAction() | ||
{ | ||
$cronManager = new CronManager(); | ||
$this->addFlash('message', $cronManager->getOutput()); | ||
$this->addFlash('error', $cronManager->getError()); | ||
|
||
$form = $this->createForm(new CronType(), new Cron()); | ||
|
||
return $this->render('FOACronBundle:Dashboard:index.html.twig', [ | ||
'crons' => $cronManager->get(), | ||
'raw' => $cronManager->getRaw(), | ||
'form' => $form->createView() | ||
]); | ||
} | ||
|
||
/** | ||
* Add a cron to the cron table | ||
* | ||
* @param Request $request | ||
* @return RedirectResponse|Response | ||
*/ | ||
public function addAction(Request $request) | ||
{ | ||
$cronManager = new CronManager(); | ||
$cron = new Cron(); | ||
$this->addFlash('message', $cronManager->getOutput()); | ||
$this->addFlash('error', $cronManager->getError()); | ||
$form = $this->createForm(new CronType(), $cron); | ||
|
||
$form->handleRequest($request); | ||
if ($form->isValid()) { | ||
$cronManager->add($cron); | ||
$this->addFlash('message', $cronManager->getOutput()); | ||
$this->addFlash('error', $cronManager->getError()); | ||
|
||
return $this->redirect($this->generateUrl('foa_cron_index')); | ||
} | ||
|
||
return $this->render('FOACronBundle:Dashboard:index.html.twig', [ | ||
'crons' => $cronManager->get(), | ||
'raw' => $cronManager->getRaw(), | ||
'form' => $form->createView() | ||
]); | ||
} | ||
|
||
/** | ||
* Edit a cron | ||
* | ||
* @param $id - the line of the cron in the cron table | ||
* @return RedirectResponse|Response | ||
*/ | ||
public function editAction($id) | ||
{ | ||
$cronManager = new CronManager(); | ||
$cronList = $cronManager->get(); | ||
$this->addFlash('message', $cronManager->getOutput()); | ||
$this->addFlash('error', $cronManager->getError()); | ||
$form = $this->createForm(new CronType(), $cronList[$id]); | ||
|
||
$request = $this->get('request'); | ||
$form->handleRequest($request); | ||
if ($form->isValid()) { | ||
$cronManager->write(); | ||
|
||
$this->addFlash('message', $cronManager->getOutput()); | ||
$this->addFlash('error', $cronManager->getError()); | ||
|
||
return $this->redirect($this->generateUrl('foa_cron_index')); | ||
} | ||
|
||
return $this->render('FOACronBundle:Dashboard:edit.html.twig', [ | ||
'form' => $form->createView() | ||
]); | ||
} | ||
|
||
/** | ||
* Wake up a cron from the cron table | ||
* | ||
* @param $id - the line of the cron in the cron table | ||
* @return RedirectResponse | ||
*/ | ||
public function wakeupAction($id) | ||
{ | ||
$cronManager = new CronManager(); | ||
$cronList = $cronManager->get(); | ||
$this->addFlash('message', $cronManager->getOutput()); | ||
$this->addFlash('error', $cronManager->getError()); | ||
|
||
/** | ||
* @var Cron $cron | ||
*/ | ||
$cron = $cronList[$id]; | ||
$cron->setSuspended(false); | ||
|
||
$cronManager->write(); | ||
$this->addFlash('message', $cronManager->getOutput()); | ||
$this->addFlash('error', $cronManager->getError()); | ||
|
||
return $this->redirect($this->generateUrl('foa_cron_index')); | ||
} | ||
|
||
/** | ||
* Suspend a cron from the cron table | ||
* | ||
* @param $id - the line of the cron in the cron table | ||
* @return RedirectResponse | ||
*/ | ||
public function suspendAction($id) | ||
{ | ||
$cronManager = new CronManager(); | ||
$cronList = $cronManager->get(); | ||
$this->addFlash('message', $cronManager->getOutput()); | ||
$this->addFlash('error', $cronManager->getError()); | ||
|
||
/** | ||
* @var Cron $cron | ||
*/ | ||
$cron = $cronList[$id]; | ||
$cron->setSuspended(true); | ||
|
||
$cronManager->write(); | ||
$this->addFlash('message', $cronManager->getOutput()); | ||
$this->addFlash('error', $cronManager->getError()); | ||
|
||
return $this->redirect($this->generateUrl('foa_cron_index')); | ||
} | ||
|
||
/** | ||
* Remove a cron from the cron table | ||
* | ||
* @param $id - the line of the cron in the cron table | ||
* @return RedirectResponse | ||
*/ | ||
public function removeAction($id) | ||
{ | ||
$cronManager = new CronManager(); | ||
$this->addFlash('message', $cronManager->getOutput()); | ||
$this->addFlash('error', $cronManager->getError()); | ||
$cronManager->remove($id); | ||
$this->addFlash('message', $cronManager->getOutput()); | ||
$this->addFlash('error', $cronManager->getError()); | ||
|
||
return $this->redirect($this->generateUrl('foa_cron_index')); | ||
} | ||
|
||
/** | ||
* Gets a log file | ||
* | ||
* @param $id - the line of the cron in the cron table | ||
* @param $type - the type of file, log or error | ||
* @return Response | ||
*/ | ||
public function fileAction($id, $type) | ||
{ | ||
$cronManager = new CronManager(); | ||
$cronList = $cronManager->get(); | ||
|
||
/** | ||
* @var Cron $cron | ||
*/ | ||
$cron = $cronList[$id]; | ||
|
||
$data = []; | ||
$data['file'] = ($type == 'log') ? $cron->getLogFile(): $cron->getErrorFile(); | ||
$data['content'] = file_get_contents($data['file']); | ||
|
||
$serializer = new Serializer([], ['json' => new JsonEncoder()]); | ||
|
||
return new Response($serializer->serialize($data, 'json')); | ||
} | ||
|
||
/** | ||
* Adds a flash to the flash bag where flashes are array of messages | ||
* | ||
* @param $type | ||
* @param $message | ||
* @return mixed | ||
*/ | ||
protected function addFlash($type, $message) | ||
{ | ||
if (empty($message)) { | ||
return; | ||
} | ||
|
||
$session = $this->get('session'); | ||
$session->getFlashBag()->add($type, $message); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace FOA\CronBundle\Form\Type; | ||
|
||
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
/** | ||
* Cron job form type | ||
*/ | ||
class CronType extends AbstractType | ||
{ | ||
public function buildForm(FormBuilderInterface $builder, array $options) | ||
{ | ||
$builder | ||
->add('minute') | ||
->add('hour') | ||
->add('dayOfMonth') | ||
->add('month') | ||
->add('dayOfWeek') | ||
->add('command') | ||
->add('logFile', 'text', [ | ||
'required' => false, | ||
]) | ||
->add('errorFile', 'text', [ | ||
'required' => false, | ||
]) | ||
->add('comment', 'text', [ | ||
'required' => false, | ||
]); | ||
} | ||
|
||
public function configureOptions(OptionsResolver $resolver) | ||
{ | ||
$resolver->setDefaults([ | ||
'data_class' => 'FOA\CronBundle\Manager\Cron' | ||
]); | ||
} | ||
|
||
/** | ||
* Returns the name of this type. | ||
* | ||
* @return string The name of this type | ||
*/ | ||
function getName() | ||
{ | ||
return 'cron'; | ||
} | ||
} |
Oops, something went wrong.