From 12e4bf4710752a940c3e6f25161e033a97efdbf5 Mon Sep 17 00:00:00 2001 From: atif-shaikh Date: Fri, 2 Jan 2015 19:47:03 +0530 Subject: [PATCH] CRM-14199 Enhancement - Incorrect Math in Import routines https://issues.civicrm.org/jira/browse/CRM-14199 --- CRM/Activity/Import/Form/DataSource.php | 2 +- CRM/Contribute/Import/Form/DataSource.php | 2 +- CRM/Core/Config/Defaults.php | 8 +++++++- CRM/Custom/Import/Form/DataSource.php | 2 +- CRM/Event/Import/Form/DataSource.php | 2 +- CRM/Import/DataSource/CSV.php | 2 +- CRM/Member/Import/Form/DataSource.php | 2 +- 7 files changed, 13 insertions(+), 7 deletions(-) diff --git a/CRM/Activity/Import/Form/DataSource.php b/CRM/Activity/Import/Form/DataSource.php index b5e9c7a9d1..c026cba134 100644 --- a/CRM/Activity/Import/Form/DataSource.php +++ b/CRM/Activity/Import/Form/DataSource.php @@ -59,7 +59,7 @@ class CRM_Activity_Import_Form_DataSource extends CRM_Core_Form { //Setting Upload File Size $config = CRM_Core_Config::singleton(); - $uploadFileSize = CRM_Core_Config_Defaults::formatUnitSize($config->maxFileSize.'m'); + $uploadFileSize = CRM_Core_Config_Defaults::formatUnitSize($config->maxFileSize.'m', TRUE); $uploadSize = round(($uploadFileSize / (1024 * 1024)), 2); $this->assign('uploadSize', $uploadSize); diff --git a/CRM/Contribute/Import/Form/DataSource.php b/CRM/Contribute/Import/Form/DataSource.php index b4ffac2ff5..0db01f96ff 100644 --- a/CRM/Contribute/Import/Form/DataSource.php +++ b/CRM/Contribute/Import/Form/DataSource.php @@ -59,7 +59,7 @@ class CRM_Contribute_Import_Form_DataSource extends CRM_Core_Form { //Setting Upload File Size $config = CRM_Core_Config::singleton(); - $uploadFileSize = CRM_Core_Config_Defaults::formatUnitSize($config->maxFileSize.'m'); + $uploadFileSize = CRM_Core_Config_Defaults::formatUnitSize($config->maxFileSize.'m', TRUE); $uploadSize = round(($uploadFileSize / (1024 * 1024)), 2); $this->assign('uploadSize', $uploadSize); diff --git a/CRM/Core/Config/Defaults.php b/CRM/Core/Config/Defaults.php index ccb1d5bff6..ddc92b5614 100644 --- a/CRM/Core/Config/Defaults.php +++ b/CRM/Core/Config/Defaults.php @@ -96,9 +96,15 @@ class CRM_Core_Config_Defaults { if ($checkForPostMax) { $maxImportFileSize = self::formatUnitSize(ini_get('upload_max_filesize')); - if($maxImportFileSize > $size) { + $postMaxSize = self::formatUnitSize(ini_get('post_max_size')); + if ($maxImportFileSize > $postMaxSize && $postMaxSize == $size) { CRM_Core_Session::setStatus(ts("Note: Upload max filesize ('upload_max_filesize') should not exceed Post max size ('post_max_size') as defined in PHP.ini, please check with your system administrator."), ts("Warning"), "alert"); } + //respect php.ini upload_max_filesize + if ($size > $maxImportFileSize) { + $size = $maxImportFileSize; + CRM_Core_Session::setStatus(ts("Note: Please verify your configuration for Maximum File Size (in MB) Administrator >> System Settings >> Misc. It should support 'upload_max_size' as defined in PHP.ini.Please check with your system administrator.", array(1 => CRM_Utils_System::url('civicrm/admin/setting/misc', 'reset=1'))), ts("Warning"), "alert"); + } } return $size; } diff --git a/CRM/Custom/Import/Form/DataSource.php b/CRM/Custom/Import/Form/DataSource.php index 71d9c497e6..8668eadbd3 100644 --- a/CRM/Custom/Import/Form/DataSource.php +++ b/CRM/Custom/Import/Form/DataSource.php @@ -89,7 +89,7 @@ class CRM_Custom_Import_Form_DataSource extends CRM_Core_Form { //Setting Upload File Size $config = CRM_Core_Config::singleton(); - $uploadFileSize = CRM_Core_Config_Defaults::formatUnitSize($config->maxFileSize.'m'); + $uploadFileSize = CRM_Core_Config_Defaults::formatUnitSize($config->maxFileSize.'m', TRUE); $uploadSize = round(($uploadFileSize / (1024 * 1024)), 2); $this->assign('uploadSize', $uploadSize); diff --git a/CRM/Event/Import/Form/DataSource.php b/CRM/Event/Import/Form/DataSource.php index 3d4505ec9c..58b2bdfe5e 100644 --- a/CRM/Event/Import/Form/DataSource.php +++ b/CRM/Event/Import/Form/DataSource.php @@ -59,7 +59,7 @@ class CRM_Event_Import_Form_DataSource extends CRM_Core_Form { //Setting Upload File Size $config = CRM_Core_Config::singleton(); - $uploadFileSize = CRM_Core_Config_Defaults::formatUnitSize($config->maxFileSize.'m'); + $uploadFileSize = CRM_Core_Config_Defaults::formatUnitSize($config->maxFileSize.'m', TRUE); $uploadSize = round(($uploadFileSize / (1024 * 1024)), 2); $this->assign('uploadSize', $uploadSize); diff --git a/CRM/Import/DataSource/CSV.php b/CRM/Import/DataSource/CSV.php index 1df59f2f20..3ebc79d3e3 100644 --- a/CRM/Import/DataSource/CSV.php +++ b/CRM/Import/DataSource/CSV.php @@ -67,7 +67,7 @@ class CRM_Import_DataSource_CSV extends CRM_Import_DataSource { $config = CRM_Core_Config::singleton(); - $uploadFileSize = CRM_Core_Config_Defaults::formatUnitSize($config->maxFileSize.'m'); + $uploadFileSize = CRM_Core_Config_Defaults::formatUnitSize($config->maxFileSize.'m', TRUE); $uploadSize = round(($uploadFileSize / (1024 * 1024)), 2); $form->assign('uploadSize', $uploadSize); $form->add('File', 'uploadFile', ts('Import Data File'), 'size=30 maxlength=255', TRUE); diff --git a/CRM/Member/Import/Form/DataSource.php b/CRM/Member/Import/Form/DataSource.php index 8e9f3054ef..e30f0225fa 100644 --- a/CRM/Member/Import/Form/DataSource.php +++ b/CRM/Member/Import/Form/DataSource.php @@ -59,7 +59,7 @@ class CRM_Member_Import_Form_DataSource extends CRM_Core_Form { //Setting Upload File Size $config = CRM_Core_Config::singleton(); - $uploadFileSize = CRM_Core_Config_Defaults::formatUnitSize($config->maxFileSize.'m'); + $uploadFileSize = CRM_Core_Config_Defaults::formatUnitSize($config->maxFileSize.'m', TRUE); $uploadSize = round(($uploadFileSize / (1024 * 1024)), 2); $this->assign('uploadSize', $uploadSize); -- 2.25.1