KT-personal-website/bin/cron.php

76 lines
2.3 KiB
PHP
Raw Normal View History

2024-10-22 12:26:08 +02:00
<?php
require_once __DIR__ . '/../vendor/autoload.php';
date_default_timezone_set('Europe/Paris');
use App\Blogs\Blogs;
use App\Cache;
use App\Fetching\Gitea;
use App\Fetching\Shaarli;
use App\Fetching\NanoGal;
use App\Utils\Debug;
use App\Utils\Config;
use GuzzleHttp\Client;
$params = ['config' => Config::loadConfig()];
$params['config']['cron'] = true;
$shaarli = new Shaarli($params);
if (Cache::isValidFeed('shaarli', $shaarli->shaarliFeedUpdate)) {
$shaarliCache = Cache::getCache('shaarli.html', 'feed');
$shaarliRegenCache = 'Shaarli : cache';
} else {
Cache::unValidateCache('shaarli.html', 'feed');
Cache::unValidateCache('home.html', 'page');
$shaarli->getLastBookmark();
$shaarliCache = $shaarli->makeList();
Cache::setCache('shaarli.html', $shaarliCache, 'feed');
$shaarliRegenCache = 'Shaarli : regen';
}
$nanogal = new NanoGal($params);
if (Cache::isValidFeed('nanogal', $nanogal->nanogalFeedUpdate)) {
$nanogalCache = Cache::getCache('nanogal.html', 'feed');
$nanogalRegenCache = 'Nanogal : cache';
} else {
Cache::unValidateCache('nanogal.html', 'feed');
Cache::unValidateCache('home.html', 'page');
$nanogal->getLastBookmark();
$nanogalCache = $nanogal->makeList();
Cache::setCache('nanogal.html', $nanogalCache, 'feed');
$nanogalRegenCache = 'Nanogal : regen';
}
$gitea = new Gitea($params);
$gitea->getLastRepo();
$repoCache = $gitea->makeList();
if (Cache::isValidApi('gitea', $gitea->giteaHash)) {
$repoCache = Cache::getCache('gitea.html', 'feed');
$giteaRegenCache = 'Gitea : cache';
} else {
Cache::unValidateCache('gitea.html', 'feed');
Cache::unValidateCache('home.html', 'page');
Cache::setCache('gitea.html', $repoCache, 'feed');
$giteaRegenCache = 'Gitea : regen';
}
$post = new Blogs($params);
$post->getLastPost();
$postCache = $post->makeList();
if (Cache::isValidApi('posts', $post->postsHash)) {
$postCache = Cache::getCache('posts.html', 'feed');
$postRegenCache = 'Post : cache';
} else {
Cache::unValidateCache('posts', 'feed');
Cache::unValidateCache('home.html', 'page');
Cache::clearCache('posts');
Cache::setCache('posts.html', $postCache, 'feed');
$postRegenCache = 'Post : regen';
}
$client = new \GuzzleHttp\Client();
$response = $client->request('GET', 'http://site.knah-tsaeb.local/');
echo "\n".$response->getStatusCode()."\n";