devsuite/cds/static/defaultscripts/uninstall.php
2024-05-27 00:44:14 -04:00

52 lines
1.4 KiB
PHP

<?php
// CDS Uninstaller
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("Uninstalling $pid v$pversion", $this::L_INFO);
$this->log("Uninstalling extensions", $this::L_NORMAL);
$extensions = $pdata["Extensions"] ?? [];
$plugins = $pdata["PackageData"]["plugins"] ?? [];
foreach ($extensions as $extid => $data) {
$this->log("Uninstalling $extid", $this::L_DEBUG);
if (in_array($extid, $plugins)) {
$this->log("Uninstalling $extid as plugin", $this::L_DEBUG);
$asset = $this->app->assets->getBySlug(
"\\Crispage\\Assets\\Plugin",
preg_replace("/[^a-z0-9]+/", "_", $extid)
);
if ($asset) $this->app->assets->delete($asset);
}
$ext = $this->app->extensions->get($extid);
if ($ext) $this->app->extensions->unregister($ext);
}
$this->log("Uninstalling package", $this::L_DEBUG);
$this->app->extensions->unregister(PACKAGE);
$this->log("Deleting files", $this::L_NORMAL);
$files = $pdata["PackageData"]["contents"] ?? [];
foreach ($files as $path) {
$this->log("Deleting $path", $this::L_DEBUG);
$rpath = ROOT . $path;
if (is_dir($rpath)) {
FileUtils::emptyDirectory($rpath);
rmdir($rpath);
}
else unlink($rpath);
}
$this->log("Uninstallation Successful!", $this::L_SUCCESS);
?>