diff --git a/Controller/DashboardController.php b/Controller/DashboardController.php new file mode 100755 index 0000000..38836e6 --- /dev/null +++ b/Controller/DashboardController.php @@ -0,0 +1,215 @@ +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); + } +} diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php deleted file mode 100755 index f28f292..0000000 --- a/DependencyInjection/Configuration.php +++ /dev/null @@ -1,22 +0,0 @@ -root('foa_cron'); - - return $treeBuilder; - } -} diff --git a/DependencyInjection/FOACronExtension.php b/DependencyInjection/FOACronExtension.php index d3be15a..d7f571e 100755 --- a/DependencyInjection/FOACronExtension.php +++ b/DependencyInjection/FOACronExtension.php @@ -14,9 +14,7 @@ class FOACronExtension extends Extension */ public function load(array $configs, ContainerBuilder $container) { - $configuration = new Configuration(); - $config = $this->processConfiguration($configuration, $configs); - $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); + $loader->load('services.xml'); } } diff --git a/FOACronBundle.php b/FOACronBundle.php index 9e9bb20..a3afeb8 100755 --- a/FOACronBundle.php +++ b/FOACronBundle.php @@ -4,6 +4,9 @@ use Symfony\Component\HttpKernel\Bundle\Bundle; +/** + * Integration of Cron management board and Akeneo + */ class FOACronBundle extends Bundle { } diff --git a/Form/Type/CronType.php b/Form/Type/CronType.php new file mode 100755 index 0000000..a912a93 --- /dev/null +++ b/Form/Type/CronType.php @@ -0,0 +1,50 @@ +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'; + } +} diff --git a/Manager/Cron.php b/Manager/Cron.php new file mode 100755 index 0000000..e64ac0d --- /dev/null +++ b/Manager/Cron.php @@ -0,0 +1,491 @@ +')) { + list($command, $errorFile) = explode('2>', $command); + $errorFile = trim($errorFile); + } + + // extract log file + if (strpos($command, '>')) { + list($command, $logFile) = explode('>', $command); + $logFile = trim($logFile); + } + + // compute last run time, and file size + $lastRunTime = null; + $logSize = null; + $errorSize = null; + if (isset($logFile) && file_exists($logFile)) { + $lastRunTime = filemtime($logFile); + $logSize = filesize($logFile); + } + if (isset($errorFile) && file_exists($errorFile)) { + $lastRunTime = max($lastRunTime ? : 0, filemtime($errorFile)); + $errorSize = filesize($errorFile); + } + + // compute status + $status = 'error'; + if (!$logSize && !$errorSize) { + $status = 'unknown'; + } else if (!$errorSize || $errorSize == 0) { + $status = 'success'; + } + + // create cron instance + $cron = new self(); + $cron->setMinute($parts[0]) + ->setHour($parts[1]) + ->setDayOfMonth($parts[2]) + ->setMonth($parts[3]) + ->setDayOfWeek($parts[4]) + ->setCommand(\trim($command)) + ->setLastRunTime($lastRunTime) + ->setLogSize($logSize) + ->setErrorSize($errorSize) + ->setStatus($status); + + if (isset($isSuspended)) { + $cron->setSuspended($isSuspended); + } + if (isset($comment)) { + $cron->setComment($comment); + } + if (isset($logFile)) { + $cron->setLogFile($logFile); + } + if (isset($errorFile)) { + $cron->setErrorFile($errorFile); + } + + return $cron; + } + + /** + * @param string $command + * @return $this + */ + public function setCommand($command) + { + $this->command = $command; + + return $this; + } + + /** + * @return string + */ + public function getCommand() + { + return $this->command; + } + + /** + * @param string $dayOfMonth + * @return $this + */ + public function setDayOfMonth($dayOfMonth) + { + $this->dayOfMonth = $dayOfMonth; + + return $this; + } + + /** + * @return string + */ + public function getDayOfMonth() + { + return $this->dayOfMonth; + } + + /** + * @param string $dayOfWeek + * @param $dayOfWeek + * @return $this + */ + public function setDayOfWeek($dayOfWeek) + { + $this->dayOfWeek = $dayOfWeek; + + return $this; + } + + /** + * @return string + */ + public function getDayOfWeek() + { + return $this->dayOfWeek; + } + + /** + * @param string $hour + * @param $hour + * @return $this + */ + public function setHour($hour) + { + $this->hour = $hour; + + return $this; + } + + /** + * @return string + */ + public function getHour() + { + return $this->hour; + } + + /** + * @param string $minute + * @return $this + */ + public function setMinute($minute) + { + $this->minute = $minute; + + return $this; + } + + /** + * @return string + */ + public function getMinute() + { + return $this->minute; + } + + /** + * @param string $month + * @return $this + */ + public function setMonth($month) + { + $this->month = $month; + + return $this; + } + + /** + * @return string + */ + public function getMonth() + { + return $this->month; + } + + /** + * @param string $comment + * @return $this + */ + public function setComment($comment) + { + $this->comment = $comment; + + return $this; + } + + /** + * @return string + */ + public function getComment() + { + return $this->comment; + } + + /** + * @param string $logFile + * @return $this + */ + public function setLogFile($logFile) + { + $this->logFile = $logFile; + + return $this; + } + + /** + * @return string + */ + public function getLogFile() + { + return $this->logFile; + } + + /** + * @param string $errorFile + * @return $this + */ + public function setErrorFile($errorFile) + { + $this->errorFile = $errorFile; + + return $this; + } + + /** + * @return string + */ + public function getErrorFile() + { + return $this->errorFile; + } + + /** + * @param int $lastRunTime + * @return $this + */ + public function setLastRunTime($lastRunTime) + { + $this->lastRunTime = $lastRunTime; + + return $this; + } + + /** + * @return int + */ + public function getLastRunTime() + { + return $this->lastRunTime; + } + + /** + * @param string $errorSize + * @return $this + */ + public function setErrorSize($errorSize) + { + $this->errorSize = $errorSize; + + return $this; + } + + /** + * @return string + */ + public function getErrorSize() + { + return $this->errorSize; + } + + /** + * @param string $logSize + * @return $this + */ + public function setLogSize($logSize) + { + $this->logSize = $logSize; + + return $this; + } + + /** + * @return string + */ + public function getLogSize() + { + return $this->logSize; + } + + /** + * @param string $status + * @return $this + */ + public function setStatus($status) + { + $this->status = $status; + + return $this; + } + + /** + * @return string + */ + public function getStatus() + { + return $this->status; + } + + /** + * Concatenate time data to get the time expression + * + * @return string + */ + public function getExpression() + { + return sprintf('%s %s %s %s %s', $this->minute, $this->hour, $this->dayOfMonth, $this->month, $this->dayOfWeek); + } + + /** + * Gets the value of isSuspended + * + * @return boolean + */ + public function isSuspended() + { + return $this->isSuspended; + } + + /** + * Sets the value of isSuspended + * + * @param boolean $isSuspended status + * + * @return Cron + */ + public function setSuspended($isSuspended = true) + { + if ($this->isSuspended != $isSuspended) { + $this->isSuspended = $isSuspended; + } + + return $this; + } + + /** + * Transforms the cron instance into a cron line + * + * @return string + */ + public function __toString() + { + $cronLine = ''; + if ($this->isSuspended()) { + $cronLine .= '#suspended: '; + } + + $cronLine .= $this->getExpression() . ' ' . $this->command; + if ('' != $this->logFile) { + $cronLine .= ' > ' . $this->logFile; + } + if ('' != $this->errorFile) { + $cronLine .= ' 2> ' . $this->errorFile; + } + if ('' != $this->comment) { + $cronLine .= ' #' . $this->comment; + } + return $cronLine; + } +} diff --git a/Manager/CronManager.php b/Manager/CronManager.php new file mode 100755 index 0000000..9f8eb5b --- /dev/null +++ b/Manager/CronManager.php @@ -0,0 +1,137 @@ +run(); + $lines = array_filter(explode(PHP_EOL, $process->getOutput()), function ($line) { + return '' != trim($line); + }); + + foreach ($lines as $lineNumber => $line) { + // if line is nt a comment, convert it to a cron + if (strpos($line, '#suspended: ', 0) === 0 || 0 !== strpos($line, '#', 0)) { + try { + $line = Cron::parse($line); + } catch (\Exception $e) { + $process->addErrorOutput('CronManager was unable to parse crontab at line ' . $lineNumber); + } + } + $this->lines['l' . $lineNumber] = $line; + } + + $this->error = $process->getErrorOutput(); + } + + /** + * Gets the array of crons indexed by line number + * + * @return array + */ + public function get() + { + return array_filter($this->lines, function ($line) { + return $line instanceof Cron; + }); + } + + /** + * Add a cron to the cron table + * + * @param Cron $cron + */ + public function add(Cron $cron) + { + $this->lines[] = $cron; + + $this->write(); + } + + /** + * Remove a cron from the cron table + * + * @param $index - the line number + */ + public function remove($index) + { + $this->lines = array_diff_key($this->lines, [$index => '']); + + $this->write(); + } + + /** + * Write the current crons in the cron table + */ + public function write() + { + $file = tempnam(sys_get_temp_dir(), 'cron'); + + file_put_contents($file, $this->getRaw() . PHP_EOL); + + $process = new Process('crontab ' . $file); + $process->run(); + + $this->error = $process->getErrorOutput(); + $this->output = $process->getOutput(); + } + + /** + * Gets the error output when using the 'crontab' command + * + * @return string + */ + public function getError() + { + return $this->error; + } + + /** + * Gets the output when using the 'crontab' command + * + * @return string + */ + public function getOutput() + { + return $this->output; + } + + /** + * Gets a representation of the cron table file + * + * @return mixed + */ + public function getRaw() + { + return implode(PHP_EOL, $this->lines); + } +} diff --git a/README.md b/README.md index 2580cde..3bd7232 100755 --- a/README.md +++ b/README.md @@ -1,2 +1,7 @@ +[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/FriendsOfAkeneo/FOACronBundle/badges/quality-score.png?b=develop)](https://scrutinizer-ci.com/g/FriendsOfAkeneo/FOACronBundle/?branch=develop) + FOACronBundle - cron manager for Akeneo ======================================= + +This bundle is adaptation of [BCCCronManagerBundle](https://github.com/michelsalib/BCCCronManagerBundle) to be compatible +with Akeneo PIM. Also it has some code quality improvements. diff --git a/Resources/config/acl.yml b/Resources/config/acl.yml new file mode 100644 index 0000000..0fb9a27 --- /dev/null +++ b/Resources/config/acl.yml @@ -0,0 +1,4 @@ +# Cron management (System tab) +foa_cron_management_index: + type: action + label: foa_cron.acl.locale.index diff --git a/Resources/config/assetic.yml b/Resources/config/assetic.yml new file mode 100755 index 0000000..0aea7e3 --- /dev/null +++ b/Resources/config/assetic.yml @@ -0,0 +1,3 @@ +assetic: + bundles: + - FOACronBundle diff --git a/Resources/config/navigation.yml b/Resources/config/navigation.yml new file mode 100755 index 0000000..0212859 --- /dev/null +++ b/Resources/config/navigation.yml @@ -0,0 +1,20 @@ +oro_menu_config: + items: + pim_cron_manager: + label: 'Cron Management' + route: 'foa_cron_index' + aclResourceId: foa_cron_management_index + extras: + routes: ['/^cron-manager/'] + description: Cron management index page + + tree: + application_menu: + children: + system_tab: + children: + pim_cron_manager: ~ + +oro_titles: + foa_cron_index: cron.page_title + foa_cron_edit: cron.edit diff --git a/Resources/config/routing.yml b/Resources/config/routing.yml new file mode 100755 index 0000000..6ac9290 --- /dev/null +++ b/Resources/config/routing.yml @@ -0,0 +1,30 @@ +foa_cron_index: + pattern: / + defaults: { _controller: FOACronBundle:Dashboard:index } + +foa_cron_edit: + pattern: /{id}/edit + defaults: { _controller: FOACronBundle:Dashboard:edit } + +foa_cron_add: + pattern: /add + defaults: { _controller: FOACronBundle:Dashboard:add } + methods: [POST] + +foa_cron_wakeup: + pattern: /{id}/wakeup + defaults: { _controller: FOACronBundle:Dashboard:wakeup } + +foa_cron_suspend: + pattern: /{id}/suspend + defaults: { _controller: FOACronBundle:Dashboard:suspend } + +foa_cron_remove: + pattern: /{id}/remove + defaults: { _controller: FOACronBundle:Dashboard:remove } + +foa_cron_file: + pattern: /{id}/file/{type} + defaults: { _controller: FOACronBundle:Dashboard:file } + requirements: + type: log|error diff --git a/Resources/config/services.xml b/Resources/config/services.xml new file mode 100755 index 0000000..60c6f77 --- /dev/null +++ b/Resources/config/services.xml @@ -0,0 +1,15 @@ + + + + + + + + %kernel.logs_dir% + %kernel.root_dir% + + + + diff --git a/Resources/config/validation.xml b/Resources/config/validation.xml new file mode 100755 index 0000000..64f16b4 --- /dev/null +++ b/Resources/config/validation.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Resources/public/css/main.css b/Resources/public/css/main.css new file mode 100755 index 0000000..a5bdd23 --- /dev/null +++ b/Resources/public/css/main.css @@ -0,0 +1,36 @@ +body { + padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */ +} + +.control-group.error label { + color: #B94A48; +} + +.command-input { + padding-top: 20px; +} + +.time-menu .caret { + margin-top: 10px; +} + +.tooltip { + font-size: 20px; + line-height: 26px; +} + +.table th, .table td { + vertical-align: middle; +} + +.table th i { + margin-right: 5px; +} + +.modal-header, table td pre { + white-space: pre-wrap; +} + +.glyphicon-white, .glyphicon-white a { + color: #fff; +} diff --git a/Resources/public/js/script.js b/Resources/public/js/script.js new file mode 100755 index 0000000..80cf04b --- /dev/null +++ b/Resources/public/js/script.js @@ -0,0 +1,49 @@ +(function ($) { + $(".collapse").collapse(); + $('.time-input, .command-preset, .time-menu, .log-preset').tooltip({}); + + var presets = { + 'yearly': ['0', '0', '1', '1', '*'], + 'monthly': ['0', '0', '1', '*', '*'], + 'weekly': ['0', '0', '*', '*', '0'], + 'daily': ['0', '0', '*', '*', '*'], + 'hourly': ['0', '*', '*', '*', '*'] + }; + + $('.time-preset').on('click', function (e) { + e.preventDefault(); + var $link = $(this); + + var preset = presets[$link.attr('id')]; + + $('#cron_minute').val(preset[0]); + $('#cron_hour').val(preset[1]); + $('#cron_dayOfMonth').val(preset[2]); + $('#cron_month').val(preset[3]); + $('#cron_dayOfWeek').val(preset[4]); + }); + + $('.command-preset').on('click', function () { + $('#cron_command').val($(this).attr('value')); + }); + + $('.log-preset').on('click', function () { + var $button = $(this); + + $button.parent().parent().find('input').val($button.attr('value')); + }); + + $('.modal-link').on('click', function (e) { + e.preventDefault(); + var $link = $(this); + $.getJSON($link.attr('href'), function (data) { + var $modal = $('#modal'); + $modal.find('.modal-header h3').text(data.file); + $modal.find('.modal-body pre').text(data.content); + $modal.modal({ + backdrop: true, + keyboard: true + }); + }); + }); +})(jQuery); diff --git a/Resources/translations/messages.en.yml b/Resources/translations/messages.en.yml new file mode 100755 index 0000000..0efc9f0 --- /dev/null +++ b/Resources/translations/messages.en.yml @@ -0,0 +1,20 @@ +cron: + page_title: 'Cron Tasks Management' + add: 'Add' + list: 'Cron list' + edit: 'Edit' + details: 'Details' + last_run: 'Last Run' + comment: 'Comment' + log_file: 'Log File' + error_file: 'Error File' + raw_cron: 'Raw cron' + wake_up: 'Wake up' + suspend: 'Suspend' + remove: 'Remove' + add_a_cron: 'Add a cron' + +foa_cron: + acl: + locale: + index: 'Cron management' diff --git a/Resources/views/Dashboard/edit.html.twig b/Resources/views/Dashboard/edit.html.twig new file mode 100755 index 0000000..094d0c1 --- /dev/null +++ b/Resources/views/Dashboard/edit.html.twig @@ -0,0 +1,25 @@ +{% extends 'FOACronBundle::layout.html.twig' %} + +{% trans_default_domain "messages" %} + +{% block content %} + +
+
+ {% include 'FOACronBundle:Dashboard:form.html.twig' with {'form': form} %} + +
+ +
+{% endblock %} diff --git a/Resources/views/Dashboard/form.html.twig b/Resources/views/Dashboard/form.html.twig new file mode 100755 index 0000000..95ae072 --- /dev/null +++ b/Resources/views/Dashboard/form.html.twig @@ -0,0 +1,113 @@ +{% form_theme form 'FOACronBundle:Form:fields.html.twig' %} + +
+ + {{ 'Keep in mind that cron user is %user% and its root directory is %root%.' | trans({'%user%': ''~wwwUser.name~'', '%root%': ''~wwwUser.dir~''}, 'BCCCronManagerBundle') | raw }} + +
+
+ +
+ {{ form_errors(form.minute) }} + {{ form_errors(form.hour) }} + {{ form_errors(form.dayOfMonth) }} + {{ form_errors(form.month) }} + {{ form_errors(form.dayOfWeek) }} +
+ +
+
+ + {{ form_widget(form.minute, {'attr':{ + 'class': 'time-input form-control ', + 'data-original-title': 'Minute' | trans ({}, 'BCCCronManagerBundle') + }}) + }} +
+
+ + {{ form_widget(form.hour, {'attr':{ + 'class': 'time-input form-control ', + 'data-original-title': 'Hour' | trans ({}, 'BCCCronManagerBundle') + }}) + }} +
+
+ + {{ form_widget(form.dayOfMonth, {'attr':{ + 'class': 'time-input form-control ', + 'data-original-title': 'Day Of Month' | trans ({}, 'BCCCronManagerBundle') + }}) + }} +
+
+ + {{ form_widget(form.month, {'attr':{ + 'class': 'time-input form-control ', + 'data-original-title': 'Month' | trans ({}, 'BCCCronManagerBundle') + }}) + }} +
+
+ + {{ form_widget(form.dayOfWeek, {'attr':{ + 'class': 'time-input form-control ', + 'data-original-title': 'Day Of Week' | trans ({}, 'BCCCronManagerBundle') + }}) + }} +
+
+ +
+ {{ form_errors(form.command) }} +
+ + {{ form_label(form.command, 'Command', {'translation_domain': 'BCCCronManagerBundle', 'attr':{'class': 'col-md-1'}}) }} + + {{- form_widget(form.command, {'attr':{'class': 'form-control'}}) }} + +
+
+ +
+ {{ form_errors(form.logFile) }} +
+ + {{ form_label(form.logFile, 'Log File', {'translation_domain': 'BCCCronManagerBundle', 'attr':{'class': 'col-md-1'}}) }} + + {{- form_widget(form.logFile, {'attr':{'class': 'form-control col-md-10'}}) }} + +
+
+ +
+ {{ form_errors(form.errorFile) }} +
+ + {{ form_label(form.errorFile, 'Error File', {'translation_domain': 'BCCCronManagerBundle', 'attr':{'class': 'col-md-1'}}) }} + + {{- form_widget(form.errorFile, {'attr':{'class': 'form-control col-md-10'}}) }} + +
+
+ +
+ {{ form_errors(form.comment) }} +
+ + {{ form_label(form.comment, 'Comment', {'translation_domain': 'BCCCronManagerBundle', 'attr':{'class': 'col-md-1'}}) }} + + {{- form_widget(form.comment, {'attr':{'class': 'form-control col-md-10'}}) }} +
+
+ +{{ form_rest(form) }} diff --git a/Resources/views/Dashboard/index.html.twig b/Resources/views/Dashboard/index.html.twig new file mode 100755 index 0000000..2fdddf7 --- /dev/null +++ b/Resources/views/Dashboard/index.html.twig @@ -0,0 +1,136 @@ +{% extends 'FOACronBundle::layout.html.twig' %} + +{% trans_default_domain "messages" %} + +{% block content %} + + +
+ + {% for index, cron in crons %} +
+
+ + {{ cron.status | trans({}, 'BCCCronManagerBundle') | capitalize }} + +
+

+ {{ cron.expression }} {{ cron.command }} +

+ +
+
+ + + + + + {% if cron.comment %} + + + + + {% endif %} + {% if cron.logFile %} + + + + + + {% endif %} + {% if cron.errorFile %} + + + + + + {% endif %} + + + + + + + + +
{{ 'cron.last_run'|trans }}{{ cron.lastRunTime ? cron.lastRunTime | date : 'Unknown' | trans({}, 'BCCCronManagerBundle') }}
{{ 'cron.comment'|trans }}{{ cron.comment }}
{{ 'cron.log_file'|trans }}{{ cron.logFile }} + {% if cron.logSize %} + + + {{ 'cron.log_file'|trans }} + + {% endif %} +
{{ 'cron.error_file'|trans }}{{ cron.errorFile }} + {% if cron.errorSize %} + + + {{ 'cron.error_file'|trans }} + + {% endif %} +
{{ 'cron.raw_cron'|trans }} + +
{{ cron }}
+
+ + + + {{ 'cron.edit'|trans }} + + {% if cron.suspended %} + + + {{ 'cron.wake_up'|trans }} + + {% else %} + + + {{ 'cron.suspend'|trans }} + + {% endif %} + + + {{ 'cron.remove'|trans }} + + +
+
+ {{ not loop.last ? '
' : '' }} + {% endfor %} +
+
+ +
+ {% include 'FOACronBundle:Dashboard:form.html.twig' with {'form': form} %} + +
+
+{% endblock %} diff --git a/Resources/views/Form/fields.html.twig b/Resources/views/Form/fields.html.twig new file mode 100755 index 0000000..41f0493 --- /dev/null +++ b/Resources/views/Form/fields.html.twig @@ -0,0 +1,20 @@ +{% block field_errors %} + {% spaceless %} + {% if errors|length > 0 %} +
+ {% for error in errors %} + {{ error.messageTemplate|trans(error.messageParameters, 'validators') }} + {% endfor %} +
+ {% endif %} + {% endspaceless %} +{% endblock field_errors %} + +{% block generic_label %} + {% spaceless %} + {% if required %} + {% set attr = attr|merge({'class': attr.class|default('') ~ ' required'}) %} + {% endif %} + {{ label|trans({}, translation_domain) }} + {% endspaceless %} + {% endblock %} \ No newline at end of file diff --git a/Resources/views/layout.html.twig b/Resources/views/layout.html.twig new file mode 100755 index 0000000..30423df --- /dev/null +++ b/Resources/views/layout.html.twig @@ -0,0 +1,38 @@ +{% extends bap.layout %} +{% import 'PimUIBundle:Default:page_elements.html.twig' as elements %} + +{% block head %} + fdsfdsfdsfsdsfds + + +{% endblock %} + +{% block page_container %} + {% block content %}{% endblock %} + +{% endblock %} diff --git a/Twig/TwigExtension.php b/Twig/TwigExtension.php new file mode 100755 index 0000000..0011834 --- /dev/null +++ b/Twig/TwigExtension.php @@ -0,0 +1,49 @@ +wwwUser = posix_getpwuid(posix_geteuid()); + } else { + $this->wwwUser = [ + 'name' => get_current_user(), + 'dir' => '-', + ]; + } + $this->logDir = $logDir; + $this->symfonyCommand = 'php ' . $kernelDir . '/console'; + } + + public function getGlobals() + { + return [ + 'wwwUser' => $this->wwwUser, + 'logDir' => $this->logDir, + 'symfonyCommand' => $this->symfonyCommand, + ]; + } + + public function getName() + { + return 'bcc-cron-manager'; + } +} diff --git a/composer.json b/composer.json index ffeaf0d..b6d1f66 100755 --- a/composer.json +++ b/composer.json @@ -4,7 +4,9 @@ "description" : "", "keywords" : [ "cron", - "Symfony2" + "Symfony2", + "Akeneo", + "PIM" ], "homepage": "https://github.com/FriendsOfAkeneo/FOACronBundle", "license": "MIT", @@ -17,5 +19,10 @@ }, "autoload" : { "psr-4" : { "FOA\\CronBundle\\" : "" } + }, + "extra": { + "branch-alias": { + "dev-develop": "1.0-dev" + } } }