Piwik\Plugins\SitesManager\API::addSiteAliasUrls PHP Метод

addSiteAliasUrls() публичный Метод

If some URLs given in parameter are already recorded as alias URLs for this website, they won't be duplicated. The 'main_url' of the website won't be affected by this method.
public addSiteAliasUrls ( integer $idSite, array | string $urls ) : integer
$idSite integer
$urls array | string When calling API via HTTP specify multiple URLs via `&urls[]=http...&urls[]=http...`.
Результат integer the number of inserted URLs
    public function addSiteAliasUrls($idSite, $urls)
    {
        Piwik::checkUserHasAdminAccess($idSite);
        if (empty($urls)) {
            return 0;
        }
        if (!is_array($urls)) {
            $urls = array($urls);
        }
        $urlsInit = $this->getSiteUrlsFromId($idSite);
        $toInsert = array_merge($urlsInit, $urls);
        $urlsProperty = new Urls($idSite);
        $urlsProperty->setValue($toInsert);
        $urlsProperty->save();
        $inserted = array_diff($urlsProperty->getValue(), $urlsInit);
        $this->postUpdateWebsite($idSite);
        return count($inserted);
    }

Usage 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')));
 }