/** * @param $statuscode * @param $remote_app_id * @param $last_response * * @throws \Exception * @throws \PropelException */ public static function create($statuscode, $remote_app_id, $last_response) { $aLogs = ApiLogQuery::create()->findByRemoteAppId($remote_app_id); foreach ($aLogs as $oLog) { $oLog->delete(); } $oApiLog = new ApiLog(); $oApiLog->setRemoteAppId($remote_app_id); $oApiLog->setStatuscode($statuscode); $oApiLog->setLastResponse($last_response); $dt = new \DateTime(); $oApiLog->setDtCall($dt); $oApiLog->save(); }
/** * Filter the query by a related ApiLog object * * @param ApiLog|PropelObjectCollection $apiLog the related object to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return RemoteAppQuery The current query, for fluid interface * @throws PropelException - if the provided filter is invalid. */ public function filterByApiLog($apiLog, $comparison = null) { if ($apiLog instanceof ApiLog) { return $this->addUsingAlias(RemoteAppPeer::ID, $apiLog->getRemoteAppId(), $comparison); } elseif ($apiLog instanceof PropelObjectCollection) { return $this->useApiLogQuery()->filterByPrimaryKeys($apiLog->getPrimaryKeys())->endUse(); } else { throw new PropelException('filterByApiLog() only accepts arguments of type ApiLog or PropelCollection'); } }
/** * Exclude object from result * * @param ApiLog $apiLog Object to remove from the list of results * * @return ApiLogQuery The current query, for fluid interface */ public function prune($apiLog = null) { if ($apiLog) { $this->addUsingAlias(ApiLogPeer::ID, $apiLog->getId(), Criteria::NOT_EQUAL); } return $this; }
/** * @param $method * @param $params * @param $url * @param $publickey * @param null $oRemoteApp * * @return array|mixed * @throws \Exception */ public static function call($method, $params, $url, $publickey, $oRemoteApp = null) { try { $sOldErrorhandler = set_error_handler('Slashworks\\AppBundle\\Services\\Api::errorHandler'); if (!is_scalar($method)) { throw new \Exception('Method name has no scalar value'); } // check if (is_array($params)) { // no keys $params = array_values($params); } else { throw new \Exception('Params must be given as array'); } // prepares the request $request = array('method' => $method, 'params' => $params, 'id' => rand(1, 999)); $request = json_encode($request); $rsa = new \Crypt_RSA(); $rsa->loadKey($publickey); $conairKey = file_get_contents(__DIR__ . "/../Resources/private/api/keys/server/public.key"); $aRequest = array('pkey' => $conairKey, 'data' => base64_encode($rsa->encrypt($request))); $sRequest = json_encode($aRequest); $headers = array('Content-Type: application/json'); if ($oRemoteApp->getApiAuthType() == "http-basic") { $sUsername = $oRemoteApp->getApiAuthHttpUser(); $sPassword = $oRemoteApp->getApiAuthHttpPassword(); if (!empty($sUsername) && !empty($sPassword)) { $headers[] = "Authorization: Basic " . base64_encode($oRemoteApp->getApiAuthHttpUser() . ":" . $oRemoteApp->getApiAuthHttpPassword()); } } $oRequest = curl_init($url); curl_setopt($oRequest, CURLOPT_HTTPHEADER, $headers); curl_setopt($oRequest, CURLOPT_TIMEOUT, 3); curl_setopt($oRequest, CURLOPT_POST, 1); curl_setopt($oRequest, CURLOPT_POSTFIELDS, $sRequest); curl_setopt($oRequest, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($oRequest); $iHttpStatus = curl_getinfo($oRequest, CURLINFO_HTTP_CODE); curl_close($oRequest); if ($response == "") { throw new \Exception("No content received"); } if ($iHttpStatus === 200) { $response = json_decode($response, true); if (!isset($response['data'])) { throw new \Exception("Invalid response format"); } $privateKey = file_get_contents(__DIR__ . "/../Resources/private/api/keys/server/private.key"); $rsa->loadKey($privateKey); $data = base64_decode($response['data']); $decoded = $rsa->decrypt($data); $response['data'] = json_decode($decoded, true); if (!is_array($response['data'])) { throw new \Exception("Invalid response format"); } $response['data']['statuscode'] = $iHttpStatus; ApiLog::create($iHttpStatus, $oRemoteApp->getId(), $decoded); restore_error_handler(); return $response['data']; } else { ApiLog::create($iHttpStatus, $oRemoteApp->getId(), $response); restore_error_handler(); return array("statuscode" => $iHttpStatus, "result" => json_encode(array("status" => false, "statuscode" => $iHttpStatus, "message" => $response))); } } catch (ContextErrorException $e) { restore_error_handler(); ApiLog::create(-1, $oRemoteApp->getId(), $e->getMessage()); return array("statuscode" => $iHttpStatus, "result" => json_encode(array("status" => false, "statuscode" => -1, "message" => $e->getMessage()))); } catch (\Exception $e) { restore_error_handler(); ApiLog::create(-1, $oRemoteApp->getId(), $e->getMessage()); return array("statuscode" => 500, "result" => json_encode(array("status" => false, "statuscode" => -1, "message" => $e->getMessage()))); } }
/** * @param ApiLog $apiLog The apiLog object to add. */ protected function doAddApiLog($apiLog) { $this->collApiLogs[] = $apiLog; $apiLog->setRemoteApp($this); }
/** * Adds an object to the instance pool. * * Propel keeps cached copies of objects in an instance pool when they are retrieved * from the database. In some cases -- especially when you override doSelect*() * methods in your stub classes -- you may need to explicitly add objects * to the cache in order to ensure that the same objects are always returned by doSelect*() * and retrieveByPK*() calls. * * @param ApiLog $obj A ApiLog object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool($obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getId(); } // if key === null ApiLogPeer::$instances[$key] = $obj; } }