29 if(!isset($params[
"FEED_TYPE"]) || $params[
"FEED_TYPE"] ==
'')
32 if($this->feedType ==
"ORDER_ACK")
33 $this->feedType =
"order-ack";
35 $this->feedType = mb_strtolower($params[
"FEED_TYPE"]);
37 if(!isset($params[
"SITE_ID"]) || $params[
"SITE_ID"] ==
'')
40 $this->siteId = $params[
"SITE_ID"];
42 if(isset($params[
"COVER_TAG"]) && $params[
"COVER_TAG"] <>
'')
43 $this->coverTag = $params[
"COVER_TAG"];
45 if(isset($params[
"SCHEMA_FILE_NAME"]))
46 $this->schemeFileName = $params[
"SCHEMA_FILE_NAME"];
48 if(isset($params[
"TIMER"]))
49 $this->timer = $params[
"TIMER"];
51 $this->fileNameSalt = time();
52 $this->remotePath =
"/store/".$this->feedType;
53 $this->path = \Bitrix\Sale\TradingPlatform\Ebay\Helper::getSftpPath().
"/".
$this->feedType;
71 $feedDataRes = QueueTable::getList(array(
73 "FEED_TYPE" => $this->feedType
77 $filePrepared =
false;
79 while($feedData = $feedDataRes->fetch())
83 $fileXml = $this->path.
"/xml/".$this->feedType.
"_".$this->fileNameSalt.
".xml";
90 if(mb_strtolower(SITE_CHARSET) !=
'utf-8')
91 $feedData[
"DATA"] = \Bitrix\Main\Text\Encoding::convertEncoding($feedData[
"DATA"], SITE_CHARSET,
'UTF-8');
93 $res = file_put_contents($fileXml, $feedData[
"DATA"], FILE_APPEND);
96 QueueTable::delete($feedData[
"ID"]);
98 throw new SystemException(
"Can't flush data feed \"".$this->feedType.
"\" to file ".$fileXml);
101 if($this->coverTag !==
null && $filePrepared)
102 file_put_contents($fileXml,
"</".$this->coverTag.
">\n", FILE_APPEND);
129 $tmpFile = $this->
packData($xmlFile);
130 $zipFile = new \Bitrix\Main\IO\File($tmpFile);
131 $zipFile->rename($this->path.
"/zip/".$this->feedType.
"_".$this->fileNameSalt.
".zip");
134 $checkResultsInterval = 5;
135 \Bitrix\Sale\TradingPlatform\Ebay\Agent::add(
'RESULTS', $this->siteId, $checkResultsInterval,
true);
142 $tmpDir = $this->path.
"/tmp";
143 $archiveName = $tmpDir.
"/".$this->feedType.
"_".$this->fileNameSalt.
".zip";
144 $oArchiver = \CBXArchive::GetArchive($archiveName,
"ZIP");
145 $oArchiver->SetOptions(array(
146 "REMOVE_PATH" => $this->path.
"/xml",
147 "ADD_PATH" => $this->feedType
150 if($oArchiver->Pack($xmlFile))
151 \Bitrix\Main\IO\File::deleteFile($xmlFile);
158 $directory = new \Bitrix\Main\IO\Directory($this->path.
"/zip");
160 if(!$directory->isExists())
161 throw new SystemException(
"Directory".$this->path.
"/zip does not exist! ".__METHOD__);
163 $filesToSend = $directory->getChildren();
165 if(empty($filesToSend))
168 $sftp = \Bitrix\Sale\TradingPlatform\Ebay\Helper::getSftp($this->siteId);
175 for($i = 0; $i < count($filesToSend); $i++)
177 $directoryEntry = $filesToSend[$i];
178 $localPath = $directoryEntry->getPath();
180 if((!($directoryEntry instanceof \
Bitrix\Main\
IO\
File)) || GetFileExtension($localPath) !=
"zip")
183 $remote = $this->remotePath.
"/".$directoryEntry->getName();
187 if($this->timer !==
null && !$this->timer->check(15))
193 if($sftp->uploadFile($localPath, $remote))
195 $directoryEntry->delete();
196 ResultsTable::add(array(
197 "FILENAME" => $directoryEntry->getName(),
198 "FEED_TYPE" => $this->feedType,