X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;ds=sidebyside;f=CRM%2FImport%2FParser.php;h=b17821f0e4776ca1f76c35d0e55e43e3d5a95183;hb=8cebffb2608fb2f197bae07a6093fa8576b7dd14;hp=738254e5c1898605fbecd18511c7b351e7923840;hpb=13501cd0fd430dc8bc434e8125cea0231dcfe7d0;p=civicrm-core.git
diff --git a/CRM/Import/Parser.php b/CRM/Import/Parser.php
index 738254e5c1..b17821f0e4 100644
--- a/CRM/Import/Parser.php
+++ b/CRM/Import/Parser.php
@@ -286,6 +286,58 @@ abstract class CRM_Import_Parser {
return $params;
}
+ /**
+ * @param $statusID
+ * @param bool $startImport
+ * True when progress bar is to be initiated.
+ * @param $startTimestamp
+ * Initial timstamp when the import was started.
+ * @param $prevTimestamp
+ * Previous timestamp when this function was last called.
+ * @param $totalRowCount
+ * Total number of rows in the import file.
+ *
+ * @return NULL|$currTimestamp
+ */
+ public function progressImport($statusID, $startImport = TRUE, $startTimestamp = NULL, $prevTimestamp = NULL, $totalRowCount = NULL) {
+ $config = CRM_Core_Config::singleton();
+ $statusFile = "{$config->uploadDir}status_{$statusID}.txt";
+
+ if ($startImport) {
+ $status = "
" . ts('No processing status reported yet.') . "
";
+ //do not force the browser to display the save dialog, CRM-7640
+ $contents = json_encode(array(0, $status));
+ file_put_contents($statusFile, $contents);
+ }
+ else {
+ $rowCount = isset($this->_rowCount) ? $this->_rowCount : $this->_lineCount;
+ $currTimestamp = time();
+ $totalTime = ($currTimestamp - $startTimestamp);
+ $time = ($currTimestamp - $prevTimestamp);
+ $recordsLeft = $totalRowCount - $rowCount;
+ if ($recordsLeft < 0) {
+ $recordsLeft = 0;
+ }
+ $estimatedTime = ($recordsLeft / 50) * $time;
+ $estMinutes = floor($estimatedTime / 60);
+ $timeFormatted = '';
+ if ($estMinutes > 1) {
+ $timeFormatted = $estMinutes . ' ' . ts('minutes') . ' ';
+ $estimatedTime = $estimatedTime - ($estMinutes * 60);
+ }
+ $timeFormatted .= round($estimatedTime) . ' ' . ts('seconds');
+ $processedPercent = (int ) (($rowCount * 100) / $totalRowCount);
+ $statusMsg = ts('%1 of %2 records - %3 remaining',
+ array(1 => $rowCount, 2 => $totalRowCount, 3 => $timeFormatted)
+ );
+ $status = " {$statusMsg}
";
+ $contents = json_encode(array($processedPercent, $status));
+
+ file_put_contents($statusFile, $contents);
+ return $currTimestamp;
+ }
+ }
+
/**
* @return array
*/