Hey hey people,
I’m looking for a way to access the content of my Kirby website within a cron job script.
Now I am not entirely sure how to make it work as I have only been getting errors
So far I have tried to go for something like that:
#!/usr/bin/env php
<?php
// check if we are indeed on the command line
if (php_sapi_name() !== 'cli') {
die();
}
// load Kirby
require __DIR__ . '/../kirby/bootstrap.php';
$props = [
'roots' => [
'index' => __DIR__ . '/..',
'content' => __DIR__ . '/../content',
'site' => __DIR__ . '/../site',
],
];
// initialize Kirby and site
echo "\033[1mLoading Kirby...\033[0m\n";
$kirby = new Kirby($props);
// re-index using the Algolia plugin
echo "\033[1mReindexing updating applications...\033[0m\n";
$site = kirby()->site();
// dump($site);
// dump($kirby);
$seminarpages = $site->find('seminare')->children();
try{
foreach($seminarpages as $seminar){
if(!empty($seminar->seminarapplications())){
$seminarapplicationcollection = $seminar->seminarapplications()->yaml();
foreach($seminarapplicationcollection as $key => $value){
if(empty($value['anmeldeid'])){
echo "fehlende Anmelde-ID gefunden!";
dump($key);
$seminarapplicationcollection[$key]['anmeldeid'] = md5(uniqid("", true).random_bytes(20));
}
}
echo "job's done!";
$kirby->impersonate('kirby');
$updatedpage = $seminar->update([
'seminarapplications' => Data::encode($seminarapplicationcollection, 'yaml')
]);
}
}
}catch(Exception $e){
echo $e;
}
echo "\033[32mSuccessfully updated all the applications. \033[0m\n";
This is based on the algolia-index script that’s on the public repository of the Kirby website.
One thing, that’s different from that repository however is that I unfortunately can’t put the script anywhere else but the content folder. Maybe that’s also what giving me issues.
The way I have to call it is like this: mysite.com/scripts/script.php
I am updating my algolia index that way as well, and that one seems to work just fine, so I am at a bit of a loss right now.
The error message I’m getting isn’t helping at all though…
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style type="text/css">
html, body, #partner, iframe {
height:100%;
width:100%;
margin:0;
padding:0;
border:0;
outline:0;
font-size:100%;
vertical-align:baseline;
background:transparent;
}
body {
overflow:hidden;
}
</style>
<meta content="NOW" name="expires">
<meta content="index, follow, all" name="GOOGLEBOT">
<meta content="index, follow, all" name="robots">
<!-- Following Meta-Tag fixes scaling-issues on mobile devices -->
<meta content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" name="viewport">
</head>
<body>
<div id="partner">
</div>
<script type="text/javascript">
document.write(
'<script type="text/javascript" language="JavaScript"'
+ 'src="//sedoparking.com/frmpark/'
+ window.location.host + '/'
+ 'IONOSParkingDE'
+ '/park.js">'
+ '<\/script>'
);
</script>
</body>
</html>
Also one thing I am really concerned about is the safety…
I am not very experienced in that field, so I’d appreciate any advice you can give me.