1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-19 16:01:34 +02:00

Working on tests

This commit is contained in:
Hillel Coren 2018-03-11 12:10:29 +02:00
parent 5cfa19a5c8
commit bf5ba05943
4 changed files with 42 additions and 45 deletions

View File

@ -158,7 +158,7 @@ if (! defined('APP_NAME')) {
define('MAX_DOCUMENT_SIZE', env('MAX_DOCUMENT_SIZE', 10000)); // KB
define('MAX_EMAIL_DOCUMENTS_SIZE', env('MAX_EMAIL_DOCUMENTS_SIZE', 10000)); // Total KB
define('MAX_ZIP_DOCUMENTS_SIZE', env('MAX_EMAIL_DOCUMENTS_SIZE', 30000)); // Total KB (uncompressed)
define('MAX_EMAILS_SENT_PER_HOUR', 90);
define('MAX_EMAILS_SENT_PER_DAY', 80);
define('DOCUMENT_PREVIEW_SIZE', env('DOCUMENT_PREVIEW_SIZE', 300)); // pixels
define('DEFAULT_FONT_SIZE', 9);
define('DEFAULT_HEADER_FONT', 1); // Roboto

View File

@ -378,26 +378,26 @@ class ContactMailer extends Mailer
$key = $account->company_id;
// http://stackoverflow.com/questions/1375501/how-do-i-throttle-my-sites-api-users
$hour = 60 * 60;
$hour_limit = MAX_EMAILS_SENT_PER_HOUR;
$hour_throttle = Cache::get("email_hour_throttle:{$key}", null);
$day = 60 * 60 * 24;
$day_limit = MAX_EMAILS_SENT_PER_DAY;
$day_throttle = Cache::get("email_day_throttle:{$key}", null);
$last_api_request = Cache::get("last_email_request:{$key}", 0);
$last_api_diff = time() - $last_api_request;
if (is_null($hour_throttle)) {
$new_hour_throttle = 0;
if (is_null($day_throttle)) {
$new_day_throttle = 0;
} else {
$new_hour_throttle = $hour_throttle - $last_api_diff;
$new_hour_throttle = $new_hour_throttle < 0 ? 0 : $new_hour_throttle;
$new_hour_throttle += $hour / $hour_limit;
$hour_hits_remaining = floor(($hour - $new_hour_throttle) * $hour_limit / $hour);
$hour_hits_remaining = $hour_hits_remaining >= 0 ? $hour_hits_remaining : 0;
$new_day_throttle = $day_throttle - $last_api_diff;
$new_day_throttle = $new_day_throttle < 0 ? 0 : $new_day_throttle;
$new_day_throttle += $day / $day_limit;
$day_hits_remaining = floor(($day - $new_day_throttle) * $day_limit / $day);
$day_hits_remaining = $day_hits_remaining >= 0 ? $day_hits_remaining : 0;
}
Cache::put("email_hour_throttle:{$key}", $new_hour_throttle, 60);
Cache::put("email_day_throttle:{$key}", $new_day_throttle, 60);
Cache::put("last_email_request:{$key}", time(), 60);
if ($new_hour_throttle > $hour) {
if ($new_day_throttle > $day) {
$errorEmail = env('ERROR_EMAIL');
if ($errorEmail && ! Cache::get("throttle_notified:{$key}")) {
Mail::raw('Account Throttle', function ($message) use ($errorEmail, $account) {
@ -406,7 +406,7 @@ class ContactMailer extends Mailer
->subject("Email throttle triggered for account " . $account->id);
});
}
Cache::put("throttle_notified:{$key}", true, 60);
Cache::put("throttle_notified:{$key}", true, 60 * 24);
return true;
}

View File

@ -134,8 +134,6 @@ class PaymentService extends BaseService
}
}
return $paymentDriver->completeOnsitePurchase(false, $paymentMethod);
/*
try {
return $paymentDriver->completeOnsitePurchase(false, $paymentMethod);
} catch (Exception $exception) {
@ -151,7 +149,6 @@ class PaymentService extends BaseService
return false;
}
*/
}
public function save($input, $payment = null, $invoice = null)

56
composer.lock generated
View File

@ -393,16 +393,16 @@
},
{
"name": "aws/aws-sdk-php",
"version": "3.52.22",
"version": "3.52.23",
"source": {
"type": "git",
"url": "https://github.com/aws/aws-sdk-php.git",
"reference": "f42076f6347590dfbf4de7befc19bb660be0ea22"
"reference": "3ce95b96c217a699168d937c4ed700e6a27ec783"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/f42076f6347590dfbf4de7befc19bb660be0ea22",
"reference": "f42076f6347590dfbf4de7befc19bb660be0ea22",
"url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/3ce95b96c217a699168d937c4ed700e6a27ec783",
"reference": "3ce95b96c217a699168d937c4ed700e6a27ec783",
"shasum": ""
},
"require": {
@ -469,7 +469,7 @@
"s3",
"sdk"
],
"time": "2018-03-07 22:55:58"
"time": "2018-03-08 22:51:35"
},
{
"name": "bacon/bacon-qr-code",
@ -4348,16 +4348,16 @@
},
{
"name": "laravel/tinker",
"version": "v1.0.4",
"version": "v1.0.5",
"source": {
"type": "git",
"url": "https://github.com/laravel/tinker.git",
"reference": "eb8d3cfb41b7f74fb0ef4724e459d44f4cbb35b8"
"reference": "94f6daf2131508cebd11cd6f8632ba586d7ecc41"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/laravel/tinker/zipball/eb8d3cfb41b7f74fb0ef4724e459d44f4cbb35b8",
"reference": "eb8d3cfb41b7f74fb0ef4724e459d44f4cbb35b8",
"url": "https://api.github.com/repos/laravel/tinker/zipball/94f6daf2131508cebd11cd6f8632ba586d7ecc41",
"reference": "94f6daf2131508cebd11cd6f8632ba586d7ecc41",
"shasum": ""
},
"require": {
@ -4407,7 +4407,7 @@
"laravel",
"psysh"
],
"time": "2018-03-06 13:48:07"
"time": "2018-03-06 17:34:36"
},
{
"name": "laravelcollective/html",
@ -4873,16 +4873,16 @@
},
{
"name": "maatwebsite/excel",
"version": "2.1.26",
"version": "2.1.27",
"source": {
"type": "git",
"url": "https://github.com/Maatwebsite/Laravel-Excel.git",
"reference": "c93b4658e73e9bafc33ad26959402ab8e9722ca2"
"reference": "ea758fe5a9d33e0d88b40f099d1df652a0c99d38"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Maatwebsite/Laravel-Excel/zipball/c93b4658e73e9bafc33ad26959402ab8e9722ca2",
"reference": "c93b4658e73e9bafc33ad26959402ab8e9722ca2",
"url": "https://api.github.com/repos/Maatwebsite/Laravel-Excel/zipball/ea758fe5a9d33e0d88b40f099d1df652a0c99d38",
"reference": "ea758fe5a9d33e0d88b40f099d1df652a0c99d38",
"shasum": ""
},
"require": {
@ -4947,7 +4947,7 @@
"import",
"laravel"
],
"time": "2018-03-05 10:01:36"
"time": "2018-03-09 13:14:19"
},
{
"name": "maximebf/debugbar",
@ -5438,20 +5438,20 @@
},
{
"name": "nesbot/carbon",
"version": "1.23.0",
"version": "1.24.1",
"source": {
"type": "git",
"url": "https://github.com/briannesbitt/Carbon.git",
"reference": "4a874a39b2b00d7e0146cd46fab6f47c41ce9e65"
"reference": "ef12cbd8ba5ce624f0a6a95e0850c4cc13e71e41"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/4a874a39b2b00d7e0146cd46fab6f47c41ce9e65",
"reference": "4a874a39b2b00d7e0146cd46fab6f47c41ce9e65",
"url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/ef12cbd8ba5ce624f0a6a95e0850c4cc13e71e41",
"reference": "ef12cbd8ba5ce624f0a6a95e0850c4cc13e71e41",
"shasum": ""
},
"require": {
"php": ">=5.3.0",
"php": ">=5.3.9",
"symfony/translation": "~2.6 || ~3.0 || ~4.0"
},
"require-dev": {
@ -5487,7 +5487,7 @@
"datetime",
"time"
],
"time": "2018-02-28 09:22:05"
"time": "2018-03-09 15:49:34"
},
{
"name": "nikic/php-parser",
@ -7426,24 +7426,24 @@
},
{
"name": "paragonie/constant_time_encoding",
"version": "v2.2.1",
"version": "v2.2.2",
"source": {
"type": "git",
"url": "https://github.com/paragonie/constant_time_encoding.git",
"reference": "7c74c5d08761ead7b5e89d07c854bc28eb0b2186"
"reference": "eccf915f45f911bfb189d1d1638d940ec6ee6e33"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/paragonie/constant_time_encoding/zipball/7c74c5d08761ead7b5e89d07c854bc28eb0b2186",
"reference": "7c74c5d08761ead7b5e89d07c854bc28eb0b2186",
"url": "https://api.github.com/repos/paragonie/constant_time_encoding/zipball/eccf915f45f911bfb189d1d1638d940ec6ee6e33",
"reference": "eccf915f45f911bfb189d1d1638d940ec6ee6e33",
"shasum": ""
},
"require": {
"php": "^7"
},
"require-dev": {
"phpunit/phpunit": "^6",
"vimeo/psalm": "^0.3|^1"
"phpunit/phpunit": "^6|^7",
"vimeo/psalm": "^1"
},
"type": "library",
"autoload": {
@ -7484,7 +7484,7 @@
"hex2bin",
"rfc4648"
],
"time": "2018-01-23 00:54:57"
"time": "2018-03-10 19:47:49"
},
{
"name": "paragonie/random_compat",