diff --git a/README.md b/README.md new file mode 100644 index 0000000..0418534 --- /dev/null +++ b/README.md @@ -0,0 +1,54 @@ +# Point Tools + +Point Tools - это сервис предоставляющий дополнительные функции для блогов [Point.im](https://point.im/). + +# Установка + +Установка сервиса довольно проста: + +## Получение исходников + +```shell +git clone https://skobkin@bitbucket.org/skobkin/point-tools.git +cd point-tools +``` + +## Выставление прав +Выставьте права на запись для директорий `app/cache` и `app/logs`. + +## Установка зависимостей + +```shell +# В dev-среде: +composer install +# В prod-среде +composer install --no-dev --optimize-autoloader +``` + +После установки зависимостей у вас будут запрошены реквизиты доступа к БД PostgreSQL и данные необходимые для функционирования сервиса. + +## Инициализация БД + +```shell +php app/console doctrine:migrations:migrate +``` + +## Установка ресурсов + +```shell +php app/console assets:install web --symlink +``` + +## Добавление задания в CRON + +```shell +crontab -e +``` + +Вставьте в ваш файл crontab конфиг задания: + +```crontab +# point.skobk.in +*/10 * * * * /usr/bin/php /path/to/point-tools/app/console point:update:subscriptions --env=prod +``` + diff --git a/app/Resources/views/base.html.twig b/app/Resources/views/base.html.twig index cacbeda..9afff0b 100644 --- a/app/Resources/views/base.html.twig +++ b/app/Resources/views/base.html.twig @@ -27,6 +27,9 @@
  • {{ 'Main'|trans }}
  • {{ 'Top'|trans }}
  • + {% endblock %} {%- endblock -%} @@ -42,11 +45,16 @@ {% block footer %}
    - {% endblock %} \ No newline at end of file diff --git a/app/SymfonyRequirements.php b/app/SymfonyRequirements.php index dbaafa8..caabe40 100644 --- a/app/SymfonyRequirements.php +++ b/app/SymfonyRequirements.php @@ -542,11 +542,22 @@ class SymfonyRequirements extends RequirementCollection /* optional recommendations follow */ - $this->addRecommendation( - file_get_contents(__FILE__) === file_get_contents(__DIR__.'/../vendor/sensio/distribution-bundle/Sensio/Bundle/DistributionBundle/Resources/skeleton/app/SymfonyRequirements.php'), - 'Requirements file should be up-to-date', - 'Your requirements file is outdated. Run composer install and re-check your configuration.' - ); + if (file_exists(__DIR__.'/../vendor/composer')) { + require_once __DIR__.'/../vendor/autoload.php'; + + try { + $r = new \ReflectionClass('Sensio\Bundle\DistributionBundle\SensioDistributionBundle'); + + $contents = file_get_contents(dirname($r->getFileName()).'/Resources/skeleton/app/SymfonyRequirements.php'); + } catch (\ReflectionException $e) { + $contents = ''; + } + $this->addRecommendation( + file_get_contents(__FILE__) === $contents, + 'Requirements file should be up-to-date', + 'Your requirements file is outdated. Run composer install and re-check your configuration.' + ); + } $this->addRecommendation( version_compare($installedPhpVersion, '5.3.4', '>='), diff --git a/app/config/config.yml b/app/config/config.yml index 6268325..9cb2514 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -5,7 +5,7 @@ imports: framework: #esi: ~ - #translator: { fallbacks: ["%locale%"] } + translator: { fallbacks: ["%locale%"] } secret: "%secret%" router: resource: "%kernel.root_dir%/config/routing.yml" diff --git a/app/config/parameters.yml.dist b/app/config/parameters.yml.dist index 7e31c09..2b5feda 100644 --- a/app/config/parameters.yml.dist +++ b/app/config/parameters.yml.dist @@ -16,6 +16,7 @@ parameters: point_api_base_url: https://point.im/api/ point_use_https: true point_login: point-tools + point_id: 435 locale: en diff --git a/composer.lock b/composer.lock index bc09293..e29b519 100644 --- a/composer.lock +++ b/composer.lock @@ -1,23 +1,23 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], "hash": "6f8a78a0b471fceb335f2e83e43985ef", "packages": [ { "name": "doctrine/annotations", - "version": "v1.2.3", + "version": "v1.2.4", "source": { "type": "git", "url": "https://github.com/doctrine/annotations.git", - "reference": "eeda578cbe24a170331a1cfdf78be723412df7a4" + "reference": "b5202eb9e83f8db52e0e58867e0a46e63be8332e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/annotations/zipball/eeda578cbe24a170331a1cfdf78be723412df7a4", - "reference": "eeda578cbe24a170331a1cfdf78be723412df7a4", + "url": "https://api.github.com/repos/doctrine/annotations/zipball/b5202eb9e83f8db52e0e58867e0a46e63be8332e", + "reference": "b5202eb9e83f8db52e0e58867e0a46e63be8332e", "shasum": "" }, "require": { @@ -72,20 +72,20 @@ "docblock", "parser" ], - "time": "2014-12-20 20:49:38" + "time": "2014-12-23 22:40:37" }, { "name": "doctrine/cache", - "version": "v1.4.0", + "version": "v1.4.1", "source": { "type": "git", "url": "https://github.com/doctrine/cache.git", - "reference": "2346085d2b027b233ae1d5de59b07440b9f288c8" + "reference": "c9eadeb743ac6199f7eec423cb9426bc518b7b03" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/cache/zipball/2346085d2b027b233ae1d5de59b07440b9f288c8", - "reference": "2346085d2b027b233ae1d5de59b07440b9f288c8", + "url": "https://api.github.com/repos/doctrine/cache/zipball/c9eadeb743ac6199f7eec423cb9426bc518b7b03", + "reference": "c9eadeb743ac6199f7eec423cb9426bc518b7b03", "shasum": "" }, "require": { @@ -96,13 +96,13 @@ }, "require-dev": { "phpunit/phpunit": ">=3.7", - "predis/predis": "~0.8", + "predis/predis": "~1.0", "satooshi/php-coveralls": "~0.6" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.4.x-dev" + "dev-master": "1.5.x-dev" } }, "autoload": { @@ -142,25 +142,28 @@ "cache", "caching" ], - "time": "2015-01-15 20:38:55" + "time": "2015-04-15 00:11:59" }, { "name": "doctrine/collections", - "version": "v1.2", + "version": "v1.3.0", "source": { "type": "git", "url": "https://github.com/doctrine/collections.git", - "reference": "b99c5c46c87126201899afe88ec490a25eedd6a2" + "reference": "6c1e4eef75f310ea1b3e30945e9f06e652128b8a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/collections/zipball/b99c5c46c87126201899afe88ec490a25eedd6a2", - "reference": "b99c5c46c87126201899afe88ec490a25eedd6a2", + "url": "https://api.github.com/repos/doctrine/collections/zipball/6c1e4eef75f310ea1b3e30945e9f06e652128b8a", + "reference": "6c1e4eef75f310ea1b3e30945e9f06e652128b8a", "shasum": "" }, "require": { "php": ">=5.3.2" }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, "type": "library", "extra": { "branch-alias": { @@ -177,17 +180,6 @@ "MIT" ], "authors": [ - { - "name": "Jonathan Wage", - "email": "jonwage@gmail.com", - "homepage": "http://www.jwage.com/", - "role": "Creator" - }, - { - "name": "Guilherme Blanco", - "email": "guilhermeblanco@gmail.com", - "homepage": "http://www.instaclick.com" - }, { "name": "Roman Borschel", "email": "roman@code-factory.org" @@ -196,11 +188,17 @@ "name": "Benjamin Eberlei", "email": "kontakt@beberlei.de" }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, { "name": "Johannes Schmitt", - "email": "schmittjoh@gmail.com", - "homepage": "https://github.com/schmittjoh", - "role": "Developer of wrapped JMSSerializerBundle" + "email": "schmittjoh@gmail.com" } ], "description": "Collections Abstraction library", @@ -210,20 +208,20 @@ "collections", "iterator" ], - "time": "2014-02-03 23:07:43" + "time": "2015-04-14 22:21:58" }, { "name": "doctrine/common", - "version": "v2.4.2", + "version": "v2.5.0", "source": { "type": "git", "url": "https://github.com/doctrine/common.git", - "reference": "5db6ab40e4c531f14dad4ca96a394dfce5d4255b" + "reference": "cd8daf2501e10c63dced7b8b9b905844316ae9d3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/common/zipball/5db6ab40e4c531f14dad4ca96a394dfce5d4255b", - "reference": "5db6ab40e4c531f14dad4ca96a394dfce5d4255b", + "url": "https://api.github.com/repos/doctrine/common/zipball/cd8daf2501e10c63dced7b8b9b905844316ae9d3", + "reference": "cd8daf2501e10c63dced7b8b9b905844316ae9d3", "shasum": "" }, "require": { @@ -240,7 +238,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.4.x-dev" + "dev-master": "2.6.x-dev" } }, "autoload": { @@ -253,17 +251,6 @@ "MIT" ], "authors": [ - { - "name": "Jonathan Wage", - "email": "jonwage@gmail.com", - "homepage": "http://www.jwage.com/", - "role": "Creator" - }, - { - "name": "Guilherme Blanco", - "email": "guilhermeblanco@gmail.com", - "homepage": "http://www.instaclick.com" - }, { "name": "Roman Borschel", "email": "roman@code-factory.org" @@ -272,11 +259,17 @@ "name": "Benjamin Eberlei", "email": "kontakt@beberlei.de" }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, { "name": "Johannes Schmitt", - "email": "schmittjoh@gmail.com", - "homepage": "https://github.com/schmittjoh", - "role": "Developer of wrapped JMSSerializerBundle" + "email": "schmittjoh@gmail.com" } ], "description": "Common Library for Doctrine projects", @@ -288,7 +281,7 @@ "persistence", "spl" ], - "time": "2014-05-21 19:28:51" + "time": "2015-04-02 19:55:44" }, { "name": "doctrine/dbal", @@ -355,16 +348,16 @@ }, { "name": "doctrine/doctrine-bundle", - "version": "v1.4.0", + "version": "v1.5.0", "source": { "type": "git", "url": "https://github.com/doctrine/DoctrineBundle.git", - "reference": "1986ff3a945b584c6505d07eae92d77e41131078" + "reference": "0b9e27037c4fdbad515ee5ec89842e9091a6480f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/DoctrineBundle/zipball/1986ff3a945b584c6505d07eae92d77e41131078", - "reference": "1986ff3a945b584c6505d07eae92d77e41131078", + "url": "https://api.github.com/repos/doctrine/DoctrineBundle/zipball/0b9e27037c4fdbad515ee5ec89842e9091a6480f", + "reference": "0b9e27037c4fdbad515ee5ec89842e9091a6480f", "shasum": "" }, "require": { @@ -372,6 +365,7 @@ "doctrine/doctrine-cache-bundle": "~1.0", "jdorn/sql-formatter": "~1.1", "php": ">=5.3.2", + "symfony/console": "~2.3", "symfony/doctrine-bridge": "~2.2", "symfony/framework-bundle": "~2.3" }, @@ -390,7 +384,7 @@ "type": "symfony-bundle", "extra": { "branch-alias": { - "dev-master": "1.4.x-dev" + "dev-master": "1.5.x-dev" } }, "autoload": { @@ -428,7 +422,7 @@ "orm", "persistence" ], - "time": "2015-02-28 11:04:45" + "time": "2015-05-28 12:27:15" }, { "name": "doctrine/doctrine-cache-bundle", @@ -521,19 +515,19 @@ "source": { "type": "git", "url": "https://github.com/doctrine/DoctrineMigrationsBundle.git", - "reference": "6a1bd731dbdd4ad952a3b246a8f38c9c12f52e62" + "reference": "1e8cd4415bd2f893eb828216b529a75e8b61d579" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/DoctrineMigrationsBundle/zipball/6a1bd731dbdd4ad952a3b246a8f38c9c12f52e62", - "reference": "6a1bd731dbdd4ad952a3b246a8f38c9c12f52e62", + "url": "https://api.github.com/repos/doctrine/DoctrineMigrationsBundle/zipball/1e8cd4415bd2f893eb828216b529a75e8b61d579", + "reference": "1e8cd4415bd2f893eb828216b529a75e8b61d579", "shasum": "" }, "require": { "doctrine/doctrine-bundle": "~1.0", "doctrine/migrations": "~1.0@dev", "php": ">=5.3.2", - "symfony/framework-bundle": "~2.1" + "symfony/framework-bundle": "~2.3|~3.0" }, "type": "symfony-bundle", "extra": { @@ -571,7 +565,7 @@ "migrations", "schema" ], - "time": "2015-02-16 13:24:46" + "time": "2015-05-06 08:32:15" }, { "name": "doctrine/inflector", @@ -700,21 +694,28 @@ "source": { "type": "git", "url": "https://github.com/doctrine/migrations.git", - "reference": "65978aa4e9ffca3bb632225ad8c6320077d80d85" + "reference": "abb87d84ed21fd30c27bd3b52252a495a36d32fb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/migrations/zipball/65978aa4e9ffca3bb632225ad8c6320077d80d85", - "reference": "65978aa4e9ffca3bb632225ad8c6320077d80d85", + "url": "https://api.github.com/repos/doctrine/migrations/zipball/abb87d84ed21fd30c27bd3b52252a495a36d32fb", + "reference": "abb87d84ed21fd30c27bd3b52252a495a36d32fb", "shasum": "" }, "require": { "doctrine/dbal": "~2.0", - "php": ">=5.3.2" + "php": ">=5.3.2", + "symfony/console": "~2.3", + "symfony/yaml": "~2.3" + }, + "conflict": { + "doctrine/orm": "<2.4" }, "require-dev": { - "symfony/console": "2.*", - "symfony/yaml": "2.*" + "doctrine/coding-standard": "dev-master", + "doctrine/orm": "2.*", + "phpunit/phpunit": "~4.0", + "satooshi/php-coveralls": "0.6.*" }, "suggest": { "symfony/console": "to run the migration from the console" @@ -750,7 +751,7 @@ "database", "migrations" ], - "time": "2015-03-23 09:47:20" + "time": "2015-05-26 15:30:26" }, { "name": "doctrine/orm", @@ -1281,17 +1282,17 @@ }, { "name": "sensio/distribution-bundle", - "version": "v3.0.20", + "version": "v3.0.25", "target-dir": "Sensio/Bundle/DistributionBundle", "source": { "type": "git", "url": "https://github.com/sensiolabs/SensioDistributionBundle.git", - "reference": "48c76189fb0a76a20a4a67a750b513ed06074b55" + "reference": "01931139b0f067a4016d5d56e82c2b3086533b89" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sensiolabs/SensioDistributionBundle/zipball/48c76189fb0a76a20a4a67a750b513ed06074b55", - "reference": "48c76189fb0a76a20a4a67a750b513ed06074b55", + "url": "https://api.github.com/repos/sensiolabs/SensioDistributionBundle/zipball/01931139b0f067a4016d5d56e82c2b3086533b89", + "reference": "01931139b0f067a4016d5d56e82c2b3086533b89", "shasum": "" }, "require": { @@ -1337,21 +1338,20 @@ "configuration", "distribution" ], - "time": "2015-03-26 11:09:50" + "time": "2015-05-29 22:35:41" }, { "name": "sensio/framework-extra-bundle", - "version": "v3.0.6", - "target-dir": "Sensio/Bundle/FrameworkExtraBundle", + "version": "v3.0.8", "source": { "type": "git", "url": "https://github.com/sensiolabs/SensioFrameworkExtraBundle.git", - "reference": "1c3ed356bd1ff67cd71806efbb71511644035c85" + "reference": "a30fc18bf147bc25faf6b1d54bf55cfad4b63cba" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sensiolabs/SensioFrameworkExtraBundle/zipball/1c3ed356bd1ff67cd71806efbb71511644035c85", - "reference": "1c3ed356bd1ff67cd71806efbb71511644035c85", + "url": "https://api.github.com/repos/sensiolabs/SensioFrameworkExtraBundle/zipball/a30fc18bf147bc25faf6b1d54bf55cfad4b63cba", + "reference": "a30fc18bf147bc25faf6b1d54bf55cfad4b63cba", "shasum": "" }, "require": { @@ -1364,6 +1364,7 @@ }, "suggest": { "symfony/expression-language": "", + "symfony/psr-http-message-bridge": "To use the PSR-7 converters", "symfony/security-bundle": "" }, "type": "symfony-bundle", @@ -1373,8 +1374,8 @@ } }, "autoload": { - "psr-0": { - "Sensio\\Bundle\\FrameworkExtraBundle": "" + "psr-4": { + "Sensio\\Bundle\\FrameworkExtraBundle\\": "" } }, "notification-url": "https://packagist.org/downloads/", @@ -1392,20 +1393,20 @@ "annotations", "controllers" ], - "time": "2015-03-24 15:12:07" + "time": "2015-05-29 18:27:23" }, { "name": "sensiolabs/security-checker", - "version": "v2.0.1", + "version": "v2.0.5", "source": { "type": "git", "url": "https://github.com/sensiolabs/security-checker.git", - "reference": "134cecf1c61256bd8e973e11376891a724543820" + "reference": "2c2a71f1c77d9765c12638c4724d9ca23658a810" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sensiolabs/security-checker/zipball/134cecf1c61256bd8e973e11376891a724543820", - "reference": "134cecf1c61256bd8e973e11376891a724543820", + "url": "https://api.github.com/repos/sensiolabs/security-checker/zipball/2c2a71f1c77d9765c12638c4724d9ca23658a810", + "reference": "2c2a71f1c77d9765c12638c4724d9ca23658a810", "shasum": "" }, "require": { @@ -1437,7 +1438,7 @@ } ], "description": "A security checker for your composer.lock", - "time": "2015-01-26 16:25:19" + "time": "2015-05-28 14:22:40" }, { "name": "swiftmailer/swiftmailer", @@ -1678,12 +1679,12 @@ "source": { "type": "git", "url": "https://github.com/symfony/symfony.git", - "reference": "6ce03d3942ae65b9bcbc2afbec800ea1cf8361d8" + "reference": "7493c2bef54fb818c5304bdd9d2194890b839422" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/symfony/zipball/6ce03d3942ae65b9bcbc2afbec800ea1cf8361d8", - "reference": "6ce03d3942ae65b9bcbc2afbec800ea1cf8361d8", + "url": "https://api.github.com/repos/symfony/symfony/zipball/7493c2bef54fb818c5304bdd9d2194890b839422", + "reference": "7493c2bef54fb818c5304bdd9d2194890b839422", "shasum": "" }, "require": { @@ -1747,7 +1748,6 @@ "ircmaxell/password-compat": "~1.0", "monolog/monolog": "~1.11", "ocramius/proxy-manager": "~0.4|~1.0", - "propel/propel1": "~1.6", "symfony/phpunit-bridge": "self.version" }, "type": "library", @@ -1757,14 +1757,14 @@ } }, "autoload": { - "psr-0": { - "Symfony\\Bridge\\Doctrine\\": "src/", - "Symfony\\Bridge\\Monolog\\": "src/", - "Symfony\\Bridge\\ProxyManager\\": "src/", - "Symfony\\Bridge\\Swiftmailer\\": "src/", - "Symfony\\Bridge\\Twig\\": "src/", - "Symfony\\Bundle\\": "src/", - "Symfony\\Component\\": "src/" + "psr-4": { + "Symfony\\Bridge\\Doctrine\\": "src/Symfony/Bridge/Doctrine/", + "Symfony\\Bridge\\Monolog\\": "src/Symfony/Bridge/Monolog/", + "Symfony\\Bridge\\ProxyManager\\": "src/Symfony/Bridge/ProxyManager/", + "Symfony\\Bridge\\Swiftmailer\\": "src/Symfony/Bridge/Swiftmailer/", + "Symfony\\Bridge\\Twig\\": "src/Symfony/Bridge/Twig/", + "Symfony\\Bundle\\": "src/Symfony/Bundle/", + "Symfony\\Component\\": "src/Symfony/Component/" }, "classmap": [ "src/Symfony/Component/HttpFoundation/Resources/stubs", @@ -1779,21 +1779,21 @@ "MIT" ], "authors": [ - { - "name": "Symfony Community", - "homepage": "http://symfony.com/contributors" - }, { "name": "Fabien Potencier", "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" } ], "description": "The Symfony PHP framework", - "homepage": "http://symfony.com", + "homepage": "https://symfony.com", "keywords": [ "framework" ], - "time": "2015-03-29 09:44:52" + "time": "2015-05-30 17:16:04" }, { "name": "twig/extensions", @@ -1849,20 +1849,20 @@ }, { "name": "twig/twig", - "version": "v1.18.0", + "version": "v1.18.1", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "4cf7464348e7f9893a93f7096a90b73722be99cf" + "reference": "9f70492f44398e276d1b81c1b43adfe6751c7b7f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/4cf7464348e7f9893a93f7096a90b73722be99cf", - "reference": "4cf7464348e7f9893a93f7096a90b73722be99cf", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/9f70492f44398e276d1b81c1b43adfe6751c7b7f", + "reference": "9f70492f44398e276d1b81c1b43adfe6751c7b7f", "shasum": "" }, "require": { - "php": ">=5.2.4" + "php": ">=5.2.7" }, "type": "library", "extra": { @@ -1902,7 +1902,7 @@ "keywords": [ "templating" ], - "time": "2015-01-25 17:32:08" + "time": "2015-04-19 08:30:27" } ], "packages-dev": [ diff --git a/src/Skobkin/Bundle/PointToolsBundle/Command/UpdateSubscriptionsCommand.php b/src/Skobkin/Bundle/PointToolsBundle/Command/UpdateSubscriptionsCommand.php index 5371711..76c02ee 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Command/UpdateSubscriptionsCommand.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Command/UpdateSubscriptionsCommand.php @@ -44,8 +44,14 @@ class UpdateSubscriptionsCommand extends ContainerAwareCommand /** @var SubscriptionsManager $subscriptionsManager */ $subscriptionsManager = $this->getContainer()->get('skobkin_point_tools.subscriptions_manager'); - $serviceUserName = $this->getContainer()->getParameter('point_login'); - $serviceUser = $this->getContainer()->get('doctrine.orm.entity_manager')->getRepository('SkobkinPointToolsBundle:User')->findOneBy(['login' => $serviceUserName]); + try { + $serviceUserId = $this->getContainer()->getParameter('point_id'); + } catch (\InvalidArgumentException $e) { + $log->alert('Could not get point_id parameter from config file', ['exception_message' => $e->getMessage()]); + return false; + } + + $serviceUser = $this->getContainer()->get('doctrine.orm.entity_manager')->getRepository('SkobkinPointToolsBundle:User')->find($serviceUserId); if (!$serviceUser) { $log->info('Service user not found'); @@ -59,16 +65,24 @@ class UpdateSubscriptionsCommand extends ContainerAwareCommand } try { - $serviceSubscribers = $api->getUserSubscribersByLogin($serviceUserName); + $serviceSubscribers = $api->getUserSubscribersById($serviceUserId); } catch (\Exception $e) { - // @todo fallback to the local subscribers list $output->writeln('Error while getting service subscribers'); - $log->error('Error while getting service subscribers.' . PHP_EOL . - $e->getMessage() . PHP_EOL . - $e->getFile() . ':' . $e->getLine() - ); + $log->error('Error while getting service subscribers.', ['user_login' => $serviceUser->getLogin(), 'user_id' => $serviceUser->getId(), 'message' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine()]); - return false; + $serviceSubscribers = []; + + foreach ($serviceUser->getSubscribers() as $subscription) { + $serviceSubscribers[] = $subscription->getSubscriber(); + } + + $output->writeln('Fallback to local list'); + $log->error('Fallback to local list'); + + if (!count($serviceSubscribers)) { + $log->info('No local subscribers. Finishing.'); + return false; + } } if ($output->isVerbose()) { @@ -79,10 +93,7 @@ class UpdateSubscriptionsCommand extends ContainerAwareCommand try { $subscriptionsManager->updateUserSubscribers($serviceUser, $serviceSubscribers); } catch (\Exception $e) { - $log->error('Error while updating service subscribers' . PHP_EOL . - $e->getMessage() . PHP_EOL . - $e->getFile() . ':' . $e->getLine() - ); + $log->error('Error while updating service subscribers', ['user_login' => $serviceUser->getLogin(), 'user_id' => $serviceUser->getId(), 'message' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine()]); return false; } @@ -97,13 +108,10 @@ class UpdateSubscriptionsCommand extends ContainerAwareCommand $log->info('Processing @' . $user->getLogin()); try { - $userCurrentSubscribers = $api->getUserSubscribersByLogin($user->getLogin()); + $userCurrentSubscribers = $api->getUserSubscribersById($user->getId()); } catch (\Exception $e) { $output->writeln(' Error while getting subscribers. Skipping.'); - $log->error('Error while getting subscribers.' . PHP_EOL . - $e->getMessage() . PHP_EOL . - $e->getFile() . ':' . $e->getLine() - ); + $log->error('Error while getting subscribers.', ['user_login' => $user->getLogin(), 'user_id' => $user->getId(), 'message' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine()]); continue; } @@ -116,10 +124,7 @@ class UpdateSubscriptionsCommand extends ContainerAwareCommand // Updating user subscribers $subscriptionsManager->updateUserSubscribers($user, $userCurrentSubscribers); } catch (\Exception $e) { - $log->error('Error while updating user subscribers' . PHP_EOL . - $e->getMessage() . PHP_EOL . - $e->getFile() . ':' . $e->getLine() - ); + $log->error('Error while updating user subscribers', ['user_login' => $user->getLogin(), 'user_id' => $user->getId(), 'message' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine()]); } // @todo move to the config diff --git a/src/Skobkin/Bundle/PointToolsBundle/Entity/User.php b/src/Skobkin/Bundle/PointToolsBundle/Entity/User.php index 38e003c..051f9be 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Entity/User.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Entity/User.php @@ -184,7 +184,7 @@ class User /** * Get subscribers * - * @return ArrayCollection + * @return Subscription[]|ArrayCollection */ public function getSubscribers() { diff --git a/src/Skobkin/Bundle/PointToolsBundle/Resources/public/css/main.css b/src/Skobkin/Bundle/PointToolsBundle/Resources/public/css/main.css index 2818740..167a190 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Resources/public/css/main.css +++ b/src/Skobkin/Bundle/PointToolsBundle/Resources/public/css/main.css @@ -38,6 +38,10 @@ body > .container { margin-top: 30px; } +.user-subscriptions-log { + margin-top: 30px; +} + h4.panel-title a { text-decoration: none; } diff --git a/src/Skobkin/Bundle/PointToolsBundle/Resources/translations/messages.ru.yml b/src/Skobkin/Bundle/PointToolsBundle/Resources/translations/messages.ru.yml new file mode 100644 index 0000000..ab55c66 --- /dev/null +++ b/src/Skobkin/Bundle/PointToolsBundle/Resources/translations/messages.ru.yml @@ -0,0 +1,32 @@ +# Russian language for Point tools + +# Шапка +Toggle navigation: Переключить навигацию +Main: Главная +Top: Топ +Report a bug: Сообщить об ошибке + +# Подвал +Source code: Исходный код + +# Главная +All users: Всего пользователей +Subscribed users: Подписчиков сервиса +24 hours events: Событий за сутки + +Username: Имя пользователя +Search: Поиск + +# Страница пользователя +Subscribers: Подписчики +Subscriptions log: Лог подписок +User: Пользователь +Action: Действие +Date: Дата + +No subscribers data found: Информация о подписчиках отсутствует +No log data found: Лог отсутствует + +# Топ пользователей +Top users: Популярные пользователи +Subscribers count: Подписчиков \ No newline at end of file diff --git a/src/Skobkin/Bundle/PointToolsBundle/Resources/views/Main/index.html.twig b/src/Skobkin/Bundle/PointToolsBundle/Resources/views/Main/index.html.twig index cc0ad24..2a2c3c9 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Resources/views/Main/index.html.twig +++ b/src/Skobkin/Bundle/PointToolsBundle/Resources/views/Main/index.html.twig @@ -3,30 +3,30 @@ {% block content %}
    {# @todo rewrite to Symfony forms #} -
    +
    - +
    @
    - +
    -
    {{ 'All users'|trans }}
    -
    {{ users_count }}
    +
    {{ 'All users'|trans }}
    +
    {{ users_count }}
    -
    {{ 'Subscribed users'|trans }}
    - +
    {{ 'Subscribed users'|trans }}
    +
    -
    {{ 'Last events'|trans }}
    -
    {{ events_count }}
    +
    {{ '24 hours events'|trans }}
    +
    {{ events_count }}
    {% endblock %} diff --git a/src/Skobkin/Bundle/PointToolsBundle/Resources/views/User/show.html.twig b/src/Skobkin/Bundle/PointToolsBundle/Resources/views/User/show.html.twig index 6d3f344..1c06370 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Resources/views/User/show.html.twig +++ b/src/Skobkin/Bundle/PointToolsBundle/Resources/views/User/show.html.twig @@ -9,68 +9,77 @@
    -
    -
    - -
    -
    - + {% if subscribers|length > 0 %} +
    +
    + +
    +
    + +
    -
    + {% else %} + + {% endif %}
    -
    -
    -
    - -
    -
    - - - - - - - - - - {% for event in log %} +
    + {% if log|length > 0 %} +
    {{ 'User'|trans }}{{ 'Action'|trans }}{{ 'Date'|trans }}
    + - - - + + + - {% endfor %} - -
    - @{{ event.subscriber.login }} - - - - {# Use DateTime helper: https://sonata-project.org/bundles/intl/master/doc/reference/datetime.html #} - {{ event.date|date('H:i:s d F Y') }} - {{ 'User'|trans }}{{ 'Action'|trans }}{{ 'Date'|trans }}
    + + + {% for event in log %} + + + @{{ event.subscriber.login }} + + + + + + {# Use DateTime helper: https://sonata-project.org/bundles/intl/master/doc/reference/datetime.html #} + {{ event.date|date('d F Y H:i:s') }} + + + {% endfor %} + + +
    -
    + {% else %} + + {% endif %}
    + {% endblock %} diff --git a/src/Skobkin/Bundle/PointToolsBundle/Service/SubscriptionsManager.php b/src/Skobkin/Bundle/PointToolsBundle/Service/SubscriptionsManager.php index 22c8a15..09579b2 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Service/SubscriptionsManager.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Service/SubscriptionsManager.php @@ -18,6 +18,7 @@ class SubscriptionsManager protected $em; + // @todo Add logger public function __construct(EntityManagerInterface $entityManager) { $this->em = $entityManager; @@ -38,6 +39,14 @@ class SubscriptionsManager $oldSubscribersList[] = $subscription->getSubscriber(); } + $isFirstTime = false; + + // Preventing to add garbage subscriptions for first processing + // @todo improve algorithm + if ((count($oldSubscribersList) === 0) && (count($newSubscribersList) > 1)) { + $isFirstTime = true; + } + unset($tmpOldSubscribers); $subscribedList = $this->getUsersListsDiff($newSubscribersList, $oldSubscribersList); @@ -53,17 +62,20 @@ class SubscriptionsManager $user->addSubscriber($subscription); - $logEvent = new SubscriptionEvent(); - $logEvent - ->setSubscriber($subscribedUser) - ->setAuthor($user) - ->setAction(SubscriptionEvent::ACTION_SUBSCRIBE) - ; + // If it's not first processing + if (!$isFirstTime) { + $logEvent = new SubscriptionEvent(); + $logEvent + ->setSubscriber($subscribedUser) + ->setAuthor($user) + ->setAction(SubscriptionEvent::ACTION_SUBSCRIBE); - $user->addNewSubscriberEvent($logEvent); + $user->addNewSubscriberEvent($logEvent); + + $this->em->persist($logEvent); + } $this->em->persist($subscription); - $this->em->persist($logEvent); } unset($subscribedList); @@ -81,7 +93,7 @@ class SubscriptionsManager $logEvent = new SubscriptionEvent(); $logEvent ->setSubscriber($unsubscribedUser) - ->setAction($user) + ->setAuthor($user) ->setAction(SubscriptionEvent::ACTION_UNSUBSCRIBE) ;