authTokenControl job

This commit is contained in:
yuri
2015-11-20 15:02:13 +02:00
parent e4e56489d7
commit a3683b76b8
10 changed files with 134 additions and 35 deletions

View File

@@ -87,16 +87,19 @@ class Container
protected function loadLog()
{
$logConfig = $this->get('config')->get('logger');
$config = $this->get('config');
$path = $config->get('logger.path', 'data/logs');
$rotation = $config->get('logger.rotation', true);
$levelCode = $config->get('logger.level', 'WARNING');
$log = new \Espo\Core\Utils\Log('Espo');
$levelCode = $log->getLevelCode($logConfig['level']);
if ($logConfig['isRotate']) {
$handler = new \Espo\Core\Utils\Log\Monolog\Handler\RotatingFileHandler($logConfig['path'], $logConfig['maxRotateFiles'], $levelCode);
if ($rotation) {
$maxFileNumber = $config->get('logger.maxFileNumber', 30);
$handler = new \Espo\Core\Utils\Log\Monolog\Handler\RotatingFileHandler($path, $maxFileNumber, $levelCode);
} else {
$handler = new \Espo\Core\Utils\Log\Monolog\Handler\StreamHandler($logConfig['path'], $levelCode);
$handler = new \Espo\Core\Utils\Log\Monolog\Handler\StreamHandler($path, $levelCode);
}
$log->pushHandler($handler);

View File

@@ -27,8 +27,8 @@
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
return array ( 'database' =>
array (
return array (
'database' => array (
'driver' => 'pdo_mysql',
'host' => 'localhost',
'port' => '',
@@ -48,13 +48,10 @@ return array ( 'database' =>
'thousandSeparator' => ',',
'decimalMark' => '.',
'exportDelimiter' => ';',
'currencyList' =>
array (
),
'currencyList' => ['USD'],
'defaultCurrency' => 'USD',
'baseCurrency' => 'USD',
'currencyRates' => array(
),
'currencyRates' => [],
'outboundEmailIsShared' => true,
'outboundEmailFromName' => 'EspoCRM',
'outboundEmailFromAddress' => '',
@@ -64,7 +61,7 @@ return array ( 'database' =>
'smtpSecurity' => '',
'smtpUsername' => '',
'smtpPassword' => '',
'languageList' => array(
'languageList' => [
'en_US',
'de_DE',
'es_ES',
@@ -77,14 +74,14 @@ return array ( 'database' =>
'pt_BR',
'uk_UA',
'vi_VN'
),
],
'language' => 'en_US',
'logger' =>
array (
'path' => 'data/logs/espo.log',
'level' => 'WARNING', /** DEBUG, INFO, NOTICE, WARNING, ERROR, CRITICAL, ALERT, EMERGENCY */
'isRotate' => true, /** rotate log files every day */
'maxRotateFiles' => 30, /** max number of rotate files */
'rotation' => true, /** create log */
'maxFileNumber' => 30, /** max number of log files */
),
'authenticationMethod' => 'Espo',
'globalSearchEntityList' =>
@@ -94,16 +91,16 @@ return array ( 'database' =>
'Lead',
'Opportunity',
),
"tabList" => array("Account", "Contact", "Lead", "Opportunity", "Calendar", "Meeting", "Call", "Task", "Case", "Email", "Document", "Campaign"),
"quickCreateList" => array("Account", "Contact", "Lead", "Opportunity", "Meeting", "Call", "Task", "Case"),
"tabList" => ["Account", "Contact", "Lead", "Opportunity", "Calendar", "Meeting", "Call", "Task", "Case", "Email", "Document", "Campaign"],
"quickCreateList" => ["Account", "Contact", "Lead", "Opportunity", "Meeting", "Call", "Task", "Case"],
'calendarDefaultEntity' => 'Meeting',
'exportDisabled' => false,
'assignmentEmailNotifications' => false,
'assignmentEmailNotificationsEntityList' => array('Lead', 'Opportunity', 'Task', 'Case'),
'assignmentNotificationsEntityList' => array('Meeting', 'Call', 'Task', 'Email'),
'assignmentEmailNotificationsEntityList' => ['Lead', 'Opportunity', 'Task', 'Case'],
'assignmentNotificationsEntityList' => ['Meeting', 'Call', 'Task', 'Email'],
'emailMessageMaxSize' => 10,
'notificationsCheckInterval' => 10,
'disabledCountQueryEntityList' => array('Email'),
'disabledCountQueryEntityList' => ['Email'],
'maxEmailAccountCount' => 2,
'followCreatedEntities' => false,
'b2cMode' => false,
@@ -112,6 +109,8 @@ return array ( 'database' =>
'massEmailMaxPerHourCount' => 100,
'personalEmailMaxPortionSize' => 10,
'inboundEmailMaxPortionSize' => 20,
'authTokenLifetime' => 0,
'authTokenMaxIdleTime' => 120
'isInstalled' => false,
);

View File

@@ -125,7 +125,9 @@ return array ( 'defaultPermissions' =>
'maxEmailAccountCount',
'massEmailMaxPerHourCount',
'personalEmailMaxPortionSize',
'inboundEmailMaxPortionSize'
'inboundEmailMaxPortionSize',
'authTokenLifetime',
'authTokenMaxIdleTime'
),
'isInstalled' => false,
);

View File

@@ -0,0 +1,70 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014-2015 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
* Website: http://www.espocrm.com
*
* EspoCRM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EspoCRM 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Jobs;
use \Espo\Core\Exceptions;
class AuthTokenControl extends \Espo\Core\Jobs\Base
{
public function run()
{
$authTokenLifetime = $this->getConfig()->get('authTokenLifetime');
$authTokenMaxIdleTime = $this->getConfig()->get('authTokenMaxIdleTime');
if (!$authTokenLifetime && !$authTokenMaxIdleTime) {
return;
}
$whereClause = array();
if ($authTokenLifetime) {
$dt = new \DateTime();
$dt->modify('-' . $authTokenLifetime . ' hours');
$authTokenLifetimeThreshold = $dt->format('Y-m-d H:i:s');
$whereClause['createdAt<'] = $authTokenLifetimeThreshold;
}
if ($authTokenMaxIdleTime) {
$dt = new \DateTime();
$dt->modify('-' . $authTokenMaxIdleTime . ' hours');
$authTokenMaxIdleTimeThreshold = $dt->format('Y-m-d H:i:s');
$whereClause['lastAccess<'] = $authTokenMaxIdleTimeThreshold;
}
$tokenList = $this->getEntityManager()->getRepository('AuthToken')->where($whereClause)->limit(0, 100)->find();
foreach ($tokenList as $token) {
$this->getEntityManager()->removeEntity($token);
}
}
}

View File

@@ -78,8 +78,10 @@ class Cleanup extends \Espo\Core\Jobs\Base
}
}
protected function getCleanupFromDate($format = 'Y-m-d')
protected function getCleanupFromDate()
{
$format = 'Y-m-d';
$datetime = new \DateTime();
$datetime->modify($this->period);
return $datetime->format($format);

View File

@@ -16,7 +16,8 @@
"Cleanup": "Clean-up",
"CheckInboundEmails": "Check Group Email Accounts",
"CheckEmailAccounts": "Check Personal Email Accounts",
"SendEmailReminders": "Send Email Reminders"
"SendEmailReminders": "Send Email Reminders",
"AuthTokenControl": "Auth Token Control"
},
"cronSetup": {
"linux": "Note: Add this line to the crontab file to run Espo Scheduled Jobs:",

View File

@@ -59,7 +59,9 @@
"massEmailMaxPerHourCount": "Max count of emails sent per hour",
"personalEmailMaxPortionSize": "Max email portion size for a personal account fetching",
"inboundEmailMaxPortionSize": "Max email portion size for a group account fetching",
"maxEmailAccountCount": "Max count of personal email accounts per user"
"maxEmailAccountCount": "Max count of personal email accounts per user",
"authTokenLifetime": "Auth Token Lifetime (hours)",
"authTokenMaxIdleTime": "Auth Token Max Idle Time (hours)"
},
"options": {
"weekStart": {
@@ -71,7 +73,9 @@
"recordsPerPageSmall": "Count of records in relatinship panels.",
"outboundEmailIsShared": "Allow users to sent emails via this SMTP.",
"followCreatedEntities": "Users will automatically follow records they created.",
"emailMessageMaxSize": "All inbound emails exceeding a specified size will be skipped."
"emailMessageMaxSize": "All inbound emails exceeding a specified size will be skipped.",
"authTokenLifetime": "Defines how long tokens can exist.\n0 - means no expiration.",
"authTokenMaxIdleTime": "Defines how long since a last access tokens can exist.\n0 - means no expiration."
},
"labels": {
"System": "System",

View File

@@ -2,7 +2,8 @@
{
"label": "Configuration",
"rows": [
[{"name": "authenticationMethod"}]
[{"name": "authenticationMethod"}, {"name": "authTokenLifetime"}],
[false, {"name": "authTokenMaxIdleTime"}]
]
},
{

View File

@@ -265,6 +265,18 @@
"massEmailMaxPerHourCount": {
"type": "int",
"min": 0
},
"authTokenLifetime": {
"type": "float",
"min": 0,
"default": 0,
"tooltip": true
},
"authTokenMaxIdleTime": {
"type": "float",
"min": 0,
"default": 0,
"tooltip": true
}
}
}

View File

@@ -29,7 +29,7 @@
return array(
'EmailTemplate' => array(
0 => array(
array(
'name' => 'Case-to-Email auto-reply',
'subject' => 'Case has been created',
'body' => '<p>{Person.name},</p><p>Case \'{Case.name}\' has been created with number {Case.number} and assigned to {User.name}.</p>',
@@ -37,36 +37,41 @@ return array(
),
),
'ScheduledJob' => array(
0 => array(
array(
'name' => 'Check Group Email Accounts',
'job' => 'CheckInboundEmails',
'status' => 'Active',
'scheduling' => '*/4 * * * *',
),
1 => array(
array(
'name' => 'Check Personal Email Accounts',
'job' => 'CheckEmailAccounts',
'status' => 'Active',
'scheduling' => '*/5 * * * *',
),
2 => array(
array(
'name' => 'Send Email Reminders',
'job' => 'SendEmailReminders',
'status' => 'Active',
'scheduling' => '*/2 * * * *',
),
3 => array(
array(
'name' => 'Clean-up',
'job' => 'Cleanup',
'status' => 'Active',
'scheduling' => '1 1 * * 0',
),
4 => array(
array(
'name' => 'Send Mass Emails',
'job' => 'ProcessMassEmail',
'status' => 'Active',
'scheduling' => '15 * * * *',
),
array(
'name' => 'Auth Token Control',
'job' => 'AuthTokenControl',
'status' => 'Active',
'scheduling' => '*/6 * * * *',
)
),
);