30 $this->exportId = $exportId;
37 $resProfiles = ExportProfileTable::getList(array(
38 "filter" => array(
'=ID' => $exportId),
39 "select" => array(
"PROCESS"),
42 $profile = $resProfiles->fetch();
45 if (!empty($profile[
'PROCESS']) && !(array_key_exists(
'STOP', $profile[
'PROCESS']) && $profile[
'PROCESS'][
'STOP']))
46 return $profile[
'PROCESS'];
54 $type = Feed\Manager::prepareType($type);
56 $journal = self::getStatistic($type, $exportId);
57 $count = $journal[$type][
'COUNT'] ? $journal[$type][
'COUNT'] : 0;
59 $detailsMsg =
'<p>' . date(
'G:i - ') .
Loc::getMessage(
'VK_JOURNAL_PROCESSING_COUNT', array(
"#C1" => $count)) .
'</p>';
62 \CAdminMessage::ShowMessage(array(
65 '<p>' . $detailsMsg .
'</p>' .
69 onclick="if(confirm(\'' .
Loc::getMessage(
"VK_JOURNAL_BUTTON_STOP_PROCESS_ALERT") .
'\'))
70 {
BX.Sale.VkAdmin.stopProcess(
' . $exportId . ');}
">',
74 $res = ob_get_clean();
79 public static function getProgressFinishMessage($ok = true)
82 Loc::getMessage("VK_JOURNAL_EXPORT_FININSH
") :
83 Loc::getMessage("VK_JOURNAL_EXPORT_ABORT
");
85 \CAdminMessage::ShowMessage(array(
90 $res = ob_get_clean();
96 public static function getTooMuchTimeExportMessage()
99 \CAdminMessage::ShowMessage(array
101 "MESSAGE
" => Loc::getMessage("VK_JOURNAL_TOO_MUCH_TIMES_NOTIFY_1
"),
102 "DETAILS
" => Loc::getMessage("VK_JOURNAL_TOO_MUCH_TIMES_NOTIFY_2
"),
106 $res = ob_get_clean();
112 public static function getCriticalErrorsMessage($exportId, $txt)
115 \CAdminMessage::ShowMessage(array("MESSAGE
" => $txt, "HTML
" => true, "TYPE
" => "ERROR
", "DETAILS
" => ''));
116 $res = ob_get_clean();
122 public static function saveProcessParams($exportId, $type = false, $position = false, $execCount = false)
124// save only if not set STOP flag
125 if (!self::checkStopProcessFlag($exportId))
127 $exportId = \EscapePHPString($exportId);
128// if set data - update, if not - clear process
130 if ($type !== false && $position !== false && $execCount !== false)
133 'EXEC_COUNT' => $execCount,
134 'START_POSITION' => $position,
136 $resUpdate = ExportProfileTable::update($exportId, array("PROCESS
" => $data));
138 return $resUpdate->isSuccess();
151 public static function clearStopProcessParams($exportId)
153 $resUpdate = ExportProfileTable::update($exportId, array("PROCESS
" => NULL));
155 return $resUpdate->isSuccess();
163 public static function stopProcessParams($exportId)
165 $exportId = \EscapePHPString($exportId);
166 $data = array('STOP' => true);
167 $resUpdate = ExportProfileTable::update($exportId, array("PROCESS
" => $data));
169 return $resUpdate->isSuccess();
173 public static function checkStopProcessFlag($exportId)
175 $exportId = \EscapePHPString($exportId);
177 $resProfiles = ExportProfileTable::getList(array(
178 "filter
" => array('=ID' => $exportId),
179 "select
" => array("PROCESS
"),
182 $profile = $resProfiles->fetch();
185 isset($profile['PROCESS']) &&
186 (array_key_exists('STOP', $profile['PROCESS']) && $profile['PROCESS']['STOP']);
196 private function getJournal()
198 $resJournal = ExportProfileTable::getList(array(
199 "filter
" => array('=ID' => $this->exportId),
200 "select
" => array("JOURNAL
"),
203 $journal = $resJournal->fetch();
205 return $journal["JOURNAL
"];
216 public function addItemsCount($count)
218 $journal = $this->getJournal();
220// existing journal - increment count
221 if (isset($journal[$this->type]["START
"]) && !isset($journal[$this->type]["END
"]))
223 $journal[$this->type]["COUNT
"] = intval($journal[$this->type]["COUNT
"]) + intval($count);
226// if not set START or set both START and END - it is new item, init them
229 $journal[$this->type] = array(
231 "COUNT
" => intval($count),
233 unset($journal[$this->type]["END
"], $journal[$this->type]["ABORT
"]);
236 $resUpdate = ExportProfileTable::update($this->exportId, array("JOURNAL
" => $journal));
238 return $resUpdate->isSuccess();
248 public function start()
250// remove old values and init new journal log for current type
251 $journal = $this->getJournal();
252 $journal[$this->type] = array('START' => time());
254 $resUpdate = ExportProfileTable::update($this->exportId, array("JOURNAL
" => $journal));
256 return $resUpdate->isSuccess();
265 public function end()
267// finish current type journal
268 $journal = $this->getJournal();
269 $journal[$this->type]["END
"] = time();
271 $resUpdate = ExportProfileTable::update($this->exportId, array("JOURNAL
" => $journal));
273 return $resUpdate->isSuccess();
277 private static function getStatistic($type, $exportId)
279 $resJournal = ExportProfileTable::getList(array(
280 "filter
" => array('=ID' => $exportId),
281 "select
" => array("JOURNAL
"),
284 $journal = $resJournal->fetch();
288 $journal = $journal["JOURNAL
"];
290 //check if process stopped, but journal not ending
291 return self::getCheckedEndingJournal($type, $exportId, $journal);
303 public static function getStatisticText($type, $exportId)
305 $journal = self::getStatistic($type, $exportId);
307 $result = "<h4>
" . Loc::getMessage("VK_JOURNAL_
" . $type) . "</h4>
";
310 if (!isset($journal[$type]["START
"]) && !isset($journal[$type]["END
"]))
312 $result .= "<p>
" . Loc::getMessage("VK_JOURNAL_NEVER
") . "</p>
";
315// export was finished
316 elseif (isset($journal[$type]["END
"]))
319 $result .= Loc::getMessage("VK_JOURNAL_LAST_EXPORT
", array(
320 '#D1' => date('d.m.y', $journal[$type]["END
"]),
321 '#D2' => date('G:i', $journal[$type]["END
"]),
323 $result .= isset($journal[$type]["ABORT
"]) && $journal[$type]["ABORT
"] ?
324 ' ' . Loc::getMessage("VK_JOURNAL_LAST_EXPORT_ABORTED
") : '';
328 if ($journal[$type]["COUNT
"])
330 Loc::getMessage("VK_JOURNAL_COUNT_WAS
", array(
331 '#C1' => $journal[$type]["COUNT
"],
337 elseif (isset($journal[$type]["START
"]))
339 $result .= "<p>
" . Loc::getMessage("VK_JOURNAL_EXPORT_NOW
") . "</p>
";
342 if ($journal[$type]["COUNT
"])
345 Loc::getMessage("VK_JOURNAL_COUNT_NOW
", array(
346 '#C1' => $journal[$type]["COUNT
"],
365 private static function getCheckedEndingJournal($type, $exportId, $journal)
367 $runningProcess = self::getCurrentProcess($exportId);
368 $runningProcessType = Feed\Manager::prepareType($runningProcess['TYPE']);
370 if ($runningProcess && $runningProcessType == $type)
372// if process was running, but not eyt cleared journal
373 if (isset($journal[$type]["START
"]) && isset($journal[$type]["END
"]))
375 unset($journal[$type]["END
"]);
376 unset($journal[$type]["ABORT
"]);
377 $journal[$type]["COUNT
"] = 0;
379 ExportProfileTable::update($exportId, array("JOURNAL
" => $journal));
385// if journal not closed, but process not running, it means that process was stopped manually - close journal
386 if (isset($journal[$type]["START
"]) && !isset($journal[$type]["END
"]))
388 $journal[$type]["ABORT
"] = true;
389 $journal[$type]["END
"] = $journal[$type]["START
"];
391 ExportProfileTable::update($exportId, array("JOURNAL
" => $journal));
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)