async deleteUser({commit}, user) {
await userService.deleteUser(user.id)
commit('DELETE_USER', user)
return user
},
async restoreUser({commit}, user) {
await userService.restoreUser(user.id)
commit('RESTORE_USER', user)
return user
},
DELETE_USER(state, user) {
state.users.forEach(u => {
if(u.id == user.id) {
u = user
}
})
},
RESTORE_USER(state, user) {
state.users.forEach(u => {
if(u.id == user.id) {
u = user
}
})
},
protected function importParams($requestXml, $params) {
foreach($params as $key => $val) {
if (is_array($val)) {
$requestXml->$key = new SimpleXMLElement("<$key/>");
foreach($val as $key2 => $val2) {
if (is_array($val2)) {
$this->importParams($requestXml->$key, $val2);
} else {
$requestXml->$key->addChild($key2, $val2);
}
}
} else {
$requestXml->addChild($key, $val);
}
}
return $requestXml;
}
<?php
/*
CREATE TABLE IF NOT EXISTS `session` (
`session_id` varchar(32) NOT NULL,
`data` text NOT NULL,
`expire` datetime NOT NULL,
PRIMARY KEY (`session_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
*/
namespace Session;
final class DB {
public $expire = 3600;
public function __construct($registry) {
$this->db = $registry->get('db');
$this->expire = ini_get('session.gc_maxlifetime');
}
public function read($session_id) {
$query = $this->db->query("SELECT `data` FROM `" . DB_PREFIX . "session` WHERE session_id = '" . $this->db->escape($session_id) . "' AND expire > '" . $this->db->escape(date('Y-m-d H:i:s')) . "'");
if ($query->num_rows) {
return json_decode($query->row['data'], true);
} else {
return false;
}
}
public function write($session_id, $data) {
if ($session_id) {
$this->db->query("REPLACE INTO `" . DB_PREFIX . "session` SET session_id = '" . $this->db->escape($session_id) . "', `data` = '" . $this->db->escape($data ? json_encode($data) : '') . "', expire = '" . $this->db->escape(date('Y-m-d H:i:s', time() + $this->expire)) . "'");
}
return true;
}
public function destroy($session_id) {
$this->db->query("DELETE FROM `" . DB_PREFIX . "session` WHERE session_id = '" . $this->db->escape($session_id) . "'");
return true;
}
public function gc($expire) {
if (ini_get('session.gc_divisor')) {
$gc_divisor = ini_get('session.gc_divisor');
} else {
$gc_divisor = 1;
}
if (ini_get('session.gc_probability')) {
$gc_probability = ini_get('session.gc_probability');
} else {
$gc_probability = 1;
}
if ((rand() % $gc_divisor) < $gc_probability) {
$this->db->query("DELETE FROM `" . DB_PREFIX . "session` WHERE expire < '" . $this->db->escape(date('Y-m-d H:i:s', time())) . "'");
}
return true;
}
}