Esempio n. 1
0
 /**
  * Saves the session into the database by inserting it or updating an existing one.
  */
 public function save()
 {
     $cleaned = array();
     foreach ($this->db_fields as $fieldname => $cleantype) {
         switch ($cleantype) {
             case vB_Cleaner::TYPE_INT:
                 $clean = isset($this->vars["{$fieldname}"]) ? intval($this->vars["{$fieldname}"]) : 0;
                 break;
             case vB_Cleaner::TYPE_STR:
             default:
                 // will be escaped by assertor
                 $clean = isset($this->vars["{$fieldname}"]) ? $this->vars["{$fieldname}"] : '';
         }
         $cleaned["{$fieldname}"] = $clean;
     }
     // since the sessionhash can be blanked out, lets make sure we pull from "dbsessionhash"
     $cleaned['sessionhash'] = $this->vars['dbsessionhash'];
     if ($this->created == true) {
         $this->dBAssertor->insertIgnore('session', $cleaned);
     } else {
         // update query
         unset($this->changes['sessionhash']);
         // the sessionhash is not updateable
         $update = array();
         foreach ($cleaned as $key => $value) {
             if (!empty($this->changes["{$key}"])) {
                 $update[$key] = $value;
             }
         }
         if (sizeof($update) > 0) {
             // note that $cleaned['sessionhash'] has been escaped as necessary above!
             $this->dBAssertor->update('session', $update, array('sessionhash' => $cleaned['sessionhash']));
         }
     }
 }