Skip to content
Permalink
Browse files

added cache auto-archiving; update #90, update #67

  • Loading branch information...
following5 committed Jun 4, 2013
1 parent 75cad8f commit 331c15edbd10a7bab023220ae6ce7261a1bdefba
@@ -368,6 +368,10 @@
// fill_gaps = false: continue with the last waypoint
$opt['logic']['waypoint_pool']['fill_gaps'] = false;
/* Automatic system user actions
*/
$opt['logic']['systemuser']['user'] = ''; // enter an active username to enable auto archiving
/* Purge log files - age in days (0 = keep infinite)
*/
$opt['logic']['logs']['purge_email'] = 30;
@@ -2489,6 +2489,8 @@ INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2067', 'Status'
INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2068', 'since June 2013', '2013-05-28 16:51:40');
INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2069', 'since February 2012', '2013-05-28 16:51:40');
INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2070', 'One ore more emails to this user could not be delivered. It might be a good idea to additionally log comments on the user\'s geocaches, and/or trying to contact him/her through other channels like a message board account or another geocaching platform.', '2013-05-28 16:51:40');
INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2071', 'This cache has been \"temporarily unavailable\" for more than one year now; therefore it is being archived automatically. The owner may decide to maintain the cache and re-enable the listing.', '2013-05-28 16:51:40');
INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2072', 'This event took place more than five weeks ago; therefore it is being archived automatically. The owner may re-enable the listing if it should stay active for some exceptional reason.', '2013-05-28 16:51:40');

-- Table sys_trans_ref
SET NAMES 'utf8';
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2068', 'DE', 'seit Juni 2013', '2013-04-25 23:00:00');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2069', 'DE', 'seit Februar 2012', '2013-04-25 23:00:00');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2070', 'DE', 'Eine oder mehrere Emails an diesen Benutzer konnten nicht zugestellt werden. Es könnte ratsam sein, Hinweise zu seinen Caches zusätzlich zu loggen, und ihn ggf. über weitere Adressen wie z.B. Forenaccounts oder andere Geocaching-Plattformen zu kontaktieren.', '2013-04-25 23:00:00');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2071', 'DE', 'Dieser Cache ist seit mehr als einem Jahr „momentan nicht verfügbar“; daher wird er automatisch archiviert. Er kann vom Besitzer jederzeit instand gesetzt und reaktiviert werden.', '2013-04-25 23:00:00');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2072', 'DE', 'Dieses Event fand vor über fünf Wochen statt; daher wird es automatisch archiviert. Das Listing kann vom Owner selbst reaktiviert werden, falls es aus besonderen Gründen weiter aktiv bleiben soll.', '2013-04-25 23:00:00');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('1', 'EN', 'Reorder IDs \r', '2010-09-02 00:15:30');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2', 'EN', 'The database could not be reconnected.', '2010-08-28 11:48:07');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('3', 'EN', 'Testing – please do not login', '2010-08-28 11:48:07');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2068', 'EN', 'since June 2013', '2013-04-25 23:00:00');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2069', 'EN', 'since February 2012', '2013-04-25 23:00:00');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2070', 'EN', 'One ore more emails to this user could not be delivered. It might be a good idea to additionally log comments on the user\'s geocaches, and/or trying to contact him/her through other channels like a message board account or another geocaching platform.', '2013-04-25 23:00:00');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2071', 'EN', 'This cache has been \"temporarily unavailable\" for more than one year now; therefore it is being archived automatically. The owner may decide to maintain the cache and re-enable the listing.', '2013-04-25 23:00:00');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2072', 'EN', 'This event took place more than five weeks ago; therefore it is being archived automatically. The owner may re-enable the listing if it should stay active for some exceptional reason.', '2013-04-25 23:00:00');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('1', 'ES', 'Reordenar ID', '2010-12-09 00:17:55');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2', 'ES', 'La base de datos no se pudo conectar.', '2010-12-09 00:17:55');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('3', 'ES', 'En pruebas - por favor, no entre.', '2010-12-09 00:17:55');
@@ -196,10 +196,10 @@ function setNode($value)
}
function setStatus($value)
{
$login;
global $login;
if (sql_value("SELECT COUNT(*) FROM `cache_status` WHERE `id`='&1'", 0, $value) == 1)
{
sql("SET @STATUS_CHANGE_USER_ID='&1'", $login->user_id);
sql("SET @STATUS_CHANGE_USER_ID='&1'", $login->userid);
return $this->reCache->setValue('status', $value);
}
else
@@ -208,6 +208,16 @@ function setStatus($value)
}
}
function getDescLanguages()
{
return explode($this->reCache->getValue('desc_languages'),',');
}
function getDefaultDescLanguage()
{
return $this->reCache->getValue('default_desclang');
}
function getAnyChanged()
{
return $this->reCache->getAnyChanged();
@@ -14,6 +14,17 @@
class cachelog
{
const LOGTYPE_FOUND = 1;
const LOGTYPE_NOTFOUND = 2;
const LOGTYPE_NOTE = 3;
const LOGTYPE_ATTENDED = 7;
const LOGTYPE_WILLATTEND = 8;
const LOGTYPE_ARCHIVED = 9;
const LOGTYPE_ACTIVE = 10;
const LOGTYPE_DISABLED = 11;
const LOGTYPE_LOCKED = 13;
const LOGTYPE_LOCKED_INVISIBLE = 14;
var $nLogId = 0;
var $reCacheLog;
@@ -35,6 +46,8 @@ static function fromUUID($uuid)
static function createNew($nCacheId, $nUserId)
{
global $opt;
// check if user is allowed to log this cache!
$cache = new cache($nCacheId);
if ($cache->exist() == false)
@@ -45,6 +58,7 @@ static function createNew($nCacheId, $nUserId)
$oCacheLog = new cachelog(ID_NEW);
$oCacheLog->setUserId($nUserId);
$oCacheLog->setCacheId($nCacheId);
$oCacheLog->setNode($opt['logic']['node']['id']);
return $oCacheLog;
}
@@ -266,6 +266,27 @@ function try_login_md5($user, $pwmd5, $permanent)
return $retval;
}
// login for cronjobs, command line tools ...
function system_login($username)
{
$this->pClear();
if ($username != "")
{
$rs = sql("SELECT `user_id`,`username`,`admin` FROM `user`
WHERE `username`='&1' AND `is_active_flag`", $username);
if ($rUser = sql_fetch_assoc($rs))
{
$this->username = $rUser['username'];
$this->userid = $rUser['user_id'];
$this->admin = $rUser['admin'];
$this->verified = true;
sqlf("UPDATE `user` SET `user`.`last_login`=NOW() WHERE `user`.`user_id`='&1'", $this->userid);
}
sql_free_result($rs);
}
return ($this->userid > 0);
}
private static function create_sessionid()
{
return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
@@ -58,8 +58,10 @@
INNER JOIN `user` AS `cacheloguser` ON `cache_logs`.`user_id`=`cacheloguser`.`user_id`
INNER JOIN `countries` ON `caches`.`country`=`countries`.`short`
LEFT JOIN `sys_trans_text` ON `countries`.`trans_id`=`sys_trans_text`.`trans_id` AND `sys_trans_text`.`lang`='&1'
WHERE `username`<>'&2'
ORDER BY " . $sqlOrderBy . "`cache_logs`.`date_created` DESC",
$opt['template']['locale']);
$opt['template']['locale'],
isset($_GET['showsyslogs']) ? '' : $opt['logic']['systemuser']['user']);
$newLogs = array();
@@ -0,0 +1,114 @@
<?php
/***************************************************************************
* For license information see doc/license.txt
*
* Unicode Reminder メモ
*
* Automatic archiving of disabled caches
***************************************************************************/
require_once($opt['rootpath'] . "lib2/logic/cache.class.php");
require_once($opt['rootpath'] . "lib2/logic/cachelog.class.php");
checkJob(new autoarchive());
class autoarchive
{
var $name = 'autoarchive';
var $interval = 120; // provisonal minimum interval for initial archiving
function run()
{
global $opt, $login;
if ($login->system_login($opt['logic']['systemuser']['user']))
{
if ($login->hasAdminPriv(ADMIN_USER))
{
$this->archive_disabled_caches();
$this->archive_events();
}
else
echo $this->name . ": user '".$opt['logic']['systemuser']['user']."' cannot maintain caches\n";
}
}
function archive_disabled_caches()
{
// Logging of status changes in cache_status_modified has started on June 1, 2013.
// For archiving caches that were disabled earlier, we also check the listing
// modification date.
$rs = sql("SELECT `caches`.`cache_id`
FROM `caches`
WHERE `caches`.`status`=2 AND `caches`.`type`<>6
AND IFNULL((SELECT MAX(`date_modified`) FROM `cache_status_modified` `csm` WHERE `csm`.`cache_id`=`caches`.`cache_id`),`caches`.`listing_last_modified`) < NOW() - INTERVAL 365 DAY
GROUP BY `caches`.`cache_id`
ORDER BY `caches`.`listing_last_modified`
LIMIT 1"); // provisional limit for initial archiving
while ($rCache = sql_fetch_assoc($rs))
{
$this->archive_cache(
$rCache['cache_id'],
'This cache has been "temporarily unavailable" for more than one year now; ' .
'therefore it is being archived automatically. The owner may decide to ' .
'maintain the cache and re-enable the listing.');
}
sql_free_result($rs);
}
function archive_events()
{
// To prevent archiving events that were accidentally published with a wrong
// event date - before the owner notices it - we also apply a limit of one month
// to the publication date.
$rs = sql("SELECT `cache_id`
FROM `caches`
WHERE `caches`.`type`=6 AND `caches`.`status`=1
AND GREATEST(`date_hidden`,`date_created`) < NOW() - INTERVAL 35 DAY
ORDER BY `date_hidden`
LIMIT 1"); // provisonal limit for initial archiving
while ($rCache = sql_fetch_assoc($rs))
{
$this->archive_cache(
$rCache['cache_id'],
'This event took place more than five weeks ago; therefore it is ' .
'being archived automatically. The owner may re-enable the listing ' .
'if it should stay active for some exceptional reason.');
}
sql_free_result($rs);
}
function archive_cache($cache_id, $comment)
{
global $opt, $login, $translate;
$log = cachelog::createNew($cache_id,$login->userid);
if (!$log)
echo $this->name . ": cannot create log for cache $cache_id\n";
else
{
$cache = new cache($cache_id);
if (!$cache->setStatus(3) || !$cache->save())
echo $this->name . ": cannot change status of cache $cache_id\n";
else
{
// create log
$log->setType(cachelog::LOGTYPE_ARCHIVED, true);
$log->setOcTeamComment(true);
$log->setDate(date('Y-m-d H:i'));
// create log text in appropriate language
$translated_comment = $translate->t($comment, '','',0,'',1, $cache->getDefaultDescLanguage());
$log->setText('<p>'.$translated_comment.'</p>');
if (!$log->save())
echo $this->name . ": could not save archive log for cache $cache_id\n";
}
}
}
}
?>

0 comments on commit 331c15e

Please sign in to comment.
You can’t perform that action at this time.