Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ongr-io/SettingsBundle
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.0.0
Choose a base ref
...
head repository: ongr-io/SettingsBundle
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 6 commits
  • 37 files changed
  • 3 contributors

Commits on Nov 15, 2016

  1. Experiments (#177)

    * added experiments controller
    
    * added device detector to composer
    
    * added a document for experiment
    
    * added a controller for experiments
    
    * added an experiment view
    
    * started writting javascript for experiments
    
    * made initial non dynamic experiment page
    
    * made the formtion of eperiment list from es
    
    * added new experiment button
    
    * added an experiment form
    
    * made experiment caching only when they are found
    
    * fixed the naming
    
    * changed details button to target column
    
    * started target loading to a modal
    
    * finished rendering the form for new experiment
    
    * added routing for experiment submit
    
    * updated the script to point to submit an experiment
    
    * added a create method in manager
    
    * added a submit experiment action
    
    * updated experiment propperty nameing
    
    * made settingsController handle experiment submition
    
    * deleted Experiment and ExperimentManager
    
    * made experements to be retrieved from settingsManager
    
    * updated the filter to skip experiments
    
    * made the display of targets nicer
    
    * removed non existing route
    
    * added an active experements setting name to manager
    
    * impremented getActiveExperiments method in manager
    
    * enabled the dynamic display of active experiments
    
    * implemented experiment toggle
    
    * emplemented experiment deletion
    
    * enabled editing experiments
    
    * added a getCachedExperiment method to manager
    
    * fixed a bug with experiment persisting to es
    
    * added an experiment event listener
    
    * done controller housekeeping
    
    * introduced experiment cookie
    
    * excluded experements in profile settings list
    
    * changed target checkboxes to multiselect
    
    * added a button for details rendering
    
    * made clients reload depending on types
    
    * made controller not return true on empty request
    
    * implemented client recheck
    
    * fixed setting wrong values in the form
    
    * improved naming in controller
    
    * updated experiment listener to handle new experiments
    
    * updated active experiments data formation
    
    * removed unused constant and added cookie deletion on update in manager
    
    * changed multiselect files to cdn
    
    * added a filter agg in iterator mock
    
    * removed setting a wrong cookie value
    
    * added tests
    
    * added cache directory to gitignore
    
    * fixed styling issues
    
    * added documentation for the experiments
    einorler authored and saimaz committed Nov 15, 2016
    Copy the full SHA
    35d0267 View commit details

Commits on Nov 16, 2016

  1. update readme

    Simonas Šerlinskas committed Nov 16, 2016
    Copy the full SHA
    1e75b06 View commit details

Commits on Mar 20, 2017

  1. Updated settings to be compatible with elasticsearch 5.0 (#181)

    * renewed dependencies
    
    * implemented integration with the new filter manager
    
    * updated namespaces in manager
    
    * replaced string type in setting document
    
    * changed deprecated method calls in profiles controller
    
    * fixed a bug with experiment disabling
    
    * written a test for the filter
    
    * written a test for request listener
    
    * updated travis file
    einorler authored and saimaz committed Mar 20, 2017
    Copy the full SHA
    f89c6cf View commit details
  2. Update Events.php (#179)

    fixed constant PRE_UPDATE value(was same as POST_UPDATE)
    dariusviciulis authored and saimaz committed Mar 20, 2017
    Copy the full SHA
    7a26469 View commit details

Commits on Mar 22, 2017

  1. Added cache documentation (#174)

    * added a cache clear command
    
    * added cache documentation
    
    * removed unnecessary use statements
    
    * updated service check
    
    * prepared the bundle for functional tests
    
    * added a functional test for the cache clear command
    
    * improved the command messages
    einorler authored and saimaz committed Mar 22, 2017
    Copy the full SHA
    0598e00 View commit details
  2. Last updates before release (#182)

    * added changelog
    
    * updated readme
    
    * updated php version requirement
    einorler authored and saimaz committed Mar 22, 2017
    Copy the full SHA
    5ae9201 View commit details
Showing with 1,750 additions and 189 deletions.
  1. +2 −0 .gitignore
  2. +16 −5 .travis.yml
  3. +13 −0 CHANGELOG.md
  4. +62 −0 Command/CacheClearCommand.php
  5. +152 −0 Controller/ExperimentsController.php
  6. +2 −2 Controller/ProfilesController.php
  7. +4 −0 Controller/SettingsController.php
  8. +11 −2 DependencyInjection/Compiler/SettingsManagerPass.php
  9. +10 −10 Document/Setting.php
  10. +1 −1 Event/Events.php
  11. +111 −0 EventListener/ExperimentListener.php
  12. +13 −4 EventListener/RequestListener.php
  13. +6 −4 Filter/SkipHiddenSettingsFilter.php
  14. +10 −4 README.md
  15. +42 −41 Resources/config/filter_manager.yml
  16. +29 −1 Resources/config/routing/management.yml
  17. +22 −2 Resources/config/services.yml
  18. +35 −0 Resources/doc/Experiments.md
  19. +42 −0 Resources/doc/cache.md
  20. +228 −5 Resources/js/script.js
  21. +1 −1 Resources/public/script.js
  22. +1 −2 Resources/public/style.css
  23. +1 −1 Resources/public/style.css.map
  24. +9 −0 Resources/sass/style.scss
  25. +70 −0 Resources/views/Experiments/_experiment-form.html.twig
  26. +27 −0 Resources/views/Experiments/list.html.twig
  27. +21 −20 Resources/views/base.html.twig
  28. +164 −3 Service/SettingsManager.php
  29. +86 −0 Tests/Functional/Command/CacheClearCommandTest.php
  30. +69 −0 Tests/Functional/EventListener/ExperimentListenerTest.php
  31. +65 −0 Tests/Functional/EventListener/RequestListenerTest.php
  32. +195 −0 Tests/Functional/Service/SettingsManagerTest.php
  33. +37 −0 Tests/Unit/Filter/SkipHiddenSettingsFilterTest.php
  34. +179 −75 Tests/Unit/Service/SettingsManagerTest.php
  35. +5 −1 Tests/app/AppKernel.php
  36. +4 −1 Tests/app/config/config_test.yml
  37. +5 −4 composer.json
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/vendor/
/Tests/app/cache/
/composer.lock
/node_modules
/Tests/app/cache/
21 changes: 16 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
sudo: false
sudo: true
language: php
php:
- 5.5
- 5.6
- 7.0
- 7.1
- hhvm
env:
global:
- JAVA_HOME="/usr/lib/jvm/java-8-oracle/jre"
- ES_URL="https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.1.2.zip"
matrix:
allow_failures:
- php: hhvm
services:
- elasticsearch
addons:
apt:
packages:
- oracle-java8-installer
install:
# Container based PHP image ues PHP 5.6.5, once it will be upgraded sudo will be not necessary
- sudo apt-get install -y oracle-java8-set-default
- curl -L -o elasticsearch.zip $ES_URL
- unzip elasticsearch.zip
- ./elasticsearch-*/bin/elasticsearch -d
before_script:
- if [[ $TRAVIS_PHP_VERSION != "7.0" ]] && [[ $TRAVIS_PHP_VERSION != "hhvm" ]]; then phpenv config-rm xdebug.ini; fi
- composer config -g github-oauth.github.com $GITHUB_COMPOSER_AUTH
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# CHANGELOG

## v2.0.0 (2017-03-22)
- Added Experiments functionality.
- Added cache clear command.
- Fixed event naming.

### Breaking changes
- Drop PHP 5.5 support. Now only PHP >=5.6 are supported.
- Drop Elasticsearch 2.x support. Now only ES >=5.0 are supported.

## v1.0.0 (2016-10-04)
- First stable release
62 changes: 62 additions & 0 deletions Command/CacheClearCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ONGR\SettingsBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

class CacheClearCommand extends ContainerAwareCommand
{
/**
* {@inheritdoc}
*/
protected function configure()
{
parent::configure();

$this
->setName('ongr:settings:cache:clear')
->setDescription('Clears a selected setting from cache.')
->addArgument(
'setting_name',
InputArgument::REQUIRED,
'Setting name to remove from cache'
);
}

/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);

if (!$this->getContainer()->has('ong_settings.cache_provider')) {
throw new \RuntimeException('`ong_settings.cache_provider` service not available');
}

$cache = $this->getContainer()->get('ong_settings.cache_provider');
$setting = $input->getArgument('setting_name');

if (!$cache->contains($setting)) {
$io->note(sprintf('Cache does not contain a setting named `%s`', $setting));
return;
}

$cache->delete($setting);

$io->success(sprintf('`%s` has been successfully cleared from cache', $setting));
}
}
152 changes: 152 additions & 0 deletions Controller/ExperimentsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<?php

/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ONGR\SettingsBundle\Controller;

use DeviceDetector\Parser\Device\DeviceParserAbstract;
use DeviceDetector\Parser\OperatingSystem;
use ONGR\SettingsBundle\Document\Setting;
use ONGR\SettingsBundle\Service\SettingsManager;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;

/**
* Class SettingsListController. Is used for managing settings in General env.
*/
class ExperimentsController extends Controller
{
public function listAction(Request $request)
{
return $this->render('ONGRSettingsBundle:Experiments:list.html.twig');
}

/**
* Returns a json list of experiments
*
* @return JsonResponse
*/
public function getFullExperimentsAction()
{
$experimentsArray = [];
/** @var SettingsManager $manager */
$manager = $this->get('ongr_settings.settings_manager');
$experiments = $manager->getAllExperiments();
$activeExperiments = $manager->getActiveExperiments();

/** @var Setting $experiment */
foreach ($experiments as $experiment) {
$experiment = $experiment->getSerializableData();
$experiment['active'] = in_array($experiment['name'], $activeExperiments);
$experimentsArray[] = $experiment;
}

return new JsonResponse(
['count' => count($experiments), 'documents' => $experimentsArray]
);
}

/**
* Returns a json list of targets for experiment
*
* @param Request $request
*
* @return JsonResponse
*/
public function getTargetsAction(Request $request)
{
$targets = [
'Devices' => [
'types' => DeviceParserAbstract::getAvailableDeviceTypeNames(),
'brands' => DeviceParserAbstract::$deviceBrands,
],
'Clients' => [
'types' => [
'Browser',
'FeedReader',
'Library',
'MediaPlayer',
'MobileApp',
'PIM',
],
'clients' => [],
],
'OS' => [
'types' => OperatingSystem::getAvailableOperatingSystems(),
]
];

if (!empty($select = json_decode($request->get('selected'), true)) && isset($select['Clients']['types'])) {
$targets['Clients']['clients'] = $this->getClientsByTypes($select['Clients']['types']);
}

return new JsonResponse($targets);
}

/**
* Returns a json list of targets for experiment
*
* @param Request $request
*
* @return JsonResponse
*/
public function getClientsByTypesAction(Request $request)
{
$types = $request->get('types');

if (!$types) {
return new JsonResponse();
}

$clients = $this->getClientsByTypes($types);

return new JsonResponse($clients);
}

/**
* @param Request $request
*
* @return JsonResponse
*/
public function toggleAction(Request $request)
{
$name = $request->get('name');
try {
$this->get('ongr_settings.settings_manager')->toggleExperiment($name);
} catch (\Exception $e) {
return new JsonResponse(['error' => true]);
}

return new JsonResponse(['error' => false]);
}

/**
* @param array $types
* @return array
*/
private function getClientsByTypes(array $types)
{
$clients = [];

try {
foreach ($types as $type) {
$clients = array_merge(
("\\DeviceDetector\\Parser\\Client\\$type")::getAvailableClients(),
$clients
);
}
} catch (\Exception $e) {
return [];
}

return $clients;
}
}
4 changes: 2 additions & 2 deletions Controller/ProfilesController.php
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@

use ONGR\ElasticsearchBundle\Result\DocumentIterator;
use ONGR\ElasticsearchBundle\Service\Repository;
use ONGR\ElasticsearchDSL\Aggregation\TermsAggregation;
use ONGR\ElasticsearchDSL\Aggregation\Bucketing\TermsAggregation;
use ONGR\ElasticsearchBundle\Result\Aggregation\AggregationValue;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
@@ -50,7 +50,7 @@ public function getAllProfilesAction()
$search->addAggregation(new TermsAggregation('profiles', 'profile'));

/** @var DocumentIterator $result */
$result = $repo->execute($search);
$result = $repo->findDocuments($search);

/** @var AggregationValue $agg */
foreach ($result->getAggregation('profiles') as $agg) {
4 changes: 4 additions & 0 deletions Controller/SettingsController.php
Original file line number Diff line number Diff line change
@@ -110,6 +110,10 @@ public function submitAction(Request $request)
$manager = $this->get('ongr_settings.settings_manager');
$data = $request->get('setting');

if (!empty($data['value']) && !is_string($data['value'])) {
$data['value'] = json_encode($data['value']);
}

if ($request->get('force')) {
$name = $request->get('name');
$manager->update($name, $data);
13 changes: 11 additions & 2 deletions DependencyInjection/Compiler/SettingsManagerPass.php
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@

namespace ONGR\SettingsBundle\DependencyInjection\Compiler;

use ONGR\FilterManagerBundle\DependencyInjection\ONGRFilterManagerExtension;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
@@ -26,23 +27,31 @@ public function process(ContainerBuilder $container)
$repo = $container->getParameter('ongr_settings.repo');
$filterManager = new Definition('ONGR\FilterManagerBundle\Search\FilterManager', [
new Reference('ongr_settings.filter_container'),
new Reference($repo)
new Reference($repo),
new Reference('event_dispatcher')
]);

$container->setDefinition('ongr_filter_manager.settings', $filterManager);
$container->setDefinition(ONGRFilterManagerExtension::getFilterManagerId('settings'), $filterManager);

$settingsManager = new Definition('ONGR\SettingsBundle\Service\SettingsManager', [
new Reference($repo),
new Reference('event_dispatcher')
]);

$settingsManager->addMethodCall('setActiveProfilesSettingName', ['%ongr_settings.active_profiles%']);
$settingsManager->addMethodCall('setActiveExperimentsSettingName', ['%ongr_settings.active_experiments%']);
$settingsManager->addMethodCall(
'setActiveProfilesCookie',
[
new Reference('ongr_settings.cookie.active_profiles')
]
);
$settingsManager->addMethodCall(
'setActiveExperimentProfilesCookie',
[
new Reference('ongr_settings.cookie.active_experiments')
]
);
$settingsManager->addMethodCall('setCache', [new Reference('ong_settings.cache_provider')]);

$container->setDefinition('ongr_settings.settings_manager', $settingsManager);
Loading