Pimcore\Update::downloadData PHP Метод

downloadData() публичный статический Метод

public static downloadData ( $revision, $url )
$revision
$url
    public static function downloadData($revision, $url)
    {
        $db = Db::get();
        $db->query("CREATE TABLE IF NOT EXISTS `" . self::$tmpTable . "` (\n          `id` int(11) NULL DEFAULT NULL,\n          `revision` int(11) NULL DEFAULT NULL,\n          `path` varchar(255) NULL DEFAULT NULL,\n          `action` varchar(50) NULL DEFAULT NULL\n        );");
        $downloadDir = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/update/" . $revision;
        if (!is_dir($downloadDir)) {
            File::mkdir($downloadDir);
        }
        $filesDir = $downloadDir . "/files";
        if (!is_dir($filesDir)) {
            File::mkdir($filesDir);
        }
        $scriptsDir = $downloadDir . "/scripts";
        if (!is_dir($scriptsDir)) {
            File::mkdir($scriptsDir);
        }
        $xml = Tool::getHttpData($url);
        if ($xml) {
            $parserOptions = LIBXML_NOCDATA;
            if (defined("LIBXML_PARSEHUGE")) {
                $parserOptions = LIBXML_NOCDATA | LIBXML_PARSEHUGE;
            }
            $updateFiles = simplexml_load_string($xml, null, $parserOptions);
            foreach ($updateFiles->file as $file) {
                if ($file->type == "file") {
                    if ($file->action == "update" || $file->action == "add") {
                        $newFile = $filesDir . "/" . $file->id . "-" . $file->revision;
                        File::put($newFile, base64_decode((string) $file->content));
                    }
                    $db->insert(self::$tmpTable, ["id" => $file->id, "revision" => $revision, "path" => (string) $file->path, "action" => (string) $file->action]);
                } elseif ($file->type == "script") {
                    $newScript = $scriptsDir . $file->path;
                    File::put($newScript, base64_decode((string) $file->content));
                }
            }
        }
    }

Usage Example

Пример #1
0
 public function jobParallelAction()
 {
     if ($this->getParam("type") == "download") {
         Update::downloadData($this->getParam("revision"), $this->getParam("url"));
     }
     $this->_helper->json(array("success" => true));
 }
All Usage Examples Of Pimcore\Update::downloadData