/**
  * Pre-flight batch.
  *
  * Production will evaluate the batch and look for any issues that might
  * cause trouble when user later on deploys the batch.
  *
  * Display any pre-flight messages that is returned by production.
  *
  * Runs on content stage.
  */
 public function prepare()
 {
     // Make sure a query param ID exists in current URL.
     if (!isset($_GET['id'])) {
         wp_die(__('No batch ID has been provided.', 'sme-content-staging'));
     }
     // Get batch ID.
     $batch_id = $_GET['id'];
     // Get batch from database.
     $batch = $this->batch_dao->find($batch_id);
     // Populate batch with actual data.
     $this->api->prepare($batch);
     // Pre-flight batch.
     $result = $this->api->preflight($batch);
     // Get status from production.
     $prod_status = isset($result['status']) ? $result['status'] : 2;
     // Get production messages.
     $prod_messages = isset($result['messages']) ? $result['messages'] : array();
     // Get status from content stage.
     $stage_status = $this->api->get_preflight_status($batch->get_id());
     // Ensure no pre-flight status is not set to failed.
     $status = $prod_status != 2 && $stage_status != 2 ? $prod_status : 2;
     // Get content stage messages.
     $stage_messages = $this->api->get_preflight_messages($batch->get_id());
     // All pre-flight messages.
     $messages = array_merge($prod_messages, $stage_messages);
     // Set success message.
     if ($status == 3) {
         $message = new Message();
         $message->set_level('success');
         $message->set_message('Pre-flight successful!');
         $message->set_code(201);
         array_push($messages, $message);
     }
     // Deploy button.
     $deploy_btn = array('disabled' => 'disabled');
     // Enable deploy button.
     if ($status == 3) {
         unset($deploy_btn['disabled']);
     }
     // Render page.
     $this->template->render('preflight-batch', array('batch' => $batch, 'status' => $status, 'messages' => $messages, 'deploy_btn' => $deploy_btn));
 }