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
rgrebenchuk committed Jun 15, 2015
2 parents 1350059 + 96761e7 commit 834e73d
Show file tree
Hide file tree
Showing 12 changed files with 142 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ public function initConfig($config)
*/
protected function initParameter($parameter)
{
if ($this->container->has($parameter)) {
if (is_string($parameter) && $this->container->has($parameter)) {
$callableService = $this->container->get($parameter);

return call_user_func($callableService);
Expand Down
13 changes: 12 additions & 1 deletion src/Oro/Bundle/EntityConfigBundle/Tools/CommandExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,18 @@ public function __construct(
* in seconds. Default timeout is 300 seconds.
* If '--ignore-errors' parameter is specified any errors are ignored;
* otherwise, an exception is raises if an error happened.
* If '--disable-cache-sync' parameter is specified a synchronization of caches between current
* process and its child processes are disabled.
*
* @param string $command
* @param array $params
* @param LoggerInterface|null $logger
*
* @return integer The exit status code
*
* @throws \RuntimeException if command failed and '--ignore-errors' parameter is not specified
*
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function runCommand($command, $params = [], LoggerInterface $logger = null)
{
Expand Down Expand Up @@ -97,6 +102,12 @@ public function runCommand($command, $params = [], LoggerInterface $logger = nul
$pb->setTimeout($this->defaultTimeout);
}

$disableCacheSync = false;
if (array_key_exists('--disable-cache-sync', $params)) {
$disableCacheSync = $params['--disable-cache-sync'];
unset($params['--disable-cache-sync']);
}

foreach ($params as $name => $val) {
$this->processParameter($pb, $name, $val);
}
Expand All @@ -119,7 +130,7 @@ function ($type, $data) use ($logger) {
);

// synchronize all data caches
if ($this->dataCacheManager) {
if ($this->dataCacheManager && !$disableCacheSync) {
$this->dataCacheManager->sync();
}

Expand Down
12 changes: 12 additions & 0 deletions src/Oro/Bundle/EntityExtendBundle/Command/UpdateSchemaCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,23 @@ public function configure()
*
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int|null|void
*/
public function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln($this->getDescription());

/**
* Unfortunately due a poor design of the Doctrine\ORM\Tools\SchemaTool::getSchemaFromMetadata
* we have to use "class_alias" to replace "Doctrine\DBAL\Schema\Visitor\RemoveNamespacedAssets"
* with "Oro\Bundle\EntityExtendBundle\Tools\ExtendSchemaUpdateRemoveNamespacedAssets".
*/
class_alias(
'Oro\Bundle\EntityExtendBundle\Tools\ExtendSchemaUpdateRemoveNamespacedAssets',
'Doctrine\DBAL\Schema\Visitor\RemoveNamespacedAssets'
);

/** @var EntityManager $em */
$em = $this->getContainer()->get('doctrine.orm.entity_manager');
/** @var ConfigManager $configManager */
Expand Down Expand Up @@ -90,6 +101,7 @@ function ($doctrineMetadata) use ($configManager) {
/**
* @param string $className
* @param ConfigManager $configManager
*
* @return bool
*/
protected function isExtendEntity($className, ConfigManager $configManager)
Expand Down
8 changes: 6 additions & 2 deletions src/Oro/Bundle/EntityExtendBundle/Extend/EntityProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@ class EntityProcessor

/**
* @var array
*
* Disable sync caches for doctrine related commands
* because in other case entity classes and Doctrine metadata do not match each other
* and as result DoctrineDataCollector raises an exception
*/
protected $commands = [
'oro:entity-extend:update-config' => [],
'oro:entity-extend:update-schema' => [],
'oro:entity-extend:update-config' => ['--disable-cache-sync' => true],
'oro:entity-extend:update-schema' => ['--disable-cache-sync' => true]
];

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace Oro\Bundle\EntityExtendBundle\Tools;

use Doctrine\DBAL\Schema\ForeignKeyConstraint;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\Sequence;
use Doctrine\DBAL\Schema\Visitor\AbstractVisitor;

/**
* This class is a copy of "Doctrine\DBAL\Schema\Visitor\RemoveNamespacedAssets" and it is used in
* the command "oro:entity-extend:update-schema" to prevent removing foreign keys between
* extended and regular entities (for details see method "acceptForeignKey").
*
* Unfortunately due a poor design of the Doctrine\ORM\Tools\SchemaTool::getSchemaFromMetadata
* we have to use "class_alias" to replace "Doctrine\DBAL\Schema\Visitor\RemoveNamespacedAssets"
* with "Oro\Bundle\EntityExtendBundle\Tools\ExtendSchemaUpdateRemoveNamespacedAssets".
* And by the same reason we cannot extend our class from "Doctrine\DBAL\Schema\Visitor\RemoveNamespacedAssets".
*/
class ExtendSchemaUpdateRemoveNamespacedAssets extends AbstractVisitor
{
/**
* @var Schema
*/
private $schema;

/**
* {@inheritdoc}
*/
public function acceptSchema(Schema $schema)
{
$this->schema = $schema;
}

/**
* {@inheritdoc}
*/
public function acceptTable(Table $table)
{
if (!$table->isInDefaultNamespace($this->schema->getName())) {
$this->schema->dropTable($table->getName());
}
}

/**
* {@inheritdoc}
*/
public function acceptSequence(Sequence $sequence)
{
if (!$sequence->isInDefaultNamespace($this->schema->getName())) {
$this->schema->dropSequence($sequence->getName());
}
}


/**
* {@inheritdoc}
*/
public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint)
{
// do nothing here
// we do not need to remove any foreign keys because extended entities can reference to regular entities
}
}
46 changes: 35 additions & 11 deletions src/Oro/Bundle/SearchBundle/Engine/Orm/PdoMysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,19 @@ public static function getPlainSql()
* @param integer $index
* @param array $searchCondition
* @param boolean $setOrderBy
*
* @return string
*/
protected function addTextField(QueryBuilder $qb, $index, $searchCondition, $setOrderBy = true)
{
$words = $this->getWords($this->filterTextFieldValue($searchCondition['fieldValue']));
$words = $this->getWords(
$this->filterTextFieldValue($searchCondition['fieldValue']),
$searchCondition['condition']
);

// TODO Need to clarify search requirements in scope of CRM-214
if ($searchCondition['condition'] == Query::OPERATOR_CONTAINS) {
$whereExpr = $this->createMatchAgainstWordsExpr($qb, $words, $index, $searchCondition, $setOrderBy);
$whereExpr = $this->createMatchAgainstWordsExpr($qb, $words, $index, $searchCondition, $setOrderBy);
$shortWords = $this->getWordsLessThanFullTextMinWordLength($words);
if ($shortWords) {
$whereExpr = $qb->expr()->orX(
Expand All @@ -84,17 +88,32 @@ protected function addTextField(QueryBuilder $qb, $index, $searchCondition, $set
* Get array of words retrieved from $value string
*
* @param string $value
* @param string $searchCondition
*
* @return array
*/
protected function getWords($value)
protected function getWords($value, $searchCondition)
{
return array_filter(explode(' ', $value));
$results = array_filter(explode(' ', $value));
$results = array_map(
function ($word) use ($searchCondition) {
if ($searchCondition === Query::OPERATOR_CONTAINS && filter_var($word, FILTER_VALIDATE_EMAIL)) {
$word = sprintf('"%s"', $word);
}

return $word;
},
$results
);

return $results;
}

/**
* Get words that have length less than $this->fullTextMinWordLength
*
* @param array $words
*
* @return array
*/
protected function getWordsLessThanFullTextMinWordLength(array $words)
Expand All @@ -121,7 +140,7 @@ function ($value) use ($length) {
protected function getFullTextMinWordLength()
{
if (null === $this->fullTextMinWordLength) {
$this->fullTextMinWordLength = (int) $this->em->getConnection()->fetchColumn(
$this->fullTextMinWordLength = (int)$this->em->getConnection()->fetchColumn(
"SHOW VARIABLES LIKE 'ft_min_word_len'",
[],
1
Expand All @@ -140,6 +159,7 @@ protected function getFullTextMinWordLength()
* @param string $index
* @param array $searchCondition
* @param bool $setOrderBy
*
* @return string
*/
protected function createMatchAgainstWordsExpr(
Expand Down Expand Up @@ -176,7 +196,7 @@ protected function createMatchAgainstWordsExpr(
)->setParameter($rawValueParameter, $fieldValue)->orderBy('rankField', 'DESC');
}

return (string) $result;
return (string)$result;
}

/**
Expand All @@ -185,8 +205,9 @@ protected function createMatchAgainstWordsExpr(
*
* @param QueryBuilder $qb
* @param array $words
* @param $index
* @param array $searchCondition
* @param $index
* @param array $searchCondition
*
* @return string
*/
protected function createLikeWordsExpr(
Expand All @@ -207,18 +228,19 @@ protected function createLikeWordsExpr(
}
if ($this->isConcreteField($fieldName) && !$this->isAllDataField($fieldName)) {
$fieldParameter = 'field' . $index;
$result = $qb->expr()->andX($result, "$joinAlias.field = :$fieldParameter");
$result = $qb->expr()->andX($result, "$joinAlias.field = :$fieldParameter");
$qb->setParameter($fieldParameter, $fieldValue);
}

return (string) $result;
return (string)$result;
}

/**
* @param QueryBuilder $qb
* @param int $index
* @param array $words,
* @param array $words
* @param array $searchCondition
*
* @return string
*/
protected function createNotLikeWordsExpr(
Expand Down Expand Up @@ -248,6 +270,7 @@ protected function createNotLikeWordsExpr(

/**
* @param array $fieldName
*
* @return bool
*/
protected function isConcreteField($fieldName)
Expand All @@ -257,6 +280,7 @@ protected function isConcreteField($fieldName)

/**
* @param array $fieldName
*
* @return bool
*/
protected function isAllDataField($fieldName)
Expand Down
2 changes: 1 addition & 1 deletion src/Oro/Bundle/SearchBundle/Query/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ public static function clearString($inputString)
preg_replace(
'/ +/',
self::DELIMITER,
preg_replace('/[^\w:*]/u', self::DELIMITER, $inputString)
preg_replace('/[^\w:*@.]/u', self::DELIMITER, $inputString)
)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,81 +5,17 @@ request:
offset: ~
max_results: ~
response:
records_count: 9
count: 9
records_count: 1
count: 1
rest:
data:
-
entity_name: Oro\Bundle\TestFrameworkBundle\Entity\Item
record_string: [email protected]
record_url: http://localhost/search/
-
entity_name: Oro\Bundle\TestFrameworkBundle\Entity\Item
record_string: [email protected]
record_url: http://localhost/search/
-
entity_name: Oro\Bundle\TestFrameworkBundle\Entity\Item
record_string: [email protected]
record_url: http://localhost/search/
-
entity_name: Oro\Bundle\TestFrameworkBundle\Entity\Item
record_string: [email protected]
record_url: http://localhost/search/
-
entity_name: Oro\Bundle\TestFrameworkBundle\Entity\Item
record_string: [email protected]
record_url: http://localhost/search/
-
entity_name: Oro\Bundle\TestFrameworkBundle\Entity\Item
record_string: [email protected]
record_url: http://localhost/search/
-
entity_name: Oro\Bundle\TestFrameworkBundle\Entity\Item
record_string: [email protected]
record_url: http://localhost/search/
-
entity_name: Oro\Bundle\TestFrameworkBundle\Entity\Item
record_string: [email protected]
record_url: http://localhost/search/
-
entity_name: Oro\Bundle\TestFrameworkBundle\Entity\Item
record_string: [email protected]
record_url: http://localhost/search/
soap:
item:
-
entityName: Oro\Bundle\TestFrameworkBundle\Entity\Item
recordTitle: [email protected]
recordUrl: http://localhost/search/
-
entityName: Oro\Bundle\TestFrameworkBundle\Entity\Item
recordTitle: [email protected]
recordUrl: http://localhost/search/
-
entityName: Oro\Bundle\TestFrameworkBundle\Entity\Item
recordTitle: [email protected]
recordUrl: http://localhost/search/
-
entityName: Oro\Bundle\TestFrameworkBundle\Entity\Item
recordTitle: [email protected]
recordUrl: http://localhost/search/
-
entityName: Oro\Bundle\TestFrameworkBundle\Entity\Item
recordTitle: [email protected]
recordUrl: http://localhost/search/
-
entityName: Oro\Bundle\TestFrameworkBundle\Entity\Item
recordTitle: [email protected]
recordUrl: http://localhost/search/
-
entityName: Oro\Bundle\TestFrameworkBundle\Entity\Item
recordTitle: [email protected]
recordUrl: http://localhost/search/
-
entityName: Oro\Bundle\TestFrameworkBundle\Entity\Item
recordTitle: [email protected]
recordUrl: http://localhost/search/
-
entityName: Oro\Bundle\TestFrameworkBundle\Entity\Item
recordTitle: [email protected]
recordUrl: http://localhost/search/
Loading

0 comments on commit 834e73d

Please sign in to comment.