How do you save a new Entry to be enabled on 2+ Sites? I've made a plugin that let's you import Entries from a CSV file and I'm working through adding localization (Sites) support to it, but I can't figure out the right way to enable an Entry for a second Site.

$entry = New Entry();
$entry-&gt;authorId = $authorId;
$entry-&gt;sectionId = $sectionId;
$entry-&gt;typeId = $typeId;
$entry-&gt;enabled = true;
$entry-&gt;title = $title;
$entry-&gt;Slug = $slug;
$entry-&gt;siteId = $firstSiteId;

$entry-&gt;setFieldValues($attrs);

Craft::$app-&gt;elements-&gt;saveElement($entry);


Everything above works, but it's this next part which I can't get to work properly. It just throws errors about violating the constraint for a duplicate element ID/site ID pair:

$entry-&gt;siteId = $secondSiteId;
Craft::$app-&gt;elements-&gt;saveElement($entry);


I also tried this, but the query never returns any results:

$findTheNewEntry = Entry::find()
    -&gt;sectionId($sectionId)
    -&gt;id($entry-&gt;id)
    -&gt;status(null)
    -&gt;siteId($secondSiteId)
    -&gt;one();

$findTheNewEntry-&gt;enabled = true;
Craft::$app-&gt;elements-&gt;saveElement($findTheNewEntry);


I wish it was as simple as being able to provide an array or such for -&gt;siteId but I know that's wrong.
I was able to get this working with this:

$findTheNewEntry = Entry::find()
    -&gt;sectionId($sectionId)
    -&gt;id($entry-&gt;id)
    -&gt;anyStatus()
    -&gt;siteId($secondSiteId)
    -&gt;one();

$findTheNewEntry-&gt;enabledForSite = true;
Craft::$app-&gt;elements-&gt;saveElement($findTheNewEntry);


When creating a new entry via -&gt;saveElement(), Craft automatically creates entries for all sites that have that section enabled. The issues I was having were because status and enabledForSite are different, and I needed to use -&gt;anyStatus() to retrieve an element that was globally enabled when I created it but not enabled for the second site yet. Once that was retrieved, I could enable that entry for the second site as well.