|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Run this script via cron every 15 minutes to send reminder notifications.
|
|
|
|
require __DIR__ . '/settings.php';
|
|
|
|
require __DIR__ . '/vendor/autoload.php';
|
|
|
|
$libs = glob(__DIR__ . "/lib/*.lib.php");
|
|
|
|
foreach ($libs as $lib) {
|
|
|
|
require_once $lib;
|
|
|
|
}
|
|
|
|
$Strings = new Strings($SETTINGS['language']);
|
|
|
|
date_default_timezone_set($SETTINGS['timezone']);
|
|
|
|
|
|
|
|
use Medoo\Medoo;
|
|
|
|
|
|
|
|
$database;
|
|
|
|
try {
|
|
|
|
$database = new Medoo([
|
|
|
|
'database_type' => $SETTINGS['database']['type'],
|
|
|
|
'database_name' => $SETTINGS['database']['name'],
|
|
|
|
'server' => $SETTINGS['database']['server'],
|
|
|
|
'username' => $SETTINGS['database']['user'],
|
|
|
|
'password' => $SETTINGS['database']['password'],
|
|
|
|
'charset' => $SETTINGS['database']['charset']
|
|
|
|
]);
|
|
|
|
} catch (Exception $ex) {
|
|
|
|
echo "Database error: $ex\n";
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
$reminders = $database->select('reminders', [
|
|
|
|
'reminderid (id)',
|
|
|
|
'noteid',
|
|
|
|
'when'
|
|
|
|
], [
|
|
|
|
'when[<]' => date("Y-m-d H:i:s", strtotime("now + 15 minutes"))
|
|
|
|
]);
|
|
|
|
|
|
|
|
echo "Start sending " . count($reminders) . " reminder notifications...\n";
|
|
|
|
|
|
|
|
$deleteids = [];
|
|
|
|
$linelimit = 3;
|
|
|
|
|
|
|
|
foreach ($reminders as $r) {
|
|
|
|
$note = Note::loadNote($r['noteid']);
|
|
|
|
$lines = explode("\n", $note->getText(), $linelimit);
|
|
|
|
if (count($lines) == $linelimit) {
|
|
|
|
array_pop($lines);
|
|
|
|
$lines[] = $Strings->build("Open {app} to read more", ["app" => $SETTINGS['site_title']], false);
|
|
|
|
}
|
|
|
|
$content = implode("\n", $lines);
|
|
|
|
Notifications::add($note->getOwner(), $Strings->get("Note Reminder", false), $content);
|
|
|
|
$deleteids[] = $r['id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
echo "Sent " . count($reminders) . " notifications.\n";
|
|
|
|
|
|
|
|
$deleted = $database->delete('reminders', ['reminderid' => $deleteids]);
|
|
|
|
|
|
|
|
echo "Outdated reminder cleanup complete: " . $deleted->rowCount() . " records removed.\n";
|