/** * perform api call * * @param RemoteApp $oRemoteApp * * @return mixed */ private function _makeCall($oRemoteApp) { // get class $this->getContainer()->get('API'); // do call Api::$_container = $this->getContainer(); $aReturn = Api::call('getData', array(array('log' => $oRemoteApp->getIncludelog(), 'format' => 'json')), $oRemoteApp->getFullApiUrl(), $oRemoteApp->getPublicKey(), $oRemoteApp); // build json response $sStatuscode = $aReturn['statuscode']; $aReturn = json_decode($aReturn['result'], true); if (!isset($aReturn['status'])) { $aReturn['status'] = true; } $aReturn['statuscode'] = $sStatuscode; if ($sStatuscode != 200) { $this->getContainer()->get('logger')->error("ERROR in " . __FILE__ . " on line " . __LINE__ . " - " . json_encode($aReturn), array("Method" => __METHOD__, "RemoteApp" => $oRemoteApp->getName(), "RemoteURL" => $oRemoteApp->getFullApiUrl())); } return $aReturn; }
/** * initiate installation of complete monitoring module * * @param $id * * @return \Symfony\Component\HttpFoundation\Response * @throws \Exception */ public function initInstallCallAction($id) { $oRemoteApp = RemoteAppQuery::create()->findOneById($id); $sResult = array("success" => false, "message" => ""); try { $this->get("API"); Api::$_container = $this->container; $mResult = Api::call("doInstall", array(), $oRemoteApp->getUpdateUrl(), $oRemoteApp->getPublicKey(), $oRemoteApp); if (!empty($mResult)) { if (!isset($mResult['result']['result'])) { $this->get('logger')->error("[INIT ERROR] " . print_r($mResult, true)); throw new \Exception($this->get("translator")->trans("remote_app.api.init.error")); } if ($mResult['result']['result'] == true) { $sResult['success'] = true; $sResult['message'] = $this->get("translator")->trans("remote_app.api.update.successful"); $this->get('logger')->info("Api-Call successful", array("Method" => __METHOD__, "RemoteApp" => $oRemoteApp->getName())); $oRemoteApp->setWebsiteHash($mResult['result']['website_hash']); $oRemoteApp->save(); } else { $this->get('logger')->error("Unknown error in " . __FILE__ . " on line " . __LINE__ . " - Result: " . json_encode($mResult), array("Method" => __METHOD__, "RemoteApp" => $oRemoteApp->getName(), "RemoteURL" => $oRemoteApp->getFullApiUrl())); throw new \Exception("error in " . __FILE__ . " on line " . __LINE__); } } } catch (\Exception $e) { $this->get('logger')->error($e->getMessage(), array("Method" => __METHOD__, "RemoteApp" => $oRemoteApp->getName(), "RemoteURL" => $oRemoteApp->getFullApiUrl())); $sResult['success'] = false; $sResult['message'] = $e->getMessage(); } $response = new Response(json_encode($sResult)); $response->headers->set('Content-Type', 'application/json'); return $response; }