Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/dev/1.6' into 1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Banin committed Aug 14, 2015
2 parents ec06466 + c562902 commit 9b19a0e
Show file tree
Hide file tree
Showing 33 changed files with 2,051 additions and 59 deletions.
14 changes: 11 additions & 3 deletions src/Oro/Bundle/DistributionBundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
oro_distribution.routing_loader.class: Oro\Bundle\DistributionBundle\Routing\OroAutoLoader
oro_distribution.routing_loader.class: Oro\Component\Routing\Loader\CumulativeRoutingFileLoader
oro_distribution.package_manager.class: Oro\Bundle\DistributionBundle\Manager\PackageManager
oro_distribution.script_runner.class: Oro\Bundle\DistributionBundle\Script\Runner
oro_distribution.composer.class: Composer\Composer
Expand Down Expand Up @@ -28,11 +28,19 @@ services:
oro_distribution.routing_loader:
class: %oro_distribution.routing_loader.class%
arguments:
- "@file_locator"
- "@kernel"
- @kernel
- @oro_distribution.routing_options_resolver
- [Resources/config/oro/routing.yml]
- oro_auto
calls:
- [setResolver, [@routing.resolver]]
tags:
- { name: routing.loader }

oro_distribution.routing_options_resolver:
class: Oro\Component\Routing\Resolver\ChainRouteOptionsResolver
public: false

oro_distribution.package_manager:
class: %oro_distribution.package_manager.class%
arguments:
Expand Down
47 changes: 0 additions & 47 deletions src/Oro/Bundle/DistributionBundle/Routing/OroAutoLoader.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function getManager()
*/
public function getForm()
{
return $this->get('oro_notification.form.type.email_notification.api');
return $this->get('oro_notification.form.email_notification.api');
}

/**
Expand Down
11 changes: 11 additions & 0 deletions src/Oro/Bundle/UIBundle/Placeholder/PlaceholderFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,15 @@ public function isInstanceOf($obj, $className)
{
return $obj instanceof $className;
}

/**
* Checks whether a given value equals TRUE
*
* @param mixed $val
* @return bool
*/
public function isTrue($val)
{
return (bool)$val;
}
}
13 changes: 11 additions & 2 deletions src/Oro/Bundle/UIBundle/Resources/public/js/mediator.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,20 @@ define([
], function (_, Backbone, Chaplin) {
'use strict';

Backbone.mediator = _.extend(Chaplin.mediator, Backbone.Events);
var mediator = Backbone.mediator = Chaplin.mediator;

_.extend(mediator, Backbone.Events);
/**
* Listen Id should be defined before Chaplin.mediator get sealed
* on application start
*/
if (!mediator._listenId) {
mediator._listenId = _.uniqueId('l');
}

/**
* @export oroui/js/mediator
* @name oro.mediator
*/
return Chaplin.mediator;
return mediator;
});
2 changes: 1 addition & 1 deletion src/Oro/Bundle/UserBundle/Controller/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public function infoAction(User $user)
return array(
'entity' => $user,
'userApi' => $this->getUserApi($user),
'viewProfile' => true
'viewProfile' => (bool)$this->getRequest()->query->get('viewProfile', false)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
{% set userInformationWidget %}
{{ oro_widget_render({
'widgetType': 'block',
'url': path('oro_user_widget_info', {id: entity.id})
'url': path('oro_user_widget_info', {id: entity.id, viewProfile: editRoute is defined })
}) }}
{% endset %}
{% set dataBlocks = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
<div class="responsive-block">
{{ _self.renderApiBlock(entity, userApi, viewProfile) }}

{% placeholder view_user_api_block_after with {entity: entity, viewProfile: viewProfile} %}

{% if resource_granted('oro_tag_view_tag_cloud') %}
{{ ui.renderHtmlProperty('oro.tag.entity_plural_label'|trans, tag.renderView(entity)) }}
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

/**
* @dbIsolation
* @dbReindex
*/
class ProcessJobRepositoryTest extends WebTestCase
{
Expand All @@ -38,6 +37,7 @@ class ProcessJobRepositoryTest extends WebTestCase
protected function setUp()
{
$this->initClient();
$this->dropJobsRecords();

$this->registry = $this->getContainer()->get('doctrine');
$this->entityManager = $this->registry->getManagerForClass('OroWorkflowBundle:ProcessJob');
Expand All @@ -46,6 +46,28 @@ protected function setUp()
$this->loadFixtures(array('Oro\Bundle\WorkflowBundle\Tests\Functional\DataFixtures\LoadProcessEntities'));
}

protected function tearDown()
{
parent::tearDown();

$this->dropJobsRecords();
}

protected function dropJobsRecords()
{
// clear DB from separate connection
$batchJobManager = $this->getContainer()->get('akeneo_batch.job_repository')->getJobManager();
$batchJobManager->createQuery('DELETE AkeneoBatchBundle:JobInstance')->execute();
$batchJobManager->createQuery('DELETE AkeneoBatchBundle:JobExecution')->execute();
$batchJobManager->createQuery('DELETE AkeneoBatchBundle:StepExecution')->execute();

$this->getContainer()
->get('doctrine')
->getManager()
->createQuery('DELETE OroWorkflowBundle:ProcessJob')
->execute();
}

public function testDeleteByHashes()
{
// fixture data
Expand All @@ -65,15 +87,15 @@ public function testFindByIds()

$expectedJobs = $this->repository->findAll();

$this->assertEquals($count, count($expectedJobs));
$this->assertCount($count, $expectedJobs);

$ids = array();
/** @var ProcessJob $job */
foreach ($expectedJobs as $job) {
$ids[] = $job->getId();
}

$this->assertEquals($count, count($ids));
$this->assertCount($count, $ids);

$actualJobs = $this->repository->findByIds($ids);

Expand All @@ -83,7 +105,7 @@ public function testFindByIds()

$actualJobs = $this->repository->findByIds($ids);

$this->assertEquals($count - 1, count($actualJobs));
$this->assertCount($count - 1, $actualJobs);
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/Oro/Component/PhpUtils/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*~
172 changes: 172 additions & 0 deletions src/Oro/Component/PhpUtils/ArrayUtil.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
<?php

namespace Oro\Component\PhpUtils;

use Symfony\Component\PropertyAccess\PropertyAccessor;
use Symfony\Component\PropertyAccess\PropertyPathInterface;

class ArrayUtil
{
/**
* Checks whether the array is associative or sequential.
*
* @param array $array
*
* @return bool
*/
public static function isAssoc(array $array)
{
return array_values($array) !== $array;
}

/**
* Sorts an array by specified property.
*
* This method uses the stable sorting algorithm. See http://en.wikipedia.org/wiki/Sorting_algorithm#Stability
* Please use this method only if you really need stable sorting because this method is not so fast
* as native PHP sort functions.
*
* @param array $array The array to be sorted
* @param bool $reverse Indicates whether the sorting should be performed
* in reverse order
* @param mixed $propertyPath The property accessor. Can be string or PropertyPathInterface or callable
* @param int $sortingFlags The sorting type. Can be SORT_NUMERIC or SORT_STRING
* Also SORT_STRING can be combined with SORT_FLAG_CASE to sort
* strings case-insensitively
*/
public static function sortBy(
array &$array,
$reverse = false,
$propertyPath = 'priority',
$sortingFlags = SORT_NUMERIC
) {
if (empty($array)) {
return;
}

/**
* we have to implement such complex logic because the stable sorting is not supported in PHP for now
* see https://bugs.php.net/bug.php?id=53341
*/

$stringComparison = 0 !== ($sortingFlags & SORT_STRING);
$caseInsensitive = 0 !== ($sortingFlags & SORT_FLAG_CASE);

$sortable = self::prepareSortable($array, $propertyPath, $reverse, $stringComparison, $caseInsensitive);
if (!empty($sortable)) {
$keys = self::getSortedKeys($sortable, $stringComparison, $reverse);

$result = [];
foreach ($keys as $key) {
if (is_string($key)) {
$result[$key] = $array[$key];
} else {
$result[] = $array[$key];
}
}
$array = $result;
}
}

/**
* @param mixed $a
* @param mixed $b
* @param bool $stringComparison
*
* @return int
*/
private static function compare($a, $b, $stringComparison = false)
{
if ($a === $b) {
return 0;
}

if ($stringComparison) {
return strcmp($a, $b);
} else {
return $a < $b ? -1 : 1;
}
}

/**
* @param array $array
* @param string|PropertyPathInterface|callable $propertyPath
* @param bool $reverse
* @param bool $stringComparison
* @param bool $caseInsensitive
*
* @return array|null
*
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
private static function prepareSortable($array, $propertyPath, $reverse, $stringComparison, $caseInsensitive)
{
$propertyAccessor = new PropertyAccessor();
$isSimplePropertyPath = is_string($propertyPath) && !preg_match('/.\[/', $propertyPath);
$isCallback = is_callable($propertyPath);
$defaultValue = $stringComparison ? '' : 0;
$needSorting = $reverse;

$result = [];
$lastVal = null;
$index = 0;
foreach ($array as $key => $value) {
if (is_array($value) && $isSimplePropertyPath) {
// get array property directly to speed up
$val = isset($value[$propertyPath]) || array_key_exists($propertyPath, $value)
? $value[$propertyPath]
: null;
} elseif ($isCallback) {
$val = call_user_func($propertyPath, $value);
} else {
$val = $propertyAccessor->getValue($value, $propertyPath);
}
if (null === $val) {
$val = $defaultValue;
} elseif ($caseInsensitive) {
$val = strtolower($val);
}

$result[$key] = [$val, $index++];

if ($lastVal === null) {
$lastVal = $val;
} elseif (0 !== self::compare($lastVal, $val, $stringComparison)) {
$lastVal = $val;
$needSorting = true;
}
}

if (!$needSorting) {
return null;
}

return $result;
}

/**
* @param array $sortable
* @param bool $stringComparison
* @param bool $reverse
*
* @return array
*/
private static function getSortedKeys($sortable, $stringComparison, $reverse)
{
uasort(
$sortable,
function ($a, $b) use ($stringComparison, $reverse) {
$result = self::compare($a[0], $b[0], $stringComparison);
if (0 === $result) {
$result = self::compare($a[1], $b[1]);
} elseif ($reverse) {
$result = 0 - $result;
}

return $result;
}
);

return array_keys($sortable);
}
}
Loading

0 comments on commit 9b19a0e

Please sign in to comment.