Piwik\Plugins\SitesManager\API::setSiteAliasUrls PHP Method

setSiteAliasUrls() public method

Completely overwrites the current list of URLs with the provided list. The 'main_url' of the website won't be affected by this method.
public setSiteAliasUrls ( $idSite, $urls = [] ) : integer
return integer the number of inserted URLs
    public function setSiteAliasUrls($idSite, $urls = array())
    {
        Piwik::checkUserHasAdminAccess($idSite);
        $mainUrl = Site::getMainUrlFor($idSite);
        array_unshift($urls, $mainUrl);
        $urlsProperty = new Urls($idSite);
        $urlsProperty->setValue($urls);
        $urlsProperty->save();
        $inserted = array_diff($urlsProperty->getValue(), $urls);
        $this->postUpdateWebsite($idSite);
        return count($inserted);
    }

Usage Example

Example #1
0
 public function testGetAllCachedSiteUrls_ShouldReturnCorrectResultEvenIfItIsCachedAsWeClearTheCacheOnAnyChange()
 {
     $this->addSite('http://www.example.com');
     // only one main URL
     $this->assertCachedSiteUrls(array(1 => array('http://www.example.com')));
     $this->addSite('http://www.example.com', 'http://www.piwik.org');
     // main URL and alias URL
     $this->assertCachedSiteUrls(array(1 => array('http://www.example.com'), 2 => array('http://www.example.com', 'http://www.piwik.org')));
     $this->api->addSiteAliasUrls(2, 'http://piwik.org');
     $this->assertCachedSiteUrls(array(1 => array('http://www.example.com'), 2 => array('http://www.example.com', 'http://piwik.org', 'http://www.piwik.org')));
     $this->api->setSiteAliasUrls(2, array());
     $this->assertCachedSiteUrls(array(1 => array('http://www.example.com'), 2 => array('http://www.example.com')));
     $this->api->updateSite(1, 'siteName3', array('http://updated.example.com', 'http://2.example.com'));
     $this->assertCachedSiteUrls(array(1 => array('http://updated.example.com', 'http://2.example.com'), 2 => array('http://www.example.com')));
 }