Create an import definition and start the import process

@param string $listId List identifier. Used as the destination object identifier.
@param string $fileName Name of the file to be imported
@return mixed Returns the import process result
356032
public function CreateAndStartListImport($listId, $fileName)
    {
        $import = new ET_Import();
        $import->authStub = $this;
        $import->props = array("Name"=> "SDK Generated Import ".uniqid());
        $import->props["CustomerKey"] = uniqid();
        $import->props["Description"] = "SDK Generated Import";
        $import->props["AllowErrors"] = "true";
        $import->props["DestinationObject"] = array("ID"=>$listId);
        $import->props["FieldMappingType"] = "InferFromColumnHeadings";
        $import->props["FileSpec"] = $fileName;
        $import->props["FileType"] = "CSV";
        $import->props["RetrieveFileTransferLocation"] = array("CustomerKey"=>"ExactTarget Enhanced FTP");
        $import->props["UpdateType"] = "AddAndUpdate";
        $result = $import->post();

        if ($result->status) {
            return $import->start();
        } else {
            throw new Exception("Unable to create import definition due to: ".print_r($result, true));
        }
    }
497093
public function create($appId, $filename, $filepath, array $queryParams = [])
    {
        $response = $this->client->post($this->uri($appId), [
            'multipart' => [
                [
                    'name' => 'upload[file]',
                    'contents' => fopen($filepath, 'r'),
                    'filename' => $filename,
                ],
            ],
            'query' => $queryParams,
        ]);

        return $this->handleResponse($response);
    }
523476
private function createList($listId, $listParameters)
    {
        $providerServiceKey = $listParameters['subscriber_provider'];
        $provider = $this->providerFactory->create($providerServiceKey);
        $subscriberList = new SubscriberList($listId, $provider, $listParameters['merge_fields']);
        $subscriberList->setWebhookUrl($listParameters['webhook_url']);
        $subscriberList->setWebhookSecret($listParameters['webhook_secret']);

        return $subscriberList;
    }
154472
public static function fromFile(string $filename): PhpInterface {
		$interface = new PhpInterface();
		$parser = new FileParser($filename);
		$parser->addVisitor(new InterfaceParserVisitor($interface));
		$parser->addVisitor(new MethodParserVisitor($interface));
		$parser->addVisitor(new ConstantParserVisitor($interface));
		$parser->parse();

		return $interface;
	}
650715
public function readFromFolder($listName, $folderName = '', $isLibrary = false, $limit = NULL, $query = NULL, $view = NULL, $sort = NULL) {
		return $this->read($listName, $limit, $query, $view, $sort, "<Folder>" . ($isLibrary ? '' : 'Lists/') . $listName . '/' . $folderName . "</Folder>" );
	}
743437
public function import()
    {
        try {
            if ($this->getRequestMethod() != Request::HTTP_POST) {
                throw new \common_exception_NotImplemented('Only post method is accepted to import Qti package.');
            }

            // Get valid package parameter
            $package = $this->getUploadedPackage();
            
            // Call service to import package
            \helpers_TimeOutHelper::setTimeOutLimit(\helpers_TimeOutHelper::LONG);
            $report = ImportService::singleton()->importQTIPACKFile(
                $package,
                $this->getDestinationClass(),
                true,
                true,
                true,
                $this->isMetadataGuardiansEnabled(),
                $this->isMetadataValidatorsEnabled(),
                $this->isItemMustExistEnabled(),
                $this->isItemMustBeOverwrittenEnabled()
            );
            \helpers_TimeOutHelper::reset();
            
            \tao_helpers_File::remove($package);
            if ($report->getType() !== \common_report_Report::TYPE_SUCCESS) {
                $message = __("An unexpected error occurred during the import of the IMS QTI Item Package. ");
                //get message of first error report
                if (!empty($report->getErrors())) {
                    $message .= $report->getErrors()[0]->getMessage();
                }
                $this->returnFailure(new \common_Exception($message));
            } else {
                $itemIds = [];
                /** @var \common_report_Report $subReport */
                foreach ($report as $subReport) {
                    $itemIds[] = $subReport->getData()->getUri();
                }
                $this->returnSuccess(array('items' => $itemIds));
            }
        } catch (ExtractException $e) {
            $this->returnFailure(new \common_Exception(__('The ZIP archive containing the IMS QTI Item cannot be extracted.')));
        } catch (ParsingException $e) {
            $this->returnFailure(new \common_Exception(__('The ZIP archive does not contain an imsmanifest.xml file or is an invalid ZIP archive.')));
        } catch (\Exception $e) {
            $this->returnFailure($e);
        }
    }
929411
public function start($identifier = null, $force = false)
    {
        if ($this->currentImport instanceof Import) {
            throw new Exception('Unable to start a new import, please stop the current import first', 1426638560);
        }

        if ($identifier !== null) {
            $existingImport = $this->importRepository->findOneByExternalImportIdentifier($identifier);
            if (!$force  && $existingImport instanceof Import) {
                throw new ImportAlreadyExecutedException(sprintf('An import referring to the external identifier "%s" has already been executed on %s.', $identifier, $existingImport->getStartTime()->format('d.m.Y h:m:s')), 1464028408403);
            }
        }

        $this->currentImport = new Import();
        $this->currentImport->setExternalImportIdentifier($identifier);

        if ($force && isset($existingImport)) {
            $this->addEventMessage(sprintf('ImportService:start', 'Forcing re-import of data set with external identifier "%s".', $identifier), LOG_NOTICE);
        }

        $this->importRepository->add($this->currentImport);
        $this->persistenceManager->persistAll();
    }
1319334
public function getList_emailByEmailIdAndListId($emailID, $listID) {
        return $this->model
            ->where('email_id', $emailID)
            ->where('list_id', $listID)
            ->first()
        ;
    }
1065351
protected function _importSql($fileName)
    {
        //rozbicie zapytań po średniku i końcu linii
        foreach (explode(';' . PHP_EOL, file_get_contents($fileName)) as $query) {
            //wykonanie zapytania
            $this->_performQuery($query);
        }
    }
605837
public function open($filename)
    {
        $this->filename = $filename;
        return $this->zipArchive->open($filename, ZIPARCHIVE::CREATE);
    }
660631
public function importSubscribers($listId = '', $subscribers = array())
    {
        $settings = CmService::$plugin->getSettings();

        try {
            $auth = array(
                'api_key' => (string)$settings->apiKey);
            $client = new \CS_REST_Subscribers(
                $listId,
                $auth);
            $result = $client->import($subscribers, false);

            if($result->was_successful()) {
                $body = $result->response;
                return [
                    'success' => true,
                    'statusCode' => $result->http_status_code,
                    'body' => $body
                ];
            } else {
                return [
                    'success' => false,
                    'statusCode' => $result->http_status_code,
                    'reason' => $result->response->Message
                ];
            }
        } catch (\Exception $e) {
            return [
                'success' => false,
                'reason' => $e->getMessage()
            ];
        }
    }
1244881
public function processImportJobFromFile($list, $file_path, $report_email = false, $postback_url = false, array $options = [ ]) {
        $data = [
            'file' => $file_path,
            'list' => $list
        ];
        return $this->processJob('import', $data, $report_email, $postback_url, [ 'file' ], $options);
    }
497752
public static function open($fileName)
    {
        self::checkRequirements();

        if (!file_exists($fileName) || !is_readable($fileName))
            throw new Exception('Could not open file: '.$fileName);

        $type = self::detectArchiveType($fileName);
        if (!self::canOpenType($type)) {
            return null;
        }

        return new self($fileName, $type);
    }
58003
@Override
    public ExplodedImporter importDirectory(String fileName, Filter<ArchivePath> filter) {
        Validate.notNull(fileName, "FileName must be specified");
        return importDirectory(new File(fileName), filter);
    }
623612
public function create($data, $listId = null)
    {
        if (isset($listId)) {
            return $this->client()->put($data, 'lists/{listId}', ['listId' => $listId]);
        }

        return $this->client()->post($data, 'lists');
    }
334523
public function create(ImportsTable $table, ImportEntity $entity, string $filename) : bool
    {
        $modelName = $this->request->getParam('controller');
        if ($this->request->getParam('plugin')) {
            $modelName = $this->request->getParam('plugin') . '.' . $modelName;
        }

        $data = [
            'filename' => $filename,
            'status' => $table::STATUS_PENDING,
            'model_name' => $modelName,
            'attempts' => 0
        ];

        $entity = $table->patchEntity($entity, $data);

        return (bool)$table->save($entity);
    }
467691
public function createTokenRecord($emailID, $listID, $token) {

        $unsubscribe = new List_Unsubscribe_Token;

        $unsubscribe->email_id = $emailID;
        $unsubscribe->list_id  = $listID;
        $unsubscribe->token    = $token;

        $unsubscribe->save();
    }