Add database table and cron job to send reminders (isue #6)

master
Skylar Ittner 5 years ago
parent 621d8f57fe
commit 60181c30ac

@ -0,0 +1,65 @@
<?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(LANGUAGE);
date_default_timezone_set(TIMEZONE);
use Medoo\Medoo;
$database;
try {
$database = new Medoo([
'database_type' => DB_TYPE,
'database_name' => DB_NAME,
'server' => DB_SERVER,
'username' => DB_USER,
'password' => DB_PASS,
'charset' => DB_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" => 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";

Binary file not shown.

@ -21,5 +21,7 @@
"Office": "Office",
"Download (Text)": "Download (Text)",
"Download (HTML)": "Download (HTML)",
"Download (Office)": "Download (Office)"
"Download (Office)": "Download (Office)",
"Note Reminder": "Note Reminder",
"Open {app} to read more": "Open {app} to read more"
}

@ -43,7 +43,7 @@ define("CAPTCHA_ENABLED", FALSE);
define('CAPTCHA_SERVER', 'https://captcheck.netsyms.com');
// See lang folder for language options
define('LANGUAGE', "en_us");
define('LANGUAGE', "en");
define("FOOTER_TEXT", "");

Loading…
Cancel
Save