/**
  * Initializes the delivery session
  */
 public function init()
 {
     $code = 200;
     try {
         $this->getCsrf()->revokeCsrfToken();
         $serviceContext = $this->getServiceContext();
         if ($this->hasRequestParameter('clientState')) {
             $clientState = $this->getRequestParameter('clientState');
             if ('paused' == $clientState) {
                 $this->runnerService->pause($serviceContext);
                 $this->runnerService->check($serviceContext);
             }
         }
         $lastStoreId = false;
         if ($this->hasRequestParameter('storeId')) {
             $receivedStoreId = $this->getRequestParameter('storeId');
             if (preg_match('/^[a-z0-9\\-]+$/i', $receivedStoreId)) {
                 $lastStoreId = $this->runnerService->switchClientStoreId($serviceContext, $receivedStoreId);
             }
         }
         $result = $this->runnerService->init($serviceContext);
         $response = ['success' => $result];
         if ($result) {
             $response['testData'] = $this->runnerService->getTestData($serviceContext);
             $response['testContext'] = $this->runnerService->getTestContext($serviceContext);
             $response['testMap'] = $this->runnerService->getTestMap($serviceContext);
             $response['lastStoreId'] = $lastStoreId;
         }
         $this->runnerService->persist($serviceContext);
     } catch (common_Exception $e) {
         $response = $this->getErrorResponse($e);
         $code = $this->getErrorCode($e);
     }
     $this->returnJson($response, $code);
 }