streams/Code/Daemon/Expire.php

94 lines
3.3 KiB
PHP
Raw Normal View History

2016-05-20 02:42:45 +00:00
<?php
2022-02-16 04:08:28 +00:00
namespace Code\Daemon;
2016-05-20 02:42:45 +00:00
2022-02-16 04:08:28 +00:00
use Code\Lib\ServiceClass;
use Code\Lib\Channel;
2022-01-25 01:26:12 +00:00
2022-11-27 09:15:28 +00:00
class Expire implements DaemonInterface
2021-12-03 03:01:39 +00:00
{
2022-11-27 09:15:28 +00:00
public function run(int $argc, array $argv): void
2021-12-03 03:01:39 +00:00
{
cli_startup();
2022-07-11 22:33:21 +00:00
// physically remove anything which has completed PHASE2 federated deletion
q("delete from item where item_pending_remove = 1");
2022-07-11 22:33:21 +00:00
// Perform final cleanup on previously deleted items where
// DROPITEM_PHASE1 has completed and more than 4 days have elapsed
// so notifications should have been delivered.
2021-12-03 03:01:39 +00:00
$pending_deletes = q(
2021-12-03 03:01:39 +00:00
"select id from item where item_deleted = 1 and item_pending_remove = 0 and changed < %s - INTERVAL %s",
db_utcnow(),
2022-07-11 22:33:21 +00:00
db_quoteinterval('4 DAY')
2021-12-03 03:01:39 +00:00
);
if ($pending_deletes) {
foreach ($pending_deletes as $item) {
drop_item($item['id'], DROPITEM_PHASE2);
2021-12-03 03:01:39 +00:00
}
}
logger('expire: start', LOGGER_DEBUG);
$site_expire = intval(get_config('system', 'default_expire_days'));
$commented_days = intval(get_config('system', 'active_expire_days'));
logger('site_expire: ' . $site_expire);
$channels = q("SELECT channel_id, channel_system, channel_address, channel_expire_days from channel where true");
2021-12-03 03:01:39 +00:00
if ($channels) {
foreach ($channels as $channel) {
2021-12-03 03:01:39 +00:00
// expire the sys channel separately
if (intval($channel['channel_system'])) {
2021-12-03 03:01:39 +00:00
continue;
}
// service class default (if non-zero) over-rides the site default
$service_class_expire = ServiceClass::fetch($channel['channel_id'], 'expire_days');
2021-12-03 03:01:39 +00:00
if (intval($service_class_expire)) {
$channel_expire = $service_class_expire;
} else {
$channel_expire = $site_expire;
}
if (
intval($channel_expire) && (intval($channel_expire) < intval($channel['channel_expire_days'])) ||
intval($channel['channel_expire_days'] == 0)
2021-12-03 03:01:39 +00:00
) {
$expire_days = $channel_expire;
} else {
$expire_days = $channel['channel_expire_days'];
2021-12-03 03:01:39 +00:00
}
// if the site or service class expiration is non-zero and less than person expiration, use that
logger('Expire: ' . $channel['channel_address'] . ' interval: ' . $expire_days, LOGGER_DEBUG);
item_expire($channel['channel_id'], $expire_days, $commented_days);
2021-12-03 03:01:39 +00:00
}
}
$sys_channel = Channel::get_system();
if ($sys_channel) {
2021-12-03 03:01:39 +00:00
// this should probably just fetch the channel_expire_days from the sys channel,
// but there's no convenient way to set it.
$expire_days = intval(get_config('system', 'sys_expire_days', 30));
2021-12-03 03:01:39 +00:00
if ($site_expire && $site_expire < $expire_days) {
2021-12-03 03:01:39 +00:00
$expire_days = $site_expire;
}
logger('Expire: sys interval: ' . $expire_days, LOGGER_DEBUG);
if ($expire_days) {
item_expire($sys_channel['channel_id'], $expire_days, $commented_days);
2021-12-03 03:01:39 +00:00
}
logger('Expire: sys: done', LOGGER_DEBUG);
}
}
2016-05-20 02:42:45 +00:00
}