コード例 #1
0
ファイル: TestersApi.php プロジェクト: ryankim07/testplanner
 /**
  * Update tester from built plan
  *
  * @param $planId
  * @param $testersData
  * @return array|bool
  */
 public function updateBuiltTesters($planId, $testersData, $origData)
 {
     $redirect = false;
     $errorMsg = '';
     // Start transaction
     DB::beginTransaction();
     // Start testers update
     try {
         $query = $this->model->where('plan_id', '=', $planId)->delete();
         foreach ($testersData as $tester) {
             $testerId = $tester['id'];
             $browsers = $tester['browsers'];
             $newCount = isset($browsers) ? count(explode(',', $browsers)) : 0;
             // Formerly selected browsers
             $oldCount = isset($origData[$testerId]) ? count(explode(',', $origData[$testerId])) : 0;
             if ($oldCount == $newCount) {
                 $updateStatus = 0;
             } elseif ($newCount > $oldCount) {
                 $updateStatus = 1;
             } elseif ($oldCount < $newCount || $oldCount > $newCount) {
                 $updateStatus = -1;
             }
             $tester += ['update_status' => $updateStatus, 'update_status_text' => Tools::planTesterChanges($updateStatus)];
             $results[] = $tester;
             // Create new or update
             if (count($tester['input-ids']) > 0 && !empty($browsers)) {
                 $this->model->create(['plan_id' => $planId, 'user_id' => $testerId, 'browsers' => $browsers]);
             }
         }
     } catch (\Exception $e) {
         $errorMsg = $e->getMessage();
         $redirect = true;
     } catch (QueryException $e) {
         $errorMsg = $e->getErrors();
         $redirect = true;
     } catch (ModelNotFoundException $e) {
         $errorMsg = $e->getErrors();
         $redirect = true;
     }
     // Redirect if errors
     if ($redirect) {
         // Rollback
         DB::rollback();
         // Log to system
         Tools::log($errorMsg, $testersData);
         return false;
     }
     // Commit all changes
     DB::commit();
     return $results;
 }
コード例 #2
0
ファイル: PlansApi.php プロジェクト: ryankim07/testplanner
 /**
  * Save new created plan
  *
  * @param $planData
  * @param $ticketsData
  * @param $testerData
  * @return $this|array
  */
 public function savePlan($planData, $ticketsData, $testerData)
 {
     $redirect = false;
     $errorMsg = '';
     // Start transaction
     DB::beginTransaction();
     // Start plan creation
     try {
         // Save new plan build
         $plan = $this->model->create($planData);
         $planId = $plan->id;
         if (isset($plan->id)) {
             // Save new tickets
             $this->ticketsModel->create(['plan_id' => $planId, 'tickets' => serialize($ticketsData)]);
             // Save new testers
             $assignedTesters = [];
             foreach ($testerData as $tester) {
                 if (count($tester['input-ids']) > 0 && !empty($tester['browsers'])) {
                     $this->testersModel->create(['plan_id' => $planId, 'user_id' => $tester['id'], 'browsers' => $tester['browsers']]);
                     $assignedTesters[] = $tester;
                 }
             }
         }
     } catch (\Exception $e) {
         $errorMsg = $e->getMessage();
         $redirect = true;
     } catch (QueryException $e) {
         $errorMsg = $e->getErrors();
         $redirect = true;
     } catch (ModelNotFoundException $e) {
         $errorMsg = $e->getErrors();
         $redirect = true;
     }
     // Redirect if errors
     if ($redirect) {
         // Rollback
         DB::rollback();
         // Log to system
         Tools::log($errorMsg, array_merge($planData, $ticketsData, $assignedTesters));
         return false;
     }
     // Commit all changes
     DB::commit();
     if (!$planId) {
         return false;
     }
     $planData += ['type' => 'plan', 'status' => 'new', 'plan_id' => $planId, 'testers' => $assignedTesters];
     return $planData;
 }