Beispiel #1
0
 /**
  * Import action
  *
  * @return void
  */
 protected function doActionImport()
 {
     foreach (\XLite\Logic\Import\Importer::getImportOptionsList() as $key) {
         \XLite\Core\Database::getRepo('XLite\\Model\\Config')->createOption(array('category' => 'Import', 'name' => $key, 'value' => isset(\XLite\Core\Request::getInstance()->options[$key]) ? \XLite\Core\Request::getInstance()->options[$key] : false));
     }
     \XLite\Core\Config::updateInstance();
     $dirTo = LC_DIR_VAR . \XLite\Logic\Import\Importer::getImportDir();
     if (!\Includes\Utils\FileManager::isExists($dirTo)) {
         \Includes\Utils\FileManager::mkdirRecursive($dirTo);
     }
     $filesToImport = array();
     if ($_FILES && isset($_FILES['files']) && $_FILES['files']['name'] && $_FILES['files']['name'][0] && \Includes\Utils\FileManager::isDirWriteable($dirTo)) {
         $list = glob($dirTo . LC_DS . '*');
         if ($list) {
             foreach ($list as $path) {
                 if (is_file($path)) {
                     \Includes\Utils\FileManager::deleteFile($path);
                 }
             }
         }
         $files = $_FILES['files'];
         foreach ($files['name'] as $key => $name) {
             $path = null;
             if ($name && UPLOAD_ERR_OK === $files['error'][$key]) {
                 $path = \Includes\Utils\FileManager::getUniquePath($dirTo, $name ?: $files['name'][$key]);
                 if (move_uploaded_file($files['tmp_name'][$key], $path)) {
                     if (\XLite\Core\Archive::getInstance()->isArchive($path) || 'csv' == substr(strrchr($path, '.'), 1)) {
                         $filesToImport[] = $path;
                     } else {
                         \XLite\Core\TopMessage::addError('The "{{file}}" is not CSV or archive', array('file' => $name));
                         \Includes\Utils\FileManager::deleteFile($path);
                     }
                 } else {
                     $path = null;
                 }
             }
             if (!$path) {
                 \XLite\Core\TopMessage::addError('The "{{file}}" file was not uploaded', array('file' => $name));
             }
         }
     }
     if ($filesToImport) {
         \XLite\Logic\Import\Importer::run(\XLite\Logic\Import\Importer::assembleImportOptions() + array('files' => $filesToImport));
     }
 }
Beispiel #2
0
 /**
  * Initialize
  *
  * @return void
  */
 protected function initialize()
 {
     $dir = \Includes\Utils\FileManager::getRealPath(LC_DIR_VAR . $this->getOptions()->dir);
     // Unpack
     foreach ($this->getOptions()->files as $path) {
         if (\XLite\Core\Archive::getInstance()->isArchive($path)) {
             \XLite\Core\Archive::getInstance()->unpack($path, $dir, true);
             $this->getOptions()->linkedFiles[$path] = \XLite\Core\Archive::getInstance()->getList($path);
         }
     }
     // Delete all logs
     \XLite\Core\Database::getRepo('XLite\\Model\\ImportLog')->clearAll();
     // Convert charsets
     if (static::DEFAULT_CHARSET != $this->getOptions()->charset) {
         $iconv = \XLite\Core\Iconv::getInstance();
         foreach ($this->getCSVList() as $file) {
             $iconv->convertFile($this->getOptions()->charset, static::DEFAULT_CHARSET, $file->getPathname());
         }
     }
     // Preprocess import data
     if ($this->preprocessImport()) {
         // Save import options if they were changed
         $record = \XLite\Core\Database::getRepo('XLite\\Model\\TmpVar')->getEventState('import');
         $record['state'] = \XLite\Core\EventTask::STATE_IN_PROGRESS;
         $record['options'] = $this->getOptions()->getArrayCopy();
         \XLite\Core\Database::getRepo('XLite\\Model\\TmpVar')->setEventState('import', $record);
     }
 }
Beispiel #3
0
 /**
  * Get allowed archive types
  *
  * @return array
  */
 protected function getAllowedArchiveTypes()
 {
     return \XLite\Core\Archive::getInstance()->getTypes();
 }