Skip to content

Commit 5396786

Browse files
🔃 [Magento Community Engineering] Community Contributions - 2.3-develop expedited
Accepted Community Pull Requests: - #15383: issue fixed #8258 - assign indices for all array inputs so that validation works properly (by @jayankaghosh) - #18075: Feature/issue 13561 2.3 (by @bnymn) Fixed GitHub Issues: - #8258: M2.1.3 : Form validation with identical field names does not work as expected. (reported by @kanduvisla) has been fixed in #15383 by @jayankaghosh in 2.3-develop branch Related commits: 1. 113440f 2. 874d770 3. 84355a3 4. d5c41b6 5. 156ac16 6. 65a2c17 7. 97c03f5 8. 224f737 9. 908100b 10. 38b9709 11. 388d31d 12. ee288c1 13. eadcff2 - #13561: Magento 2 and SSL connection to MySQL (reported by @craigcarnell) has been fixed in #18075 by @bnymn in 2.3-develop branch Related commits: 1. 41e1793 2. 3b67548 3. def50d5 4. 7c7cc9b 5. ddad680 6. fa659d2 7. 968a59c 8. 5cfad03 9. 7c7760b 10. 6f19bf0 11. d97af67 12. 6cd243d 13. 7b13705 14. 93931d2 15. db60f71 16. d27e9a4 17. f06a4b7 18. 309e906 19. f04a5a9 20. f7ee0cc 21. c4cc952 22. 26980d8 23. 610dcff
2 parents aaf024f + 0fbe2c9 commit 5396786

File tree

26 files changed

+522
-65
lines changed

26 files changed

+522
-65
lines changed

dev/tests/functional/tests/app/Magento/CheckoutAgreements/Test/Block/Adminhtml/Block/Agreement/Edit/AgreementsForm.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<input>select</input>
1919
</mode>
2020
<stores>
21-
<selector>[name="stores[]"]</selector>
21+
<selector>[name="stores[0]"]</selector>
2222
<input>multiselectgrouplist</input>
2323
</stores>
2424
<checkbox_text />

dev/tests/functional/tests/app/Magento/Customer/Test/Block/Form/CustomerForm.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class CustomerForm extends Form
2929
*
3030
* @var string
3131
*/
32-
protected $customerAttribute = "[name='%s[]']";
32+
protected $customerAttribute = "[orig-name='%s[]']";
3333

3434
/**
3535
* Validation text message for a field.

dev/tests/functional/tests/app/Magento/Newsletter/Test/Block/Adminhtml/Queue/Edit/QueueForm.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<selector>input[name='start_at']</selector>
1212
</queue_start_at>
1313
<stores>
14-
<selector>select[name="stores[]"]</selector>
14+
<selector>select[name="stores[0]"]</selector>
1515
<input>multiselectgrouplist</input>
1616
</stores>
1717
<newsletter_subject>

dev/tests/functional/tests/app/Magento/Reports/Test/Block/Adminhtml/Sales/Coupons/Filter.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<input>select</input>
3030
</price_rule_type>
3131
<order_statuses>
32-
<selector>[name="order_statuses[]"]</selector>
32+
<selector>[name="order_statuses[0]"]</selector>
3333
<input>multiselect</input>
3434
</order_statuses>
3535
<rules_list>

dev/tests/functional/tests/app/Magento/Reports/Test/Block/Adminhtml/Sales/TaxRule/Filter.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<input>select</input>
2424
</show_order_statuses>
2525
<order_statuses>
26-
<selector>[name="order_statuses[]"]</selector>
26+
<selector>[name="order_statuses[0]"]</selector>
2727
<input>multiselect</input>
2828
</order_statuses>
2929
<show_empty_rows>

dev/tests/functional/tests/app/Magento/Review/Test/Block/Adminhtml/Rating/Edit/RatingForm.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<strategy>css selector</strategy>
1313
<fields>
1414
<stores>
15-
<selector>[name="stores[]"]</selector>
15+
<selector>[name="stores[0]"]</selector>
1616
<input>multiselectgrouplist</input>
1717
</stores>
1818
<is_active>

dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Report/Filter/Form.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<input>select</input>
2727
</show_order_statuses>
2828
<order_statuses>
29-
<selector>[name="order_statuses[]"]</selector>
29+
<selector>[name="order_statuses[0]"]</selector>
3030
<input>multiselect</input>
3131
</order_statuses>
3232
<show_actual_columns>

dev/tests/functional/tests/app/Magento/Widget/Test/Block/Adminhtml/Widget/Instance/Edit/Tab/ParametersType/RecentlyComparedProducts.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
</page_size>
1313
<show_attributes>
1414
<selector>
15-
.control [name="parameters[show_attributes][]"]
15+
.control [name="parameters[show_attributes][1]"]
1616
</selector>
1717
<input>multiselect</input>
1818
</show_attributes>
1919
<show_buttons>
2020
<selector>
21-
.control [name="parameters[show_buttons][]"]
21+
.control [name="parameters[show_buttons][2]"]
2222
</selector>
2323
<input>multiselect</input>
2424
</show_buttons>

dev/tests/functional/tests/app/Magento/Widget/Test/Block/Adminhtml/Widget/Instance/Edit/Tab/ParametersType/RecentlyViewedProducts.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
</page_size>
1313
<show_attributes>
1414
<selector>
15-
.control [name="parameters[show_attributes][]"]
15+
.control [name="parameters[show_attributes][1]"]
1616
</selector>
1717
<input>multiselect</input>
1818
</show_attributes>
1919
<show_buttons>
2020
<selector>
21-
.control [name="parameters[show_buttons][]"]
21+
.control [name="parameters[show_buttons][2]"]
2222
</selector>
2323
<input>multiselect</input>
2424
</show_buttons>

dev/tests/functional/tests/app/Magento/Widget/Test/Block/Adminhtml/WidgetForm.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@
3232
<page_size />
3333
<show_attributes>
3434
<selector>
35-
.control [name="parameters[show_attributes][]"]
35+
.control [name="parameters[show_attributes][1]"]
3636
</selector>
3737
<input>multiselect</input>
3838
</show_attributes>
3939
<show_buttons>
4040
<selector>
41-
.control [name="parameters[show_buttons][]"]
41+
.control [name="parameters[show_buttons][2]"]
4242
</selector>
4343
<input>multiselect</input>
4444
</show_buttons>

lib/internal/Magento/Framework/Config/ConfigOptionsListConstants.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class ConfigOptionsListConstants
2121
const CONFIG_PATH_CRYPT_KEY = 'crypt/key';
2222
const CONFIG_PATH_SESSION_SAVE = 'session/save';
2323
const CONFIG_PATH_RESOURCE_DEFAULT_SETUP = 'resource/default_setup/connection';
24+
const CONFIG_PATH_DB_CONNECTION_DEFAULT_DRIVER_OPTIONS = 'db/connection/default/driver_options';
2425
const CONFIG_PATH_DB_CONNECTION_DEFAULT = 'db/connection/default';
2526
const CONFIG_PATH_DB_CONNECTIONS = 'db/connection';
2627
const CONFIG_PATH_DB_PREFIX = 'db/table_prefix';
@@ -64,6 +65,10 @@ class ConfigOptionsListConstants
6465
const INPUT_KEY_DB_MODEL = 'db-model';
6566
const INPUT_KEY_DB_INIT_STATEMENTS = 'db-init-statements';
6667
const INPUT_KEY_DB_ENGINE = 'db-engine';
68+
const INPUT_KEY_DB_SSL_KEY = 'db-ssl-key';
69+
const INPUT_KEY_DB_SSL_CERT = 'db-ssl-cert';
70+
const INPUT_KEY_DB_SSL_CA = 'db-ssl-ca';
71+
const INPUT_KEY_DB_SSL_VERIFY = 'db-ssl-verify';
6772
const INPUT_KEY_RESOURCE = 'resource';
6873
const INPUT_KEY_SKIP_DB_VALIDATION = 'skip-db-validation';
6974
const INPUT_KEY_CACHE_HOSTS = 'http-cache-hosts';
@@ -104,6 +109,20 @@ class ConfigOptionsListConstants
104109
const KEY_MODEL = 'model';
105110
const KEY_INIT_STATEMENTS = 'initStatements';
106111
const KEY_ACTIVE = 'active';
112+
const KEY_DRIVER_OPTIONS = 'driver_options';
113+
/**#@-*/
114+
115+
/**#@+
116+
* Array keys for database driver options configurations
117+
*/
118+
const KEY_MYSQL_SSL_KEY = \PDO::MYSQL_ATTR_SSL_KEY;
119+
const KEY_MYSQL_SSL_CERT = \PDO::MYSQL_ATTR_SSL_CERT;
120+
const KEY_MYSQL_SSL_CA = \PDO::MYSQL_ATTR_SSL_CA;
121+
/**
122+
* Constant \PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT cannot be used as it was introduced in PHP 7.1.4
123+
* and Magento 2 is currently supporting PHP 7.1.3.
124+
*/
125+
const KEY_MYSQL_SSL_VERIFY = 1014;
107126
/**#@-*/
108127

109128
/**

lib/web/mage/validation.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1925,6 +1925,7 @@
19251925
* @protected
19261926
*/
19271927
_create: function () {
1928+
this._prepareArrayInputs();
19281929
this.validate = this.element.validate(this.options);
19291930

19301931
// ARIA (adding aria-required attribute)
@@ -1937,8 +1938,53 @@
19371938
this._listenFormValidate();
19381939
},
19391940

1941+
/**
1942+
* Validation creation.
1943+
*
1944+
* @protected
1945+
*/
1946+
_prepareArrayInputs: function () {
1947+
/* Store original names for array inputs */
1948+
var originalElements = [],
1949+
originalSubmitHandler = this.options.submitHandler;
1950+
1951+
/* For all array inputs, assign index so that validation is proper */
1952+
this.element.find('[name$="[]"]').each(function (key, input) {
1953+
var originalName, name;
1954+
1955+
input = $(input);
1956+
originalName = input.attr('name');
1957+
name = originalName.replace('[]', '[' + key + ']');
1958+
$(input).attr('name', name);
1959+
$(input).attr('orig-name', originalName);
1960+
originalElements.push({
1961+
element: $(input),
1962+
name: originalName
1963+
});
1964+
});
1965+
1966+
if (originalElements.length) {
1967+
/**
1968+
* Before submitting the actual form, remove the previously assigned indices
1969+
* @param {Object} form
1970+
*/
1971+
this.options.submitHandler = function (form) {
1972+
originalElements.forEach(function (element) {
1973+
element.element.attr('name', element.name);
1974+
element.element.removeAttr('orig-name');
1975+
});
1976+
1977+
console.error(this.submit);
1978+
1979+
/* Call the originalSubmitHandler if it's a function */
1980+
typeof originalSubmitHandler === 'function' ? originalSubmitHandler(form) : form.submit();
1981+
};
1982+
}
1983+
},
1984+
19401985
/**
19411986
* Validation listening.
1987+
*
19421988
* @protected
19431989
*/
19441990
_listenFormValidate: function () {

lib/web/mage/validation/validation.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,17 @@
4949
'validate-one-checkbox-required-by-name': [
5050
function (value, element, params) {
5151
var checkedCount = 0,
52-
container;
52+
selector,
53+
container,
54+
origNameSelector,
55+
nameSelector;
5356

5457
if (element.type === 'checkbox') {
55-
$('[name="' + element.name + '"]').each(function () {
58+
/* If orig-name attribute is present, use it for validation. Else use name */
59+
origNameSelector = '[orig-name="' + element.getAttribute('orig-name') + '"]';
60+
nameSelector = '[name="' + element.name + '"]';
61+
selector = element.getAttribute('orig-name') ? origNameSelector : nameSelector;
62+
$(selector).each(function () {
5663
if ($(this).is(':checked')) {
5764
checkedCount += 1;
5865

setup/src/Magento/Setup/Controller/DatabaseCheck.php

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55
*/
66
namespace Magento\Setup\Controller;
77

8+
use Magento\Framework\Config\ConfigOptionsListConstants;
89
use Magento\Setup\Validator\DbValidator;
910
use Zend\Json\Json;
1011
use Zend\Mvc\Controller\AbstractActionController;
1112
use Zend\View\Model\JsonModel;
1213

14+
/**
15+
* Class DatabaseCheck
16+
*/
1317
class DatabaseCheck extends AbstractActionController
1418
{
1519
/**
@@ -37,12 +41,45 @@ public function indexAction()
3741
try {
3842
$params = Json::decode($this->getRequest()->getContent(), Json::TYPE_ARRAY);
3943
$password = isset($params['password']) ? $params['password'] : '';
40-
$this->dbValidator->checkDatabaseConnection($params['name'], $params['host'], $params['user'], $password);
44+
$driverOptions = [];
45+
if ($this->isDriverOptionsGiven($params)) {
46+
if (empty($params['driverOptionsSslVerify'])) {
47+
$params['driverOptionsSslVerify'] = 0;
48+
}
49+
$driverOptions = [
50+
ConfigOptionsListConstants::KEY_MYSQL_SSL_KEY => $params['driverOptionsSslKey'],
51+
ConfigOptionsListConstants::KEY_MYSQL_SSL_CERT => $params['driverOptionsSslCert'],
52+
ConfigOptionsListConstants::KEY_MYSQL_SSL_CA => $params['driverOptionsSslCa'],
53+
ConfigOptionsListConstants::KEY_MYSQL_SSL_VERIFY => (int) $params['driverOptionsSslVerify'],
54+
];
55+
}
56+
$this->dbValidator->checkDatabaseConnectionWithDriverOptions(
57+
$params['name'],
58+
$params['host'],
59+
$params['user'],
60+
$password,
61+
$driverOptions
62+
);
4163
$tablePrefix = isset($params['tablePrefix']) ? $params['tablePrefix'] : '';
4264
$this->dbValidator->checkDatabaseTablePrefix($tablePrefix);
4365
return new JsonModel(['success' => true]);
4466
} catch (\Exception $e) {
4567
return new JsonModel(['success' => false, 'error' => $e->getMessage()]);
4668
}
4769
}
70+
71+
/**
72+
* Is Driver Options Given
73+
*
74+
* @param array $params
75+
* @return bool
76+
*/
77+
private function isDriverOptionsGiven($params)
78+
{
79+
return !(
80+
empty($params['driverOptionsSslKey']) ||
81+
empty($params['driverOptionsSslCert']) ||
82+
empty($params['driverOptionsSslCa'])
83+
);
84+
}
4885
}

setup/src/Magento/Setup/Model/ConfigGenerator.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414
use Magento\Framework\Config\ConfigOptionsListConstants;
1515
use Magento\Framework\App\State;
1616
use Magento\Framework\Math\Random;
17+
use Magento\Setup\Model\ConfigOptionsList\DriverOptions;
1718

1819
/**
1920
* Creates deployment config data based on user input array
20-
* this class introduced to break down Magento\Setup\Model\ConfigOptionsList::createConfig
21+
*
22+
* This class introduced to break down {@see Magento\Setup\Model\ConfigOptionsList::createConfig}
2123
*/
2224
class ConfigGenerator
2325
{
@@ -61,28 +63,37 @@ class ConfigGenerator
6163
*/
6264
private $cryptKeyGenerator;
6365

66+
/**
67+
* @var DriverOptions
68+
*/
69+
private $driverOptions;
70+
6471
/**
6572
* Constructor
6673
*
6774
* @param Random $random Deprecated since 100.2.0
6875
* @param DeploymentConfig $deploymentConfig
6976
* @param ConfigDataFactory|null $configDataFactory
7077
* @param CryptKeyGeneratorInterface|null $cryptKeyGenerator
78+
* @param DriverOptions|null $driverOptions
7179
*/
7280
public function __construct(
7381
Random $random,
7482
DeploymentConfig $deploymentConfig,
7583
ConfigDataFactory $configDataFactory = null,
76-
CryptKeyGeneratorInterface $cryptKeyGenerator = null
84+
CryptKeyGeneratorInterface $cryptKeyGenerator = null,
85+
DriverOptions $driverOptions = null
7786
) {
7887
$this->random = $random;
7988
$this->deploymentConfig = $deploymentConfig;
8089
$this->configDataFactory = $configDataFactory ?? ObjectManager::getInstance()->get(ConfigDataFactory::class);
8190
$this->cryptKeyGenerator = $cryptKeyGenerator ?? ObjectManager::getInstance()->get(CryptKeyGenerator::class);
91+
$this->driverOptions = $driverOptions ?? ObjectManager::getInstance()->get(DriverOptions::class);
8292
}
8393

8494
/**
8595
* Creates encryption key config data
96+
*
8697
* @param array $data
8798
* @return ConfigData
8899
*/
@@ -179,6 +190,9 @@ public function createDbConfig(array $data)
179190
$configData->set($dbConnectionPrefix . ConfigOptionsListConstants::KEY_ACTIVE, '1');
180191
}
181192

193+
$driverOptions = $this->driverOptions->getDriverOptions($data);
194+
$configData->set($dbConnectionPrefix . ConfigOptionsListConstants::KEY_DRIVER_OPTIONS, $driverOptions);
195+
182196
return $configData;
183197
}
184198

0 commit comments

Comments
 (0)