private function getSitesIdFromPattern($pattern, $_restrictSitesToLogin)
    {
        // First clear cache
        Site::clearCache();

        if (empty($pattern)) {

            /** @var Scheduler $scheduler */
            $scheduler = StaticContainer::getContainer()->get('Piwik\Scheduler\Scheduler');
            // Then, warm the cache with only the data we should have access to
            if (Piwik::hasUserSuperUserAccess()
                // Hack: when this API function is called as a Scheduled Task, Super User status is enforced.
                // This means this function would return ALL websites in all cases.
                // Instead, we make sure that only the right set of data is returned
                && !$scheduler->isRunningTask()
            ) {
                APISitesManager::getInstance()->getAllSites();
            } else {
                APISitesManager::getInstance()->getSitesWithAtLeastViewAccess($limit = false, $_restrictSitesToLogin);
            }

        } else {
            $sites = Request::processRequest('SitesManager.getPatternMatchSites',
                array('pattern'   => $pattern,
                      // added because caller could overwrite these
                      'limit'       => SettingsPiwik::getWebsitesCountToDisplay(),
                      'showColumns' => '',
                      'hideColumns' => '',
                      'format'      => 'original'));

            if (!empty($sites)) {
                Site::setSitesFromArray($sites);
            }
        }

        // Both calls above have called Site::setSitesFromArray. We now get these sites:
        $sitesToProblablyAdd = Site::getSites();

        return $sitesToProblablyAdd;
    }