/** * Run a merge using the AIR2Merge library. * * @param array $response_data */ protected function run($response_data = array()) { // turn off logging during the merge $was_logging_enabled = AIR2Logger::$ENABLE_LOGGING; AIR2Logger::$ENABLE_LOGGING = false; // run the merge and reset logging $type = $this->my_type; $errs = AIR2Merge::merge($this->prime, $this->merge, $this->ops, $this->commit_on_success); $result = AIR2Merge::get_result(); AIR2Logger::$ENABLE_LOGGING = $was_logging_enabled; // what happened? $status = 200; if ($errs === true) { $response_data['success'] = true; $response_data['message'] = "Successfully merged {$type}s"; // attach the "merged" object to data $response_data['ResultSource'] = $result['result']; air2_clean_radix($response_data['ResultSource'], $this->radix_whitelist); // attach ops used $response_data['op_prime'] = $result['prime']; $response_data['op_merge'] = $result['merge']; // log the merge if ($this->commit_on_success) { $this->log_activity($result, $response_data); } } elseif (is_string($errs)) { $response_data['success'] = false; $response_data['message'] = $errs; $status = 500; } else { $response_data['success'] = false; $response_data['message'] = "Unable to merge {$type}s"; $response_data['errors'] = $errs; $status = 400; // attach ops used $response_data['op_prime'] = $result['prime']; $response_data['op_merge'] = $result['merge']; } // attach fact data $rs = AIR2_DBManager::get_connection()->fetchAll('select * from fact'); $response_data['facts'] = array(); foreach ($rs as $row) { $response_data['facts'][$row['fact_id']] = $row; } // respond with data $this->response($response_data, $status); }