/** * 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 $id the ID of the model to be loaded * @return BadUrlLog the loaded model * @throws CHttpException */ public function loadModel($id) { $model = BadUrlLog::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
/** * Creates the controller and performs the specified action. * @param string $route the route of the current request. See {@link createController} for more details. * @throws CHttpException if the controller could not be created. */ public function runController($route) { try { parent::runController($route); } catch (CHttpException $x) { if (\Yii::app()->params['site']['logError404']) { \Yii::import('admin.models.BadUrlLog'); if (!\BadUrlLog::saveLog()) { throw $x; } // Si tout va bien, on enregistre l'erreur sans envoyer de mail à l'administrateur // On redirige le client vers la page d'erreur personnalisée \Yii::import('admin.*'); /** @var \AdminModule $adminModule */ $adminModule = \Yii::app()->getModule('admin'); $this->runController($adminModule->routeFor404ErrorPage); } else { throw $x; } } }
/** * @test */ public function search() { // recherche par event_date $model = new BadUrlLog('search'); $model->unsetAttributes(); $model->event_date = "2014"; $data = $model->search()->data; $this->assertEquals(2, count($data)); $model->unsetAttributes(); $model->event_date = "2019"; $data = $model->search()->data; $this->assertEquals(0, count($data)); // recherche par cookie_data $model->unsetAttributes(); $model->cookie_data = 'cookie_da'; $data = $model->search()->data; $this->assertEquals(1, count($data)); // recherche par server_data $model->unsetAttributes(); $model->server_data = 'server_da'; $data = $model->search()->data; $this->assertEquals(1, count($data)); // recherche par remote_addr $model->unsetAttributes(); $model->remote_addr = "127.0.0"; $data = $model->search()->data; $this->assertEquals(1, count($data)); // recherche par remote_port $model->unsetAttributes(); $model->remote_port = '80'; $data = $model->search()->data; $this->assertEquals(1, count($data)); // recherche par request_method $model->unsetAttributes(); $model->request_method = 'GET'; $data = $model->search()->data; $this->assertEquals(1, count($data)); $model->unsetAttributes(); $model->request_method = 'GE'; // doit être complet $data = $model->search()->data; $this->assertEquals(0, count($data)); // recherche par request_uri $model->unsetAttributes(); $model->request_uri = 'site'; $data = $model->search()->data; $this->assertEquals(1, count($data)); // recherche par query_string $model->unsetAttributes(); $model->query_string = ''; // devrait trouver celui qui a une chaine vide et celui qui est NULL $data = $model->search()->data; $this->assertEquals(2, count($data)); }
/** * Méthode appelée quand une action est introuvable. * @internal Pour traiter le cas d'un module ou d'un contrôleur introuvables, cf. BaseWebApplication * @param string $actionID */ public function missingAction($actionID) { if (\Yii::app()->params['site']['logError404']) { \Yii::import('admin.models.BadUrlLog'); if (!\BadUrlLog::saveLog()) { parent::missingAction($actionID); } // Si tout va bien, on enregistre l'erreur sans envoyer de mail à l'administrateur // On redirige le client vers la page d'erreur personnalisée \Yii::import('admin.*'); /** @var \AdminModule $adminModule */ $adminModule = \Yii::app()->getModule('admin'); $this->forward($adminModule->routeFor404ErrorPage); } else { parent::missingAction($actionID); } }
/** * @return bool */ public static function saveLog() { $log = new \BadUrlLog(); $log->setEventDate(); $log->initializeFromGlobalVariables(); if (!$log->save()) { // En cas de problème on enregistre l'erreur et on revient au comportement par défaut (throw CHttpException) Yii::log(h::_('Erreur sur BadUrlLog::save()', __FILE__, __LINE__, __METHOD__), \CLogger::LEVEL_ERROR); return false; } return true; }