/** * Perform pre-flight checks to ensure that batch is ready for deploy. * * Runs on production when a pre-flight request has been received. * * @param array $args * * @return string */ public function verify(array $args) { if ($messages = $this->xmlrpc_client->handle_request($args)) { return $messages; } $result = $this->xmlrpc_client->get_request_data(); // Check if a batch has been provided. if (!isset($result['batch']) || !$result['batch'] instanceof Batch) { $message = new Message(); $message->set_level('error'); $message->set_message('Invalid batch.'); return $this->xmlrpc_client->prepare_response(array('status' => 2, 'messages' => array($message))); } // Get batch. $batch = $result['batch']; // Check if a production version of this batch exists. $batch_id = $this->batch_dao->get_id_by_guid($batch->get_guid()); // Replace batch content stage ID with production ID. $batch->set_id($batch_id); // Hook in before batch is stored. do_action('sme_store', $batch); // Create new batch or update existing one. if (!$batch_id) { $this->batch_dao->insert($batch); } else { $this->batch_dao->update_batch($batch); } // Hook in when batch is ready to be verified. do_action('sme_verify', $batch); // What different type of data needs verification? $types = array('attachments', 'users', 'posts'); // Go through each data type. foreach ($types as $type) { $this->verify_by_type($batch, $type); } // Verify custom data. foreach ($batch->get_custom_data() as $addon => $data) { do_action('sme_verify_' . $addon, $data, $batch); } // Get pre-flight status. $status = $this->api->get_preflight_status($batch->get_id()); // Get all messages set during verification of this batch. $messages = $this->api->get_preflight_messages($batch->get_id()); // Prepare response. $response = array('status' => $status ? $status : 3, 'messages' => $messages); // Hook in when batch is ready for pre-flight. $response = apply_filters('sme_verified', $response, $batch); // Get status received from production. $status = isset($response['status']) ? $response['status'] : 2; // Get messages received from production. $messages = isset($response['messages']) ? $response['messages'] : array(); // Prepare response. $response = array('status' => $status, 'messages' => $messages); // Prepare and return the XML-RPC response data. return $this->xmlrpc_client->prepare_response($response); }