Skip to content

Commit

Permalink
Merge branch '1.4' of github.com:laboro/platform into 1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
rgrebenchuk committed Oct 15, 2014
2 parents 4310021 + 6c7bfbc commit bb4a097
Show file tree
Hide file tree
Showing 222 changed files with 5,720 additions and 1,915 deletions.
10 changes: 10 additions & 0 deletions UPGRADE-1.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ UPGRADE FROM 1.3 to 1.4
- `Manager\DTO\Email` now is extended by `Oro\Bundle\EmailBundle\Model\EmailHeader`
- In `Manager\ImapEmailManager` new method `hasCapability` has been added

####ImportExportBundle:
- Added console command `oro:import:csv` to perform import from CSV file using CLI

####InstallerBundle:
- New option `symlink` has been added into `Command\InstallCommand` and `Command\PlatformUpdateCommand`

Expand All @@ -70,6 +73,11 @@ UPGRADE FROM 1.3 to 1.4
- `Entity\Organization` now is extendable and implement `\Serializable`
- In `Entity\Repository\BusinessUnitRepository` new method `getOrganizationBusinessUnitsTree` has been added

####PlatformBundle:
- Some doctrine listeners can be disabled for console commands, see command `oro.platform.optional_listeners` for
full list of optional listeners, listener manager `Manager/OptionalListenerManager` and console listener
`EventListener/Console/OptionalListenersListener` for implementation

####QueryDesignerBundle:
- In `QueryDesigner\JoinIdentifierHelper` new methods `isUnidirectionalJoinWithCondition` and `getUnidirectionalJoinEntityName` have been added

Expand All @@ -82,6 +90,8 @@ UPGRADE FROM 1.3 to 1.4
####SecurityBundle:
- New method `setConfigProvider` has been added into `Acl\Voter\AclVoter`
- New method `setClass` has been added into `Annotation\Acl`
- New listener `EventListener\ConsoleContextListener` that allows to specify current user and organization in
console commands

####SoapBundle:
- New argument `$filters` in `Controller\Api\Rest\RestApiReadInterface` method `handleGetListRequest` has been added
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"ext-gd": "*",
"ext-xml": "*",
"symfony/symfony": "2.3.*",
"twig/twig": "<=1.16.0",
"doctrine/orm": "2.4.5",
"doctrine/doctrine-bundle": "1.2.0",
"doctrine/dbal": "2.4.x-dev",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ protected function loadEntities(ObjectManager $manager)
// save
$manager->persist($addressType);
}

$manager->flush();
}

$manager->flush();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
use Oro\Bundle\AddressBundle\Entity\Country;
use Oro\Bundle\AddressBundle\Entity\Region;

class LoadCountryData extends AbstractTranslatableEntityFixture implements VersionedFixtureInterface
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

class LoadCountryData extends AbstractTranslatableEntityFixture implements
VersionedFixtureInterface,
ContainerAwareInterface
{
const COUNTRY_PREFIX = 'country';
const REGION_PREFIX = 'region';
Expand All @@ -32,6 +37,19 @@ class LoadCountryData extends AbstractTranslatableEntityFixture implements Versi
*/
protected $structureFileName = '/data/countries.yml';

/**
* @var ContainerInterface
*/
protected $container;

/**
* {@inheritdoc}
*/
public function setContainer(ContainerInterface $container = null)
{
$this->container = $container;
}

/**
* {@inheritdoc}
*/
Expand All @@ -55,10 +73,9 @@ protected function loadEntities(ObjectManager $manager)
*/
protected function getFileName()
{
$fileName = __DIR__ . $this->structureFileName;
$fileName = str_replace('/', DIRECTORY_SEPARATOR, $fileName);

return $fileName;
return $this->container
->get('kernel')
->locateResource('@OroAddressBundle/Migrations/Data/ORM' . $this->structureFileName);
}

/**
Expand Down Expand Up @@ -173,10 +190,9 @@ protected function loadCountriesAndRegions(ObjectManager $manager, array $countr
}
}
}

$manager->flush();
}

$manager->flush();
$manager->clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
width: 60%;
height: 420px;
}
.map-address-list, .map-visual-frame {
.forScreen(@smallScreen, width, 100%);
.forScreen(@smallScreen, height, auto);
.responsive-small & {
.map-address-list, .map-visual-frame {
width: 100%;
height: auto;
}
}
.map-visual {
height: 420px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ services:

oro_attachment.twig.file_extension:
class: %oro_attachment.twig.file_extension.class%
arguments: [@oro_attachment.manager, @oro_entity_config.config_manager]
arguments: [@oro_attachment.manager, @oro_entity_config.config_manager, @doctrine]
tags:
- { name: twig.extension }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class FileExtensionTest extends \PHPUnit_Framework_TestCase
/** @var \PHPUnit_Framework_MockObject_MockObject */
protected $attachmentConfigProvider;

/** @var \PHPUnit_Framework_MockObject_MockObject */
protected $doctrine;

/** @var TestAttachment */
protected $attachment;

Expand All @@ -34,12 +37,15 @@ public function setUp()
$configManager = $this->getMockBuilder('Oro\Bundle\EntityConfigBundle\Config\ConfigManager')
->disableOriginalConstructor()
->getMock();
$this->doctrine = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')
->disableOriginalConstructor()
->getMock();
$configManager->expects($this->once())
->method('getProvider')
->with('attachment')
->will($this->returnValue($this->attachmentConfigProvider));

$this->extension = new FileExtension($this->manager, $configManager);
$this->extension = new FileExtension($this->manager, $configManager, $this->doctrine);
$this->attachment = new TestAttachment();
}

Expand Down Expand Up @@ -211,4 +217,35 @@ public function testGetConfiguredImageUrl()

$this->extension->getConfiguredImageUrl($parent, 'testField', $this->attachment);
}

public function testGetImageViewWIthIntegerAttachmentParameter()
{
$parentEntity = new TestClass();
$this->attachment->setFilename('test.doc');
$attachmentId = 1;
$repo = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectRepository')
->disableOriginalConstructor()
->getMock();
$this->doctrine->expects($this->once())
->method('getRepository')
->will($this->returnValue($repo));
$repo->expects($this->once())
->method('find')
->with($attachmentId)
->will($this->returnValue($this->attachment));
$environment = $this->getMockBuilder('\Twig_Environment')
->disableOriginalConstructor()
->getMock();
$template = new TestTemplate(new \Twig_Environment());
$environment->expects($this->once())
->method('loadTemplate')
->will($this->returnValue($template));
$this->manager->expects($this->once())
->method('getResizedImageUrl')
->with($this->attachment, 16, 16);
$this->manager->expects($this->once())
->method('getFileUrl');

$this->extension->getImageView($environment, $parentEntity, $attachmentId);
}
}
34 changes: 31 additions & 3 deletions src/Oro/Bundle/AttachmentBundle/Twig/FileExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Oro\Bundle\AttachmentBundle\Twig;

use Doctrine\Common\Persistence\ManagerRegistry;

use Symfony\Component\PropertyAccess\PropertyAccess;
use Symfony\Component\Security\Core\Util\ClassUtils;

Expand All @@ -24,14 +26,18 @@ class FileExtension extends \Twig_Extension
/** @var ConfigProvider */
protected $attachmentConfigProvider;

/** @var ManagerRegistry */
protected $doctrine;

/**
* @param AttachmentManager $manager
* @param ConfigManager $configManager
*/
public function __construct(AttachmentManager $manager, ConfigManager $configManager)
public function __construct(AttachmentManager $manager, ConfigManager $configManager, ManagerRegistry $doctrine)
{
$this->manager = $manager;
$this->attachmentConfigProvider = $configManager->getProvider('attachment');
$this->doctrine = $doctrine;
}

/**
Expand Down Expand Up @@ -128,6 +134,12 @@ public function getFileView(
$fieldName,
$attachment = null
) {
/**
* @todo: should be refactored in BAP-5637
*/
if (is_int($attachment)) {
$attachment = $this->getFileById($attachment);
}
if ($attachment && $attachment->getFilename()) {
return $environment->loadTemplate(self::FILES_TEMPLATE)->render(
[
Expand All @@ -146,18 +158,24 @@ public function getFileView(
*
* @param \Twig_Environment $environment
* @param object $parentEntity
* @param File $attachment
* @param mixed $attachment
* @param string|object $entityClass
* @param string $fieldName
* @return string
*/
public function getImageView(
\Twig_Environment $environment,
$parentEntity,
File $attachment = null,
$attachment = null,
$entityClass = null,
$fieldName = ''
) {
/**
* @todo: should be refactored in BAP-5637
*/
if (is_int($attachment)) {
$attachment = $this->getFileById($attachment);
}
if ($attachment && $attachment->getFilename()) {
$width = self::DEFAULT_THUMB_SIZE;
$height = self::DEFAULT_THUMB_SIZE;
Expand Down Expand Up @@ -216,4 +234,14 @@ public function getFilteredImageUrl(File $attachment, $filterName)
{
return $this->manager->getFilteredImageUrl($attachment, $filterName);
}

/**
* @param int $id
*
* @return File
*/
protected function getFileById($id)
{
return $this->doctrine->getRepository('OroAttachmentBundle:File')->find($id);
}
}
50 changes: 43 additions & 7 deletions src/Oro/Bundle/BatchBundle/ORM/Query/QueryCountCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace Oro\Bundle\BatchBundle\ORM\Query;

use Doctrine\ORM\NoResultException;
use Doctrine\ORM\Query;
use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\Parameter;
use Doctrine\ORM\Query\QueryException;
use Doctrine\ORM\Tools\Pagination\CountWalker;
use Doctrine\ORM\Tools\Pagination\Paginator;

/**
* Calculates total count of query records
Expand Down Expand Up @@ -57,14 +57,32 @@ public function setUseWalker($value)
public function getCount(Query $query)
{
if ($this->useWalker($query)) {
// cheap way to test whether query is distinct
if (stripos($query->getDQL(), 'DISTINCT') === false) {
if (!$query->contains('DISTINCT')) {
$query->setHint(CountWalker::HINT_DISTINCT, false);
}

$paginator = new Paginator($query);
$paginator->setUseOutputWalkers(false);
$result = $paginator->count();
// fix of doctrine count walker bug
// TODO revert changes when doctrine version >= 2.5 in scope of BAP-5577
/* @var $countQuery Query */
$countQuery = clone $query;
$countQuery->setParameters(clone $query->getParameters());
foreach ($query->getHints() as $name => $value) {
$countQuery->setHint($name, $value);
}
if (!$countQuery->hasHint(CountWalker::HINT_DISTINCT)) {
$countQuery->setHint(CountWalker::HINT_DISTINCT, true);
}

$this->appendTreeWalker($countQuery, 'Oro\Bundle\BatchBundle\ORM\Query\Walker\CountWalker');
$countQuery->setFirstResult(null)->setMaxResults(null);

try {
$data = $countQuery->getScalarResult();
$data = array_map('current', $data);
$result = array_sum($data);
} catch (NoResultException $e) {
$result = 0;
}
} else {
$parser = new Parser($query);
$parserResult = $parser->parse();
Expand All @@ -76,7 +94,7 @@ public function getCount(Query $query)
$sqlParameters,
$parameterTypes
);
$result = $statement->fetchColumn();
$result = $statement->fetchColumn();
}

return $result ? (int)$result : 0;
Expand Down Expand Up @@ -150,4 +168,22 @@ private function useWalker(Query $query)

return $this->shouldUseWalker;
}

/**
* Appends a custom tree walker to the tree walkers hint.
*
* @param Query $query
* @param string $walkerClass
*/
private function appendTreeWalker(Query $query, $walkerClass)
{
$hints = $query->getHint(Query::HINT_CUSTOM_TREE_WALKERS);

if ($hints === false) {
$hints = [];
}

$hints[] = $walkerClass;
$query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, $hints);
}
}
Loading

0 comments on commit bb4a097

Please sign in to comment.