Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Issue #12, added Bootstrap 3 support #18

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions Command/ClearCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?php
namespace Lexik\Bundle\MonologBrowserBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Doctrine\DBAL\Types\Type;
/**
* Description of ClearCommand
*
* @author Dmitry Anikeev <da@kww.su>
*/
class ClearCommand extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName('lexik:monolog-browser:clear')
->setDescription('Delete stored logs')
->addOption(
'days',
null,
InputOption::VALUE_OPTIONAL,
'Deletes all logs up to current date sub days',
null
)
->addOption(
'level_name',
null,
InputOption::VALUE_OPTIONAL,
'Level of logs for delete',
null
)
->addOption(
'force',
null,
InputOption::VALUE_NONE,
'Confirm execute. Prints sql query if option is missing'
)
;
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$container = $this->getContainer();
/* @var $connection \Doctrine\DBAL\Connection */
$connection = $container->get('lexik_monolog_browser.doctrine_dbal.connection');
$tableName = $this->getContainer()->getParameter('lexik_monolog_browser.doctrine.table_name');
$qb = $connection->createQueryBuilder();
$days = $input->getOption('days');
if ($days)
{
$current = new \DateTime();
$current->sub(new \DateInterval('P'.$days.'D'));
$qb
->andWhere($qb->expr()->lte('datetime', ':date'))
->setParameter('date', $current, \Doctrine\DBAL\Types\Type::DATETIME)
;
}
$level_name = $input->getOption('level_name');
if ($level_name)
{
$qb
->andWhere($qb->expr()->eq('level_name', ':level_name'))
->setParameter('level_name', $level_name, \PDO::PARAM_STR)
;
}
$ok = 1;
if (!$input->getOption('force'))
{
try
{
$qb
->select('COUNT(*)')
->from($tableName,'e')
;
$output->writeln(sprintf('<info>Will be deleted %s rows</info>', $qb->execute()->fetchColumn()));
}
catch (Exception $ex)
{
$output->writeln(sprintf('<error>%s</error>', $ex->getMessage()));
$ok = 0;
}
}
else
{
try
{
$qb
->delete($tableName)
;
$output->writeln(sprintf('<info>Deleted %s rows</info>', $qb->execute()));
}
catch (Exception $ex)
{
$output->writeln(sprintf('<error>%s</error>', $ex->getMessage()));
$ok = 0;
}
}
return $ok;
}

protected function convertDate($date, $qb)
{
return Type::getType('datetime')->convertToDatabaseValue($date, $qb->getConnection()->getDatabasePlatform());
}
}
33 changes: 15 additions & 18 deletions Form/LogSearchType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\OptionsResolver\Options;

use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Connection;

Expand All @@ -31,25 +30,25 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'required' => false,
))
->add('date_from', 'datetime', array(
'date_widget' => 'single_text',
'date_format' => 'MM/dd/yyyy',
'time_widget' => 'text',
'widget' => 'single_text',
'format' => 'd.M.y H:m:s',
'date_format' => 'd.M.y H:m:s',
'required' => false,
))
->add('date_to', 'datetime', array(
'date_widget' => 'single_text',
'date_format' => 'MM/dd/yyyy',
'time_widget' => 'text',
'widget' => 'single_text',
'format' => 'd.M.y H:m:s',
'date_format' => 'd.M.y H:m:s',
'required' => false,
))
;

;
$qb = $options['query_builder'];
$convertDateToDatabaseValue = function(\DateTime $date) use ($qb) {
return Type::getType('datetime')->convertToDatabaseValue($date, $qb->getConnection()->getDatabasePlatform());
};

$builder->addEventListener(FormEvents::POST_BIND, function(FormEvent $event) use ($qb, $convertDateToDatabaseValue) {
$builder->addEventListener(FormEvents::POST_SUBMIT, function(FormEvent $event) use ($qb, $convertDateToDatabaseValue) {
$data = $event->getData();

if (null !== $data['term']) {
Expand All @@ -64,18 +63,18 @@ public function buildForm(FormBuilderInterface $builder, array $options)
->setParameter('level', $data['level']);
}

if ($data['date_from'] instanceof \DateTime) {
if (isset($data['date_from']) && $data['date_from'] instanceof \DateTime) {
$qb->andWhere('l.datetime >= :date_from')
->setParameter('date_from', $convertDateToDatabaseValue($data['date_from']));
}

if ($data['date_to'] instanceof \DateTime) {
if (isset($data['date_to']) && $data['date_to'] instanceof \DateTime) {
$qb->andWhere('l.datetime <= :date_to')
->setParameter('date_to', $convertDateToDatabaseValue($data['date_to']));
}
});
}

}
/**
* {@inheritdoc}
*/
Expand All @@ -89,10 +88,8 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
'log_levels' => array(),
'csrf_protection' => false,
))
->setAllowedTypes(array(
'log_levels' => 'array',
'query_builder' => '\Doctrine\DBAL\Query\QueryBuilder',
))
->addAllowedTypes('log_levels','array')
->addAllowedTypes('query_builder','\Doctrine\DBAL\Query\QueryBuilder')
;
}

Expand Down
3 changes: 3 additions & 0 deletions Processor/WebExtendedProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public function __invoke(array $record)
// skip processing if for some reason request data
// is not present (CLI or wonky SAPIs)
if (!isset($this->serverData['REQUEST_URI'])) {
$record['http_server'] = array();
$record['http_post'] = array();
$record['http_get'] = array();
return $record;
}

Expand Down
5 changes: 5 additions & 0 deletions Resources/public/css/bootstrap-datetimepicker.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

182 changes: 0 additions & 182 deletions Resources/public/css/datepicker.css

This file was deleted.

Loading