250 if (!(is_array($post) &&
251 $this->log[
"filesCount"] > 0 &&
252 $post[
"filesCount"] == $this->log[
"filesCount"] &&
253 is_array($postFiles) &&
264 $type = $post[
"type"] ??
null;
265 if ($type !==
"brief")
268 if ($this->log[
"executeStatus"] !=
"executed")
270 $eventName = ($this->cidLog[
"executeStatus"] ===
"executed" ?
"onUploadIsContinued" :
"onUploadIsStarted");
271 $this->cidLog[
"executeStatus"] =
"executed";
275 if (ExecuteModuleEventEx($event, array(&$this->log, &$this->cidLog, &$unescapedPost, &
$files, &$error)) ===
false)
278 $eventName =
"onPackageIsStarted";
282 $eventName =
"onPackageIsContinued";
285 $this->log[
"executeStatus"] =
"executed";
288 if (ExecuteModuleEventEx($event, array(&$this->log, &$this->cidLog, &$unescapedPost, &
$files, &$error)) ===
false)
295 foreach($postFiles as $fileID => $file)
299 if (isset($file[
"removed"]))
301 $f = array_merge($file, array(
"id" => $fileID));
308 else if (isset($file[
"restored"]))
310 $f = array_merge($file, array(
"id" => $fileID));
311 if ($f[
"restored"] ===
"Y")
320 if (array_key_exists(
"files", $file) && is_array($file[
"files"]))
322 foreach ($file[
"files"] as $serviceName => $f)
324 if (is_array($f) && array_key_exists(
"tmp_url", $f))
334 $filesRaw[] = array_merge($f, array(
336 "code" => $serviceName
346 foreach(
$files[
"name"] as $fileID => $fileNames)
348 if (is_array($fileNames))
350 foreach ($fileNames as $fileName => $val)
355 "tmp_name" =>
$files[
"tmp_name"][$fileID][$fileName],
356 "type" =>
$files[
"type"][$fileID][$fileName],
357 "size" =>
$files[
"size"][$fileID][$fileName],
358 "error" =>
$files[
"error"][$fileID][$fileName]
366 "code" => $fileNames,
367 "tmp_name" =>
$files[
"tmp_name"][$fileID],
368 "type" =>
$files[
"type"][$fileID],
369 "size" =>
$files[
"size"][$fileID],
370 "error" =>
$files[
"error"][$fileID]
377 $filesFromLog = is_array($this->log[
"files"]) ? $this->log[
"files"] : array();
378 $filesOnThisPack = array();
379 if ($fileRaw = reset($filesRaw))
381 $this->log[
"uploadStatus"] =
"inprogress";
384 if (!array_key_exists($fileRaw[
"id"], $postFiles))
388 if (!array_key_exists($fileRaw[
"id"], $filesOnThisPack))
390 if (!empty($fileRaw[
"removed"]))
393 'id' => $fileRaw[
'id'],
394 'name' => $postFiles[$fileRaw[
"id"]][
"name"]
399 $file =
new File($this, array(
400 "id" => $fileRaw[
"id"],
401 "name" => $postFiles[$fileRaw[
"id"]][
"name"],
402 "type" => $postFiles[$fileRaw[
"id"]][
"type"],
403 "size" => $postFiles[$fileRaw[
"id"]][
"size"]
404 ) + (is_array($postFiles[$fileRaw[
"id"]]) ? $postFiles[$fileRaw[
"id"]] : []));
405 if (isset($fileRaw[
"restored"]))
407 if ($file->isExecuted())
408 $file->setExecuteStatus(
"none");
409 $fileRaw = $file->getFile(
"default");
410 if (empty($fileRaw) || !is_array($fileRaw))
414 $filesOnThisPack[$fileRaw[
"id"]] = $file;
417 $file = $filesOnThisPack[$fileRaw[
"id"]];
418 if ($file->hasError() || $file instanceof
FileRemoved)
423 if ($result->isSuccess() && ($result = $file->saveFile($fileRaw, $this->getStorage(), $this->getCopies())) && $result->isSuccess() &&
425 $file->isUploaded() &&
429 $file->setExecuteStatus(
"executed");
430 $fileArray = $file->toArray();
434 if (!ExecuteModuleEventEx($event, array($file->getHash(), &$fileArray,
439 $result->addError(
new Error($error,
"BXU350.1"));
443 $file->fromArray($fileArray);
445 if (!$result->isSuccess())
446 $file->addError($result->getErrorCollection()->current());
447 }
while ($fileRaw = next($filesRaw));
452 foreach ($filesOnThisPack as $file)
454 $response[$file->getId()] = $file->toArray();
455 $filesFromLog[$file->getId()] = $response[$file->getId()][
"status"] = $file->isUploaded() ?
"uploaded" :
"inprogress";
456 if ($file->hasError())
458 $response[$file->getId()][
"status"] =
"error";
459 $response[$file->getId()][
"error"] = $file->getErrorMessage();
460 $filesFromLog[$file->getId()] =
"error";
463 $this->files = $filesOnThisPack;
464 $this->log[
"files"] = $filesFromLog;
465 $declaredFiles = (int) $this->log[
"filesCount"];
468 foreach ($filesFromLog as $status)
469 $cnt += ($status ==
"uploaded" || $status ==
"error" ? 1 : 0);
471 if ($declaredFiles > 0 && $declaredFiles <= $cnt)
473 if ($type !==
"brief")
475 $this->log[
"uploadStatus"] =
"uploaded";
479 if (ExecuteModuleEventEx($event, array(&$this->log, &$this->cidLog, &$unescapedPost, &$response, &$error)) ===
false)