Пример #1
0
 /**
  * @dataProvider gridProvider
  *
  * @param array $requestData
  */
 public function testGrid($requestData)
 {
     $gridName = $requestData['gridParameters']['gridName'];
     $expectedResultCount = (int) $requestData['expectedResultCount'];
     $shouldPassIdentifier = array_key_exists('id', $requestData['gridParameters']);
     $shouldPassIntegration = array_key_exists('channel', $requestData['gridParameters']);
     $shouldPassRemoved = array_key_exists('is_removed', $requestData['gridParameters']);
     $shouldAssertData = $expectedResultCount === 1;
     if ($shouldPassIdentifier) {
         $paramName = $gridName . '[' . $requestData['gridParameters']['id'] . ']';
         $requestData['gridParameters'][$paramName] = $this->getMainEntityId();
     }
     if ($shouldPassIntegration) {
         $paramName = $gridName . '[' . $requestData['gridParameters']['channel'] . ']';
         $requestData['gridParameters'][$paramName] = self::$integration->getId();
     }
     if ($shouldPassRemoved) {
         $paramName = $gridName . '[' . $requestData['gridParameters']['is_removed'] . ']';
         $requestData['gridParameters'][$paramName] = $requestData['gridFilters']['magento-cart-grid[_filter][is_removed][value]'];
     }
     $this->client->requestGrid($requestData['gridParameters'], $requestData['gridFilters']);
     $response = $this->client->getResponse();
     $result = $this->getJsonResponseContent($response, 200);
     foreach ($result['data'] as $row) {
         if ($shouldAssertData) {
             foreach ($requestData['assert'] as $fieldName => $value) {
                 $this->assertEquals($value, $row[$fieldName], sprintf('Incorrect value for %s', $fieldName));
             }
             break;
         }
     }
     $this->assertCount($expectedResultCount, $result['data']);
 }
Пример #2
0
 /**
  * Remove workflow records
  *
  * @param string $entityClassName
  *
  * @return $this
  */
 protected function removeWorkflowDefinitions($entityClassName)
 {
     $workflowMetadata = $this->em->getClassMetadata('OroWorkflowBundle:WorkflowItem');
     $entityMetadata = $this->em->getClassMetadata($entityClassName);
     $this->em->getConnection()->executeQuery(sprintf('Delete FROM %s WHERE id IN (SELECT o.workflow_item_id FROM %s o WHERE o.channel_id=%s)', $workflowMetadata->getTableName(), $entityMetadata->getTableName(), $this->channel->getId()));
     return $this;
 }
Пример #3
0
 /**
  * @dataProvider gridProvider
  *
  * @param array $requestData
  */
 public function testGrid($requestData)
 {
     $gridName = $requestData['gridParameters']['gridName'];
     $expectedResultCount = (int) $requestData['expectedResultCount'];
     $shouldPassIdentifier = isset($requestData['gridParameters']['id']);
     $shouldPassIntegration = isset($requestData['gridParameters']['channel']);
     $shouldAssertData = $expectedResultCount === 1;
     if ($shouldPassIdentifier) {
         $paramName = $gridName . '[' . $requestData['gridParameters']['id'] . ']';
         $requestData['gridParameters'][$paramName] = $this->getMainEntityId();
     }
     if ($shouldPassIntegration) {
         $paramName = $gridName . '[' . $requestData['gridParameters']['channel'] . ']';
         $requestData['gridParameters'][$paramName] = self::$integration->getId();
     }
     $this->client->requestGrid($requestData['gridParameters'], $requestData['gridFilters']);
     $response = $this->client->getResponse();
     $result = $this->getJsonResponseContent($response, 200);
     foreach ($result['data'] as $row) {
         if ($shouldAssertData) {
             foreach ($requestData['assert'] as $fieldName => $value) {
                 $this->assertEquals($value, $row[$fieldName]);
             }
             break;
         }
     }
     $this->assertCount($expectedResultCount, $result['data']);
 }
 /**
  * @return Channel
  */
 protected function getChannel()
 {
     if ($this->channel === null || $this->context->getOption('channel') !== $this->channel->getId()) {
         $this->channel = $this->connectorContextMediator->getChannel($this->context);
     }
     return $this->channel;
 }
Пример #5
0
 /**
  * @param Integration $integration
  * @return Integration|null
  */
 protected function getIntegration(Integration $integration)
 {
     if (!$integration->getId()) {
         return null;
     }
     $oldIntegration = $this->em->find('OroIntegrationBundle:Channel', $integration->getId());
     return $oldIntegration ? clone $oldIntegration : null;
 }
Пример #6
0
 /**
  * @param Integration $integration
  * @param bool $markReadOnly
  *
  * @return TransportInterface
  */
 public function getInitializedTransport(Integration $integration, $markReadOnly = false)
 {
     if (!empty($this->transportByIntegration[$integration->getId()])) {
         return $this->transportByIntegration[$integration->getId()];
     }
     $transport = $this->getTransport($integration, $markReadOnly);
     $transport->init($integration->getTransport());
     $this->transportByIntegration[$integration->getId()] = $transport;
     return $transport;
 }
Пример #7
0
 public function testDeleteChannel()
 {
     $oldChannel = clone $this->channel;
     $this->client->request('DELETE', $this->getUrl('oro_api_delete_integration', ['id' => $this->channel->getId()]));
     $result = $this->client->getResponse();
     $this->assertEmptyResponseStatusCodeEquals($result, 204);
     $this->assertNull($this->getChannel());
     $this->assertNull($this->getCartByChannel($oldChannel));
     $this->assertNull($this->getOrderByChannel($oldChannel));
     $this->assertNull($this->getCustomerByChannel($oldChannel));
 }
Пример #8
0
 /**
  * @param Integration $integration
  *
  * @param bool        $optional
  *
  * @throws \LogicException
  * @return null|Channel
  */
 public function getChannel(Integration $integration, $optional = false)
 {
     $this->ensureInitialized();
     if (isset($this->integrationToChannelMap[$integration->getId()])) {
         /** @var EntityManager $em */
         $em = $this->registry->getManager();
         $id = $this->integrationToChannelMap[$integration->getId()];
         $channel = $em->getPartialReference('OroCRMChannelBundle:Channel', $id);
         return $channel;
     } elseif (!$optional) {
         throw new \LogicException('Unable to find channel for given integration');
     }
     return null;
 }
 /**
  * @param Channel $channel
  * @param mixed $entity
  */
 public function refreshChannel(ZohoEntityType $entity, Channel $channel)
 {
     if ($channel->getId()) {
         $channel = $this->oroProvider->getChannelById($channel->getId());
         $entity->setChannel($channel);
     }
 }
Пример #10
0
 /**
  * @Route("/schedule/{id}", requirements={"id"="\d+"}, name="oro_integration_schedule")
  * @AclAncestor("oro_integration_update")
  */
 public function scheduleAction(Integration $integration)
 {
     $job = new Job(SyncCommand::COMMAND_NAME, ['--integration-id=' . $integration->getId(), '-v']);
     $status = Codes::HTTP_OK;
     $response = ['successful' => true, 'message' => ''];
     try {
         $em = $this->get('doctrine.orm.entity_manager');
         $em->persist($job);
         $em->flush($job);
         $jobViewLink = sprintf('<a href="%s" class="job-view-link">%s</a>', $this->get('router')->generate('oro_cron_job_view', ['id' => $job->getId()]), $this->get('translator')->trans('oro.integration.progress'));
         $response['message'] = str_replace('{{ job_view_link }}', $jobViewLink, $this->get('translator')->trans('oro.integration.sync'));
         $response['job_id'] = $job->getId();
     } catch (\Exception $e) {
         $status = Codes::HTTP_BAD_REQUEST;
         $response['successful'] = false;
         $response['message'] = sprintf($this->get('translator')->trans('oro.integration.sync_error'), $e->getMessage());
     }
     return new JsonResponse($response, $status);
 }
Пример #11
0
 /**
  * Schedules backward sync job
  *
  * @param Integration $integration
  * @param string      $connectorType
  * @param array       $params
  * @param bool        $useFlush
  *
  * @throws LogicException
  */
 public function schedule(Integration $integration, $connectorType, $params = [], $useFlush = true)
 {
     if (!$integration->getEnabled()) {
         return;
     }
     $connector = $this->typesRegistry->getConnectorType($integration->getType(), $connectorType);
     if (!$connector instanceof TwoWaySyncConnectorInterface) {
         throw new LogicException(sprintf('Unable to schedule job for "%s" connector type', $connectorType));
     }
     $args = ['--integration=' . $integration->getId(), '--connector=' . $connectorType, '--params=' . serialize($params)];
     $job = new Job(self::JOB_NAME, $args);
     if ($useFlush) {
         $this->em->persist($job);
         $this->em->flush();
     } else {
         $uow = $this->em->getUnitOfWork();
         $uow->persist($job);
         $jobMeta = $this->em->getMetadataFactory()->getMetadataFor('JMS\\JobQueueBundle\\Entity\\Job');
         $uow->computeChangeSet($jobMeta, $job);
     }
 }
Пример #12
0
 /**
  * Schedules backward sync job
  *
  * @param Integration $integration
  * @param string      $connectorType
  * @param array       $params
  * @param bool        $useFlush
  *
  * @throws LogicException
  */
 public function schedule(Integration $integration, $connectorType, $params = [], $useFlush = true)
 {
     if (!$integration->isEnabled()) {
         return;
     }
     $connector = $this->typesRegistry->getConnectorType($integration->getType(), $connectorType);
     if (!$connector instanceof TwoWaySyncConnectorInterface) {
         throw new LogicException(sprintf('Unable to schedule job for "%s" connector type', $connectorType));
     }
     $args = ['--integration=' . $integration->getId(), '--connector=' . $connectorType, '--params=' . serialize($params)];
     if (!$this->isScheduled($args)) {
         $job = new Job(self::JOB_NAME, $args);
         /** @var EntityManager $em */
         $em = $this->registry->getManagerForClass('JMSJobQueueBundle:Job');
         $em->persist($job);
         if (true === $useFlush) {
             $em->flush();
         } else {
             $jobMeta = $em->getClassMetadata('JMSJobQueueBundle:Job');
             $em->getUnitOfWork()->computeChangeSet($jobMeta, $job);
         }
     }
 }
Пример #13
0
 /**
  * @param Integration $integration
  * @return bool
  */
 protected function isInitialJobRunning(Integration $integration)
 {
     $initialJobsRunning = $this->getChannelRepository()->getRunningSyncJobsCount(InitialSyncCommand::COMMAND_NAME, $integration->getId());
     return $initialJobsRunning > 0;
 }
Пример #14
0
 /**
  * Disable fields that are not allowed to be modified since integration has at least one sync completed
  *
  * @param FormInterface $form
  * @param Integration       $integration
  */
 protected function muteFields(FormInterface $form, Integration $integration = null)
 {
     if (!($integration && $integration->getId())) {
         // do nothing if integration is new
         return;
     }
     if ($integration->getEditMode() !== Integration::EDIT_MODE_ALLOW) {
         // disable type field
         FormUtils::replaceField($form, 'type', ['disabled' => true]);
     }
     if (Integration::EDIT_MODE_DISALLOW === $integration->getEditMode()) {
         FormUtils::replaceField($form, 'connectors', ['disabled' => true, 'attr' => ['class' => 'hide']]);
     }
 }
 /**
  * @param Channel $channel
  *
  * @return bool
  */
 protected function isBlockingJobRunning(Channel $channel)
 {
     $managerRegistry = $this->getService('doctrine');
     /** @var ManagerRegistry $managerRegistry */
     $running = $managerRegistry->getRepository('OroIntegrationBundle:Channel')->getRunningSyncJobsCount(SyncCommand::COMMAND_NAME, $channel->getId());
     return $running > 0;
 }