public function install(InstallFile $fileInfo) : bool
{
$supplier = $this->supplier->getName();
$fileName = $supplier . '.' . $this->package . '.phar';
$metadata = $this->getMetadata($fileInfo);
// Move .phar file to its destination.
if (!empty($metadata['cabin'])) {
$gadgetConfigFile = ROOT . '/Cabin/' . $metadata['cabin'] . '/config/gadgets.json';
// Cabin-specific gadget
$cabin = ROOT . '/Cabin/' . $metadata['cabin'] . '/Gadgets';
if (!\is_dir($cabin)) {
$this->log('Could not install; cabin "' . $metadata['cabin'] . '" is not installed.', LogLevel::ERROR);
return false;
}
$filePath = $cabin . '/' . $supplier . '/' . $fileName;
if (!\is_dir($cabin . '/' . $supplier)) {
\mkdir($cabin . '/' . $supplier, 0775);
}
} else {
$gadgetConfigFile = ROOT . '/config/gadgets.json';
// Universal gadget. (Probably affects the Engine.)
$filePath = ROOT . '/Gadgets/' . $supplier . '/' . $fileName;
if (!\is_dir(ROOT . '/Gadgets/' . $supplier)) {
\mkdir(ROOT . '/Gadgets/' . $supplier, 0775);
}
}
$gadgetConfig = \Airship\loadJSON($gadgetConfigFile);
$gadgetConfig[] = [['supplier' => $supplier, 'name' => $this->package, 'version' => $metadata['version'] ?? null, 'path' => $filePath, 'enabled' => true]];
\Airship\saveJSON($gadgetConfigFile, $gadgetConfig);
\rename($fileInfo->getPath(), $filePath);
// If cabin-specific, add to the cabin's gadget.json
if ($metadata['cabin']) {
$this->addToCabin($metadata['cabin']);
}
// Run the update hooks:
$alias = 'gadget.' . $fileName;
$phar = new \Phar($filePath, \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::KEY_AS_FILENAME);
$phar->setAlias($alias);
// Run the update trigger.
if (\file_exists('phar://' . $alias . '/update_trigger.php')) {
Sandbox::safeRequire('phar://' . $alias . '/update_trigger.php');
}
self::$continuumLogger->store(LogLevel::INFO, 'Install successful', $this->getLogContext($fileInfo));
// Finally, clear the cache files:
return $this->clearCache();
}