public function install(InstallFile $fileInfo) : bool
{
$path = $fileInfo->getPath();
$zip = new \ZipArchive();
$res = $zip->open($path);
if ($res !== true) {
$this->log('Could not open the ZipArchive.', LogLevel::ERROR);
return false;
}
// Extraction destination directory
$dir = \implode(DIRECTORY_SEPARATOR, [ROOT, 'Motifs', $this->supplier->getName(), $this->package]);
if (!\is_dir($dir)) {
\mkdir($dir, 0775, true);
}
// Grab metadata
$metadata = \Airship\parseJSON($zip->getArchiveComment(\ZipArchive::FL_UNCHANGED), true);
if (isset($metadata['cabin'])) {
$cabin = $this->expandCabinName($metadata['cabin']);
if (!\is_dir(ROOT . '/Cabin/' . $cabin)) {
$this->log('Could not install; cabin "' . $cabin . '" is not installed.', LogLevel::ERROR);
return false;
}
} else {
$cabin = null;
}
// Extract the new files to the current directory
if (!$zip->extractTo($dir)) {
$this->log('Could not extract Motif to its destination.', LogLevel::ERROR);
return false;
}
// Add to the relevant motifs.json files
if ($cabin) {
$this->addMotifToCabin($cabin);
} else {
foreach (\glob(ROOT . '/Cabin/') as $cabin) {
if (\is_dir($cabin)) {
$this->addMotifToCabin(\Airship\path_to_filename($cabin));
}
}
}
self::$continuumLogger->store(LogLevel::INFO, 'Motif install successful', $this->getLogContext($fileInfo));
// Finally, nuke the cache:
return $this->clearCache();
}