/** * Build the limits array * * @param \DreamFactory\Enterprise\Database\Models\Instance $instance * * @return array */ public static function buildLimitsMetadata(Instance $instance) { /** @type Limit[] $_limits */ $_limits = Limit::byClusterInstance($instance->cluster_id, $instance->id)->get(); $_api_array = []; // Added label_text so the instance can identify which limit was triggered in the 429 message foreach ($_limits as $_limit) { $_api_array[$_limit->limit_key_text] = ['limit' => $_limit->limit_nbr, 'period' => $_limit->period_nbr, 'name' => $_limit->label_text]; } // In the future, there could be additional keys, such as 'bandwidth' or 'storage' return ['api' => (array) $_api_array]; }
/** * @return array */ protected function gatherConsoleStatistics() { $_stats = ['uri' => config('app.url', \Request::getSchemeAndHttpHost()), 'user' => ServiceUser::count(), 'mount' => Mount::count(), 'server' => Server::count(), 'cluster' => Cluster::count(), 'limit' => Limit::count(), 'instance' => Instance::count()]; return $_stats; // The new way //return $this->telemetry->make('console')->getTelemetry(); }
/** * @param $ids * * @return array|bool|\stdClass */ public function destroy($ids) { try { $limit_names = []; if ($ids == 'multi') { $params = \Input::all(); $selected = $params['_selected']; $id_array = explode(',', $selected); } else { $id_array = explode(',', $ids); } foreach ($id_array as $id) { $limit = Limit::where('id', '=', $id); $limit_name = $limit->get(['label_text']); array_push($limit_names, '"' . $limit_name[0]->label_text . '"'); $limit->delete(); } if (count($id_array) > 1) { $limits = ''; foreach ($limit_names as $i => $name) { $limits .= $name; if (count($limit_names) > $i + 1) { $limits .= ', '; } } $result_text = 'The limits ' . $limits . ' were deleted successfully!'; } else { $result_text = 'The limit ' . $limit_names[0] . ' was deleted successfully!'; } Session::flash('flash_message', $result_text); Session::flash('flash_type', 'alert-success'); $_redirect = '/'; $_redirect .= $this->getUiPrefix(); $_redirect .= '/limits'; return \Redirect::to($_redirect); } catch (QueryException $e) { //$res_text = $e->getMessage(); Session::flash('flash_message', 'An error occurred! Please try again.'); Session::flash('flash_type', 'alert-danger'); logger('Error deleting limit: ' . $e->getMessage()); return redirect('/v1/limits')->withInput(); } }