Skip to content

Commit

Permalink
Merge remote-tracking branch 'mainline/develop' into pr-539
Browse files Browse the repository at this point in the history
  • Loading branch information
vzabaznov committed Apr 16, 2016
2 parents 3b06adc + e04ef1b commit 59cda3c
Show file tree
Hide file tree
Showing 35 changed files with 546 additions and 248 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function afterInitialize(
if (!$linkData || (isset($linkData['is_delete']) && (bool)$linkData['is_delete'])) {
continue;
} else {
unset($linkData['link_id']);
//unset($linkData['link_id']);
// TODO: need to implement setLinkFileContent()
$link = $this->linkFactory->create(['data' => $linkData]);
if (isset($linkData['type'])) {
Expand All @@ -89,7 +89,9 @@ public function afterInitialize(
if (isset($linkData['file_content'])) {
$link->setLinkFileContent($linkData['file_content']);
}
$link->setId(null);
if (isset($linkData['link_id'])) {
$link->setId($linkData['link_id']);
}
if (isset($linkData['sample']['type'])) {
$link->setSampleType($linkData['sample']['type']);
}
Expand Down Expand Up @@ -125,10 +127,11 @@ public function afterInitialize(
if (!$sampleData || (isset($sampleData['is_delete']) && (bool)$sampleData['is_delete'])) {
continue;
} else {
unset($sampleData['sample_id']);
$sample = $this->sampleFactory->create(['data' => $sampleData]);
$sample->setId(null);
$sample->setStoreId($product->getStoreId());
if (isset($sampleData['sample_id'])) {
$sample->setId($sampleData['sample_id']);
}
if (isset($sampleData['type'])) {
$sample->setSampleType($sampleData['type']);
}
Expand Down
17 changes: 13 additions & 4 deletions app/code/Magento/Downloadable/Model/Link/SaveHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,26 @@ public function __construct(LinkRepository $linkRepository)
*/
public function execute($entityType, $entity, $arguments = [])
{
/** @var \Magento\Catalog\Api\Data\ProductInterface $entity */
if ($entity->getTypeId() !== 'downloadable') {
return $entity;
}
/** @var \Magento\Catalog\Api\Data\ProductInterface $entity */
foreach ($this->linkRepository->getList($entity->getSku()) as $link) {
$this->linkRepository->delete($link->getId());
}

$oldLinks = $this->linkRepository->getList($entity->getSku());
$links = $entity->getExtensionAttributes()->getDownloadableProductLinks() ?: [];
$updatedLinkIds = [];
foreach ($links as $link) {
if ($link->getId()) {
$updatedLinkIds[] = $link->getId();
}
$this->linkRepository->save($entity->getSku(), $link, !(bool)$entity->getStoreId());
}
foreach ($oldLinks as $link) {
if (!in_array($link->getId(), $updatedLinkIds)) {
$this->linkRepository->delete($link->getId());
}
}

return $entity;
}
}
16 changes: 12 additions & 4 deletions app/code/Magento/Downloadable/Model/Sample/SaveHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,22 @@ public function execute($entityType, $entity, $arguments = [])
if ($entity->getTypeId() != \Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE) {
return $entity;
}
/** @var \Magento\Catalog\Api\Data\ProductInterface $entity */
foreach ($this->sampleRepository->getList($entity->getSku()) as $sample) {
$this->sampleRepository->delete($sample->getId());
}

$oldSamples = $this->sampleRepository->getList($entity->getSku());
$samples = $entity->getExtensionAttributes()->getDownloadableProductSamples() ?: [];
$updatedSampleIds = [];
foreach ($samples as $sample) {
if ($sample->getId()) {
$updatedSampleIds[] = $sample->getId();
}
$this->sampleRepository->save($entity->getSku(), $sample, !(bool)$entity->getStoreId());
}
foreach ($oldSamples as $sample) {
if (!in_array($sample->getId(), $updatedSampleIds)) {
$this->sampleRepository->delete($sample->getId());
}
}

return $entity;
}
}
4 changes: 4 additions & 0 deletions app/code/Magento/Payment/Model/Method/Cc.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ public function validate()
'|8[6-9][0-9]{10}|9[0-9]{11})|62(2(12[6-9][0-9]{10}|1[3-9][0-9]{11}|[2-8][0-9]{12}' .
'|9[0-1][0-9]{11}|92[0-5][0-9]{10})|[4-6][0-9]{13}|8[2-8][0-9]{12})|6(4[4-9][0-9]{13}' .
'|5[0-9]{14}))$/',
'MI' => '/^(5(0|[6-9])|63|67(?!59|6770|6774))\d*$/',
'MD' => '/^(6759(?!24|38|40|6[3-9]|70|76)|676770|676774)\d*$/',
];

$ccNumAndTypeMatches = isset(
Expand Down Expand Up @@ -213,6 +215,8 @@ public function getVerificationRegEx()
'SO' => '/^[0-9]{3,4}$/',
'OT' => '/^[0-9]{3,4}$/',
'JCB' => '/^[0-9]{3,4}$/',
'MI' => '/^[0-9]{3}$/',
'MD' => '/^[0-9]{3}$/',
];
return $verificationExpList;
}
Expand Down
54 changes: 47 additions & 7 deletions app/code/Magento/Paypal/Model/Report/Settlement.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace Magento\Paypal\Model\Report;

use DateTime;
use Magento\Framework\Filesystem;
use Magento\Framework\Filesystem\DirectoryList;

Expand Down Expand Up @@ -162,6 +163,13 @@ class Settlement extends \Magento\Framework\Model\AbstractModel
*/
protected $_scopeConfig;

/**
* Columns with DateTime data type
*
* @var array
*/
private $dateTimeColumns = ['transaction_initiation_date', 'transaction_completion_date'];

/**
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Registry $registry
Expand Down Expand Up @@ -249,7 +257,8 @@ public function fetchAndSave(\Magento\Framework\Filesystem\Io\Sftp $connection)

// Set last modified date, this value will be overwritten during parsing
if (isset($attributes['mtime'])) {
$lastModified = new \DateTime($attributes['mtime']);
$date = new \DateTime();
$lastModified = $date->setTimestamp($attributes['mtime']);
$this->setReportLastModified(
$lastModified->format('Y-m-d H:i:s')
);
Expand Down Expand Up @@ -324,7 +333,7 @@ public function parseCsv($localCsv, $format = 'new')
$rowMap = $this->_csvColumns[$format]['rowmap'];

$flippedSectionColumns = array_flip($sectionColumns);
$stream = $this->_tmpDirectory->openFile($localCsv);
$stream = $this->_tmpDirectory->openFile($localCsv, 'r');
while ($line = $stream->readCsv()) {
if (empty($line)) {
// The line was empty, so skip it.
Expand Down Expand Up @@ -360,11 +369,7 @@ public function parseCsv($localCsv, $format = 'new')
break;
case 'SB':
// Section body.
$bodyItem = [];
for ($i = 1; $i < count($line); $i++) {
$bodyItem[$rowMap[$flippedSectionColumns[$i]]] = $line[$i];
}
$this->_rows[] = $bodyItem;
$this->_rows[] = $this->getBodyItems($line, $flippedSectionColumns, $rowMap);
break;
case 'SC':
// Section records count.
Expand All @@ -385,6 +390,41 @@ public function parseCsv($localCsv, $format = 'new')
return $this;
}

/**
* Parse columns from line of csv file
*
* @param array $line
* @param array $sectionColumns
* @param array $rowMap
* @return array
*/
private function getBodyItems(array $line, array $sectionColumns, array $rowMap)
{
$bodyItem = [];
for ($i = 1, $count = count($line); $i < $count; $i++) {
if(isset($rowMap[$sectionColumns[$i]])) {
if (in_array($rowMap[$sectionColumns[$i]], $this->dateTimeColumns)) {
$line[$i] = $this->formatDateTimeColumns($line[$i]);
}
$bodyItem[$rowMap[$sectionColumns[$i]]] = $line[$i];
}
}
return $bodyItem;
}

/**
* Format date columns in UTC
*
* @param string $lineItem
* @return string
*/
private function formatDateTimeColumns($lineItem)
{
/** @var DateTime $date */
$date = new DateTime($lineItem, new \DateTimeZone('UTC'));
return $date->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT);
}

/**
* Load report by unique key (accoutn + report date)
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Search\Adapter\Mysql\Query\Preprocessor;
namespace Magento\Search\Adapter\Query\Preprocessor;

use Magento\Framework\Search\Adapter\Preprocessor\PreprocessorInterface;
use Magento\Search\Api\SynonymAnalyzerInterface;
Expand Down
11 changes: 10 additions & 1 deletion app/code/Magento/Search/Api/SynonymGroupRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ interface SynonymGroupRepositoryInterface
* Save synonym group data
*
* @param \Magento\Search\Api\Data\SynonymGroupInterface $synonymGroup
* @param bool $errorOnMergeConflict
* @return \Magento\Search\Api\Data\SynonymGroupInterface saved attribute set
*/
public function save(\Magento\Search\Api\Data\SynonymGroupInterface $synonymGroup);
public function save(\Magento\Search\Api\Data\SynonymGroupInterface $synonymGroup, $errorOnMergeConflict = false);

/**
* Remove given synonym group data
Expand All @@ -25,4 +26,12 @@ public function save(\Magento\Search\Api\Data\SynonymGroupInterface $synonymGrou
* @return bool
*/
public function delete(\Magento\Search\Api\Data\SynonymGroupInterface $synonymGroup);

/**
* Return a paritcular synonym group interface instance based on passed in synonym group id
*
* @param int $synonymGroupId
* @return \Magento\Search\Api\Data\SynonymGroupInterface
*/
public function get($synonymGroupId);
}
51 changes: 43 additions & 8 deletions app/code/Magento/Search/Controller/Adminhtml/Synonyms/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,45 @@

namespace Magento\Search\Controller\Adminhtml\Synonyms;

use Magento\Search\Controller\Adminhtml\Synonyms;

/**
* Delete Controller
*/
class Delete extends Synonyms
class Delete extends \Magento\Backend\App\Action
{
/**
* Authorization level of a basic admin session
*
* @see _isAllowed()
*/
const ADMIN_RESOURCE = 'Magento_Search::synonyms';

/**
* @var \Psr\Log\LoggerInterface $logger
*/
private $logger;

/**
* @var \Magento\Search\Api\SynonymGroupRepositoryInterface $synGroupRepository
*/
private $synGroupRepository;

/**
* Constructor
*
* @param \Magento\Backend\App\Action\Context $context
* @param \Magento\Search\Api\SynonymGroupRepositoryInterface $synGroupRepository
* @param \Psr\Log\LoggerInterface $logger
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Search\Api\SynonymGroupRepositoryInterface $synGroupRepository,
\Psr\Log\LoggerInterface $logger
) {
$this->synGroupRepository = $synGroupRepository;
$this->logger = $logger;
parent::__construct($context);
}

/**
* Delete action
*
Expand All @@ -25,13 +57,16 @@ public function execute()
$resultRedirect = $this->resultRedirectFactory->create();
if ($id) {
try {
$model = $this->_objectManager->create('Magento\Search\Model\SynonymGroup');
$model->load($id);
$repository = $this->_objectManager->create('Magento\Search\Api\SynonymGroupRepositoryInterface');
$repository->delete($model);
/** @var \Magento\Search\Model\SynonymGroup $synGroupModel */
$synGroupModel = $this->synGroupRepository->get($id);
$this->synGroupRepository->delete($synGroupModel);
$this->messageManager->addSuccess(__('The synonym group has been deleted.'));
} catch (\Exception $e) {
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addError($e->getMessage());
$this->logger->error($e);
} catch (\Exception $e) {
$this->messageManager->addError(__('An error was encountered while performing delete operation.'));
$this->logger->error($e);
}
} else {
$this->messageManager->addError(__('We can\'t find a synonym group to delete.'));
Expand Down
Loading

0 comments on commit 59cda3c

Please sign in to comment.