Merge pull request #4630 from atif-shaikh/CRM-15546
[civicrm-core.git] / CRM / Import / DataSource / CSV.php
index d6d8ccc003f8620044f7e335a1543bef7226c189..12026b7f43696222178427bba254b8d75b9ee775 100644 (file)
@@ -36,23 +36,44 @@ class CRM_Import_DataSource_CSV extends CRM_Import_DataSource {
   CONST
     NUM_ROWS_TO_INSERT = 100;
 
+  /**
+   * Provides information about the data source
+   *
+   * @return array collection of info about this data source
+   *
+   * @access public
+   *
+   */
   function getInfo() {
     return array('title' => ts('Comma-Separated Values (CSV)'));
   }
 
+  /**
+   * Set variables up before form is built
+   *
+   * @access public
+   */
   function preProcess(&$form) {}
 
+  /**
+   * This is function is called by the form object to get the DataSource's
+   * form snippet. It should add all fields necesarry to get the data
+   * uploaded to the temporary table in the DB.
+   *
+   * @param CRM_Core_Form $form
+   *
+   * @return void (operates directly on form argument)
+   * @access public
+   */
   function buildQuickForm(&$form) {
     $form->add('hidden', 'hidden_dataSource', 'CRM_Import_DataSource_CSV');
 
     $config = CRM_Core_Config::singleton();
 
-    // FIXME: why do we limit the file size to 8 MiB if it's larger in config?
-    $uploadFileSize = $config->maxImportFileSize >= 8388608 ? 8388608 : $config->maxImportFileSize;
+    $uploadFileSize = CRM_Core_Config_Defaults::formatUnitSize($config->maxFileSize.'m');
     $uploadSize = round(($uploadFileSize / (1024 * 1024)), 2);
     $form->assign('uploadSize', $uploadSize);
-    $form->add('file', 'uploadFile', ts('Import Data File'), 'size=30 maxlength=255', TRUE);
-
+    $form->add('File', 'uploadFile', ts('Import Data File'), 'size=30 maxlength=255', TRUE);
     $form->setMaxFileSize($uploadFileSize);
     $form->addRule('uploadFile', ts('File size should be less than %1 MBytes (%2 bytes)', array(1 => $uploadSize, 2 => $uploadFileSize)), 'maxfilesize', $uploadFileSize);
     $form->addRule('uploadFile', ts('Input file must be in CSV format'), 'utf8File');
@@ -61,9 +82,13 @@ class CRM_Import_DataSource_CSV extends CRM_Import_DataSource {
     $form->addElement('checkbox', 'skipColumnHeader', ts('First row contains column headers'));
   }
 
+  /**
+   * Process the form submission
+   *
+   * @access public
+   */
   function postProcess(&$params, &$db, &$form) {
     $file = $params['uploadFile']['name'];
-
     $result = self::_CsvToTable($db,
       $file,
       CRM_Utils_Array::value('skipColumnHeader', $params, FALSE),
@@ -219,6 +244,11 @@ class CRM_Import_DataSource_CSV extends CRM_Import_DataSource {
   }
 }
 
+/**
+ * @param $string
+ *
+ * @return string
+ */
 function civicrm_mysql_real_escape_string($string) {
   static $dao = NULL;
   if (!$dao) {