Skip to content
Permalink
Browse files

archive some disabled caches after 6 months; closes #808

- if disabled by OC admins, or
- if disabled by the owner and the owner was not logged in since then

... if no newer logs have been posted and the owner is inactive for
at least 45 days.
  • Loading branch information...
following5 committed Jan 19, 2016
1 parent 757df41 commit dca7e77fe681e1eaca022b25a83651accb82914b
Showing with 50 additions and 18 deletions.
  1. +4 −4 htdocs/doc/sql/static-data/data.sql
  2. +46 −14 htdocs/util2/cron/modules/autoarchive_caches.class.php
@@ -2473,7 +2473,7 @@ 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 deletion date 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 use alternative contact addresses 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 ('2071', 'This cache has been \"temporarily unavailable\" for more than %1 months 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');
INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2073', 'This user account is disabled.', '2013-05-28 16:51:40');
INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2074', 'Adoptions_', '2013-05-28 16:51:40');
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 Löschdatum 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/oder weitere Kontaktmöglichkeiten wie z.B. Forenaccounts oder andere Geocaching-Plattformen zu nutzen.', '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 ('2071', 'DE', 'Dieser Cache ist seit mehr als %1 Monaten \„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 ('2073', 'DE', 'Dieser Benutzer ist deaktiviert.', '2013-04-25 23:00:00');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2074', 'DE', 'Adoptionen', '2013-04-25 23:00:00');
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 deletion date 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 use alternative contact addresses 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 ('2071', 'EN', 'This cache has been \"temporarily unavailable\" for more than %1 months 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 ('2073', 'EN', 'This user account is disabled.', '2013-04-25 23:00:00');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2074', 'EN', 'Adoptions', '2013-04-25 23:00:00');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2068', 'FR', 'depuis Juin 2013', '2015-08-25 01:29:00');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2069', 'FR', 'depuis la date de suppression en Février 2012', '2015-08-25 01:29:00');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2070', 'FR', 'Une ou plusieurs e-mails à cet utilisateur ne pouvaient pas être livrés. Il pourrait être une bonne idée de connecter plus de commentaires sur les géocaches de l\'utilisateur, et / ou d\'utiliser des adresses de contact de rechange comme un compte message de conseil ou d\'une autre plate-forme de géocaching.', '2015-08-25 01:29:00');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2071', 'FR', 'Cette cache a été \"temporairement indisponible\" pendant plus d\'un an maintenant\ ; par conséquent, il est archivée automatiquement. Le propriétaire peut décider de maintenir le cache et réactiver la liste.', '2015-08-25 01:29:00');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2071', 'FR', 'Cette cache a été \"temporairement indisponible\" pendant plus %1 mois maintenant\ ; par conséquent, il est archivée automatiquement. Le propriétaire peut décider de maintenir le cache et réactiver la liste.', '2015-08-25 01:29:00');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2072', 'FR', 'Cet événement a eu lieu il y a plus de cinq semaines\ ; par conséquent, il est archivé automatiquement. Le propriétaire peut réactiver la liste si elle devrait rester actif pour une raison exceptionnelle.', '2015-08-25 01:29:00');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2073', 'FR', 'Ce compte d\'utilisateur est désactivé.', '2015-08-25 01:29:00');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2074', 'FR', 'Adoptions', '2015-08-25 01:29:00');
@@ -16,7 +16,7 @@
class autoarchive
{
var $name = 'autoarchive';
var $interval = 3600; // once per hour
var $interval = 43200; // twice per day
function run()
@@ -42,20 +42,51 @@ 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 IFNULL((SELECT MAX(`date_modified`) FROM `cache_status_modified` `csm` WHERE `csm`.`cache_id`=`caches`.`cache_id`),`caches`.`listing_last_modified`) < NOW() - INTERVAL 366 DAY
GROUP BY `caches`.`cache_id`
ORDER BY `caches`.`listing_last_modified`
LIMIT 3"); // limit to avoid mass emails and spam-filter triggers
// This statement shout be optimized. It typically runs for ~20 seconds at OC.de.
$rs = sql("
SELECT `cache_id`,
`caches`.`user_id`,
DATEDIFF(NOW(), `listing_last_modified`) AS `listing_age`,
(SELECT MAX(`date_modified`) FROM `cache_status_modified` `csm`
WHERE `csm`.`cache_id`=`caches`.`cache_id` AND `csm`.`new_state`=2)
`disable_date`,
(SELECT MAX(`user_id`) FROM `cache_status_modified` `csm`
WHERE `csm`.`cache_id`=`cache_id` AND `csm`.`date_modified`=`disable_date`)
`disabled_by`,
IFNULL(DATEDIFF(NOW(), `user`.`last_login`), 150) `login_lag`
FROM `caches`
LEFT JOIN `user` ON `user`.`user_id`=`caches`.`user_id`
WHERE `status`=2 AND DATEDIFF(NOW(), `listing_last_modified`) > 184
ORDER BY `listing_last_modified`");
$archived = 0;
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.');
if ($rCache['listing_age'] > 366 ||
($rCache['listing_age'] > 184 &&
(sql_value("SELECT DATEDIFF(NOW(),'&1')", 0, $rCache['disable_date']) > 366 ||
((($rCache['disabled_by'] != 0 && $rCache['disabled_by'] != $rCache['user_id'] && $rCache['login_lag'] > 45)
||
($rCache['disabled_by'] == $rCache['user_id'] && $rCache['login_lag'] >= $rCache['listing_age']))
&&
sql_value("SELECT MAX(`date`) FROM `cache_logs` WHERE `cache_logs`.`cache_id`='&1'", "", $rCache['cache_id']) < $rCache['disable_date']
)
)
)
)
{
$months = ($rCache['listing_age'] > 366 ? 12 : 6);
$this->archive_cache(
$rCache['cache_id'],
'This cache has been "temporarily unavailable" for more than %1 months now; ' .
'therefore it is being archived automatically. The owner may decide to ' .
'maintain the cache and re-enable the listing.',
$months);
++$archived;
// if ($archived >= 3)
// break;
}
}
sql_free_result($rs);
}
@@ -82,7 +113,7 @@ function archive_events()
sql_free_result($rs);
}
function archive_cache($cache_id, $comment)
function archive_cache($cache_id, $comment, $months=0)
{
global $opt, $login, $translate;
@@ -105,6 +136,7 @@ function archive_cache($cache_id, $comment)
// create log text in appropriate language
$translated_comment = $translate->t($comment, '','',0,'',1, $cache->getDefaultDescLanguage());
$translated_comment = str_replace('%1', $months, $translated_comment);
$log->setText('<p>'.$translated_comment.'</p>');
$log->setTextHtml(1);

0 comments on commit dca7e77

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