Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ElementHelper::supportedSitesForElement's static $siteUidMap is problematic #3824

Closed
nicholasc opened this issue Feb 11, 2019 · 1 comment
Closed

Comments

@nicholasc
Copy link

Description

We have cli script that installs and configures Craft 3 and since we updated craft to 3.1.8 it has stopped working properly. After investigating we figured the our problem was the new static $siteUidMap that is used to store each site uid. When Craft installs, the static variable is filled with the uid of the default site. So when we decide to programmatically add a new site and create a section for it, it does not exist in the static $siteUidMap array causing an undefined index '2' at line 233.

Steps to reproduce

  1. Install craft programatically using the $app->runAction. This at some point uses the ElementHelper::supportedSitesForElement function therefore populating the static $siteUidMap here.
Craft::$app->runAction('install/craft', [
    'username' => $username,
    'password' => $password,
    'email'    => $email,
    'language' => $lang,
    'siteUrl'  => '@web',
    'siteName' => $this->siteName,
]);
  1. Create a new site with the same group id used in the default one. When we do this, there should be a way to inform the static $siteUidMap about this new site.
Craft::$app->getSites()->saveSite(new Site([
    'groupId' => $defaultSite->groupId,
    'name' => 'Alternate',
    'handle' => 'alt',
    'hasUrls' => true,
    'baseUrl' => '@web/alt/',
    'language' => 'en'
]));
  1. Create a home section for all the new sites effectively crashing the script because it cannot find the uid for the alternate site that we created.
$homeSection = new Section([
    'name' => 'Home',
    'handle' => 'home',
    'type' => Section::TYPE_SINGLE,
    'enableVersioning' => false,
    'propagateEntries' => true,
]);

$allSiteSettings = [];
foreach (Craft::$app->getSites()->getAllSites() as $site) {
    $siteSettings = new Section_SiteSettings([
        'siteId' => $site->id,
        'hasUrls' => true,
        'uriFormat' => '__home__',
        'template' => 'index',
    ]);

    $allSiteSettings[$site->id] = $siteSettings;
}

$homeSection->setSiteSettings($allSiteSettings);
        
// this crashes because `static $siteUidMap[2]` is not defined.
Craft::$app->getSections()->saveSection($homeSection);

Additional info

  • Craft version: 3.1.8
  • PHP version: 7.1.19
  • Database driver & version: mariadb 10.3.12
  • Plugins & versions: None
@brandonkelly
Copy link
Member

Fixed for the next release. Thanks for tracking that down and reporting it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants