Skip to content

Commit 77988b6

Browse files
author
Kopylova,Olga(okopylova)
committed
Merge pull request #253 from magento-ogre/PR_Branch
[Ogres] bug fixes
2 parents f7226f8 + 81f4925 commit 77988b6

File tree

24 files changed

+768
-119
lines changed

24 files changed

+768
-119
lines changed

.travis.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ language: php
22
php:
33
- 5.5
44
- 5.6
5+
- 7.0
56
env:
67
- TEST_SUITE=unit
78
- TEST_SUITE=integration_part_1
@@ -37,13 +38,7 @@ before_script:
3738
# Mock mail
3839
- sudo service postfix stop
3940
- smtp-sink -d "%d.%H.%M.%S" localhost:2500 1000 &
40-
- echo -e '#!/usr/bin/env bash\nexit 0' | sudo tee /usr/sbin/sendmail
41-
- >
42-
echo 'sendmail_path = "/usr/sbin/sendmail -t -i "'
43-
| sudo tee "/home/travis/.phpenv/versions/`php -i
44-
| grep "PHP Version"
45-
| head -n 1
46-
| grep -o -P '\d+\.\d+\.\d+.*'`/etc/conf.d/sendmail.ini"
41+
- echo 'sendmail_path = "/usr/sbin/sendmail -t -i "' > $(php --ini|grep -m 1 "ini files in:"|cut -d ":" -f 2)/sendmail.ini
4742
# Disable xDebug
4843
- echo '' > ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini
4944
# Install MySQL 5.6, create DB for integration tests

app/autoload.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,16 @@
1313
*/
1414
define('BP', dirname(__DIR__));
1515

16-
$vendorDir = require BP . '/app/etc/vendor_path.php';
16+
define('VENDOR_PATH', BP . '/app/etc/vendor_path.php');
17+
18+
if (!file_exists(VENDOR_PATH)) {
19+
throw new \Exception(
20+
'We can\'t read some files that are required to run the Magento application. '
21+
. 'This usually means file permissions are set incorrectly.'
22+
);
23+
}
24+
25+
$vendorDir = require VENDOR_PATH;
1726
$vendorAutoload = BP . "/{$vendorDir}/autoload.php";
1827

1928
/* 'composer install' validation */

app/code/Magento/Backend/Block/Store/Switcher.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,19 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
/**
8-
* Store switcher block
9-
*
10-
* @author Magento Core Team <core@magentocommerce.com>
11-
*/
127
namespace Magento\Backend\Block\Store;
138

149
/**
10+
* Store switcher block
11+
*
1512
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1613
*/
1714
class Switcher extends \Magento\Backend\Block\Template
1815
{
1916
/**
2017
* URL for store switcher hint
2118
*/
22-
const HINT_URL = 'http://www.magentocommerce.com/knowledge-base/entry/understanding-store-scopes';
19+
const HINT_URL = 'http://docs.magento.com/m2/ce/user_guide/stores/configuration.html';
2320

2421
/**
2522
* Name of website variable
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Search\Api;
8+
9+
/**
10+
* @api
11+
*/
12+
interface SynonymAnalyzerInterface
13+
{
14+
/**
15+
* Get synonyms for specified phrase
16+
*
17+
* For phrase: "Elizabeth is the English queen" correct output is an array of arrays containing synonyms for each
18+
* word in the phrase:
19+
*
20+
* [
21+
* 0 => [ 0 => "elizabeth" ],
22+
* 1 => [ 0 => "is" ],
23+
* 2 => [ 0 => "the" ],
24+
* 3 => [ 0 => "british", 1 => "english" ],
25+
* 4 => [ 0 => "queen", 1 => "monarch" ]
26+
* ]
27+
*
28+
* @param string $phrase
29+
* @return array
30+
*/
31+
public function getSynonymsForPhrase($phrase);
32+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Search\Model\ResourceModel;
8+
9+
use Magento\Framework\Model\AbstractModel;
10+
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
11+
use Magento\Search\Model\SynonymReader as SynReaderModel;
12+
use Magento\Framework\DB\Helper\Mysql\Fulltext;
13+
14+
/**
15+
* Synonym Reader resource model
16+
*/
17+
class SynonymReader extends AbstractDb
18+
{
19+
/**
20+
* @var Fulltext $fullTextSelect
21+
*/
22+
private $fullTextSelect;
23+
24+
/**
25+
* @param \Magento\Framework\Model\ResourceModel\Db\Context $context
26+
* @param Fulltext $fulltext
27+
* @param string $connectionName
28+
*/
29+
public function __construct(
30+
\Magento\Framework\Model\ResourceModel\Db\Context $context,
31+
Fulltext $fulltext,
32+
$connectionName = null
33+
) {
34+
parent::__construct($context, $connectionName);
35+
$this->fullTextSelect = $fulltext;
36+
}
37+
38+
/**
39+
* Custom load model: Get data by store view id
40+
*
41+
* @param AbstractModel $object
42+
* @param int $value
43+
* @return $this
44+
*/
45+
public function loadByStoreViewId(AbstractModel $object, $value)
46+
{
47+
$select = $this->getConnection()->select()->from(
48+
$this->getMainTable()
49+
)->where(
50+
'store_id = ?',
51+
$value
52+
);
53+
$data = $this->getConnection()->fetchAll($select);
54+
if ($data) {
55+
$object->setData($data);
56+
$this->_afterLoad($object);
57+
}
58+
return $this;
59+
}
60+
61+
/**
62+
* Custom load model: Get data by user query phrase and store view id
63+
*
64+
* @param SynReaderModel $object
65+
* @param string $value
66+
* @return $this
67+
*/
68+
public function loadByPhrase(SynReaderModel $object, $value)
69+
{
70+
$phrase = strtolower($value);
71+
$matchQuery = $this->fullTextSelect->getMatchQuery(
72+
['synonyms' => 'synonyms'],
73+
$phrase,
74+
Fulltext::FULLTEXT_MODE_BOOLEAN
75+
);
76+
$query = $this->getConnection()->select()->from(
77+
$this->getMainTable()
78+
)->where(
79+
'store_id = ?',
80+
$object->getStoreViewId()
81+
)->where($matchQuery);
82+
83+
$rows = $this->getConnection()->fetchAll($query);
84+
$object->setData($rows);
85+
$this->_afterLoad($object);
86+
return $this;
87+
}
88+
89+
/**
90+
* Init resource data
91+
*
92+
* @return void
93+
*/
94+
protected function _construct()
95+
{
96+
$this->_init('search_synonyms', 'group_id');
97+
}
98+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Search\Model;
7+
8+
use Magento\Search\Api\SynonymAnalyzerInterface;
9+
use Magento\Search\Model\SynonymsReader;
10+
11+
class SynonymAnalyzer implements SynonymAnalyzerInterface
12+
{
13+
/**
14+
* @var SynonymReader $synReaderModel
15+
*/
16+
protected $synReaderModel;
17+
18+
/**
19+
* Constructor
20+
*
21+
* @param SynonymReader $synReader
22+
*/
23+
public function __construct(SynonymReader $synReader)
24+
{
25+
$this->synReaderModel = $synReader;
26+
}
27+
28+
/**
29+
* Returns an array of arrays consisting of the synonyms found for each word in the input phrase
30+
*
31+
* @param string $phrase
32+
* @return array
33+
*/
34+
public function getSynonymsForPhrase($phrase)
35+
{
36+
$synGroups = [];
37+
38+
if (empty($phrase)) {
39+
return $synGroups;
40+
}
41+
42+
// strip off all the white spaces, comma, semicolons, and other such
43+
// "non-word" characters. Then implode it into a single string using white space as delimiter
44+
//$words = preg_split('/\W+/', strtolower($phrase), -1, PREG_SPLIT_NO_EMPTY);
45+
$words = preg_split(
46+
'/[~`!@#$%^&*()_+={}\[\]:"\',\s\.<>?\/\;\\\]+/',
47+
strtolower($phrase),
48+
-1,
49+
PREG_SPLIT_NO_EMPTY
50+
);
51+
$phrase = implode(' ', $words);
52+
53+
$rows = $this->synReaderModel->loadByPhrase($phrase)->getData();
54+
$synonyms = [];
55+
foreach ($rows as $row) {
56+
$synonyms [] = $row['synonyms'];
57+
}
58+
59+
// Go through every returned record looking for presence of the actual phrase. If there were no matching
60+
// records found in DB then create a new entry for it in the returned array
61+
foreach ($words as $w) {
62+
$position = $this->findInArray($w, $synonyms);
63+
if ($position !== false) {
64+
$synGroups[] = explode(',', $synonyms[$position]);
65+
} else {
66+
// No synonyms were found. Return the original word in this position
67+
$synGroups[] = [$w];
68+
}
69+
}
70+
return $synGroups;
71+
}
72+
73+
/**
74+
* Helper method to find the presence of $word in $wordsArray. If found, the particular array index is returned.
75+
* Otherwise false will be returned.
76+
*
77+
* @param string $word
78+
* @param $array $wordsArray
79+
* @return boolean | int
80+
*/
81+
private function findInArray($word, $wordsArray)
82+
{
83+
if (empty($wordsArray)) {
84+
return false;
85+
}
86+
$position = 0;
87+
foreach ($wordsArray as $wordsLine) {
88+
$pattern = '/^' . $word . ',|,' . $word . ',|,' . $word . '$/';
89+
$rv = preg_match($pattern, $wordsLine);
90+
if ($rv != 0) {
91+
return $position;
92+
}
93+
$position++;
94+
}
95+
return false;
96+
}
97+
}

0 commit comments

Comments
 (0)