2011-06-17 18:24:34 +09:00
|
|
|
<?php
|
2019-09-11 18:07:54 +09:00
|
|
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
|
|
|
//
|
|
|
|
// GNU social is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// GNU social is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2011-06-17 18:24:34 +09:00
|
|
|
/**
|
|
|
|
* Data class for email reminders
|
|
|
|
*
|
|
|
|
* @category Data
|
|
|
|
* @package EmailReminder
|
|
|
|
* @author Zach Copley <zach@status.net>
|
|
|
|
* @copyright 2011 StatusNet, Inc.
|
2019-09-11 18:07:54 +09:00
|
|
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
2011-06-17 18:24:34 +09:00
|
|
|
*/
|
|
|
|
|
2019-09-11 18:07:54 +09:00
|
|
|
defined('GNUSOCIAL') || die();
|
|
|
|
|
2011-06-17 18:24:34 +09:00
|
|
|
class Email_reminder extends Managed_DataObject
|
|
|
|
{
|
|
|
|
public $__table = 'email_reminder';
|
|
|
|
|
2015-02-13 02:18:55 +09:00
|
|
|
public $type; // type of reminder varchar(191) not 255 because utf8mb4 takes more space
|
|
|
|
public $code; // confirmation code varchar(191) not 255 because utf8mb4 takes more space
|
2011-06-17 18:24:34 +09:00
|
|
|
public $days; // number of days after code was created
|
|
|
|
public $sent; // timestamp
|
|
|
|
public $created; // timestamp
|
|
|
|
public $modified; // timestamp
|
|
|
|
|
|
|
|
/**
|
2011-06-21 04:58:14 +09:00
|
|
|
* Do we need to send a reminder?
|
2011-06-17 18:24:34 +09:00
|
|
|
*
|
2011-06-21 04:58:14 +09:00
|
|
|
* @param string $type type of reminder
|
|
|
|
* @param Object $object an object with a 'code' property
|
|
|
|
* (Confirm_address or Invitation)
|
|
|
|
* @param int $days Number of days after the code was created
|
|
|
|
* @return boolean true if any Email_reminder records were found
|
2011-06-17 18:24:34 +09:00
|
|
|
*/
|
2019-09-11 18:07:54 +09:00
|
|
|
public static function needsReminder($type, $object, $days = null)
|
|
|
|
{
|
2011-06-17 18:24:34 +09:00
|
|
|
$reminder = new Email_reminder();
|
|
|
|
$reminder->type = $type;
|
2011-06-21 04:58:14 +09:00
|
|
|
$reminder->code = $object->code;
|
|
|
|
if (!empty($days)) {
|
|
|
|
$reminder->days = $days;
|
|
|
|
}
|
|
|
|
$result = $reminder->find();
|
2011-06-17 18:24:34 +09:00
|
|
|
|
2011-06-21 04:58:14 +09:00
|
|
|
if (!empty($result)) {
|
|
|
|
return false;
|
2011-06-17 18:24:34 +09:00
|
|
|
}
|
|
|
|
|
2011-06-21 04:58:14 +09:00
|
|
|
return true;
|
2011-06-17 18:24:34 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-06-21 04:58:14 +09:00
|
|
|
* Record a record of sending the reminder
|
2011-06-17 18:24:34 +09:00
|
|
|
*
|
2011-06-21 04:58:14 +09:00
|
|
|
* @param string $type type of reminder
|
|
|
|
* @param Object $object an object with a 'code' property
|
|
|
|
* (Confirm_address or Invitation)
|
|
|
|
* @param int $days Number of days after the code was created
|
|
|
|
* @return int $result row ID of the new reminder record
|
2011-06-17 18:24:34 +09:00
|
|
|
*/
|
2019-09-11 18:07:54 +09:00
|
|
|
public static function recordReminder($type, $object, $days)
|
|
|
|
{
|
2011-06-17 18:24:34 +09:00
|
|
|
$reminder = new Email_reminder();
|
|
|
|
$reminder->type = $type;
|
2011-06-21 04:58:14 +09:00
|
|
|
$reminder->code = $object->code;
|
2011-06-17 18:24:34 +09:00
|
|
|
$reminder->days = $days;
|
|
|
|
$reminder->sent = $reminder->created = common_sql_now();
|
|
|
|
$result = $reminder->insert();
|
|
|
|
|
|
|
|
if (empty($result)) {
|
|
|
|
common_log_db_error($reminder, 'INSERT', __FILE__);
|
2019-09-11 18:07:54 +09:00
|
|
|
throw new ServerException(
|
|
|
|
// TRANS: Server exception thrown when a reminder record could not be inserted into the database.
|
|
|
|
_m('Database error inserting reminder record.')
|
2011-06-17 18:24:34 +09:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Data definition for email reminders
|
|
|
|
*/
|
|
|
|
public static function schemaDef()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
'description' => 'Record of email reminders that have been sent',
|
|
|
|
'fields' => array(
|
|
|
|
'type' => array(
|
|
|
|
'type' => 'varchar',
|
2015-02-13 02:18:55 +09:00
|
|
|
'length' => 191,
|
2011-06-17 18:24:34 +09:00
|
|
|
'not null' => true,
|
|
|
|
'description' => 'type of reminder'
|
|
|
|
),
|
|
|
|
'code' => array(
|
|
|
|
'type' => 'varchar',
|
2019-09-11 18:07:54 +09:00
|
|
|
'not null' => true,
|
2015-02-13 02:18:55 +09:00
|
|
|
'length' => 191,
|
2011-06-17 18:24:34 +09:00
|
|
|
'description' => 'confirmation code'
|
|
|
|
),
|
|
|
|
'days' => array(
|
|
|
|
'type' => 'int',
|
2019-09-11 18:07:54 +09:00
|
|
|
'not null' => true,
|
2011-06-17 18:24:34 +09:00
|
|
|
'description' => 'number of days since code creation'
|
|
|
|
),
|
|
|
|
'sent' => array(
|
|
|
|
'type' => 'datetime',
|
|
|
|
'not null' => true,
|
|
|
|
'description' => 'Date and time the reminder was sent'
|
|
|
|
),
|
|
|
|
'created' => array(
|
|
|
|
'type' => 'datetime',
|
|
|
|
'not null' => true,
|
|
|
|
'description' => 'Date and time the record was created'
|
|
|
|
),
|
|
|
|
'modified' => array(
|
|
|
|
'type' => 'timestamp',
|
|
|
|
'not null' => true,
|
|
|
|
'description' => 'Date and time the record was last modified'
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'primary key' => array('type', 'code', 'days'),
|
|
|
|
'indexes' => array(
|
|
|
|
'sent_idx' => array('sent'),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|