Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2232: Commit with fix bug two extension in json. #14

Merged
merged 1 commit into from
May 11, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 41 additions & 31 deletions Controller/Index/Packagist.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Magento\Customer\Controller\AbstractAccount;
use Magento\Framework\App\Action\Context;
use Magento\Framework\Controller\Result\JsonFactory;
use Magento\Framework\Api\FilterBuilder;

/**
* Class Packagist
Expand Down Expand Up @@ -71,9 +72,14 @@ class Packagist extends AbstractAccount
* @var SearchCriteriaBuilder
*/
private $searchCriteria;
/**
* @var FilterBuilder
*/
private $filterBuilder;

private $jsonResultFactory;


/**
* Packagist constructor.
* @param Context $context
Expand All @@ -89,6 +95,7 @@ class Packagist extends AbstractAccount
* @param CustomerPackagesFactory $customerPackagesFactory
* @param CustomerAuthRepository $customerAuthRepository
* @param SearchCriteriaBuilder $searchCriteria
* @param FilterBuilder $filterBuilder
*/

public function __construct(
Expand All @@ -105,22 +112,24 @@ public function __construct(
CustomerPackagesFactory $customerPackagesFactory,
CustomerAuthRepository $customerAuthRepository,
SearchCriteriaBuilder $searchCriteria,
FilterBuilder $filterBuilder,
\Magento\Framework\Controller\Result\JsonFactory $jsonResultFactory
) {
parent::__construct($context);
$this->session = $session;
$this->packages = $packages;
$this->resultJsonFactory = $resultJsonFactory;
$this->packagesRepository = $packagesRepository;
$this->customerPackages = $customerPackages;
$this->session = $session;
$this->packages = $packages;
$this->resultJsonFactory = $resultJsonFactory;
$this->packagesRepository = $packagesRepository;
$this->customerPackages = $customerPackages;
$this->customerPackagesRepository = $customerPackagesRepository;
$this->composerRepoRepository = $composerRepoRepository;
$this->customerAuth = $customerAuth;
$this->customerAuthFactory = $customerAuthFactory;
$this->customerPackagesFactory = $customerPackagesFactory;
$this->customerAuthRepository = $customerAuthRepository;
$this->searchCriteria = $searchCriteria;
$this->jsonResultFactory = $jsonResultFactory;
$this->composerRepoRepository = $composerRepoRepository;
$this->customerAuth = $customerAuth;
$this->customerAuthFactory = $customerAuthFactory;
$this->customerPackagesFactory = $customerPackagesFactory;
$this->customerAuthRepository = $customerAuthRepository;
$this->searchCriteria = $searchCriteria;
$this->jsonResultFactory = $jsonResultFactory;
$this->filterBuilder = $filterBuilder;
}

public function execute()
Expand All @@ -132,12 +141,10 @@ public function execute()
return false;
}

$authCriteriaBuilder = $this->searchCriteria;
$authCriteria = $authCriteriaBuilder->addFilter(
'auth_key',
$authKey,
'eq'
)->create();
$searchCriteriaBuilder = $this->searchCriteria;
$authCriteria = $searchCriteriaBuilder
->addFilter('auth_key', $authKey, 'eq')
->create();

$authList = $this->customerAuthRepository->getList($authCriteria);
$items = $authList->getItems();
Expand Down Expand Up @@ -165,38 +172,41 @@ public function execute()
$customerPackage = $customerPackages->getItems();

foreach ($customerPackage as $customerData) {
$packageId = $customerData->getData('package_id');
$packageId[] = $customerData->getData('package_id');
}

$packageFilter[] = $this->filterBuilder
->setField('entity_id')
->setValue($packageId)
->setConditionType('in')
->create();


$searchCriteriaBuilder = $this->searchCriteria;
$searchCriteria = $searchCriteriaBuilder
->addFilter('entity_id', $packageId)
->addFilters($packageFilter)
->create();
$packages = $this->packagesRepository->getList($searchCriteria);
$items = $packages->getItems();

foreach ($items as $packageId) {
$packageJson = $packageId->getData('package_json');
$name = $packageId->getData('name');
$decodeJson = json_decode($packageJson);
$decodeJson[$name] = json_decode($packageJson);
}

if ($customerId && $packageId) {
$responseData = [
'notify-batch' => 'https://www.eadesign.ro/eadesign_composerrepo/index/packagist/',
'cached' => false,
'packages' => [
$name => $decodeJson,
]
];
$responseData = [
'notify-batch' => 'https://www.eadesign.ro/eadesign_composerrepo/index/packagist/',
'cached' => false,
'packages' => [$decodeJson]
];

if ($customerId && $packageId) {
$res = json_encode($responseData, JSON_NUMERIC_CHECK | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
$resultJson = $this->resultJsonFactory->create();
$response = $resultJson->setJsonData($res);
}

return $response;

}

public function unAuthResponse()
Expand Down