public function actionIndex() { $operation = Operation::model()->findByAttributes(['module' => $this->getModule()->getId(), 'controller' => $this->getId(), 'action' => $this->getAction()->getId()]); if ($operation->getAttribute('level') == 1) { $maxLevel = 2; } else { $maxLevel = PHP_INT_MAX; } $operation = $this->auth->getOperationByPk($operation->getAttribute('id')); $child = $operation->getChild(); usort($child, function ($a, $b) { if ($a->getRawData('sort') == $b->getRawData('sort')) { return 0; } if ($a->getRawData('sort') < $b->getRawData('sort')) { return 1; } else { return 0; } }); $nav = array(); foreach ($child as $item) { if ($item->getStatus() || $item->getLevel() > $maxLevel) { continue; } $nav[] = [$item->getName(), $this->app->createUrl($item->getModule() . '/' . $item->getController() . '/' . $item->getAction())]; } $this->render('/public/nav', ['nav' => $nav]); }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = Operation::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function actionDisplayOperation($id = null) { $model = Record::model()->findAllByAttributes(array('operation_id' => $id)); $values = CHtml::listData($model, 'port_id', 'value', 'timestamp'); $jsonarray = array(); foreach ($values as $date => $value) { $jsonarray[] = array_merge(array($date), $value); } $model = Operation::model()->with('iface')->findByPK($id); $model->nextPrev(); $this->render('displayOperation', array('values' => $jsonarray, 'operation' => $model)); }
/** * This method deletes all completed operations not in top count. * @param type $topCount Count of recent operations to keep. * @return void */ public static function deleteOldOperations($topCount = 1000) { // Get total count of records $totalCount = Operation::model()->count(); $limitCount = $totalCount - $topCount; if ($limitCount <= 0) { return; } // Do nothing // Select the oldest operation records for deleting $criteria = new CDbCriteria(); $criteria->select = '*'; $criteria->compare('status', '<>' . self::STATUS_STARTED); $criteria->order = 'timestamp DESC'; $criteria->limit = $limitCount; $ops = Operation::model()->findAll($criteria); foreach ($ops as $op) { $op->delete(); } }
public function testDeleteOldOperations() { // Create 10 operations $i = 0; for ($i = 0; $i < 10; $i++) { $op = new Operation(); $op->status = Operation::STATUS_SUCCEEDED; $op->timestamp = time(); $op->srcid = $i; $op->cmdid = '1234.' . $i; $op->optype = Operation::OPTYPE_IMPORTPDB; $op->operand1 = "C:\\Program Files\\Apache Software Foundations\\htdocs\\crashfix\\protected\\data\\debugInfo\\CrashRpt{$i}.pdb"; $op->operand2 = "C:\\Program Files\\Apache Software Foundations\\htdocs\\crashfix\\protected\runtime\tmp1234{$i}.tmp"; $this->assertTrue($op->save()); } // Delete old operations Operation::deleteOldOperations(5); // Expect there are 5 ops now $count = Operation::model()->count(); $this->assertTrue($count == 5); }
public function save() { try { if ($this->id) { $model = Operation::model()->findByPk($this->id); if (empty($model)) { throw new CDbException('参数出错', 1, []); } } else { $model = new Operation(); } $model->attributes = ['name' => $this->name, 'description' => $this->description, 'module' => $this->module, 'controller' => $this->controller, 'action' => $this->action, 'status' => $this->status, 'sort' => $this->sort]; if ($model->save() === false) { throw new CDbException('更新用户出错', 2, $model->getErrors()); } } catch (CDbException $e) { $this->addErrors($e->errorInfo); return false; } return true; }
public function view() { $roleId = $this->request->getPost('role', 0); $role = $this->auth->getRoleByPk($roleId); if ($role == false) { $this->response(404, '参数错误'); } else { $operations = Operation::model()->findAll(['condition' => '`level`=2']); $opera = []; foreach ($operations as $operation) { $auth = $this->auth->getOperationByPk($operation->getAttribute('id')); $opera[] = ['data' => $auth, 'child' => $auth->getChild()]; } $assigns = $role->getAssigns(); $assign = []; foreach ($assigns as $item) { if ($item !== false) { $assign[] = $item->getId(); } } $this->render('assign', ['opera' => $opera, 'role' => $role, 'assign' => $assign]); } }
protected function model() { return Operation::model(); }
public function model() { return Operation::model(); }
private function checkDebugInfoDeletionOperations() { Yii::log('Checking debug info deletion operations in progress...', 'info'); // Get the list of debug info deletion operations that were started recently $criteria = new CDbCriteria(); $criteria->select = '*'; $criteria->condition = 'optype=:optype AND status=:status'; $criteria->params = array(':optype' => Operation::OPTYPE_DELETE_DEBUG_INFO, ':status' => Operation::STATUS_STARTED); $criteria->limit = 500; $operations = Operation::model()->findAll($criteria); if ($operations == Null) { Yii::log('There are no operations in progress', 'info'); } else { Yii::log('Found ' . count($operations) . ' operations in progress', 'info'); } foreach ($operations as $op) { $cmdRetCode = -1; $cmdRetMsg = ""; $check = $this->checkAssyncCommand($op->cmdid, $cmdRetCode, $cmdRetMsg); if ($check == self::CAC_STILL_RUNNING) { continue; } // Command is still running $opStatus = Operation::STATUS_FAILED; if ($check == self::CAC_COMPLETED) { // The operation seems to be completed. $debugInfoId = $op->srcid; $debugInfo = DebugInfo::model()->findByPk($debugInfoId); if ($debugInfo != null) { // Delete debug info record $debugInfo->delete(); // Set operation status to 'Succeeded' $opStatus = Operation::STATUS_SUCCEEDED; } } else { if ($check == self::CAC_ERROR) { // Delete debug info record $debugInfoId = $op->srcid; $debugInfo = DebugInfo::model()->findByPk($debugInfoId); if ($debugInfo != null) { $debugInfo->delete(); } // Set operation status to 'Failed' $opStatus = Operation::STATUS_FAILED; } } // Finish operation $this->finalizeOperation($op, $opStatus); } Yii::log("Finished checking debug info deletion operations in progress.", "info"); }