devsuite/cds/static/defaultscripts/install.php

65 lines
1.6 KiB
PHP
Raw Normal View History

2024-05-27 00:44:14 -04:00
<?php
// CDS Installer
use \Crispage\Utils\FileUtils;
use \Crispage\Extensions\Extension;
$pdata = $this->getPackageInfo(PACKAGE);
$pid = $pdata["ExtensionInfo"]["id"] ?? "unknown";
$pversion = $pdata["ExtensionInfo"]["version"] ?? "0.0";
$this->log("Installing $pid v$pversion", $this::L_INFO);
$this->log("Copying files", $this::L_NORMAL);
$files = array_merge(
["/user"],
$pdata["PackageData"]["contents"] ?? []
);
foreach ($files as $path) {
$this->log("Copying $path", $this::L_DEBUG);
$from = PACKAGE_PATH . $path;
$to = ROOT . $path;
if (!file_exists($from)) {
$this->log("$path does not exist", $this::L_WARNING);
continue;
}
if (is_dir($from)) FileUtils::copyDirectory($from, $to);
else copy($from, $to);
}
$this->log("Installing extensions", $this::L_NORMAL);
$extensions = $pdata["Extensions"] ?? [];
$plugins = $pdata["PackageData"]["plugins"] ?? [];
foreach ($extensions as $extid => $data) {
$this->log("Installing $extid", $this::L_DEBUG);
$ext = new Extension(
$data["id"] ?? $extid,
$data["version"] ?? $pversion,
$data["package"] ?? $pid,
$data["classname"] ?? "unknown",
$data["type"] ?? "unknown",
$pdata["ExtensionData"][$extid] ?? []
);
$this->app->extensions->register($ext);
if (in_array($extid, $plugins)) {
$this->log("Installing $extid as plugin", $this::L_DEBUG);
$this->app->assets->create(
"\\Crispage\\Assets\\Plugin", [
"slug" => preg_replace("/[^a-z0-9]+/", "_", $extid),
"classname" => $data["classname"] ?? "\\Crispage\\Plugins\\DefaultPluginClass"
]
);
}
}
$this->log("Installation Successful!", $this::L_SUCCESS);
?>