Audit::save PHP Метод

save() публичный Метод

public save ( $runValidation = true, $attributes = null, $allow_overriding = false )
    public function save($runValidation = true, $attributes = null, $allow_overriding = false)
    {
        if (isset($_SERVER['REMOTE_ADDR'])) {
            if (!($ipaddr = AuditIPAddr::model()->find('name=?', array($_SERVER['REMOTE_ADDR'])))) {
                $ipaddr = new AuditIPAddr();
                $ipaddr->name = $_SERVER['REMOTE_ADDR'];
                if (!$ipaddr->save()) {
                    throw new Exception('Unable to save audit IP address: ' . print_r($ipaddr->getErrors(), true));
                }
            }
            if (isset($_SERVER['HTTP_USER_AGENT'])) {
                if (!($useragent = AuditUseragent::model()->find('name=?', array($_SERVER['HTTP_USER_AGENT'])))) {
                    $useragent = new AuditUseragent();
                    $useragent->name = $_SERVER['HTTP_USER_AGENT'];
                    if (!$useragent->save()) {
                        throw new Exception('Unable to save user agent: ' . print_r($useragent->getErrors(), true));
                    }
                }
                $this->useragent_id = $useragent->id;
            }
            if (!($server = AuditServer::model()->find('name=?', array($_SERVER['SERVER_NAME'])))) {
                $server = new AuditServer();
                $server->name = $_SERVER['SERVER_NAME'];
                if (!$server->save()) {
                    throw new Exception('Unable to save server: ' . print_r($server->getErrors(), true));
                }
            }
            $this->ipaddr_id = $ipaddr->id;
            $this->server_id = $server->id;
            $this->request_uri = $_SERVER['REQUEST_URI'];
            if ($this->user) {
                $this->site_id = Yii::app()->session['selected_site_id'];
                $this->firm_id = Yii::app()->session['selected_firm_id'];
            }
        }
        return parent::save($runValidation, $attributes, $allow_overriding);
    }

Usage Example

Пример #1
0
 public static function logAudit($entity, $action, $description)
 {
     $audit = new Audit();
     $audit->date = date('Y-m-d');
     $audit->description = $description;
     $audit->user = Confide::user()->username;
     $audit->entity = $entity;
     $audit->action = $action;
     $audit->save();
 }
All Usage Examples Of Audit::save