return $success; } private function getCounterForPeriod($quotaName) { /** * @var Counter $counter */ $counter = new Counter(); // Validation based on (Drupal-based UI) code from e3_ui_policy_add_context_submit_validate if (!empty($_POST[$quotaName]['warning']) || !empty($_POST[$quotaName]['threshold'])) { $counter->setAction($_POST[$quotaName]['action']); // $counter->setStatus($_POST[$quotaName]['status']); $threshold = !empty($_POST[$quotaName]['threshold']) ? trim($_POST[$quotaName]['threshold']) : "0"; $warning = !empty($_POST[$quotaName]['warning']) ? trim($_POST[$quotaName]['warning']) : "0"; $counter->setThreshold($threshold); $counter->setWarning($warning); if (strlen($threshold) > 0 && strlen($warning) == 0) { $counter->setWarning(0.0); } } return $counter; } private static function validateCounterForPeriod($counter, $quotaName, &$validationErrors) { /** * @var Counter $counter */
/** * * Insert/Update an Policy on the database * @param Policy $policy * @throws Exception */ private function _setPolicy(Policy &$policy, $insertMode = FALSE) { $method = "PUT"; $url = E3_PROV_URL_POLICY . "/" . rawurlencode($policy->getId()); if ($insertMode) { $method = "POST"; $url = E3_PROV_URL_POLICY; } /** * Send the XML payload the the Provisioning Backend */ LoggerInterface::log(($insertMode ? "Creating" : "Updating") . " Policy: {$policy->toXML()}\nEndpoint: ({$method}) {$url}", LoggerInterface::INFO); $reply = $this->restClient->makeCall($url, $method, $policy->toXML()); $xml = simplexml_load_string($reply->getPayload()); if ($reply->getHTTPCode() === "200") { if ($insertMode) { if ($policy->getId() == NULL) { $policy->setId((string) $xml->id); } } return true; } else { $error = $insertMode ? "Unable to create policy" : "Unable to update policy with id: " . $policy->getId(); // default error msg if ($xml != null) { $errorText = $xml->xpath('/response/error/errorText'); // error msg from response if (count($errorText) > 0) { $error = (string) $errorText[0]; } } PolicyManager::error($error); return false; } }