コード例 #1
0
ファイル: Popup.php プロジェクト: aiesh/magento2
 /**
  * Get associated grouped products grid popup
  *
  * @return void
  */
 public function execute()
 {
     $productId = (int) $this->getRequest()->getParam('id');
     /** @var $product \Magento\Catalog\Model\Product */
     $product = $this->factory->create();
     $product->setStoreId($this->getRequest()->getParam('store', 0));
     $typeId = $this->getRequest()->getParam('type');
     if (!$productId && $typeId) {
         $product->setTypeId($typeId);
     }
     $product->setData('_edit_mode', true);
     if ($productId) {
         try {
             $product->load($productId);
         } catch (\Exception $e) {
             $product->setTypeId(\Magento\Catalog\Model\Product\Type::DEFAULT_TYPE);
             $this->logger->logException($e);
         }
     }
     $setId = (int) $this->getRequest()->getParam('set');
     if ($setId) {
         $product->setAttributeSetId($setId);
     }
     $this->registry->register('current_product', $product);
     $this->_view->loadLayout(false);
     $this->_view->renderLayout();
 }
コード例 #2
0
ファイル: Builder.php プロジェクト: aiesh/magento2
 /**
  * Build product based on user request
  *
  * @param RequestInterface $request
  * @return \Magento\Catalog\Model\Product
  */
 public function build(RequestInterface $request)
 {
     $productId = (int) $request->getParam('id');
     /** @var $product \Magento\Catalog\Model\Product */
     $product = $this->productFactory->create();
     $product->setStoreId($request->getParam('store', 0));
     $typeId = $request->getParam('type');
     if (!$productId && $typeId) {
         $product->setTypeId($typeId);
     }
     $product->setData('_edit_mode', true);
     if ($productId) {
         try {
             $product->load($productId);
         } catch (\Exception $e) {
             $product->setTypeId(\Magento\Catalog\Model\Product\Type::DEFAULT_TYPE);
             $this->logger->logException($e);
         }
     }
     $setId = (int) $request->getParam('set');
     if ($setId) {
         $product->setAttributeSetId($setId);
     }
     $this->registry->register('product', $product);
     $this->registry->register('current_product', $product);
     $this->wysiwygConfig->setStoreId($request->getParam('store'));
     return $product;
 }
コード例 #3
0
ファイル: OrderCreate.php プロジェクト: aiesh/magento2
 /**
  * Create order
  *
  * @param \Magento\Sales\Service\V1\Data\Order $orderDataObject
  * @return bool
  * @throws \Exception
  */
 public function invoke(\Magento\Sales\Service\V1\Data\Order $orderDataObject)
 {
     try {
         $order = $this->orderConverter->getModel($orderDataObject);
         return (bool) $order->save();
     } catch (\Exception $e) {
         $this->logger->logException($e);
         throw new \Exception(__('An error has occurred during order creation'));
     }
 }
コード例 #4
0
ファイル: EmailSender.php プロジェクト: aiesh/magento2
 /**
  * Send email about new order.
  * Process mail exception
  *
  * @param Order $order
  * @return bool
  */
 public function send(Order $order)
 {
     try {
         $this->orderSender->send($order);
     } catch (\Magento\Framework\Mail\Exception $exception) {
         $this->logger->logException($exception);
         $this->messageManager->addWarning(__('You did not email your customer. Please check your email settings.'));
         return false;
     }
     return true;
 }
コード例 #5
0
ファイル: Index.php プロジェクト: Atlis/docker-magento2
 /**
  * Instantiate IPN model and pass IPN request to it
  *
  * @return void
  */
 public function execute()
 {
     if (!$this->getRequest()->isPost()) {
         return;
     }
     try {
         $data = $this->getRequest()->getPost();
         $this->_ipnFactory->create(array('data' => $data))->processIpnRequest();
     } catch (\Exception $e) {
         $this->_logger->logException($e);
     }
 }
コード例 #6
0
ファイル: InvoiceCreate.php プロジェクト: aiesh/magento2
 /**
  * @param \Magento\Sales\Service\V1\Data\Invoice $invoiceDataObject
  * @return bool
  * @throws \Exception
  */
 public function invoke(\Magento\Sales\Service\V1\Data\Invoice $invoiceDataObject)
 {
     try {
         /** @var \Magento\Sales\Model\Order\Invoice $invoice */
         $invoice = $this->invoiceConverter->getModel($invoiceDataObject);
         if (!$invoice) {
             return false;
         }
         $invoice->register();
         $invoice->save();
         return true;
     } catch (\Exception $e) {
         $this->logger->logException($e);
         throw new \Exception(__('An error has occurred during creating Invoice'));
     }
 }
コード例 #7
0
 /**
  * {@inheritdoc}
  */
 public function setAddress($cartId, $addressData)
 {
     /** @var \Magento\Sales\Model\Quote $quote */
     $quote = $this->quoteLoader->load($cartId, $this->storeManager->getStore()->getId());
     if ($quote->isVirtual()) {
         throw new NoSuchEntityException('Cart contains virtual product(s) only. Shipping address is not applicable');
     }
     /** @var \Magento\Sales\Model\Quote\Address $address */
     $address = $this->quoteAddressFactory->create();
     $this->addressValidator->validate($addressData);
     if ($addressData->getId()) {
         $address->load($addressData->getId());
     }
     $address = $this->addressConverter->convertDataObjectToModel($addressData, $address);
     $address->setSameAsBilling(0);
     $quote->setShippingAddress($address);
     $quote->setDataChanges(true);
     try {
         $quote->save();
     } catch (\Exception $e) {
         $this->logger->logException($e);
         throw new InputException('Unable to save address. Please, check input data.');
     }
     return $quote->getShippingAddress()->getId();
 }
コード例 #8
0
ファイル: Observer.php プロジェクト: pavelnovitsky/magento2
 /**
  * Create Backup
  *
  * @return $this
  */
 public function scheduledBackup()
 {
     if (!$this->_scopeConfig->isSetFlag(self::XML_PATH_BACKUP_ENABLED, ScopeInterface::SCOPE_STORE)) {
         return $this;
     }
     if ($this->_scopeConfig->isSetFlag(self::XML_PATH_BACKUP_MAINTENANCE_MODE, ScopeInterface::SCOPE_STORE)) {
         $this->maintenanceMode->set(true);
     }
     $type = $this->_scopeConfig->getValue(self::XML_PATH_BACKUP_TYPE, ScopeInterface::SCOPE_STORE);
     $this->_errors = array();
     try {
         $backupManager = $this->_backupFactory->create($type)->setBackupExtension($this->_backupData->getExtensionByType($type))->setTime(time())->setBackupsDir($this->_backupData->getBackupsDir());
         $this->_coreRegistry->register('backup_manager', $backupManager);
         if ($type != \Magento\Framework\Backup\Factory::TYPE_DB) {
             $backupManager->setRootDir($this->_filesystem->getPath(\Magento\Framework\App\Filesystem::ROOT_DIR))->addIgnorePaths($this->_backupData->getBackupIgnorePaths());
         }
         $backupManager->create();
         $message = $this->_backupData->getCreateSuccessMessageByType($type);
         $this->_logger->log($message);
     } catch (\Exception $e) {
         $this->_errors[] = $e->getMessage();
         $this->_errors[] = $e->getTrace();
         $this->_logger->log($e->getMessage(), \Zend_Log::ERR);
         $this->_logger->logException($e);
     }
     if ($this->_scopeConfig->isSetFlag(self::XML_PATH_BACKUP_MAINTENANCE_MODE, ScopeInterface::SCOPE_STORE)) {
         $this->maintenanceMode->set(false);
     }
     return $this;
 }
コード例 #9
0
ファイル: AbstractReport.php プロジェクト: aiesh/magento2
 /**
  * Retrieve transitions for offsets of given timezone
  *
  * @param string $timezone
  * @param mixed $from
  * @param mixed $to
  * @return array
  */
 protected function _getTZOffsetTransitions($timezone, $from = null, $to = null)
 {
     $tzTransitions = array();
     try {
         if (!empty($from)) {
             $from = new \Magento\Framework\Stdlib\DateTime\Date($from, \Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT);
             $from = $from->getTimestamp();
         }
         $to = new \Magento\Framework\Stdlib\DateTime\Date($to, \Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT);
         $nextPeriod = $this->_getWriteAdapter()->formatDate($to->toString(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT));
         $to = $to->getTimestamp();
         $dtz = new \DateTimeZone($timezone);
         $transitions = $dtz->getTransitions();
         $dateTimeObject = new \Magento\Framework\Stdlib\DateTime\Date('c');
         for ($i = count($transitions) - 1; $i >= 0; $i--) {
             $tr = $transitions[$i];
             try {
                 $this->timezoneValidator->validate($tr['ts'], $to);
             } catch (\Magento\Framework\Stdlib\DateTime\Timezone\ValidationException $e) {
                 continue;
             }
             $dateTimeObject->set($tr['time']);
             $tr['time'] = $this->_getWriteAdapter()->formatDate($dateTimeObject->toString(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT));
             $tzTransitions[$tr['offset']][] = array('from' => $tr['time'], 'to' => $nextPeriod);
             if (!empty($from) && $tr['ts'] < $from) {
                 break;
             }
             $nextPeriod = $tr['time'];
         }
     } catch (\Exception $e) {
         $this->_logger->logException($e);
     }
     return $tzTransitions;
 }
コード例 #10
0
ファイル: Oauth.php プロジェクト: pavelnovitsky/magento2
 /**
  * {@inheritdoc}
  */
 public function postToConsumer($consumerId, $endpointUrl)
 {
     try {
         $consumer = $this->_consumerFactory->create()->load($consumerId);
         if (!$consumer->getId()) {
             throw new \Magento\Framework\Oauth\Exception(__('A consumer with ID %1 does not exist', $consumerId), OauthInterface::ERR_PARAMETER_REJECTED);
         }
         $consumerData = $consumer->getData();
         $verifier = $this->_tokenFactory->create()->createVerifierToken($consumerId);
         $storeBaseUrl = $this->_storeManager->getStore()->getBaseUrl();
         $this->_httpClient->setUri($endpointUrl);
         $this->_httpClient->setParameterPost(array('oauth_consumer_key' => $consumerData['key'], 'oauth_consumer_secret' => $consumerData['secret'], 'store_base_url' => $storeBaseUrl, 'oauth_verifier' => $verifier->getVerifier()));
         $maxredirects = $this->_dataHelper->getConsumerPostMaxRedirects();
         $timeout = $this->_dataHelper->getConsumerPostTimeout();
         $this->_httpClient->setConfig(array('maxredirects' => $maxredirects, 'timeout' => $timeout));
         $this->_httpClient->request(\Magento\Framework\HTTP\ZendClient::POST);
         return $verifier->getVerifier();
     } catch (\Magento\Framework\Model\Exception $exception) {
         throw $exception;
     } catch (\Magento\Framework\Oauth\Exception $exception) {
         throw $exception;
     } catch (\Exception $exception) {
         $this->_logger->logException($exception);
         throw new \Magento\Framework\Oauth\Exception('Unable to post data to consumer due to an unexpected error');
     }
 }
コード例 #11
0
ファイル: ErrorProcessor.php プロジェクト: aiesh/magento2
 /**
  * Log information about exception to exception log.
  *
  * @param \Exception $exception
  * @return string $reportId
  */
 protected function _logException(\Exception $exception)
 {
     $exceptionClass = get_class($exception);
     $reportId = uniqid("webapi-");
     $exceptionForLog = new $exceptionClass("Report ID: {$reportId}; Message: {$exception->getMessage()}", $exception->getCode());
     $this->_logger->logException($exceptionForLog);
     return $reportId;
 }
コード例 #12
0
ファイル: ShipmentCreate.php プロジェクト: aiesh/magento2
 /**
  * Invoke CreateShipment service
  *
  * @param \Magento\Sales\Service\V1\Data\Shipment $shipmentDataObject
  * @return bool
  * @throws \Exception
  */
 public function invoke(\Magento\Sales\Service\V1\Data\Shipment $shipmentDataObject)
 {
     try {
         /** @var \Magento\Sales\Model\Order\Shipment $shipment */
         $shipment = $this->shipmentConverter->getModel($shipmentDataObject);
         if (!$shipment) {
             return false;
         }
         $shipment->getOrder()->setIsInProcess(true);
         $shipment->register();
         $shipment->save();
         return true;
     } catch (\Exception $e) {
         $this->logger->logException($e);
         throw new \Exception(__('An error has occurred during creating Shipment'));
     }
 }
コード例 #13
0
ファイル: AbstractNotifier.php プロジェクト: aiesh/magento2
 /**
  * Notify user
  *
  * @param AbstractModel $model
  * @return bool
  * @throws \Magento\Framework\Mail\Exception
  */
 public function notify(\Magento\Sales\Model\AbstractModel $model)
 {
     try {
         $this->sender->send($model);
         if (!$model->getEmailSent()) {
             return false;
         }
         $historyItem = $this->historyCollectionFactory->create()->getUnnotifiedForInstance($model);
         if ($historyItem) {
             $historyItem->setIsCustomerNotified(1);
             $historyItem->save();
         }
     } catch (Exception $e) {
         $this->logger->logException($e);
         return false;
     }
     return true;
 }
コード例 #14
0
 /**
  * {@inheritdoc}
  */
 public function removePermissions($integrationId)
 {
     try {
         $this->_deleteRole($integrationId);
     } catch (\Exception $e) {
         $this->_logger->logException($e);
         throw new LocalizedException('Error happened while deleting role and permissions. Check exception log for details.');
     }
 }
コード例 #15
0
ファイル: Index.php プロジェクト: aiesh/magento2
 /**
  * Instantiate IPN model and pass IPN request to it
  *
  * @return void
  */
 public function execute()
 {
     if (!$this->getRequest()->isPost()) {
         return;
     }
     try {
         $data = $this->getRequest()->getPost();
         $this->_ipnFactory->create(array('data' => $data))->processIpnRequest();
     } catch (UnavailableException $e) {
         $this->_logger->logException($e);
         $this->getResponse()->setHeader('HTTP/1.1', '503 Service Unavailable')->sendResponse();
         /** @todo eliminate usage of exit statement */
         exit;
     } catch (\Exception $e) {
         $this->_logger->logException($e);
         $this->getResponse()->setHttpResponseCode(500);
     }
 }
コード例 #16
0
ファイル: CreditmemoCreate.php プロジェクト: aiesh/magento2
 /**
  * @param \Magento\Sales\Service\V1\Data\Creditmemo $creditmemoDataObject
  * @throws \Exception
  * @return bool
  */
 public function invoke(\Magento\Sales\Service\V1\Data\Creditmemo $creditmemoDataObject)
 {
     try {
         /** @var \Magento\Sales\Model\Order\Creditmemo $creditmemo */
         $creditmemo = $this->creditmemoConverter->getModel($creditmemoDataObject);
         if (!$creditmemo) {
             return false;
         }
         if (!$creditmemo->isValidGrandTotal()) {
             return false;
         }
         $creditmemo->register();
         $creditmemo->save();
         return true;
     } catch (\Exception $e) {
         $this->logger->logException($e);
         throw new \Exception(__('An error has occurred during creating Creditmemo'));
     }
 }
コード例 #17
0
ファイル: Filter.php プロジェクト: Atlis/docker-magento2
 /**
  * Filter the string as template.
  * Rewrited for logging exceptions
  *
  * @param string $value
  * @return string
  * @SuppressWarnings(PHPMD.ConstructorWithNameAsEnclosingClass)
  */
 public function filter($value)
 {
     try {
         $value = parent::filter($value);
     } catch (\Exception $e) {
         $value = '';
         $this->_logger->logException($e);
     }
     return $value;
 }
コード例 #18
0
 /**
  * Check whether integration is inactive and don't allow using this integration in this case.
  *
  * It's ok that we break invocation chain since we're dealing with ACL here - if something is not allowed at any
  * point it couldn't be made allowed at some other point.
  *
  * @param \Magento\Authz\Service\AuthorizationV1 $subject
  * @param callable $proceed
  * @param mixed $resources
  * @param UserIdentifier $userIdentifier
  *
  * @return bool
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function aroundIsAllowed(\Magento\Authz\Service\AuthorizationV1 $subject, \Closure $proceed, $resources, \Magento\Authz\Model\UserIdentifier $userIdentifier = null)
 {
     /** @var UserIdentifier $userIdentifierObject */
     $userIdentifierObject = $userIdentifier ?: $this->_userIdentifier;
     if ($userIdentifierObject->getUserType() !== UserIdentifier::USER_TYPE_INTEGRATION) {
         return $proceed($resources, $userIdentifier);
     }
     try {
         $integration = $this->_integrationService->get($userIdentifierObject->getUserId());
     } catch (\Exception $e) {
         // Wrong integration ID or DB not reachable or whatever - give up and don't allow just in case
         $this->_logger->logException($e);
         return false;
     }
     if ($integration->getStatus() !== Integration::STATUS_ACTIVE) {
         return false;
     }
     return $proceed($resources, $userIdentifier);
 }
コード例 #19
0
 /**
  * Get store model
  *
  * @param null|string|bool|int|\\Magento\Store\Model\Store $store
  * @return \\Magento\Store\Model\Store
  */
 protected function getStore($store = null)
 {
     try {
         if (!$store instanceof \Magento\Store\Model\Store) {
             $store = $this->storeManager->getStore($store);
         }
     } catch (\Exception $e) {
         $this->logger->logException($e);
         $store = $this->storeManager->getStore();
     }
     return $store;
 }
コード例 #20
0
 /**
  * Analyze user-agent information to override custom design settings
  *
  * @param \Magento\Framework\App\RequestInterface $request
  * @return bool
  */
 protected function _applyUserAgentDesignException($request)
 {
     try {
         $theme = $this->_designExceptions->getThemeByRequest($request);
         if (false !== $theme) {
             $this->_getDesign()->setDesignTheme($theme);
             return true;
         }
     } catch (\Exception $e) {
         $this->_logger->logException($e);
     }
     return false;
 }
コード例 #21
0
 /**
  * Attempt to merge assets, falling back to original non-merged ones, if merging fails
  *
  * @return void
  */
 protected function initialize()
 {
     if (!$this->isInitialized) {
         $this->isInitialized = true;
         try {
             $mergedAsset = $this->createMergedAsset($this->assets);
             $this->mergeStrategy->merge($this->assets, $mergedAsset);
             $this->assets = array($mergedAsset);
         } catch (\Exception $e) {
             $this->logger->logException($e);
         }
     }
 }
コード例 #22
0
ファイル: Onepage.php プロジェクト: Atlis/docker-magento2
 /**
  * Create order based on checkout type. Create customer if necessary.
  *
  * @return $this
  */
 public function saveOrder()
 {
     $this->validate();
     $isNewCustomer = false;
     switch ($this->getCheckoutMethod()) {
         case self::METHOD_GUEST:
             $this->_prepareGuestQuote();
             break;
         case self::METHOD_REGISTER:
             $this->_prepareNewCustomerQuote();
             $isNewCustomer = true;
             break;
         default:
             $this->_prepareCustomerQuote();
             break;
     }
     /** @var \Magento\Sales\Model\Service\Quote $quoteService */
     $quoteService = $this->_serviceQuoteFactory->create(array('quote' => $this->getQuote()));
     $quoteService->submitAllWithDataObject();
     if ($isNewCustomer) {
         try {
             $this->_involveNewCustomer();
         } catch (\Exception $e) {
             $this->_logger->logException($e);
         }
     }
     $this->_checkoutSession->setLastQuoteId($this->getQuote()->getId())->setLastSuccessQuoteId($this->getQuote()->getId())->clearHelperData();
     $order = $quoteService->getOrder();
     if ($order) {
         $this->_eventManager->dispatch('checkout_type_onepage_save_order_after', array('order' => $order, 'quote' => $this->getQuote()));
         /**
          * a flag to set that there will be redirect to third party after confirmation
          */
         $redirectUrl = $this->getQuote()->getPayment()->getOrderPlaceRedirectUrl();
         /**
          * we only want to send to customer about new order when there is no redirect to third party
          */
         if (!$redirectUrl && $order->getCanSendNewEmailFlag()) {
             try {
                 $order->sendNewOrderEmail();
             } catch (\Exception $e) {
                 $this->_logger->logException($e);
             }
         }
         // add order information to the session
         $this->_checkoutSession->setLastOrderId($order->getId())->setRedirectUrl($redirectUrl)->setLastRealOrderId($order->getIncrementId());
     }
     $this->_eventManager->dispatch('checkout_submit_all_after', array('order' => $order, 'quote' => $this->getQuote()));
     return $this;
 }
コード例 #23
0
ファイル: File.php プロジェクト: aiesh/magento2
 /**
  * Save file to storage
  *
  * @param  array $file
  * @param  bool $overwrite
  * @throws \Magento\Framework\Model\Exception
  * @return bool
  */
 public function saveFile($file, $overwrite = true)
 {
     if (isset($file['filename']) && !empty($file['filename']) && isset($file['content']) && !empty($file['content'])) {
         try {
             $filename = isset($file['directory']) && !empty($file['directory']) ? $file['directory'] . '/' . $file['filename'] : $file['filename'];
             return $this->_fileUtility->saveFile($filename, $file['content'], $overwrite);
         } catch (\Exception $e) {
             $this->_logger->logException($e);
             throw new \Magento\Framework\Model\Exception(__('Unable to save file "%1" at "%2"', $file['filename'], $file['directory']));
         }
     } else {
         throw new \Magento\Framework\Model\Exception(__('Wrong file info format'));
     }
     return false;
 }
コード例 #24
0
 /**
  * Minify content of child asset
  *
  * @return void
  */
 protected function process()
 {
     if ($this->isFileMinified($this->originalAsset->getPath())) {
         $this->fillPropertiesByOriginalAsset();
     } else {
         if ($this->hasPreminifiedFile($this->originalAsset->getSourceFile())) {
             $this->fillPropertiesByOriginalAssetWithMin();
         } else {
             try {
                 $this->fillPropertiesByMinifyingAsset();
             } catch (\Exception $e) {
                 $this->logger->logException(new \Magento\Framework\Exception('Could not minify file: ' . $this->originalAsset->getSourceFile(), 0, $e));
                 $this->fillPropertiesByOriginalAsset();
             }
         }
     }
 }
コード例 #25
0
ファイル: Observer.php プロジェクト: aiesh/magento2
 /**
  * Apply customized static files to frontend
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function applyThemeCustomization(\Magento\Framework\Event\Observer $observer)
 {
     /** @var $themeFile \Magento\Core\Model\Theme\File */
     foreach ($this->_currentTheme->getCustomization()->getFiles() as $themeFile) {
         try {
             $service = $themeFile->getCustomizationService();
             if ($service instanceof \Magento\Framework\View\Design\Theme\Customization\FileAssetInterface) {
                 $identifier = $themeFile->getData('file_path');
                 $dirPath = \Magento\Framework\View\Design\Theme\Customization\Path::DIR_NAME . '/' . $this->_currentTheme->getId();
                 $asset = $this->_assetRepo->createArbitrary($identifier, $dirPath, \Magento\Framework\App\Filesystem::MEDIA_DIR, \Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
                 $this->_pageAssets->add($identifier, $asset);
             }
         } catch (\InvalidArgumentException $e) {
             $this->_logger->logException($e);
         }
     }
 }
コード例 #26
0
ファイル: Observer.php プロジェクト: zhangjiachao/magento2
 /**
  * Goes to reports.paypal.com and fetches Settlement reports.
  *
  * @return void
  */
 public function fetchReports()
 {
     try {
         /** @var \Magento\Paypal\Model\Report\Settlement $reports */
         $reports = $this->_settlementFactory->create();
         /* @var $reports \Magento\Paypal\Model\Report\Settlement */
         $credentials = $reports->getSftpCredentials(true);
         foreach ($credentials as $config) {
             try {
                 $reports->fetchAndSave(\Magento\Paypal\Model\Report\Settlement::createConnection($config));
             } catch (\Exception $e) {
                 $this->_logger->logException($e);
             }
         }
     } catch (\Exception $e) {
         $this->_logger->logException($e);
     }
 }
コード例 #27
0
 /**
  * Check if user who has role is allowed to access requested resources.
  *
  * @param string[] $resources
  * @param UserIdentifier $userIdentifier
  * @return bool
  */
 protected function _isUserWithRoleAllowed($resources, UserIdentifier $userIdentifier)
 {
     try {
         $role = $this->_getUserRole($userIdentifier);
         if (!$role) {
             throw NoSuchEntityException::doubleField('userId', $userIdentifier->getUserId(), 'userType', $userIdentifier->getUserType());
         }
         foreach ($resources as $resource) {
             if (!$this->_aclBuilder->getAcl()->isAllowed($role->getId(), $resource)) {
                 return false;
             }
         }
         return true;
     } catch (\Exception $e) {
         $this->_logger->logException($e);
         return false;
     }
 }
コード例 #28
0
ファイル: Combine.php プロジェクト: aiesh/magento2
 /**
  * @param array $arr
  * @param string $key
  * @return $this
  */
 public function loadArray($arr, $key = 'conditions')
 {
     $this->setAggregator(isset($arr['aggregator']) ? $arr['aggregator'] : (isset($arr['attribute']) ? $arr['attribute'] : null))->setValue(isset($arr['value']) ? $arr['value'] : (isset($arr['operator']) ? $arr['operator'] : null));
     if (!empty($arr[$key]) && is_array($arr[$key])) {
         foreach ($arr[$key] as $condArr) {
             try {
                 $cond = $this->_getNewConditionModelInstance($condArr['type']);
                 if ($cond) {
                     $this->addCondition($cond);
                     $cond->loadArray($condArr, $key);
                 }
             } catch (\Exception $e) {
                 $this->_logger->logException($e);
             }
         }
     }
     return $this;
 }
コード例 #29
0
 /**
  * Create preview image duplicate
  *
  * @param ThemeInterface $theme
  * @return bool
  */
 public function createPreviewImageCopy(ThemeInterface $theme)
 {
     $previewDir = $this->themeImagePath->getImagePreviewDirectory();
     $sourcePath = $theme->getThemeImage()->getPreviewImagePath();
     $sourceRelativePath = $this->rootDirectory->getRelativePath($sourcePath);
     if (!$theme->getPreviewImage() && !$this->mediaDirectory->isExist($sourceRelativePath)) {
         return false;
     }
     $isCopied = false;
     try {
         $destinationFileName = \Magento\Framework\File\Uploader::getNewFileName($sourcePath);
         $targetRelativePath = $this->mediaDirectory->getRelativePath($previewDir . '/' . $destinationFileName);
         $isCopied = $this->rootDirectory->copyFile($sourceRelativePath, $targetRelativePath, $this->mediaDirectory);
         $this->theme->setPreviewImage($destinationFileName);
     } catch (\Magento\Framework\Filesystem\FilesystemException $e) {
         $this->theme->setPreviewImage(null);
         $this->logger->logException($e);
     }
     return $isCopied;
 }
コード例 #30
0
ファイル: AclRetriever.php プロジェクト: aiesh/magento2
 /**
  * Get a list of available resources using user details
  *
  * @param string $userType
  * @param int $userId
  * @return string[]
  * @throws AuthorizationException
  * @throws LocalizedException
  */
 public function getAllowedResourcesByUser($userType, $userId)
 {
     if ($userType == UserContextInterface::USER_TYPE_GUEST) {
         return [self::PERMISSION_ANONYMOUS];
     } elseif ($userType == UserContextInterface::USER_TYPE_CUSTOMER) {
         return [self::PERMISSION_SELF];
     }
     try {
         $role = $this->_getUserRole($userType, $userId);
         if (!$role) {
             throw new AuthorizationException('The role associated with the specified user cannot be found.');
         }
         $allowedResources = $this->getAllowedResourcesByRole($role->getId());
     } catch (AuthorizationException $e) {
         throw $e;
     } catch (\Exception $e) {
         $this->logger->logException($e);
         throw new LocalizedException('Error happened while getting a list of allowed resources. Check exception log for details.');
     }
     return $allowedResources;
 }