public function save() { if ($this->validate()) { $changes = []; $conn = Connection::findOne($this->id); if ($this->acceptRelease) { if ($conn->getStartDateTime() != DateUtils::fromLocal($this->start)) { $changes['needRelease'] = true; $changes['start'] = DateUtils::localToUTC($this->start); } if ($conn->bandwidth != $this->bandwidth) { $changes['needRelease'] = true; $changes['bandwidth'] = $this->bandwidth; } } if ($conn->getEndDateTime() != DateUtils::fromLocal($this->end)) { $changes['end'] = DateUtils::localToUTC($this->end); } if (count($changes) > 0) { return $conn->buildEvent(ConnectionEvent::TYPE_USER_UPDATE)->setData(json_encode($changes))->setAuthor(Yii::$app->user->getId())->save(); } return false; } return false; }
static function create($connection_id) { $connection = Connection::findOne($connection_id); if (!$connection) { return; } $reservation = Reservation::findOne($connection->reservation_id); if (!$reservation) { return; } if ($reservation->type == Reservation::TYPE_TEST) { return; } $user_id = $reservation->request_user_id; //Confere se já foi feita uma notificação de algum circuito desta reserva, se sim, reutiliza a mesma notificação $not = null; $notifications = Notification::find()->where(['user_id' => $reservation->request_user_id, 'type' => Notification::TYPE_RESERVATION])->all(); foreach ($notifications as $notification) { if ($notification->info == $reservation->id) { $not = $notification; break; } } if ($not) { //Se já existe, atualiza e coloca nova data //Pequena maquipulação do horário para que nunca existam duas notificações com o mesmo horário $date = new \DateTime('now', new \DateTimeZone("UTC")); $dateAux = $date->format("Y-m-d H:i:s"); while (Notification::find()->where(['user_id' => $user_id, 'date' => $dateAux])->one()) { $date->modify('-1 second'); $dateAux = $date->format("Y-m-d H:i:s"); } $not->date = $dateAux; $not->viewed = 0; $not->save(); } else { //Se for nova, cria notificação $not = new Notification(); $not->user_id = $reservation->request_user_id; //Pequena maquipulação do horário para que nunca existam duas notificações com o mesmo horário $date = new \DateTime('now', new \DateTimeZone("UTC")); $dateAux = $date->format("Y-m-d H:i:s"); while (Notification::find()->where(['user_id' => $user_id, 'date' => $dateAux])->one()) { $date->modify('-1 second'); $dateAux = $date->format("Y-m-d H:i:s"); } $not->date = $dateAux; $not->type = Notification::TYPE_RESERVATION; $not->viewed = 0; $not->info = (string) $reservation->id; $not->save(); } }
function getConnectionStatus() { $conn = Connection::find()->where(['id' => Connection::find()->where(['reservation_id' => $this->id])->max("id")])->select(['status'])->one(); if ($conn) { switch ($conn->status) { case Connection::STATUS_PENDING: case Connection::STATUS_CREATED: case Connection::STATUS_CONFIRMED: return Yii::t("circuits", "Testing"); case Connection::STATUS_SUBMITTED: return Yii::t("circuits", "Passed"); case Connection::STATUS_FAILED_CREATE: case Connection::STATUS_FAILED_CONFIRM: case Connection::STATUS_FAILED_SUBMIT: return Yii::t("circuits", "Failed"); } } else { return "Never tested"; } }
/** * * @param int $id * @return boolean */ public static function disable($id) { $workflow = BpmWorkflow::findOne(['id' => $id]); $workflow->active = 0; $domain = Domain::findOne(['name' => $workflow->domain]); if (!$domain) { return false; } if (!$workflow->save()) { return false; } // Procura por execuções em aberto envolvendo o workflow. $flows = BpmFlow::find()->where(['workflow_id' => $id])->all(); foreach ($flows as $flow) { $conId = $flow->connection_id; //Deleta o fluxo $flow->delete(); //Deleta autorizações ConnectionAuth::deleteAll(['connection_id' => $conId, 'domain' => $domain->name]); //Cria novo fluxo, com workflow desativado BpmFlow::startFlow($conId, $domain->name); //Dispara continuidade dos workflows Connection::continueWorkflows($conId, true); } return true; }
public function createConnections($events) { $paths = $this->getPaths()->all(); Yii::trace($events); for ($i = 0; $i < count($events['start']); $i++) { $conn = new Connection(); $date = new \DateTime($events['start'][$i]); $conn->start = $date->format('Y-m-d H:i'); $date = new \DateTime($events['finish'][$i]); $conn->finish = $date->format('Y-m-d H:i'); $conn->reservation_id = $this->id; $conn->status = Connection::STATUS_PENDING; $conn->dataplane_status = Connection::DATA_STATUS_INACTIVE; $conn->auth_status = Connection::AUTH_STATUS_UNEXECUTED; $conn->resources_status = Connection::RES_STATUS_RELEASED; $conn->version = 0; $conn->bandwidth = $this->bandwidth; $conn->type = Connection::TYPE_NSI; if ($conn->save()) { $k = 0; foreach ($paths as $resPath) { $connPath = new ConnectionPath(); $connPath->path_order = $k; $connPath->conn_id = $conn->id; $connPath->domain = explode(":", $resPath->port_urn)[0]; $k++; $connPath->port_urn = $resPath->port_urn; $connPath->vlan = $resPath->vlan; $connPath->save(); } } else { Yii::trace($conn->getErrors()); } } }
public function actionGetAll($status, $type) { self::beginAsyncAction(); $data = Yii::$app->cache->get('circuits.oscars.all'); if ($data === false) { OscarsService::loadCircuits(Yii::$app->params['oscars.bridge.provider.url']); // store $data in cache so that it can be retrieved next time Yii::$app->cache->set('circuits.oscars.all', 'true', 120000); } $conns = Connection::find()->where(['dataplane_status' => $status, 'type' => $type])->with('fullPath')->asArray()->all(); return json_encode($conns); }
public static function cancelConnAuthRequest($connId) { $types = [self::TYPE_USER, self::TYPE_GROUP]; $auth = ConnectionAuth::find()->where(['connection_id' => $connId, 'status' => Connection::AUTH_STATUS_PENDING])->andWhere(['in', 'type', $types])->one(); if ($auth) { $auth->changeStatusToExpired(); $connection = Connection::findOne($connId); $connection->auth_status = Connection::AUTH_STATUS_EXPIRED; $connection->save(); } }
static function clearAuthorizations($userId) { //Limpa as notificações de autorização que ja foram respondidas $notAuth = Notification::find()->where(['user_id' => $userId, 'type' => Notification::TYPE_AUTHORIZATION, 'viewed' => false])->all(); foreach ($notAuth as $not) { //Confere todas notificações do tipo autorização $auth = ConnectionAuth::findOne($not->info); if ($auth) { $connection = Connection::findOne($auth->connection_id); if ($connection) { $connections = Connection::find()->where(['reservation_id' => $connection->reservation_id])->all(); $answered = true; foreach ($connections as $conn) { //Confere todas conexões da reserva conferindo se alguma ainda esta pendente $auths = ConnectionAuth::find()->where(['domain' => $auth->domain, 'connection_id' => $conn->id])->all(); foreach ($auths as $a) { //Confere as autorizaçòes daquela conexão if ($a->type != ConnectionAuth::TYPE_WORKFLOW && $a->status == Connection::AUTH_STATUS_PENDING) { $answered = false; break; } } if ($answered == false) { break; } } if ($answered) { //Se ja foi respondida modifica notificação para visualizada $not->viewed = true; $not->save(); } } } } }
public function querySummaryConfirmed($response) { $conn = Connection::find()->where(['external_id' => $response->reservation->connectionId])->one(); if (!$conn) { return ""; } $conn->buildEvent(ConnectionEvent::TYPE_NSI_SUMMARY_CONFIRMED, Yii::$app->request->getRawBody())->save(); if ($conn->version != $response->reservation->criteria->version) { $conn->start = (new \DateTime($response->reservation->criteria->schedule->startTime))->format("Y-m-d H:i:s"); $conn->finish = (new \DateTime($response->reservation->criteria->schedule->endTime))->format("Y-m-d H:i:s"); $this->updateConnectionBandwidth($conn, $response); if ($conn->version == 0) { if ($this->updateConnectionPath($conn, $response)) { //Como eh a primeira versao deve ser verificado se ha autorizacao para este circuito. $conn->confirmRead(); } else { /////Path invalido /////Inconsistencias na topologia Yii::trace("path invalid?"); } } $conn->version = $response->reservation->criteria->version; } if ($response->reservation->connectionStates->lifecycleState == "Terminated") { $conn->status = "CANCELLED"; } elseif ($response->reservation->connectionStates->provisionState == "Provisioned") { $conn->resources_status = 'PROVISIONED'; $conn->status = "PROVISIONED"; } else { $conn->resources_status = 'RELEASED'; } $conn->setActiveDataStatus($response->reservation->connectionStates->dataPlaneStatus->active); $conn->save(); return ""; }
/** * * @param BpmFlow $flow */ public function removeFlow($flow) { $type = $flow->type; $connection_id = $flow->connection_id; $flow->delete(); if ($type != 'Accept_Automatically') { if (BpmFlow::find()->where(['domain' => $flow->domain, 'connection_id' => $connection_id])->count() == 0) { BpmFlow::deleteAll(['connection_id' => $connection_id]); $conn = Connection::findOne(['id' => $connection_id]); $conn->auth_status = Connection::AUTH_STATUS_REJECTED; if (!$conn->save()) { Yii::error('Unsuccesful save in Request'); } $auth = new ConnectionAuth(); $auth->domain = $flow->domain; $auth->status = Connection::AUTH_STATUS_REJECTED; $auth->type = ConnectionAuth::TYPE_WORKFLOW; $auth->manager_workflow_id = $flow->workflow_id; $auth->connection_id = $connection_id; $auth->save(); ReservationNotification::create($connection_id); } } else { $auth = new ConnectionAuth(); $auth->domain = $flow->domain; $auth->status = Connection::AUTH_STATUS_APPROVED; $auth->type = ConnectionAuth::TYPE_WORKFLOW; $auth->manager_workflow_id = $flow->workflow_id; $auth->connection_id = $connection_id; $auth->save(); } }
public function searchTerminatedByDomains($params, $allowed_domains) { $validDomains = []; $this->load($params); $userId = Yii::$app->user->getId(); $domains_name = []; foreach ($allowed_domains as $domain) { $domains_name[] = $domain->name; } $connPaths = []; if ($this->src_domain && $this->dst_domain) { //if(in_array($this->src_domain, $domains_name) && in_array($this->dst_domain, $domains_name)){ $dstPaths = ConnectionPath::findBySql("\n SELECT cp1.conn_id\n FROM (\n SELECT conn_id, MAX(`path_order`) AS last_path\n FROM `meican_connection_path`\n GROUP BY `conn_id`\n ) cp2\n JOIN `meican_connection_path` cp1\n ON cp1.conn_id = cp2.conn_id AND cp1.domain = '" . $this->dst_domain . "' AND cp1.path_order = cp2.last_path")->asArray()->all(); $allowedConns = []; foreach ($dstPaths as $dstPath) { $allowedConns[] = $dstPath['conn_id']; } //filtra por conn aceitas pela query anterior $connPaths = ConnectionPath::find()->where(['in', 'domain', [$this->src_domain]])->andWhere(['path_order' => 0])->andWhere(['in', 'conn_id', $allowedConns])->select(["conn_id"])->distinct(true)->asArray()->all(); //} } elseif ($this->src_domain) { //if(in_array($this->src_domain, $domains_name)){ $connPaths = ConnectionPath::find()->where(['in', 'domain', [$this->src_domain]])->andWhere(['path_order' => 0])->select(["conn_id"])->distinct(true)->asArray()->all(); //} } elseif ($this->dst_domain) { //if(in_array($this->dst_domain, $domains_name)){ $connPaths = ConnectionPath::findBySql("\n SELECT cp1.conn_id\n FROM (\n SELECT conn_id, MAX(`path_order`) AS last_path\n FROM `meican_connection_path`\n GROUP BY `conn_id`\n ) cp2\n JOIN `meican_connection_path` cp1\n ON cp1.conn_id = cp2.conn_id AND cp1.domain = '" . $this->dst_domain . "' AND cp1.path_order = cp2.last_path")->asArray()->all(); //} } else { foreach ($allowed_domains as $domain) { $validDomains[] = $domain->name; } $connPaths = ConnectionPath::find()->where(['in', 'domain', $validDomains])->select(["conn_id"])->distinct(true)->asArray()->all(); } $validConnIds = []; foreach ($connPaths as $connPath) { $validConnIds[] = $connPath['conn_id']; } $validConns = Connection::find()->where(['in', 'id', $validConnIds])->select('reservation_id')->distinct(true)->asArray()->all(); $validIds = []; foreach ($validConns as $conn) { $validIds[] = $conn['reservation_id']; } $invalidConnections = Connection::find()->where(['>=', 'finish', DateUtils::now()])->andWhere(['status' => ["PENDING", "CREATED", "CONFIRMED", "SUBMITTED", "PROVISIONED"]])->select(["reservation_id"])->distinct(true)->asArray()->all(); $invalidIds = []; foreach ($invalidConnections as $conn) { $invalidIds[] = $conn['reservation_id']; } if (!$this->src_domain && !$this->dst_domain) { $reservations = Reservation::find()->where(['in', 'id', $validIds])->orWhere(['request_user_id' => Yii::$app->user->getId()])->andWhere(['not in', 'id', $invalidIds])->andWhere(['type' => self::TYPE_NORMAL])->orderBy(['date' => SORT_DESC])->asArray()->all(); } else { $reservations = Reservation::find()->where(['not in', 'id', $invalidIds])->andWhere(['in', 'id', $validIds])->andWhere(['type' => self::TYPE_NORMAL])->orderBy(['date' => SORT_DESC])->asArray()->all(); } $validResIds = []; foreach ($reservations as $res) { if ($res['request_user_id'] == $userId) { $validResIds[] = $res['id']; } else { if (!$this->request_user) { $conns = Connection::find()->where(['reservation_id' => $res['id']])->select(["id"])->asArray()->all(); if (!empty($conns)) { $conn_ids = []; foreach ($conns as $conn) { $conn_ids[] = $conn['id']; } $paths = ConnectionPath::find()->where(['in', 'domain', $domains_name])->andWhere(['in', 'conn_id', $conn_ids])->select(["conn_id"])->distinct(true)->asArray()->all(); if (!empty($paths)) { $validResIds[] = $res['id']; } } } } } $dataProvider = new ActiveDataProvider(['query' => Reservation::find()->where(['in', 'id', $validResIds])->orderBy(['date' => SORT_DESC]), 'sort' => false, 'pagination' => ['pageSize' => 10]]); return $dataProvider; }
static function createNotificationsGroup($user_id, $group_name, $domain) { $user = User::findOne($user_id); $group = Group::findOne(['role_name' => $group_name]); if ($user && $group) { Yii::trace("Criar notificações do grupo " . $group->name . " para usuário " . $user->name); //Busca todas autorizações pendentes do grupo //Se tem dominio, procura só as relacionadas ao dominio do papel if ($domain) { $auths = ConnectionAuth::find()->where(['status' => Connection::AUTH_STATUS_PENDING, 'domain' => $domain, 'type' => ConnectionAuth::TYPE_GROUP, 'manager_group_id' => $group->id])->all(); } else { $auths = ConnectionAuth::find()->where(['status' => Connection::AUTH_STATUS_PENDING, 'type' => ConnectionAuth::TYPE_GROUP, 'manager_group_id' => $group->id])->all(); } //Passa por todas criando uma notificação foreach ($auths as $auth) { $connection = Connection::findOne($auth->connection_id); $reservation = Reservation::findOne($connection->reservation_id); AuthorizationNotification::createToUser($user->id, $auth->domain, $connection->reservation_id, $auth->id, $reservation->date); } } }
<?php echo Grid::widget(['options' => ['class' => 'list'], 'dataProvider' => new ArrayDataProvider(['allModels' => $requests, 'sort' => false, 'pagination' => ['pageSize' => 4]]), 'id' => 'gridRequest', 'layout' => "{items}{summary}{pager}", 'rowOptions' => function ($model, $key, $index, $grid) { return ['id' => $model['id'], 'onclick' => 'toDate(id)']; }, 'columns' => array(['class' => 'yii\\grid\\ActionColumn', 'template' => '{accept}{reject}', 'contentOptions' => function ($model) { return ['style' => 'white-space: nowrap;']; }, 'buttons' => ['accept' => function ($url, $model) { return Html::a('<span class="fa fa-thumbs-o-up"></span>', null, ['disabled' => $model->isAnswered(), 'class' => 'btn btn-accept', 'id' => $model->id]); }, 'reject' => function ($url, $model) { return Html::a('<span class="fa fa-thumbs-o-down"></span>', null, ['disabled' => $model->isAnswered(), 'class' => 'btn btn-reject', 'id' => $model->id]); }]], ['label' => Yii::t('circuits', 'Initial Date/Time'), 'value' => function ($req) { return Yii::$app->formatter->asDatetime(Connection::findOne(['id' => $req->connection_id])->start); }, 'contentOptions' => ['style' => 'min-width: 70px;']], ['label' => Yii::t('circuits', 'Final Date/Time'), 'value' => function ($req) { return Yii::$app->formatter->asDatetime(Connection::findOne(['id' => $req->connection_id])->finish); }, 'contentOptions' => ['style' => 'min-width: 70px;']], ['label' => Yii::t('circuits', 'Duration'), 'value' => function ($req) { $start = strtotime(Connection::findOne(['id' => $req->connection_id])->start); $finish = strtotime(Connection::findOne(['id' => $req->connection_id])->finish); $mins = ($finish - $start) / 60; $hours = 0; while ($mins > 59) { $hours++; $mins -= 60; } return $hours . "h" . $mins . "m"; }, 'contentOptions' => ['style' => 'min-width: 70px;']], ['format' => 'raw', 'label' => Yii::t('circuits', 'Status'), 'value' => function ($req) { if ($req->status == Connection::AUTH_STATUS_APPROVED) { return '<span class="label label-success">' . $req->getStatus() . '</span>'; } if ($req->status == Connection::AUTH_STATUS_REJECTED || $req->status == Connection::AUTH_STATUS_EXPIRED) { return '<span class="label label-danger">' . $req->getStatus() . '</span>'; } return '<span class="label label-warning">' . $req->getStatus() . '</span>';
public function actionIndex($format = 'json', $status = null, $type = null) { Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; return new ActiveDataProvider(['query' => Connection::find()]); }
private static function associateNSICircuits($conn) { $srcPoint = $conn->getFirstPath()->asArray()->one(); $dstPoint = $conn->getLastPath()->asArray()->one(); //procura circuitos NSI ativos e agendados para o mesmo horario //que o circuito OSCARS. $nsiActiveCircuits = Connection::find()->where(['type' => 'NSI', 'start' => $conn->start, 'finish' => $conn->finish])->all(); foreach ($nsiActiveCircuits as $nsiCircuit) { $candidateSrcPoint = $nsiCircuit->getFirstPath()->asArray()->one(); $candidateDstPoint = $nsiCircuit->getLastPath()->asArray()->one(); Yii::trace($candidateSrcPoint); Yii::trace($candidateDstPoint); //Nao podemos atualmente garantir que a traducao de URNs funcione para outros dominios if ($candidateSrcPoint['domain'] != 'cipo.rnp.br' || $candidateDstPoint['domain'] != 'cipo.rnp.br') { return; } //URNs NMWG sao padronizadas entao podemos parsear //URNs NSI nao sao, logo teremos que fazer uma busca na URN //pelos elementos node e port da URN NMWG. Se estiverem presentes, //iremos considerar que representam a mesma porta. $srcDev = explode(':', $srcPoint['port_urn']); $srcDev = explode('=', $srcDev[4])[1]; $dstDev = explode(':', $dstPoint['port_urn']); $dstDev = explode('=', $dstDev[4])[1]; $srcPort = explode(':', $srcPoint['port_urn']); $srcPort = explode('=', $srcPort[5])[1]; $dstPort = explode(':', $dstPoint['port_urn']); $dstPort = explode('=', $dstPort[5])[1]; $dstPort = str_replace('/', '_', $dstPort); $srcPort = str_replace('/', '_', $srcPort); Yii::trace($srcDev); Yii::trace($dstDev); //Se ambos paths comecam e terminam na mesma VLAN e porta //eles representam o mesmo circuito. if ($srcPoint['vlan'] == $candidateSrcPoint['vlan'] && $dstPoint['vlan'] == $candidateDstPoint['vlan'] && StringUtils::contains($srcDev, $candidateSrcPoint['port_urn']) && StringUtils::contains($dstDev, $candidateDstPoint['port_urn']) && StringUtils::contains($srcPort, $candidateSrcPoint['port_urn']) && StringUtils::contains($dstPort, $candidateDstPoint['port_urn'])) { $conn->parent_id = $nsiCircuit->id; $conn->save(); } } }
/** * ACTION REJECT ALL * @param string $id * @param string $domainTop * @param string $message */ public function actionRejectAll($id = null, $domainTop = null, $message = null) { Yii::trace("Reject ALL"); Yii::trace("Reservation ID: " . $id); Yii::trace("Msg: " . $message); if ($id && $domainTop) { $userId = Yii::$app->user->getId(); $reservation = Reservation::findOne(['id' => $id]); $allRequest = null; $connections = Connection::find()->where(['reservation_id' => $id])->all(); foreach ($connections as $conn) { if ($allRequest == null) { $allRequest = ConnectionAuth::find()->where(['connection_id' => $conn->id, 'domain' => $domainTop]); } else { $allRequest->union(ConnectionAuth::find()->where(['connection_id' => $conn->id, 'domain' => $domainTop])); } } $allRequest = $allRequest->all(); $domainRoles = User::findOne(['id' => $userId])->getRoles()->all(); $requests = []; foreach ($allRequest as $request) { if ($request->manager_user_id == $userId) { $requests[$request->id] = $request; } else { foreach ($domainRoles as $domainRule) { $groupId = $domainRule->getGroup()->id; if ($request->manager_group_id == $groupId) { $requests[$request->id] = $request; } } } } foreach ($requests as $req) { if ($req->status == Connection::AUTH_STATUS_PENDING) { if ($req->type == ConnectionAuth::TYPE_GROUP) { $req->manager_user_id = Yii::$app->user->getId(); } if ($message) { $req->manager_message = $message; } $req->status = Connection::AUTH_STATUS_REJECTED; $req->save(); $flow = new BpmFlow(); $flow->response($req->connection_id, $req->domain, BpmFlow::STATUS_NO); } } } }
public function searchByDomains($params) { $this->load($params); $userId = Yii::$app->user->getId(); $now = DateUtils::now(); $authorizations = []; //Armazena os pedidos $reservationsVisited = []; //Armazena as reservas ja incluidas nos pedidos e o dominio ao qual o pedido foi feito. //Pega todas requisições feitas para o usuário if ($this->domain) { $userRequests = ConnectionAuth::find()->where(['domain' => $this->domain, 'manager_user_id' => $userId, 'status' => Connection::AUTH_STATUS_PENDING])->all(); } else { $userRequests = ConnectionAuth::find()->where(['manager_user_id' => $userId, 'status' => Connection::AUTH_STATUS_PENDING])->all(); } foreach ($userRequests as $request) { //Limpa mantendo apenas 1 por reserva $uniq = true; $conn = Connection::find()->where(['id' => $request->connection_id])->andWhere(['<=', 'start', DateUtils::now()])->one(); if (isset($conn)) { $request->changeStatusToExpired(); $conn->auth_status = Connection::AUTH_STATUS_EXPIRED; $conn->save(); ReservationNotification::create($conn->id); } else { $conn = Connection::find()->where(['id' => $request->connection_id])->andWhere(['>', 'start', DateUtils::now()])->one(); foreach ($reservationsVisited as $res) { if ($conn->reservation_id == $res[0] && $request->domain == $res[1]) { $uniq = false; } } if ($uniq) { $aux = []; $aux[0] = $conn->reservation_id; $aux[1] = $request->domain; $reservationsVisited[] = $aux; $source = $conn->getFirstPath()->one(); $destination = $conn->getLastPath()->one(); if (!$this->src_domain || $this->src_domain == $source->domain) { if (!$this->dst_domain || $this->dst_domain == $destination->domain) { $form = new AuthorizationForm(); $form->setValues(Reservation::findOne(['id' => $conn->reservation_id]), $request->domain, $source->domain, $destination->domain); $authorizations[] = $form; } } } } } //Pega todos os papeis do usuário $domainRoles = User::findOne(['id' => $userId])->getRoles()->all(); foreach ($domainRoles as $role) { //Passa por todos papeis if ($this->domain) { $groupRequests = ConnectionAuth::find()->where(['domain' => $this->domain, 'manager_group_id' => $role->getGroup()->id, 'status' => Connection::AUTH_STATUS_PENDING])->all(); } else { $groupRequests = ConnectionAuth::find()->where(['manager_group_id' => $role->getGroup()->id, 'status' => Connection::AUTH_STATUS_PENDING])->all(); } foreach ($groupRequests as $request) { //Passa por todas requisições para testar se o dominio corresponde $domain = Domain::findOne(['name' => $request->domain]); if ($domain) { if ($role->domain == NULL || $role->domain == $domain->name) { $uniq = true; $conn = Connection::find()->where(['id' => $request->connection_id])->andWhere(['<=', 'start', DateUtils::now()])->one(); if (isset($conn)) { $request->changeStatusToExpired(); $conn->auth_status = Connection::AUTH_STATUS_EXPIRED; $conn->save(); ReservationNotification::create($conn->id); } else { $conn = Connection::find()->where(['id' => $request->connection_id])->andWhere(['>', 'start', DateUtils::now()])->one(); foreach ($reservationsVisited as $res) { if ($conn->reservation_id == $res[0] && $domain->name == $res[1]) { $uniq = false; } } if ($uniq) { $aux = []; $aux[0] = $conn->reservation_id; $aux[1] = $request->domain; $reservationsVisited[] = $aux; $source = $conn->getFirstPath()->one(); $destination = $conn->getLastPath()->one(); if (!$this->src_domain || $this->src_domain == $source->domain) { if (!$this->dst_domain || $this->dst_domain == $destination->domain) { $form = new AuthorizationForm(); $form->setValues(Reservation::findOne(['id' => $conn->reservation_id]), $request->domain, $source->domain, $destination->domain); $authorizations[] = $form; } } } } } } } } $dataProvider = new ArrayDataProvider(['allModels' => $authorizations, 'sort' => false, 'pagination' => ['pageSize' => 15]]); return $dataProvider; }
public function getConnection() { return $this->hasOne(Connection::className(), ['id' => 'conn_id']); }
public static function continueWorkflows($id, $asking = true) { Yii::trace("CONTINUA WORKFLOWS"); $paths = ConnectionPath::find()->select('DISTINCT `domain`')->where(['conn_id' => $id])->all(); Yii::trace("Dominios envolvidos:"); foreach ($paths as $path) { Yii::trace($path->domain); } //Analisa se existem pedidos em espera. Neste momento, realiza as perguntas aos admins. foreach ($paths as $path) { if (Connection::findOne(['id' => $id])->auth_status == self::AUTH_STATUS_REJECTED) { break; } else { $domain = Domain::findOne(['name' => $path->domain]); if (isset($domain)) { BpmFlow::doRequest($id, $domain->name, $asking); } } if (ConnectionAuth::find()->where(['connection_id' => $id, 'status' => self::AUTH_STATUS_PENDING])->count() > 0) { break; } //Se tem uma pergunta ativa. } if (!$asking || ConnectionAuth::find()->where(['connection_id' => $id, 'status' => self::AUTH_STATUS_PENDING])->count() > 0) { return; } $conn = Connection::findOne(['id' => $id]); if ($conn->auth_status == self::AUTH_STATUS_PENDING) { $conn->auth_status = self::AUTH_STATUS_APPROVED; if (!$conn->save()) { } if (!$conn->isCancelStatus()) { $conn->requestProvision(); } } //Remove fluxos não finalizados BpmFlow::removeFlows($id); }