Exemplo n.º 1
0
 public function import()
 {
     if ($this->getError()) {
         $this->saveImportLog();
         return;
     }
     $this->collectItems();
     if ($this->getError()) {
         $this->saveImportLog();
         return;
     }
     $this->collectItemData();
     if ($this->getError()) {
         $this->saveImportLog();
         return;
     }
     if ($this->isFinishedImport()) {
         $this->collectDeadItem();
     }
     if ($this->getError()) {
         $this->saveImportLog();
         return;
     }
     if ($this->isFinishedImport()) {
         $this->itemCollector->setItemLogFinish();
     }
     $this->saveImportLog();
     parent::import();
 }
Exemplo n.º 2
0
 /**
  * @see SugarView::display()
  */
 public function display()
 {
     global $mod_strings, $app_strings, $current_user;
     global $sugar_config;
     if ($this->importSource === FALSE) {
         $GLOBALS['log']->fatal("Found invalid adapter");
         $this->handleImportError($mod_strings['LBL_EXTERNAL_ERROR_NO_SOURCE']);
     }
     $columncount = isset($_REQUEST['columncount']) ? $_REQUEST['columncount'] : '';
     $fieldKeyTranslator = $this->getSugarToExternalFieldMapping($columncount);
     try {
         $this->importSource->loadDataSet($this->recordsPerImport);
     } catch (Exception $e) {
         $GLOBALS['log']->fatal("Unable to import external feed, exception: " . $e->getMessage());
         $this->handleImportError($mod_strings['LBL_EXTERNAL_ERROR_FEED_CORRUPTED']);
     }
     if (!ImportCacheFiles::ensureWritable()) {
         $GLOBALS['log']->fatal($mod_strings['LBL_ERROR_IMPORT_CACHE_NOT_WRITABLE']);
         $this->handleImportError($mod_strings['LBL_ERROR_IMPORT_CACHE_NOT_WRITABLE']);
     }
     $importer = new Importer($this->importSource, $this->bean);
     $importer->setFieldKeyTranslator($fieldKeyTranslator);
     $importer->import();
     //Send back our results.
     $metaResult = array('done' => FALSE, 'totalRecordCount' => $this->importSource->getTotalRecordCount());
     echo json_encode($metaResult);
     sugar_cleanup(TRUE);
 }
Exemplo n.º 3
0
 public function testImport()
 {
     $results = [[['id' => 1, 'madeIn' => 'China', 'title' => 'Phone'], ['id' => 2, 'madeIn' => 'USA', 'title' => 'Chicken wings'], ['id' => 3, 'madeIn' => 'Russia', 'title' => 'Topol-M']], [['id' => 4, 'madeIn' => 'France', 'title' => 'Wine'], ['id' => 5, 'madeIn' => 'Germany', 'title' => 'Audi'], ['id' => 6, 'madeIn' => 'Denmark', 'title' => 'Tulip']]];
     $reader = $this->getReaderMock($this, $results);
     $fields = ['madeIn' => ['name' => 'two'], 'id' => ['name' => 'one'], 'title' => ['name' => 'three']];
     $importer = new Importer($this->db, $this->table, $fields);
     $tableName = $importer->import($reader);
     $this->assertEquals(6, $this->db->execute('SELECT COUNT(*) count FROM ?F', [$tableName])->fetchResult());
     $this->assertEquals('USA', $this->db->execute("SELECT two FROM ?F WHERE one = '2'", [$tableName])->fetchResult());
     $this->assertEquals('Tulip', $this->db->execute("SELECT three FROM ?F WHERE one = '6'", [$tableName])->fetchResult());
 }
Exemplo n.º 4
0
 /** 
  * @see SugarView::display()
  */
 public function display()
 {
     global $mod_strings, $sugar_config;
     // Check to be sure we are getting an import file that is in the right place
     if (realpath(dirname($_REQUEST['tmp_file']) . '/') != realpath($sugar_config['upload_dir'])) {
         trigger_error($mod_strings['LBL_CANNOT_OPEN'], E_USER_ERROR);
     }
     // Open the import file
     $importSource = new ImportFile($_REQUEST['tmp_file'], $_REQUEST['custom_delimiter'], html_entity_decode($_REQUEST['custom_enclosure'], ENT_QUOTES));
     //Ensure we have a valid file.
     if (!$importSource->fileExists()) {
         trigger_error($mod_strings['LBL_CANNOT_OPEN'], E_USER_ERROR);
     }
     $importer = new Importer($importSource, $this->bean);
     $importer->import();
 }
Exemplo n.º 5
0
 /**
  * @see SugarView::display()
  */
 public function display()
 {
     global $mod_strings, $sugar_config;
     // Check to be sure we are getting an import file that is in the right place
     $uploadFile = "upload://" . basename($_REQUEST['tmp_file']);
     if (!file_exists($uploadFile)) {
         trigger_error($mod_strings['LBL_CANNOT_OPEN'], E_USER_ERROR);
     }
     // Open the import file
     $importSource = new ImportFile($uploadFile, $_REQUEST['custom_delimiter'], html_entity_decode($_REQUEST['custom_enclosure'], ENT_QUOTES));
     //Ensure we have a valid file.
     if (!$importSource->fileExists()) {
         trigger_error($mod_strings['LBL_CANNOT_OPEN'], E_USER_ERROR);
     }
     if (!ImportCacheFiles::ensureWritable()) {
         trigger_error($mod_strings['LBL_ERROR_IMPORT_CACHE_NOT_WRITABLE'], E_USER_ERROR);
     }
     $importer = new Importer($importSource, $this->bean);
     $importer->import();
 }
Exemplo n.º 6
0
 public function testParentsAreRelatedDuringImport()
 {
     $file = 'upload://test50438.csv';
     $ret = file_put_contents($file, $this->fileArr);
     $this->assertGreaterThan(0, $ret, 'Failed to write to ' . $file . ' for content ' . var_export($this->fileArr, true));
     $importSource = new ImportFile($file, ',', '"');
     $bean = loadBean('Calls');
     $_REQUEST['columncount'] = 5;
     $_REQUEST['colnum_0'] = 'id';
     $_REQUEST['colnum_1'] = 'subject';
     $_REQUEST['colnum_2'] = 'status';
     $_REQUEST['colnum_3'] = 'parent_type';
     $_REQUEST['colnum_4'] = 'parent_id';
     $_REQUEST['import_module'] = 'Contacts';
     $_REQUEST['importlocale_charset'] = 'UTF-8';
     $_REQUEST['importlocale_timezone'] = 'GMT';
     $_REQUEST['importlocale_default_currency_significant_digits'] = '2';
     $_REQUEST['importlocale_currency'] = '-99';
     $_REQUEST['importlocale_dec_sep'] = '.';
     $_REQUEST['importlocale_currency'] = '-99';
     $_REQUEST['importlocale_default_locale_name_format'] = 's f l';
     $_REQUEST['importlocale_num_grp_sep'] = ',';
     $_REQUEST['importlocale_dateformat'] = 'm/d/y';
     $_REQUEST['importlocale_timeformat'] = 'h:i:s';
     $importer = new Importer($importSource, $bean);
     $importer->import();
     //fetch the bean using the passed in id and get related contacts
     require_once 'modules/Calls/Call.php';
     $call = new Call();
     $call->retrieve($this->call_id);
     $call->load_relationship('contacts');
     $related_contacts = $call->contacts->get();
     //test that the contact id is in the array of related contacts.
     $this->assertContains($this->contact->id, $related_contacts, ' Contact was not related during simulated import despite being set in related parent id');
     unset($call);
     /*
     if (is_file($file)) {
         unlink($file);
     }
     */
 }
Exemplo n.º 7
0
 /**
  * @dataProvider providerCsvData
  */
 public function testDateTimeImport($content_idx, $expected_datetime, $date_format, $time_format)
 {
     $file = $GLOBALS['sugar_config']['upload_dir'] . 'test.csv';
     $ret = file_put_contents($file, self::$CsvContent[$content_idx]);
     $this->assertGreaterThan(0, $ret, 'Failed to write to ' . $file . ' for content ' . $content_idx);
     $importSource = new ImportFile($file, ',', '"');
     $bean = loadBean($this->_importModule);
     $_REQUEST['columncount'] = 2;
     $_REQUEST['colnum_0'] = 'date_entered';
     $_REQUEST['colnum_1'] = 'last_name';
     $_REQUEST['import_module'] = 'Contacts';
     $_REQUEST['importlocale_charset'] = 'UTF-8';
     $_REQUEST['importlocale_dateformat'] = $date_format;
     $_REQUEST['importlocale_timeformat'] = $time_format;
     $_REQUEST['importlocale_timezone'] = 'GMT';
     $_REQUEST['importlocale_default_currency_significant_digits'] = '2';
     $_REQUEST['importlocale_currency'] = '-99';
     $_REQUEST['importlocale_dec_sep'] = '.';
     $_REQUEST['importlocale_currency'] = '-99';
     $_REQUEST['importlocale_default_locale_name_format'] = 's f l';
     $_REQUEST['importlocale_num_grp_sep'] = ',';
     $importer = new Importer($importSource, $bean);
     $importer->import();
     $query = "SELECT date_entered from contacts where created_by='{$GLOBALS['current_user']->id}'";
     $result = $GLOBALS['db']->query($query);
     $row = $GLOBALS['db']->fetchByAssoc($result);
     $this->assertEquals($expected_datetime, $GLOBALS['db']->fromConvert($row['date_entered'], 'datetime'), 'Got incorrect date_entered.');
 }
Exemplo n.º 8
0
<?php

session_start();
include "../../Includes.php";
function redirect()
{
    header("location: ../../index.php?info=admin/vartotojai");
}
$login = new Session(1);
if (!$login->isLogedin()) {
    die("You must loged in!");
}
$file = $_FILES['file'];
if ($file['error'] != 0) {
    die("<p style='color:red;'>Ivyko klaida ikeliant faila! Error nr: " . $file['error'] . "</p>");
}
if ($file['type'] != "application/vnd.ms-excel") {
    die("<p style='color:red;'>Blogas failo formatas!</p>");
}
$importer = new Importer($file['tmp_name']);
$importer->import();
echo "<p style='color:green;'>Importuota.</p>";
Exemplo n.º 9
0
 /**
  * Check if semi-colon separated non-primary mails
  * are being imported properly
  *
  * @dataProvider providerEmailImport
  */
 public function testEmailImport($module, $lastName, $expected, $test)
 {
     $fileCreated = sugar_file_put_contents($this->_file, $test);
     $this->assertGreaterThan(0, $fileCreated, 'Failed to write to ' . $this->_file);
     // Create the ImportFile the Importer uses from our CSV
     $importSource = new ImportFile($this->_file, ',', '"');
     // Create the bean type we're importing
     $this->_importObject = $bean = new $module();
     // Setup needed $_REQUEST data
     $_REQUEST['columncount'] = 2;
     $_REQUEST['colnum_0'] = 'email_addresses_non_primary';
     $_REQUEST['colnum_1'] = 'last_name';
     // A few changed for Accounts module
     if ($module == "Account") {
         $_REQUEST['columncount'] = 3;
         $_REQUEST['colnum_1'] = 'name';
         $_REQUEST['colnum_2'] = 'team_id';
     }
     $_REQUEST['import_module'] = $bean->module_dir;
     $_REQUEST['importlocale_charset'] = 'UTF-8';
     $_REQUEST['importlocale_dateformat'] = "m/d/Y";
     $_REQUEST['importlocale_timeformat'] = "h:i a";
     $_REQUEST['importlocale_timezone'] = 'GMT';
     $_REQUEST['importlocale_default_currency_significant_digits'] = '2';
     $_REQUEST['importlocale_currency'] = '-99';
     $_REQUEST['importlocale_dec_sep'] = '.';
     $_REQUEST['importlocale_currency'] = '-99';
     $_REQUEST['importlocale_default_locale_name_format'] = 's f l';
     $_REQUEST['importlocale_num_grp_sep'] = ',';
     // Create the Importer and try importing
     $importer = new Importer($importSource, $bean);
     $importer->import();
     // Check if the Lead is created
     $query = "SELECT id FROM {$bean->table_name} WHERE {$_REQUEST['colnum_1']} = '{$lastName}'";
     $result = $GLOBALS['db']->query($query);
     $row = $GLOBALS['db']->fetchByAssoc($result);
     $this->assertNotEmpty($row['id'], $module . ' not created');
     // Save Lead id for easier cleanup after test
     $this->_cleanId = $row['id'];
     // Check if all of the mails got created and linked properly
     foreach ($expected as $mail) {
         // Check if the mail got created
         $query = "SELECT id FROM email_addresses WHERE email_address = '{$mail}'";
         $result = $GLOBALS['db']->query($query);
         $row = $GLOBALS['db']->fetchByAssoc($result);
         $this->assertNotEmpty($row['id'], 'Mail not created');
         $mailId = $row['id'];
         // Check if the mail is linked
         $query = "SELECT id FROM email_addr_bean_rel WHERE email_address_id = '{$mailId}' AND bean_module = '{$bean->module_dir}' AND deleted = 0 AND primary_address = 0";
         $result = $GLOBALS['db']->query($query);
         $row = $GLOBALS['db']->fetchByAssoc($result);
         $this->assertNotEmpty($row['id'], 'Mail not linked');
     }
 }
Exemplo n.º 10
0
/**
 * Includes a file with an empty variable scope.
 *
 * You can "use" this function with PHP 5.6 if you like.
 * ```php
 * use function Brads\import;
 * ```
 *
 * @param  string     $file    The path to the file to import.
 * @param  array|null $scope   A custom scope to give to the file.
 * @param  boolean    $require Whether to use require() or include().
 * @return mixed               Anything the file returns.
 */
function import($file, $scope = null, $require = true)
{
    return Importer::import($file, $scope, $require);
}
Exemplo n.º 11
0
 function showImportRes()
 {
     /* update last page */
     $_SESSION['LASTPAGE'] = substr($_SESSION['LASTPAGE'], 0, strripos($_SESSION['LASTPAGE'], "res"));
     require_once "importer.php";
     $importer = new Importer();
     $result = $importer->import();
     $displaySysAdmin = new DisplaySysAdmin();
     if ($result == "") {
         $content = $displaySysAdmin->displaySuccess(Language::messageToolsImportOk());
     } else {
         $content = $displaySysAdmin->displayError(Language::messageToolsImportNotOk($result));
     }
     return $displaySysAdmin->showImport($content);
 }