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

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

If only one URL is specified then only the main url will be updated. If several URLs are specified, both the main URL and the alias URLs will be updated.
public updateSite ( integer $idSite, string $siteName = null, string | array $urls = null, integer $ecommerce = null, null | integer $siteSearch = null, string $searchKeywordParameters = null, string $searchCategoryParameters = null, string $excludedIps = null, null | string $excludedQueryParameters = null, string $timezone = null, string $currency = null, string $group = null, string $startDate = null, null | string $excludedUserAgents = null, integer | null $keepURLFragments = null, string $type = null, array | null $settingValues = null, boolean | null $excludeUnknownUrls = null ) : boolean
$idSite integer website ID defining the website to edit
$siteName string website name
$urls string | array the website URLs When calling API via HTTP specify multiple URLs via `&urls[]=http...&urls[]=http...`.
$ecommerce integer Whether Ecommerce is enabled, 0 or 1
$siteSearch null | integer Whether site search is enabled, 0 or 1
$searchKeywordParameters string Comma separated list of search keyword parameter names
$searchCategoryParameters string Comma separated list of search category parameter names
$excludedIps string Comma separated list of IPs to exclude from being tracked (allows wildcards)
$excludedQueryParameters null | string
$timezone string Timezone
$currency string Currency code
$group string Group name where this website belongs
$startDate string Date at which the statistics for this website will start. Defaults to today's date in YYYY-MM-DD format
$excludedUserAgents null | string
$keepURLFragments integer | null If 1, URL fragments will be kept when tracking. If 2, they will be removed. If 0, the default global behavior will be used.
$type string The Website type, default value is "website"
$settingValues array | null JSON serialized settings eg {settingName: settingValue, ...}
$excludeUnknownUrls boolean | null Track only URL matching one of website URLs
Результат boolean true on success
    public function updateSite($idSite, $siteName = null, $urls = null, $ecommerce = null, $siteSearch = null, $searchKeywordParameters = null, $searchCategoryParameters = null, $excludedIps = null, $excludedQueryParameters = null, $timezone = null, $currency = null, $group = null, $startDate = null, $excludedUserAgents = null, $keepURLFragments = null, $type = null, $settingValues = null, $excludeUnknownUrls = null)
    {
        Piwik::checkUserHasAdminAccess($idSite);
        $idSites = $this->getSitesId();
        if (!in_array($idSite, $idSites)) {
            throw new Exception("website id = {$idSite} not found");
        }
        // Build the SQL UPDATE based on specified updates to perform
        $bind = array();
        if (!is_null($siteName)) {
            $this->checkName($siteName);
            $bind['name'] = $siteName;
        }
        if (empty($settingValues)) {
            $settingValues = array();
        }
        if (isset($urls)) {
            $settingValues = $this->setSettingValue('urls', $urls, $settingValues);
        }
        if (isset($ecommerce)) {
            $settingValues = $this->setSettingValue('ecommerce', $ecommerce, $settingValues);
        }
        if (isset($siteSearch)) {
            $settingValues = $this->setSettingValue('sitesearch', $siteSearch, $settingValues);
        }
        if (isset($searchKeywordParameters)) {
            $settingValues = $this->setSettingValue('sitesearch_keyword_parameters', explode(',', $searchKeywordParameters), $settingValues);
        }
        if (isset($searchCategoryParameters)) {
            $settingValues = $this->setSettingValue('sitesearch_category_parameters', explode(',', $searchCategoryParameters), $settingValues);
        }
        if (isset($keepURLFragments)) {
            $settingValues = $this->setSettingValue('keep_url_fragment', $keepURLFragments, $settingValues);
        }
        if (isset($excludeUnknownUrls)) {
            $settingValues = $this->setSettingValue('exclude_unknown_urls', $excludeUnknownUrls, $settingValues);
        }
        if (isset($excludedIps)) {
            $settingValues = $this->setSettingValue('excluded_ips', explode(',', $excludedIps), $settingValues);
        }
        if (isset($excludedQueryParameters)) {
            $settingValues = $this->setSettingValue('excluded_parameters', explode(',', $excludedQueryParameters), $settingValues);
        }
        if (isset($excludedUserAgents)) {
            $settingValues = $this->setSettingValue('excluded_user_agents', explode(',', $excludedUserAgents), $settingValues);
        }
        if (isset($currency)) {
            $currency = trim($currency);
            $this->checkValidCurrency($currency);
            $bind['currency'] = $currency;
        }
        if (isset($timezone)) {
            $timezone = trim($timezone);
            $this->checkValidTimezone($timezone);
            $bind['timezone'] = $timezone;
        }
        if (isset($group) && Piwik::hasUserSuperUserAccess()) {
            $bind['group'] = trim($group);
        }
        if (isset($startDate)) {
            $bind['ts_created'] = Date::factory($startDate)->getDatetime();
        }
        if (isset($type)) {
            $bind['type'] = $this->checkAndReturnType($type);
        }
        if (!empty($settingValues)) {
            $this->setAndValidateMeasurableSettings($idSite, $idType = null, $settingValues);
        }
        if (!empty($bind)) {
            $this->getModel()->updateSite($bind, $idSite);
        }
        if (!empty($settingValues)) {
            $this->saveMeasurableSettings($idSite, $idType = null, $settingValues);
        }
        $this->postUpdateWebsite($idSite);
    }

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