protected function runInstall($componentsToInstall, $ep, $epId, $flags)
{
$installedModules = array();
$result = true;
// ----- installation process
try {
foreach ($componentsToInstall as $item) {
list($installer, $component, $action) = $item;
if ($action == Resolver::ACTION_INSTALL) {
if ($installer && $flags & self::FLAG_INSTALL_MODULE) {
$installer->install();
}
$this->installerIni->setValue($component->getName() . '.installed', 1, $epId);
$this->installerIni->setValue($component->getName() . '.version', $component->getSourceVersion(), $epId);
$this->installerIni->setValue($component->getName() . '.version.date', $component->getSourceDate(), $epId);
$this->installerIni->setValue($component->getName() . '.firstversion', $component->getSourceVersion(), $epId);
$this->installerIni->setValue($component->getName() . '.firstversion.date', $component->getSourceDate(), $epId);
$this->ok('install.module.installed', $component->getName());
$installedModules[] = array($installer, $component, $action);
} elseif ($action == Resolver::ACTION_UPGRADE) {
$lastversion = '';
foreach ($installer as $upgrader) {
if ($flags & self::FLAG_UPGRADE_MODULE) {
$upgrader->install();
}
// we set the version of the upgrade, so if an error occurs in
// the next upgrader, we won't have to re-run this current upgrader
// during a future update
$this->installerIni->setValue($component->getName() . '.version', $upgrader->version, $epId);
$this->installerIni->setValue($component->getName() . '.version.date', $upgrader->date, $epId);
$this->ok('install.module.upgraded', array($component->getName(), $upgrader->version));
$lastversion = $upgrader->version;
}
// we set the version to the component version, because the version
// of the last upgrader could not correspond to the component version.
if ($lastversion != $component->getSourceVersion()) {
$this->installerIni->setValue($component->getName() . '.version', $component->getSourceVersion(), $epId);
$this->installerIni->setValue($component->getName() . '.version.date', $component->getSourceDate(), $epId);
$this->ok('install.module.upgraded', array($component->getName(), $component->getSourceVersion()));
}
$installedModules[] = array($installer, $component, $action);
} else {
if ($action == Resolver::ACTION_REMOVE) {
if ($installer && $flags & self::FLAG_REMOVE_MODULE) {
$installer->uninstall();
}
$this->installerIni->removeValue($component->getName() . '.installed', $epId);
$this->installerIni->removeValue($component->getName() . '.version', $epId);
$this->installerIni->removeValue($component->getName() . '.version.date', $epId);
$this->installerIni->removeValue($component->getName() . '.firstversion', $epId);
$this->installerIni->removeValue($component->getName() . '.firstversion.date', $epId);
$this->ok('install.module.uninstalled', $component->getName());
$installedModules[] = array($installer, $component, $action);
}
}
// we always save the configuration, so it invalidates the cache
$ep->getConfigIni()->save();
$this->xmlMapFile->save();
// we re-load configuration file for each module because
// previous module installer could have modify it.
$compiler = new \Jelix\Core\Config\Compiler($ep->getConfigFile(), $ep->scriptName, $ep->isCliScript);
$ep->setConfigObj($compiler->read(true));
App::setConfig($ep->getConfigObj());
}
} catch (Exception $e) {
$result = false;
$this->error($e->getLocaleKey(), $e->getLocaleParameters());
} catch (\Exception $e) {
$result = false;
$this->error('install.module.error', array($component->getName(), $e->getMessage()));
}
if (!$result) {
return false;
}
return $installedModules;
}