public function processApplyAction() { $updateFileId = (int) $this->_getParam('updateFileId'); $updateFile = new UpdateFile(); $updateFile->updateFileId = $updateFileId; $updateFile->populate(); $ok = true; $ret = __('Failed to apply.'); $notes = unserialize($updateFile->notes); if (isset($notes['validateApi'])) { try { $validateApi = new SimpleXMLElement($notes['validateApi']); if ($validateApi->object) { $className = (string) $validateApi->object; $methodName = (string) $validateApi->method; $params = array($updateFileId); foreach ($validateApi->argument as $argument) { $params[] = (string) $argument; } if (!class_exists($className) || !method_exists($className, $methodName)) { throw new Exception('Your install may be out of date or is out of date for this update.' . $className . ' ' . $methodName); } if (strtolower(substr($className, -10)) == 'controller' && strtolower(substr($methodName, -6)) == 'action') { $controller = substr(strtolower(preg_replace('/([A-Z]{1})/', '-\\1', substr($className, 0, strlen($className) - 10))), 1); $action = strtolower(preg_replace('/([A-Z]{1})/', '-\\1', substr($methodName, 0, strlen($methodName) - 6))); $ctr = count($params); $arg = array('updateFileId' => $updateFileId); for ($i = 1, $ctr = count($params); $i < $ctr; $i++) { $arg[$i] = $params[$i]; } $ret = array('url' => Zend_Registry::get('baseUrl') . $controller . '.raw/' . $action . '?' . http_build_query($arg)); } else { $ret = array('data' => call_user_func_array(array($className, $methodName), $params)); } $ok = false; } else { if ($validateApi->function) { $functionName = (string) $validateApi->function; $params = array($updateFileId); foreach ($validateApi->argument as $argument) { $params[] = (string) $argument; } if (!function_exists($functionName)) { throw new Exception('Your install may be out of date or is out of date for this update.'); } $ret = array('data' => call_user_func_array($functionName, $params)); $ok = false; } } } catch (Exception $e) { $ret = array('error' => $e->getMessage()); $ok = false; } } if ($ok) { $updateFile->install(); $ret = true; } $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json'); $json->suppressExit = true; $json->direct($ret); }
public function processRegistrationAction() { $updateFileId = (int) $this->_getParam('updateFileId'); $data = array(); $users = array(); $xml = new SimpleXMLElement('<clearhealth/>'); $xml->addChild('apiKey', Zend_Registry::get('config')->healthcloud->apiKey); $xml->addChild('authorizingUserId', (int) Zend_Auth::getInstance()->getIdentity()->personId); $xml->addChild('authorizingUser', Zend_Auth::getInstance()->getIdentity()->username); foreach (User::listActiveUsers() as $user) { $xmlUser = $xml->addChild('user'); $xmlUser->addChild('userId', (int) $user->personId); $xmlUser->addChild('username', (string) $user->username); } $ch = curl_init(); $url = Zend_Registry::get('config')->healthcloud->updateServerUrl . '/activate-users'; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $xml->asXML()); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); try { $response = curl_exec($ch); if (curl_errno($ch)) { throw new Exception(curl_error($ch)); } curl_close($ch); trigger_error($response); $responseXml = new SimpleXMLElement($response); if ($responseXml->error) { throw new Exception((string) $responseXml->error->errorMsg, (string) $responseXml->error->errorCode); } $data['data'] = (string) $responseXml->response; $updateFile = new UpdateFile(); $updateFile->updateFileId = $updateFileId; $updateFile->populate(); $updateFile->install(); } catch (Exception $e) { $error = $e->getMessage(); trigger_error($error); $data['error'] = $error; } $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json'); $json->suppressExit = true; $json->direct($data); }