Merged in sentry_logging (pull request #20)

Sentry logging and dep updates
This commit is contained in:
Alexey Eschenko 2019-01-19 00:18:51 +00:00
commit 101619f7b5
14 changed files with 1314 additions and 631 deletions

View File

@ -22,6 +22,7 @@ class AppKernel extends Kernel
new Ob\HighchartsBundle\ObHighchartsBundle(),
new Knp\Bundle\MarkdownBundle\KnpMarkdownBundle(),
new Knp\Bundle\PaginatorBundle\KnpPaginatorBundle(),
new Sentry\SentryBundle\SentryBundle(),
new Skobkin\Bundle\PointToolsBundle\SkobkinPointToolsBundle(),
];
@ -30,10 +31,6 @@ class AppKernel extends Kernel
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle();
if ('dev' === $this->getEnvironment()) {
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
}
}
return $bundles;

View File

@ -389,7 +389,7 @@ class SymfonyRequirements extends RequirementCollection
{
/* mandatory requirements follow */
$installedPhpVersion = phpversion();
$installedPhpVersion = PHP_VERSION;
$requiredPhpVersion = $this->getPhpRequiredVersion();
$this->addRecommendation(
@ -448,15 +448,8 @@ class SymfonyRequirements extends RequirementCollection
}
if (false !== $requiredPhpVersion && version_compare($installedPhpVersion, $requiredPhpVersion, '>=')) {
$timezones = array();
foreach (DateTimeZone::listAbbreviations() as $abbreviations) {
foreach ($abbreviations as $abbreviation) {
$timezones[$abbreviation['timezone_id']] = true;
}
}
$this->addRequirement(
isset($timezones[@date_default_timezone_get()]),
in_array(@date_default_timezone_get(), DateTimeZone::listIdentifiers(), true),
sprintf('Configured default timezone "%s" must be supported by your installation of PHP', @date_default_timezone_get()),
'Your default timezone is not supported by PHP. Check for typos in your <strong>php.ini</strong> file and have a look at the list of deprecated timezones at <a href="http://php.net/manual/en/timezones.others.php">http://php.net/manual/en/timezones.others.php</a>.'
);
@ -731,7 +724,7 @@ class SymfonyRequirements extends RequirementCollection
'Install and/or enable a <strong>PHP accelerator</strong> (highly recommended).'
);
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
if ('WIN' === strtoupper(substr(PHP_OS, 0, 3))) {
$this->addRecommendation(
$this->getRealpathCacheSize() >= 5 * 1024 * 1024,
'realpath_cache_size should be at least 5M in php.ini',

View File

@ -91,4 +91,7 @@ knp_paginator:
pagination: KnpPaginatorBundle:Pagination:twitter_bootstrap_v3_pagination.html.twig
csa_guzzle:
profiler: '%kernel.debug%'
profiler: '%kernel.debug%'
sentry:
dsn: "%sentry_dsn%"

View File

@ -37,3 +37,6 @@ parameters:
telegram_max_connections: 2
# Telegram monolog handler
telegram_log_chat_id: ~
# Sentry
sentry_dsn: ~

View File

@ -1,29 +1,20 @@
#!/usr/bin/env php
<?php
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Debug\Debug;
// if you don't want to setup permissions the proper way, just uncomment the following PHP line
// read http://symfony.com/doc/current/setup.html#checking-symfony-application-configuration-and-setup
// read https://symfony.com/doc/current/setup.html#checking-symfony-application-configuration-and-setup
// for more information
//umask(0000);
umask(0002);
set_time_limit(0);
/** @var \Composer\Autoload\ClassLoader $loader */
$loader = require __DIR__.'/autoload.php';
require __DIR__.'/../vendor/autoload.php';
$input = new ArgvInput();
$env = $input->getParameterOption(['--env', '-e'], getenv('SYMFONY_ENV') ?: 'dev');
$debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption(['--no-debug', '']) && $env !== 'prod';
$env = $input->getParameterOption(['--env', '-e'], getenv('SYMFONY_ENV') ?: 'dev', true);
$debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption('--no-debug', true) && $env !== 'prod';
if ($debug) {
Debug::enable();
}
$kernel = new AppKernel($env, $debug);
$application = new Application($kernel);
$application->run($input);
$application->run($input);

View File

@ -13,7 +13,7 @@
},
"require": {
"php": ">=7.1.0",
"symfony/symfony": "3.4.x-dev",
"symfony/symfony": "^3.4",
"doctrine/orm": "^2.5",
"doctrine/annotations": "^1.3.0",
"doctrine/doctrine-bundle": "^1.6",
@ -33,10 +33,10 @@
"unreal4u/telegram-api": "^2.2",
"csa/guzzle-bundle": "3.0.x-dev",
"unreal4u/monolog-telegram": "^0.2.0",
"symfony/web-server-bundle": "^3.3"
"symfony/web-server-bundle": "^3.3",
"sentry/sentry-symfony": "^2.2"
},
"require-dev": {
"sensio/generator-bundle": "^3.0",
"symfony/phpunit-bridge": "^3.0",
"phpunit/phpunit": "^5.7",
"doctrine/doctrine-fixtures-bundle": "^2.3"

1824
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -192,16 +192,19 @@ class UpdateSubscriptionsCommand extends Command
try {
$serviceUser = $this->userRepo->findActiveUserWithSubscribers($this->appUserId);
} catch (\Exception $e) {
$this->logger->error('Error while getting active user with subscribers', ['app_user_id' => $appUserId]);
$this->logger->error('Error while getting active user with subscribers', ['app_user_id' => $this->appUserId]);
throw $e;
}
if (!$serviceUser) {
$this->logger->critical('Service user not found or marked as removed');
// @todo Retrieving user
$this->logger->warning('Service user not found or marked as removed. Falling back to API.');
throw new \RuntimeException('Service user not found in the database');
try {
$serviceUser = $this->api->getUserById($this->appUserId);
} catch (UserNotFoundException $e) {
throw new \RuntimeException('Service user not found in the database and could not be retrieved from API.');
}
}
$this->logger->info('Getting service subscribers');

View File

@ -164,9 +164,13 @@ class UpdateUsersPrivacyCommand extends Command
}
if (!$serviceUser) {
$this->logger->critical('Service user not found or marked as removed');
$this->logger->warning('Service user not found or marked as removed. Falling back to API.');
throw new \RuntimeException('Service user not found in the database');
try {
$serviceUser = $this->api->getUserById($this->appUserId);
} catch (UserNotFoundException $e) {
throw new \RuntimeException('Service user not found in the database and could not be retrieved from API.');
}
}
$this->logger->info('Getting service subscribers');

View File

@ -2,14 +2,14 @@
namespace Skobkin\Bundle\PointToolsBundle\Controller;
use Knp\Component\Pager\Paginator;
use Knp\Component\Pager\PaginatorInterface;
use Skobkin\Bundle\PointToolsBundle\Repository\SubscriptionEventRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\{Request, Response};
class EventsController extends AbstractController
{
public function lastAction(Request $request, SubscriptionEventRepository $eventRepository, Paginator $paginator): Response
public function lastAction(Request $request, SubscriptionEventRepository $eventRepository, PaginatorInterface $paginator): Response
{
$eventsPagination = $paginator->paginate(
$eventRepository->createLastSubscriptionEventsQuery(),

View File

@ -2,7 +2,7 @@
namespace Skobkin\Bundle\PointToolsBundle\Controller;
use Knp\Component\Pager\Paginator;
use Knp\Component\Pager\PaginatorInterface;
use Skobkin\Bundle\PointToolsBundle\Repository\Blogs\PostRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
@ -11,7 +11,7 @@ class PublicFeedController extends AbstractController
{
private const POSTS_PER_PAGE = 20;
public function indexAction(Request $request, PostRepository $postRepository, Paginator $paginator)
public function indexAction(Request $request, PostRepository $postRepository, PaginatorInterface $paginator)
{
$postsPagination = $paginator->paginate(
$postRepository->createPublicFeedPostsQuery(),

View File

@ -2,7 +2,7 @@
namespace Skobkin\Bundle\PointToolsBundle\Controller;
use Knp\Component\Pager\Paginator;
use Knp\Component\Pager\PaginatorInterface;
use Skobkin\Bundle\PointToolsBundle\DTO\{DailyEvents, TopUserDTO};
use Skobkin\Bundle\PointToolsBundle\Entity\User;
use Skobkin\Bundle\PointToolsBundle\Repository\{SubscriptionEventRepository, UserRenameEventRepository, UserRepository};
@ -30,7 +30,7 @@ class UserController extends AbstractController
SubscriptionEventRepository $subscriptionEventRepository,
UserRepository $userRepository,
UserRenameEventRepository $renameEventRepository,
Paginator $paginator
PaginatorInterface $paginator
): Response {
/** @var User $user */
$user = $userRepository->findUserByLogin($login);

View File

@ -1,17 +1,14 @@
<?php
use Symfony\Component\HttpFoundation\Request;
/** @var \Composer\Autoload\ClassLoader $loader */
$loader = require __DIR__.'/../app/autoload.php';
include_once __DIR__.'/../app/bootstrap.php.cache';
umask(0002);
require __DIR__.'/../vendor/autoload.php';
if (PHP_VERSION_ID < 70000) {
include_once __DIR__.'/../app/bootstrap.php.cache';
}
$kernel = new AppKernel('prod', false);
$kernel->loadClassCache();
if (PHP_VERSION_ID < 70000) {
$kernel->loadClassCache();
}
//$kernel = new AppCache($kernel);
// When using the HttpCache, you need to call the method in your front controller instead of relying on the configuration parameter
//Request::enableHttpMethodParameterOverride();
$request = Request::createFromGlobals();

View File

@ -1,31 +1,25 @@
<?php
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Debug\Debug;
use Symfony\Component\HttpFoundation\Request;
// If you don't want to setup permissions the proper way, just uncomment the following PHP line
// read http://symfony.com/doc/current/book/installation.html#configuration-and-setup for more information
// read https://symfony.com/doc/current/setup.html#checking-symfony-application-configuration-and-setup
// for more information
umask(0002);
// This check prevents access to debug front controllers that are deployed by accident to production servers.
// Feel free to remove this, extend it, or make something more sophisticated.
if (isset($_SERVER['HTTP_CLIENT_IP'])
|| isset($_SERVER['HTTP_X_FORWARDED_FOR'])
|| !(
in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', 'fe80::1', '::1')) ||
php_sapi_name() === 'cli-server'
)
|| !(in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1'], true) || PHP_SAPI === 'cli-server')
) {
header('HTTP/1.0 403 Forbidden');
exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}
/** @var \Composer\Autoload\ClassLoader $loader */
$loader = require __DIR__.'/../app/autoload.php';
require __DIR__.'/../vendor/autoload.php';
Debug::enable();
$kernel = new AppKernel('dev', true);
$kernel->loadClassCache();
if (PHP_VERSION_ID < 70000) {
$kernel->loadClassCache();
}
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();