streams/Code/Daemon/Cron_weekly.php

89 lines
2.2 KiB
PHP
Raw Normal View History

<?php
2022-02-16 04:08:28 +00:00
namespace Code\Daemon;
2022-02-16 04:08:28 +00:00
use Code\Lib\Channel;
use Code\Extend\Hook;
2022-01-25 01:26:12 +00:00
2021-12-03 03:01:39 +00:00
class Cron_weekly
{
2021-12-03 03:01:39 +00:00
public static function run($argc, $argv)
{
2021-12-03 03:01:39 +00:00
/**
* Cron Weekly
*
* Actions in the following block are executed once per day only on Sunday (once per week).
*
*/
2022-08-15 11:19:29 +00:00
$data = datetime_convert();
Hook::call('cron_weekly', $data);
2021-12-03 03:01:39 +00:00
z_check_cert();
2021-12-03 03:01:39 +00:00
prune_hub_reinstalls();
2021-12-03 03:01:39 +00:00
mark_orphan_hubsxchans();
2021-12-03 03:01:39 +00:00
// Find channels that were removed in the last three weeks, but
// haven't been finally cleaned up. These should be older than 10
// days to ensure that "purgeall" messages have gone out or bounced
// or timed out.
$r = q(
"select channel_id from channel where channel_removed = 1 and
channel_deleted > %s - INTERVAL %s and channel_deleted < %s - INTERVAL %s",
2021-12-03 03:01:39 +00:00
db_utcnow(),
db_quoteinterval('21 DAY'),
db_utcnow(),
db_quoteinterval('10 DAY')
);
if ($r) {
foreach ($r as $rv) {
2022-01-25 01:26:12 +00:00
Channel::channel_remove_final($rv['channel_id']);
2021-12-03 03:01:39 +00:00
}
}
2022-08-15 11:19:29 +00:00
// get rid of ancient poco records
2021-12-03 03:01:39 +00:00
q(
"delete from xlink where xlink_updated < %s - INTERVAL %s and xlink_static = 0 ",
db_utcnow(),
db_quoteinterval('14 DAY')
);
// Check for dead sites
Run::Summon(['Checksites' ]);
// clean up image cache - use site expiration or 60 days if not set or zero
$files = glob('cache/img/*/*');
$expire_days = intval(get_config('system', 'default_expire_days'));
if ($expire_days <= 0) {
$expire_days = 60;
}
$now = time();
$maxage = 86400 * $expire_days;
if ($files) {
foreach ($files as $file) {
if (is_file($file)) {
if ($now - filemtime($file) >= $maxage) {
unlink($file);
}
}
}
}
// update searchable doc indexes
Run::Summon([ 'Importdoc']);
/**
* End Cron Weekly
*/
}
}