Skip to content

Commit

Permalink
pagekit#886 Module name change prevents execution of update scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
tobbexiv committed Jan 8, 2018
1 parent 0a41097 commit 43e69cf
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions app/installer/src/Package/PackageManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,17 @@ public function __construct($output = null)
*/
public function install(array $install = [], $packagist = false, $preferSource = false)
{
$previousPackageConfigs = App::package()->all(null, true);

$this->composer->install($install, $packagist, $preferSource);

$packages = App::package()->all(null, true);
foreach ($install as $name => $version) {
if (isset($packages[$name]) && App::module($packages[$name]->get('module'))) {
$this->enable($packages[$name]);
$moduleAlreadyExisted = isset($previousPackageConfigs[$name]) && App::module($previousPackageConfigs[$name]->get('module'));

if ($moduleAlreadyExisted == true) {
$previousPackageConfig = isset($previousPackageConfigs[$name]) ? $previousPackageConfigs[$name] : null;
$this->enable($packages[$name], $previousPackageConfig);
} elseif (isset($packages[$name])) {
$this->doInstall($packages[$name]);
}
Expand Down Expand Up @@ -88,18 +93,32 @@ public function uninstall($uninstall)

/**
* @param $packages
* @param $previousPackageConfigs
*/
public function enable($packages)
public function enable($packages, $previousPackageConfigs = [])
{
if (!is_array($packages)) {
$packages = [$packages];
}

if (!is_array($previousPackageConfigs)) {
$previousPackageConfigs = [$previousPackageConfigs];
}

foreach ($packages as $package) {

// Get the old package config if provided. If there is no old config available, then use the new config (usually fist installation).
$previousPackageConfig = $package;
foreach ($previousPackageConfigs as $packageConfig) {
if ($packageConfig->get('name') == $package->get('name')) {
$previousPackageConfig = $packageConfig;
break;
}
}

App::trigger('package.enable', [$package]);

if (!$current = App::config('system')->get('packages.' . $package->get('module'))) {
if (!$current = App::config('system')->get('packages.' . $previousPackageConfig->get('module'))) {
$current = $this->doInstall($package);
}

Expand Down

0 comments on commit 43e69cf

Please sign in to comment.