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

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

public static installData ( $revision )
$revision
    public static function installData($revision)
    {
        $db = Db::get();
        $files = $db->fetchAll("SELECT * FROM `" . self::$tmpTable . "` WHERE revision = ?", $revision);
        foreach ($files as $file) {
            if ($file["action"] == "update" || $file["action"] == "add") {
                if (!is_dir(dirname(PIMCORE_DOCUMENT_ROOT . $file["path"]))) {
                    if (!self::$dryRun) {
                        File::mkdir(dirname(PIMCORE_DOCUMENT_ROOT . $file["path"]));
                    }
                }
                if (array_key_exists("id", $file) && $file["id"]) {
                    // this is the new style, see https://www.pimcore.org/issues/browse/PIMCORE-2722
                    $srcFile = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/update/" . $revision . "/files/" . $file["id"] . "-" . $file["revision"];
                } else {
                    // this is the old style, which we still have to support here, otherwise there's the risk that the
                    // running update cannot be finished
                    $srcFile = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/update/" . $revision . "/files/" . str_replace("/", "~~~", $file["path"]);
                }
                $destFile = PIMCORE_DOCUMENT_ROOT . $file["path"];
                if (!self::$dryRun) {
                    if ($file["path"] == "/composer.json") {
                        // composer.json needs some special processing
                        self::installComposerJson($srcFile, $destFile);
                    } else {
                        copy($srcFile, $destFile);
                    }
                }
            } elseif ($file["action"] == "delete") {
                if (!self::$dryRun) {
                    if (file_exists(PIMCORE_DOCUMENT_ROOT . $file["path"])) {
                        unlink(PIMCORE_DOCUMENT_ROOT . $file["path"]);
                    }
                    clearstatcache();
                    // remove also directory if its empty
                    if (count(glob(dirname(PIMCORE_DOCUMENT_ROOT . $file["path"]) . "/*")) === 0) {
                        recursiveDelete(dirname(PIMCORE_DOCUMENT_ROOT . $file["path"]), true);
                    }
                }
            }
        }
        self::clearOPCaches();
    }

Usage Example

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $status = ["success" => true];
     $config = $input->getArgument("config");
     if ($config) {
         $job = json_decode($config, true);
         if (is_array($job)) {
             if (isset($job["dry-run"])) {
                 // do not do anything here
                 \Logger::info("skipped update job because it is in dry-run mode", $job);
             } elseif ($job["type"] == "files") {
                 Update::installData($job["revision"]);
             } elseif ($job["type"] == "clearcache") {
                 \Pimcore\Cache::clearAll();
             } elseif ($job["type"] == "preupdate") {
                 $status = Update::executeScript($job["revision"], "preupdate");
             } elseif ($job["type"] == "postupdate") {
                 $status = Update::executeScript($job["revision"], "postupdate");
             } elseif ($job["type"] == "cleanup") {
                 Update::cleanup();
             }
         }
     }
     $this->output->write(json_encode($status));
 }
All Usage Examples Of Pimcore\Update::installData