| verzia 1.30, 2002/04/19 23:56:05 |
verzia 1.31, 2002/04/26 16:59:06 |
|
|
| * - striping slashes from HTTP headers |
* - striping slashes from HTTP headers |
| * - using appropriate PEAR DB function for slashes adding |
* - using appropriate PEAR DB function for slashes adding |
| * 19/04/2002 - support for query strings truncating |
* 19/04/2002 - support for query strings truncating |
| |
* 26/04/2002 - getInactiveSessions() method implemented |
| |
* - setPropertyValue() bugfix |
| |
* - DB write part of registerAccess() is now in writeValues() |
| |
* - getAccessesOfSession(), readIntoValues() and deleteSession() |
| |
* methods added |
| |
* - with usage of methods above convert() method for conversion |
| |
* from raw log into normal implemented |
| */ |
*/ |
| |
|
| define('WEB_LOG_VALUE_SUBSTR_LENGTH', 255); |
define('WEB_LOG_VALUE_SUBSTR_LENGTH', 255); |
| Riadok 132 class Web_Log { |
|
| Riadok 139 class Web_Log { |
|
| /* Cache variables |
/* Cache variables |
| |
|
| $_cache_active_sessions - cached result of active sessions query |
$_cache_active_sessions - cached result of active sessions query |
| |
$_cache_inactive_sessions - cached result of inactive sessions query |
| */ |
*/ |
| |
|
| //var $_cache_sessions_count; |
//var $_cache_sessions_count; |
| Riadok 139 class Web_Log { |
|
| Riadok 147 class Web_Log { |
|
| |
|
| var $_cache_active_sessions; |
var $_cache_active_sessions; |
| var $_cache_raw_log_active_sessions; |
var $_cache_raw_log_active_sessions; |
| |
var $_cache_inactive_sessions; |
| |
var $_cache_raw_log_inactive_sessions; |
| |
|
| /* $_props - properties array |
/* $_props - properties array |
| |
|
| Riadok 159 class Web_Log { |
|
| Riadok 169 class Web_Log { |
|
| value value of property |
value value of property |
| id id of property; defined only if value is stored in its own |
id id of property; defined only if value is stored in its own |
| separate table |
separate table |
| disabled if non zero, property is disabled; no action with that property |
enabled if empty, property is disabled; no action with that property |
| is done; by default, all properties are enabled (not disabled) |
is done; by default, all properties are enabled (not disabled) |
| */ |
*/ |
| |
|
| Riadok 348 class Web_Log { |
|
| Riadok 358 class Web_Log { |
|
| //unset($this->_cache_raw_log_sessions_count); |
//unset($this->_cache_raw_log_sessions_count); |
| unset($this->_cache_active_sessions); |
unset($this->_cache_active_sessions); |
| unset($this->_cache_raw_log_active_sessions); |
unset($this->_cache_raw_log_active_sessions); |
| |
unset($this->_cache_inactive_sessions); |
| |
unset($this->_cache_raw_log_inactive_sessions); |
| |
|
| if (! empty($dsn)) { |
if (! empty($dsn)) { |
| $this->setDSN($dsn); |
$this->setDSN($dsn); |
| } |
} |
| |
|
| foreach (array_keys($this->_props) as $prop) { |
foreach (array_keys($this->_props) as $prop) { |
| $this->_props[$prop]['disabled'] = false; |
$this->_props[$prop]['enabled'] = true; |
| |
$this->_props[$prop]['enabled_cache'] = false; |
| } |
} |
| } |
} |
| |
|
| Riadok 485 class Web_Log { |
|
| Riadok 498 class Web_Log { |
|
| } |
} |
| |
|
| /* |
/* |
| |
* enablePropertyCache(), disablePropertyCache() |
| |
* TODO: getPropertyCache(), setPropertyCache() - ??? |
| |
* enableAllPropertiesCaches(), disableAllPropertiesCaches() |
| |
* |
| |
* Enable/disable of specific property cache. |
| |
*/ |
| |
|
| |
function enablePropertyCache($property) |
| |
{ |
| |
if (isset($this->_props[$property])) |
| |
$this->_props[$property]['enabled_cache'] = true; |
| |
} |
| |
|
| |
function disablePropertyCache($property) |
| |
{ |
| |
if (isset($this->_props[$property])) |
| |
$this->_props[$property]['enabled_cache'] = false; |
| |
} |
| |
|
| |
function enableAllPropertiesCaches() |
| |
{ |
| |
foreach (array_keys($this->_props) as $property) { |
| |
$this->_props[$property]['enabled_cache'] = true; |
| |
} |
| |
|
| |
return true; |
| |
} |
| |
|
| |
function disableAllPropertiesCaches() |
| |
{ |
| |
foreach (array_keys($this->_props) as $property) { |
| |
$this->_props[$property]['enabled_cache'] = false; |
| |
} |
| |
|
| |
return true; |
| |
} |
| |
|
| |
/* |
| * enableProperty(), disableProperty() |
* enableProperty(), disableProperty() |
| * |
* |
| * Enable/disable loging of specific property. |
* Enable/disable loging of specific property. |
| Riadok 493 class Web_Log { |
|
| Riadok 544 class Web_Log { |
|
| function enableProperty($property) |
function enableProperty($property) |
| { |
{ |
| if (isset($this->_props[$property])) |
if (isset($this->_props[$property])) |
| $this->_props[$property]['disabled'] = false; |
$this->_props[$property]['enabled'] = true; |
| } |
} |
| |
|
| function disableProperty($property) |
function disableProperty($property) |
| { |
{ |
| if (isset($this->_props[$property])) |
if (isset($this->_props[$property])) |
| $this->_props[$property]['disabled'] = true; |
$this->_props[$property]['enabled'] = false; |
| } |
} |
| |
|
| /* |
/* |
| Riadok 511 class Web_Log { |
|
| Riadok 562 class Web_Log { |
|
| function getPropertyValue($prop_name) |
function getPropertyValue($prop_name) |
| { |
{ |
| if (isset($this->_props[$prop_name])) { |
if (isset($this->_props[$prop_name])) { |
| if ($this->_props[$prop_name]['disabled']) |
if (! $this->_props[$prop_name]['enabled']) |
| return false; |
return false; |
| |
|
| return $this->_props[$prop_name]['value']; |
return $this->_props[$prop_name]['value']; |
| Riadok 520 class Web_Log { |
|
| Riadok 571 class Web_Log { |
|
| return false; |
return false; |
| } |
} |
| |
|
| function setPropertyValue($value) |
function setPropertyValue($prop_name, $value) |
| { |
{ |
| if (isset($this->_props[$prop_name])) { |
if (isset($this->_props[$prop_name])) { |
| $this->_props[$prop_name]['value'] = $value; |
$this->_props[$prop_name]['value'] = $value; |
| Riadok 550 class Web_Log { |
|
| Riadok 601 class Web_Log { |
|
| function enableAllProperties() |
function enableAllProperties() |
| { |
{ |
| foreach (array_keys($this->_props) as $property) { |
foreach (array_keys($this->_props) as $property) { |
| $this->_props[$property]['disabled'] = false; |
$this->_props[$property]['enabled'] = true; |
| } |
} |
| |
|
| return true; |
return true; |
| Riadok 559 class Web_Log { |
|
| Riadok 610 class Web_Log { |
|
| function disableAllProperties() |
function disableAllProperties() |
| { |
{ |
| foreach (array_keys($this->_props) as $property) { |
foreach (array_keys($this->_props) as $property) { |
| $this->_props[$property]['disabled'] = true; |
$this->_props[$property]['enabled'] = false; |
| } |
} |
| |
|
| return true; |
return true; |
| Riadok 725 class Web_Log { |
|
| Riadok 776 class Web_Log { |
|
| |
|
| foreach (array_keys($this->_props) as $prop_name) { |
foreach (array_keys($this->_props) as $prop_name) { |
| |
|
| if ($this->_props[$prop_name]['disabled']) |
if (! $this->_props[$prop_name]['enabled']) |
| continue; |
continue; |
| |
|
| if (! empty($this->_props[$prop_name]['var'])) { |
if (! empty($this->_props[$prop_name]['var'])) { |
| Riadok 797 class Web_Log { |
|
| Riadok 848 class Web_Log { |
|
| /* REMOVE ME */ |
/* REMOVE ME */ |
| //$remote_addr .= ", 192.168.1.3, 111.111.2., unknown"; |
//$remote_addr .= ", 192.168.1.3, 111.111.2., unknown"; |
| |
|
| if (! $this->_props['remote_addr']['disabled']) |
if ($this->_props['remote_addr']['enabled']) |
| $this->_props['remote_addr']['value'] = $this->_truncate_names |
$this->_props['remote_addr']['value'] = $this->_truncate_names |
| ? $this->_truncateName($remote_addr) |
? $this->_truncateName($remote_addr) |
| : $remote_addr; |
: $remote_addr; |
| |
|
| if (! $this->_props['proxy_addr']['disabled']) |
if ($this->_props['proxy_addr']['enabled']) |
| $this->_props['proxy_addr']['value'] = $this->_truncate_names |
$this->_props['proxy_addr']['value'] = $this->_truncate_names |
| ? $this->_truncateName($proxy_addr) |
? $this->_truncateName($proxy_addr) |
| : $proxy_addr; |
: $proxy_addr; |
| Riadok 811 class Web_Log { |
|
| Riadok 862 class Web_Log { |
|
| * Host names resolving. |
* Host names resolving. |
| */ |
*/ |
| |
|
| if (! $this->_props['remote_host']['disabled']) { |
if ($this->_props['remote_host']['enabled']) { |
| $remote_host = empty($HTTP_SERVER_VARS["REMOTE_HOST"]) |
$remote_host = empty($HTTP_SERVER_VARS["REMOTE_HOST"]) |
| ? $this->_resolveIP($remote_addr) |
? $this->_resolveIP($remote_addr) |
| : stripslashes($HTTP_SERVER_VARS["REMOTE_HOST"]); |
: stripslashes($HTTP_SERVER_VARS["REMOTE_HOST"]); |
| Riadok 822 class Web_Log { |
|
| Riadok 873 class Web_Log { |
|
| } |
} |
| |
|
| if ($proxy_addr) { |
if ($proxy_addr) { |
| if ($this->_props['proxy_host']['disabled']) { |
/* XXX: there was a bug, I fixed it, but it is really OK now? |
| |
Nepto [26/4/2002] */ |
| |
if ($this->_props['proxy_host']['enabled']) { |
| $proxy_host = $this->_resolveIP($proxy_addr); |
$proxy_host = $this->_resolveIP($proxy_addr); |
| $this->_props['proxy_host']['value'] = $this->_truncate_names |
$this->_props['proxy_host']['value'] = $this->_truncate_names |
| ? $this->_truncateName($proxy_host) |
? $this->_truncateName($proxy_host) |
| Riadok 853 class Web_Log { |
|
| Riadok 906 class Web_Log { |
|
| * Ident protocol stuff. |
* Ident protocol stuff. |
| */ |
*/ |
| |
|
| if (! $this->_props['ident_username']['disabled'] |
if ($this->_props['ident_username']['enabled'] |
| || ! $this->_props['ident_username']['disabled']) { |
|| $this->_props['ident_username']['enabled']) { |
| |
|
| $ident = new Net_Ident($remote_addr, |
$ident = new Net_Ident($remote_addr, |
| stripslashes($HTTP_SERVER_VARS["REMOTE_PORT"]), |
stripslashes($HTTP_SERVER_VARS["REMOTE_PORT"]), |
| Riadok 864 class Web_Log { |
|
| Riadok 917 class Web_Log { |
|
| // print "Ident query failed: " . $ident->error() . ".<br>\n"; |
// print "Ident query failed: " . $ident->error() . ".<br>\n"; |
| } |
} |
| else { |
else { |
| if (! $this->_props['ident_username']['disabled']) |
if ($this->_props['ident_username']['enabled']) |
| $this->_props['ident_username']['value'] = $ident->user(); |
$this->_props['ident_username']['value'] = $ident->user(); |
| if (! $this->_props['ident_ostype']['disabled']) |
if ($this->_props['ident_ostype']['enabled']) |
| $this->_props['ident_ostype']['value'] = $ident->osType(); |
$this->_props['ident_ostype']['value'] = $ident->osType(); |
| } |
} |
| } |
} |
| Riadok 876 class Web_Log { |
|
| Riadok 929 class Web_Log { |
|
| |
|
| function _setValueValue($value = 0) |
function _setValueValue($value = 0) |
| { |
{ |
| if (! $this->_props['value']['disabled']) |
if ($this->_props['value']['enabled']) |
| $this->_props['value']['value'] = $value; |
$this->_props['value']['value'] = $value; |
| |
|
| return true; |
return true; |
| Riadok 892 class Web_Log { |
|
| Riadok 945 class Web_Log { |
|
| if (isset($this->_props[$prop_name]['value'])) { |
if (isset($this->_props[$prop_name]['value'])) { |
| |
|
| if (! empty($this->_props[$prop_name]['table'])) { |
if (! empty($this->_props[$prop_name]['table'])) { |
| $id = $this->_getID( |
/* |
| $this->_props[$prop_name]['table'], |
$id = $this->_getID( |
| $this->_props[$prop_name]['value']); |
$this->_props[$prop_name]['table'], |
| |
$this->_props[$prop_name]['value']); |
| |
*/ |
| |
$id = $this->_getID($prop_name); |
| |
|
| if (DB::isError($id)) |
if (DB::isError($id)) |
| return $id; |
return $id; |
| Riadok 914 class Web_Log { |
|
| Riadok 970 class Web_Log { |
|
| |
|
| function _setSessionIDValue() |
function _setSessionIDValue() |
| { |
{ |
| if (! $this->_props['session_id']['disabled']) { |
if ($this->_props['session_id']['enabled']) { |
| $session_id = $this->_getSessionID(); |
$session_id = $this->_getSessionID(); |
| |
|
| if (DB::isError($session_id)) |
if (DB::isError($session_id)) |
| Riadok 932 class Web_Log { |
|
| Riadok 988 class Web_Log { |
|
| function _setDatetimeValue() |
function _setDatetimeValue() |
| { |
{ |
| /* TODO: make this database independent (or sysdate() is?) */ |
/* TODO: make this database independent (or sysdate() is?) */ |
| if (! $this->_props['datetime']['disabled']) |
if ($this->_props['datetime']['enabled']) |
| $this->_props['datetime']['id'] = |
$this->_props['datetime']['id'] = |
| $this->_props['datetime']['value'] = |
$this->_props['datetime']['value'] = |
| 'SYSDATE()'; |
'SYSDATE()'; |
| Riadok 982 class Web_Log { |
|
| Riadok 1038 class Web_Log { |
|
| /* |
/* |
| * registerAccess() |
* registerAccess() |
| * |
* |
| * Register access. Insert one record to accesses table. |
* Register access. Set values and write them into web log. |
| * Also insert records into another tables if it is neccessary. |
|
| */ |
*/ |
| |
|
| function registerAccess($value = 0) |
function registerAccess($value = 0) |
| Riadok 991 class Web_Log { |
|
| Riadok 1046 class Web_Log { |
|
| /* NOTES: containing variable parts |
/* NOTES: containing variable parts |
| query_string, request_uri, http_referer |
query_string, request_uri, http_referer |
| */ |
*/ |
| |
|
| /* |
/* |
| * Setting values |
* Setting values |
| */ |
*/ |
| $this->setValues($value); |
$this->setValues($value); |
| |
|
| |
/* |
| |
* Writting values |
| |
*/ |
| |
return $this->writeValues(); |
| |
} |
| |
|
| |
/* |
| |
* writeValues() |
| |
* |
| |
* Insert one record to accesses table. |
| |
* Also insert records into another tables if it is neccessary. |
| |
*/ |
| |
|
| |
function writeValues() |
| |
{ |
| $keys = ''; |
$keys = ''; |
| $vals = ''; |
$vals = ''; |
| |
|
| Riadok 1024 class Web_Log { |
|
| Riadok 1095 class Web_Log { |
|
| if (isset($this->_props[$prop_name]['id']) |
if (isset($this->_props[$prop_name]['id']) |
| && ! empty($this->_props[$prop_name]['id'])) { |
&& ! empty($this->_props[$prop_name]['id'])) { |
| $val = $this->_props[$prop_name]['id']; |
$val = $this->_props[$prop_name]['id']; |
| |
// FIXME: nasty datetime quoting hack |
| |
if ($prop_name == 'datetime' && strcasecmp('sysdate()', |
| |
$this->_props[$prop_name]['value'])) { |
| |
$val = "'$val'"; |
| |
} |
| } |
} |
| else { |
else { |
| $val = 0; |
$val = 0; |
| Riadok 1058 class Web_Log { |
|
| Riadok 1134 class Web_Log { |
|
| * If $value is not in table, record will be inserted and ID returned. |
* If $value is not in table, record will be inserted and ID returned. |
| */ |
*/ |
| |
|
| function _getID($table, $value) |
function _getID($property) |
| { |
{ |
| |
$table = $this->_props[$property]['table']; |
| |
$value = $this->_props[$property]['value']; |
| |
$enabled_cache = $this->_props[$property]['enabled_cache']; |
| |
|
| |
if ($enabled_cache) { |
| |
//echo "DEBUG: cache is enabled for '$property'\n"; |
| |
if (! isset($this->_props[$property]['cache'])) { |
| |
$query = 'SELECT id, value FROM ' . $table; |
| |
|
| |
if (DB::isError($cache = $this->_db->getAssoc($query))) |
| |
return $cache; |
| |
|
| |
$this->_props[$property]['cache'] = $cache; |
| |
unset($cache); |
| |
} |
| |
|
| |
$ret = array_search($value, $this->_props[$property]['cache']); |
| |
if ($ret) |
| |
return $ret; |
| |
} |
| |
|
| for ($i = 0; $i < 2; $i++) { |
for ($i = 0; $i < 2; $i++) { |
| |
|
| // TODO: LIMIT is MySQL dependent? Yes it is! |
$query = sprintf('SELECT id FROM %s WHERE value = "%s"', |
| // use appropriate PEAR DB method |
|
| $query = sprintf('SELECT id FROM %s' |
|
| .' WHERE value = "%s"' |
|
| /*.' LIMIT 1'*/, |
|
| $table, $this->_db->quoteString( |
$table, $this->_db->quoteString( |
| substr($value, 0, WEB_LOG_VALUE_SUBSTR_LENGTH))); |
substr($value, 0, WEB_LOG_VALUE_SUBSTR_LENGTH))); |
| |
|
| if (DB::isError($id = $this->_db->getOne($query))) |
if (DB::isError($id = $this->_db->getOne($query))) |
| return $id; |
return $id; |
| |
|
| if ($id) |
if ($id) { |
| |
if ($enabled_cache) |
| |
$this->_props[$property]['cache'][$id] = $value; |
| |
|
| return $id; |
return $id; |
| |
} |
| |
|
| /* Important note: |
/* Important note: |
| |
|
| Riadok 1124 class Web_Log { |
|
| Riadok 1221 class Web_Log { |
|
| if (DB::isError($id = $this->_db->getOne($query))) |
if (DB::isError($id = $this->_db->getOne($query))) |
| return $id; |
return $id; |
| |
|
| if ($id) |
if ($id) { |
| |
if ($enabled_cache) |
| |
$this->_props[$property]['cache'][$id] = $value; |
| |
|
| return $id; |
return $id; |
| |
} |
| |
|
| return 0; |
return 0; |
| } |
} |
| Riadok 1259 class Web_Log { |
|
| Riadok 1360 class Web_Log { |
|
| } |
} |
| |
|
| /* |
/* |
| |
* getSessions() |
| |
* |
| |
* Returns session IDs. |
| |
* |
| |
* TODO: |
| |
* For $state equal 0 all sessions, -1 for inactive sessions, 1 for active. |
| |
*/ |
| |
|
| |
function _getSessions($active = true) |
| |
{ |
| |
if ($this->_checkDB() == false) |
| |
return $this->_db; |
| |
|
| |
$accesses_table = $this->_raw_log |
| |
? 'weblog_accesses_raw' |
| |
: 'weblog_accesses'; |
| |
|
| |
$query = sprintf('SELECT session_id FROM %s' |
| |
.' GROUP BY session_id' |
| |
.' HAVING UNIX_TIMESTAMP(SYSDATE())' |
| |
.' - UNIX_TIMESTAMP(MAX(datetime)) %s %s' |
| |
.' ORDER BY session_id ASC', |
| |
$accesses_table, |
| |
$active ? '<' : '>=', |
| |
intval($this->_session_timeout)); |
| |
|
| |
return $this->_db->getCol($query); |
| |
} |
| |
|
| |
/* |
| * getActiveSessions() |
* getActiveSessions() |
| * |
* |
| * Returns array with IDs of active sessions. |
* Returns array with IDs of active sessions. |
| Riadok 1275 class Web_Log { |
|
| Riadok 1406 class Web_Log { |
|
| return $this->_cache_active_sessions; |
return $this->_cache_active_sessions; |
| } |
} |
| |
|
| |
$active_sessions = $this->_getSessions(true); |
| |
if (DB::isError($active_sessions)) |
| |
return $active_sessions; |
| |
|
| |
if ($this->_raw_log) |
| |
$this->_cache_raw_log_active_sessions = $active_sessions; |
| |
else |
| |
$this->_cache_active_sessions = $active_sessions; |
| |
|
| |
return $active_sessions; |
| |
} |
| |
|
| |
/* |
| |
* getInactiveSessions() |
| |
* |
| |
* Returns array with IDs of inactive sessions. |
| |
*/ |
| |
|
| |
function getInactiveSessions() |
| |
{ |
| |
if ($this->_raw_log) { |
| |
if (isset($this->_cache_raw_log_inactive_sessions)) |
| |
return $this->_cache_inactive_sessions; |
| |
} |
| |
else { |
| |
if (isset($this->_cache_inactive_sessions)) |
| |
return $this->_cache_inactive_sessions; |
| |
} |
| |
|
| |
$inactive_sessions = $this->_getSessions(false); |
| |
if (DB::isError($inactive_sessions)) |
| |
return $inactive_sessions; |
| |
|
| |
if ($this->_raw_log) |
| |
$this->_cache_raw_log_inactive_sessions = $inactive_sessions; |
| |
else |
| |
$this->_cache_inactive_sessions = $inactive_sessions; |
| |
|
| |
return $inactive_sessions; |
| |
} |
| |
|
| |
/* |
| |
* Raw converting functions |
| |
*/ |
| |
|
| |
function getAccessesOfSession($session_id) |
| |
{ |
| if ($this->_checkDB() == false) |
if ($this->_checkDB() == false) |
| return $this->_db; |
return $this->_db; |
| |
|
| |
if (is_array($session_id)) { |
| |
for ($i = 0; $i < count($session_id); $i++) |
| |
$session_id[$i] = intval($session_id[$i]); |
| |
} |
| |
|
| $accesses_table = $this->_raw_log |
$accesses_table = $this->_raw_log |
| ? 'weblog_accesses_raw' |
? 'weblog_accesses_raw' |
| : 'weblog_accesses'; |
: 'weblog_accesses'; |
| |
|
| $query = 'SELECT session_id' |
$query = "SELECT id FROM $accesses_table WHERE session_id "; |
| .' FROM ' . $accesses_table |
$query .= is_array($session_id) |
| .' GROUP BY session_id' |
? 'IN (' . join(', ', $session_id) . ')' |
| .' HAVING UNIX_TIMESTAMP(SYSDATE())' |
: (intval($session_id) == 0 |
| .' - UNIX_TIMESTAMP(MAX(datetime)) < ' . $this->_session_timeout; |
? 'IS NULL' |
| |
: '= ' . intval($session_id)); |
| |
|
| $active_sessions = $this->_db->getCol($query); |
if (DB::isError($ids = $this->_db->getCol($query))) |
| |
return $ids; |
| |
|
| if (DB::isError($active_sessions)) { |
return $ids; |
| return $active_sessions; |
} |
| //$this->_error($active_sessions->getMessage()); |
|
| |
function readIntoValues($access_id) |
| |
{ |
| |
if (! $this->_raw_log) { |
| |
die("readIntoValues(): not implemented for normal log\n"); |
| } |
} |
| |
|
| if ($this->_raw_log) |
if ($this->_checkDB() == false) |
| $this->_cache_raw_log_active_sessions = $active_sessions; |
return $this->_db; |
| else |
|
| $this->_cache_active_sessions = $active_sessions; |
|
| |
|
| return $active_sessions; |
/* Note: we are selecting all from DB, but probably better will be to |
| |
select only enabled properties. */ |
| |
|
| |
$query = sprintf('SELECT * FROM %s WHERE id = %s', |
| |
'weblog_accesses_raw', intval($access_id)); |
| |
|
| |
if (DB::isError($ar = $this->_db->getRow($query))) |
| |
return $ar; |
| |
|
| |
foreach (array_keys($this->_props) as $prop) { |
| |
//echo "DEBUG: checking property $prop - "; |
| |
if (isset($ar[$this->_props[$prop]['column']])) { |
| |
$this->_props[$prop]['value'] = |
| |
$ar[$this->_props[$prop]['column']]; |
| |
//echo " is set: "; |
| |
//echo $this->_props[$prop]['value']; |
| |
//echo "\n"; |
| |
} |
| |
else { |
| |
//echo " is NOT set\n"; |
| |
} |
| |
} |
| |
|
| |
return true; |
| |
} |
| |
|
| |
function deleteSession($session_id) |
| |
{ |
| |
if ($this->_checkDB() == false) |
| |
return $this->_db; |
| |
|
| |
if (is_array($session_id)) { |
| |
for ($i = 0; $i < count($session_id); $i++) |
| |
$session_id[$i] = intval($session_id[$i]); |
| |
} |
| |
|
| |
$accesses_table = $this->_raw_log |
| |
? 'weblog_accesses_raw' |
| |
: 'weblog_accesses'; |
| |
|
| |
$query = "DELETE FROM $accesses_table WHERE session_id "; |
| |
$query .= is_array($session_id) |
| |
? 'IN (' . join(', ', $session_id) . ')' |
| |
: (intval($session_id) == 0 |
| |
? 'IS NULL' |
| |
: '= ' . intval($session_id)); |
| |
|
| |
if (DB::isError($res = $this->_db->query($query))) |
| |
return $ids; |
| |
|
| |
return true; |
| |
} |
| |
|
| |
function convert() |
| |
{ |
| |
$this->enableRawLog(); |
| |
$inactive_sessions = $this->getInactiveSessions(); |
| |
if (DB::isError($inactive_sessions)) |
| |
return $inactive_sessions; |
| |
/* |
| |
echo "Active sessions: [" . implode($active_sessions, '][') . "]\n"; |
| |
echo "Inactive sessions: [" . implode($inactive_sessions, '][') . "]\n"; |
| |
*/ |
| |
|
| |
if (count($inactive_sessions) < 2) { |
| |
// $this->destroy(); |
| |
// die("No inactive sessions.\n"); |
| |
return true; |
| |
} |
| |
|
| |
/* The highest session ID will remain. */ |
| |
array_pop($inactive_sessions); |
| |
$this->enableAllPropertiesCaches(); |
| |
|
| |
foreach ($inactive_sessions as $sid) { |
| |
|
| |
echo "[$sid]::"; |
| |
$ids = $this->getAccessesOfSession($sid); |
| |
if (DB::isError($ids)) |
| |
return $ids; |
| |
|
| |
foreach ($ids as $id) { |
| |
$this->enableRawLog(); |
| |
$this->clearAllProperties(); |
| |
if (DB::isError($res = $this->readIntoValues($id))) |
| |
return res; |
| |
$this->setPropertyValue('id', 0); |
| |
$this->disableRawLog(); |
| |
if (DB::isError($res = $this->_setIDs())) |
| |
return res; |
| |
if (DB::isError($res = $this->writeValues())) |
| |
return $res; |
| |
|
| |
echo "[$id]"; |
| |
} |
| |
|
| |
$this->enableRawLog(); |
| |
if (DB::isError($res = $this->deleteSession($sid))) |
| |
return $res; |
| |
|
| |
echo "\n"; |
| |
|
| |
// debug purpose |
| |
//break; |
| |
} |
| } |
} |
| } |
} |
| |
|