Skip to content

Commit

Permalink
Merge pull request #343 from lenybernard/upgrade/2.8-deprecations
Browse files Browse the repository at this point in the history
Upgrade/2.8 deprecations
  • Loading branch information
Leny BERNARD committed Feb 24, 2016
2 parents 2840bed + 6e3e340 commit 7a1abab
Show file tree
Hide file tree
Showing 131 changed files with 1,911 additions and 1,933 deletions.
13 changes: 8 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ php:
- 5.6

services:
- mysql
- redis-server

env:
Expand All @@ -20,7 +21,7 @@ before_script:
- mkdir fails
- composer self-update
- composer config --global github-oauth.github.com $gh_auth_token
- COMPOSER_ROOT_VERSION=dev-master composer install --prefer-dist
- COMPOSER_ROOT_VERSION=1.5 composer install --prefer-dist
# Prepare database
- php Tests/Functionnal/bin/console --env=test doctrine:database:create
- php Tests/Functionnal/bin/console --env=test doctrine:schema:create
Expand All @@ -39,6 +40,9 @@ before_script:
- "nohup java -jar selenium-server-standalone-2.49.0.jar > /dev/null &"
- sleep 5

script:
- './vendor/bin/behat'
- 'phpunit --coverage-text'

after_script:
- php Tests/Functionnal/bin/console --env=test doctrine:database:drop --force
Expand All @@ -47,10 +51,9 @@ after_failure:
- vendor/lakion/mink-debug-extension/travis/tools/upload-textfiles "fails/*.log"
- vendor/lakion/mink-debug-extension/travis/tools/upload-screenshots "fails/*.png"

script:
- './vendor/bin/behat'
- 'phpunit --coverage-text'

cache:
directories:
- $HOME/.composer/cache

notifications:
slack: appventus:Xy4yq4kXpBK9XHgfz8t9VBPl
8 changes: 5 additions & 3 deletions Bundle/BlogBundle/Controller/ArticleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use Victoire\Bundle\BlogBundle\Entity\Blog;
use Victoire\Bundle\BlogBundle\Entity\Tag;
use Victoire\Bundle\BlogBundle\Event\ArticleEvent;
use Victoire\Bundle\BlogBundle\Form\ArticleSettingsType;
use Victoire\Bundle\BlogBundle\Form\ArticleType;
use Victoire\Bundle\BlogBundle\VictoireBlogEvents;

/**
Expand All @@ -35,7 +37,7 @@ public function createAction(Blog $blog)
$entityManager = $this->get('doctrine.orm.entity_manager');
$article = new Article();
$article->setBlog($blog);
$form = $this->createForm('victoire_article_type', $article);
$form = $this->createForm(ArticleType::class, $article);

$form->handleRequest($this->get('request'));
if ($form->isValid()) {
Expand Down Expand Up @@ -106,7 +108,7 @@ public function newBlogArticleAction(Blog $blog)
$article = new Article();
$article->setBlog($blog);
try {
$form = $this->createForm('victoire_article_type', $article);
$form = $this->createForm(ArticleType::class, $article);
} catch (NoResultException $e) {
return new JsonResponse(['success' => false, 'message' => $e->getMessage()]);
}
Expand Down Expand Up @@ -135,7 +137,7 @@ public function newBlogArticleAction(Blog $blog)
*/
public function settingsAction(Request $request, Article $article)
{
$form = $this->createForm('victoire_article_settings_type', $article);
$form = $this->createForm(ArticleSettingsType::class, $article);
$pageHelper = $this->get('victoire_page.page_helper');
$businessProperties = [];

Expand Down
13 changes: 8 additions & 5 deletions Bundle/BlogBundle/Controller/BlogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Victoire\Bundle\BlogBundle\Entity\Blog;
use Victoire\Bundle\BlogBundle\Form\BlogCategoryType;
use Victoire\Bundle\BlogBundle\Form\BlogSettingsType;
use Victoire\Bundle\BlogBundle\Form\BlogType;
use Victoire\Bundle\BlogBundle\Form\ChooseBlogType;
use Victoire\Bundle\BlogBundle\Repository\BlogRepository;
use Victoire\Bundle\BusinessPageBundle\Entity\BusinessTemplate;
Expand Down Expand Up @@ -61,13 +64,13 @@ public function indexAction(Request $request, $blogId = null, $tab = 'articles')
}
$options['blog'] = $blog;
$template = $this->getBaseTemplatePath().':index.html.twig';
$chooseBlogForm = $this->createForm(new ChooseBlogType(), null, $options);
$chooseBlogForm = $this->createForm(ChooseBlogType::class, null, $options);

$chooseBlogForm->handleRequest($request);
if ($chooseBlogForm->isValid()) {
$blog = $chooseBlogForm->getData()['blog'];
$template = $this->getBaseTemplatePath().':_blogItem.html.twig';
$chooseBlogForm = $this->createForm(new ChooseBlogType(), null, ['blog' => $blog]);
$chooseBlogForm = $this->createForm(ChooseBlogType::class, null, ['blog' => $blog]);
}
$businessProperties = [];

Expand Down Expand Up @@ -299,23 +302,23 @@ public function deleteAction(BasePage $blog)
*/
protected function getPageSettingsType()
{
return 'victoire_blog_settings_type';
return BlogSettingsType::class;
}

/**
* @return string
*/
protected function getPageCategoryType()
{
return 'victoire_blog_category_type';
return BlogCategoryType::class;
}

/**
* @return string
*/
protected function getNewPageType()
{
return 'victoire_blog_type';
return BlogType::class;
}

/**
Expand Down
40 changes: 14 additions & 26 deletions Bundle/BlogBundle/Filter/CategoryFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Translation\TranslatorInterface;
use Victoire\Bundle\BlogBundle\Entity\Category;
use Victoire\Bundle\FilterBundle\Filter\BaseFilter;
Expand All @@ -14,19 +15,16 @@
*/
class CategoryFilter extends BaseFilter
{
protected $em;
protected $request;
protected $translator;

/**
* @param EntityManager $em
* @param \Victoire\Bundle\FilterBundle\Filter\Request $request
* @param TranslatorInterface $translator
* @param EntityManager $entityManager
* @param Request $request
* @param TranslatorInterface $translator
*/
public function __construct(EntityManager $em, $request, TranslatorInterface $translator)
public function __construct(EntityManager $entityManager, Request $request, TranslatorInterface $translator)
{
$this->em = $em;
$this->request = $request;
parent::__construct($entityManager, $request);
$this->translator = $translator;
}

Expand All @@ -50,14 +48,14 @@ public function buildQuery(QueryBuilder $qb, array $parameters)
if ($parameter === '') {
unset($parameters['category'][$index]);
} else {
$parentCategory = $this->em->getRepository('VictoireBlogBundle:Category')->findOneById($parameter);
$parentCategory = $this->getEntityManager()->getRepository('VictoireBlogBundle:Category')->findOneById($parameter);
$childrenArray = array_merge($childrenArray, $this->getCategoryChildrens($parentCategory, []));
}
}

if (count($childrenArray) > 0) {
if (array_key_exists('strict', $parameters)) {
$repository = $this->em->getRepository('VictoireBlogBundle:Article');
$repository = $this->getEntityManager()->getRepository('VictoireBlogBundle:Article');
foreach ($childrenArray as $index => $category) {
$parameter = ':category'.$index;
$subquery = $repository->createQueryBuilder('article_'.$index)
Expand Down Expand Up @@ -101,9 +99,9 @@ public function buildForm(FormBuilderInterface $builder, array $options)
{

//getAll categories
$categoryQb = $this->em->getRepository('VictoireBlogBundle:Category')->getAll();
$categoryQb = $this->getEntityManager()->getRepository('VictoireBlogBundle:Category')->getAll();
//getAll published articles
$articleQb = $this->em->getRepository('VictoireBlogBundle:Article')->getAll(true);
$articleQb = $this->getEntityManager()->getRepository('VictoireBlogBundle:Article')->getAll(true);

//get Listing
$listing = $options['widget']->getListing();
Expand All @@ -128,14 +126,14 @@ public function buildForm(FormBuilderInterface $builder, array $options)
$categoryQb->clearInstance();
$articleQb->clearInstance();
$data = null;
if ($this->request->query->has('filter') && array_key_exists('category_filter', $this->request->query->get('filter'))) {
if ($this->getRequest()->query->has('filter') && array_key_exists('category_filter', $this->getRequest()->query->get('filter'))) {
if ($options['multiple']) {
$data = [];
foreach ($this->request->query->get('filter')['category_filter']['category'] as $id => $selectedCategory) {
foreach ($this->getRequest()->query->get('filter')['category_filter']['category'] as $id => $selectedCategory) {
$data[$id] = $selectedCategory;
}
} else {
$data = $this->request->query->get('filter')['category_filter']['tags'];
$data = $this->getRequest()->query->get('filter')['category_filter']['tags'];
}
}
$builder
Expand Down Expand Up @@ -199,16 +197,6 @@ public function buildHierarchy($categories, $validCategories)
*/
public function getFilters($filters)
{
return $this->em->getRepository('VictoireBlogBundle:Category')->findById($filters['category']);
}

/**
* get form name.
*
* @return string name
*/
public function getName()
{
return 'category_filter';
return $this->getEntityManager()->getRepository('VictoireBlogBundle:Category')->findById($filters['category']);
}
}
53 changes: 8 additions & 45 deletions Bundle/BlogBundle/Filter/DateFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Victoire\Bundle\BlogBundle\Filter;

use Doctrine\ORM\EntityManager;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
use Victoire\Bundle\FilterBundle\Filter\BaseFilter;

Expand All @@ -12,21 +12,6 @@
*/
class DateFilter extends BaseFilter
{
protected $em;
protected $request;

/**
* Constructor.
*
* @param EntityManager $em
* @param unknown $request
*/
public function __construct(EntityManager $em, $request)
{
$this->em = $em;
$this->request = $request;
}

/**
* Build the query.
*
Expand All @@ -37,7 +22,7 @@ public function __construct(EntityManager $em, $request)
*/
public function buildQuery(QueryBuilder $qb, array $parameters)
{
$emConfig = $this->em->getConfiguration();
$emConfig = $this->getEntityManager()->getConfiguration();
$emConfig->addCustomDatetimeFunction('YEAR', 'DoctrineExtensions\Query\Mysql\Year');
$emConfig->addCustomDatetimeFunction('MONTH', 'DoctrineExtensions\Query\Mysql\Month');
$emConfig->addCustomDatetimeFunction('DAY', 'DoctrineExtensions\Query\Mysql\Day');
Expand Down Expand Up @@ -68,7 +53,7 @@ public function buildQuery(QueryBuilder $qb, array $parameters)
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$articles = $this->em->getRepository('VictoireBlogBundle:Article')->getAll(true)->run();
$articles = $this->getEntityManager()->getRepository('VictoireBlogBundle:Article')->getAll(true)->run();
$years = $months = $days = [];
foreach ($articles as $key => $_article) {
$years[$_article->getPublishedAt()->format('Y')] = $_article->getPublishedAt()->format('Y');
Expand All @@ -91,19 +76,19 @@ public function buildForm(FormBuilderInterface $builder, array $options)
}

$data = ['year' => null, 'month' => null, 'day' => null];
if ($this->request->query->has('filter') && array_key_exists('date_filter', $this->request->query->get('filter'))) {
$_request = $this->request->query->get('filter')['date_filter'];
if ($this->getRequest()->query->has('filter') && array_key_exists('date_filter', $this->getRequest()->query->get('filter'))) {
$_request = $this->getRequest()->query->get('filter')['date_filter'];
$data = $_request;
}

if (in_array($options['widget']->getFormat(), ['year', 'month', 'day'])) {
if (!$data['year']) {
// set default value to date filter and set listing to request while not better way
$data['year'] = $options['widget']->getDefaultValue();
$this->request->query->replace(
$this->getRequest()->query->replace(
[
'filter' => [
$this->getName() => [
self::class => [
'year' => $options['widget']->getDefaultValue(),
],
'listing' => $options['widget']->getListing()->getId(),
Expand All @@ -113,7 +98,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
}
$builder
->add(
'year', 'choice', [
'year', ChoiceType::class, [
'label' => false,
'choices' => $years,
'required' => false,
Expand All @@ -125,26 +110,4 @@ public function buildForm(FormBuilderInterface $builder, array $options)
);
}
}

/**
* Get the filters.
*
* @param array $filters
*
* @return array The filters
*/
public function getFilters($filters)
{
return $this->em->getRepository('VictoireBlogBundle:Article')->findAll();
}

/**
* get form name.
*
* @return string name
*/
public function getName()
{
return 'date_filter';
}
}
Loading

0 comments on commit 7a1abab

Please sign in to comment.