public function deleteGoal($idSite, $idGoal) { Piwik::checkUserHasAdminAccess($idSite); Piwik_Query("UPDATE " . Piwik::prefixTable('goal') . "\n\t\t\t\t\t\t\t\t\t\tSET deleted = 1\n\t\t\t\t\t\t\t\t\t\tWHERE idsite = ? \n\t\t\t\t\t\t\t\t\t\t\tAND idgoal = ?", array($idSite, $idGoal)); Zend_Registry::get('db')->query("DELETE FROM " . Piwik::prefixTable("log_conversion") . " WHERE idgoal = ?", $idGoal); Piwik_Common::regenerateCacheWebsiteAttributes($idSite); }
public function deleteGoal($idSite, $idGoal) { Piwik::checkUserHasAdminAccess($idSite); $where[] = 'idsite = ' . Zend_Registry::get('db')->quote($idSite); $where[] = 'idgoal = ' . Zend_Registry::get('db')->quote($idGoal); Zend_Registry::get('db')->update(Piwik::prefixTable('goal'), array('deleted' => 1), $where); Zend_Registry::get('db')->delete(Piwik::prefixTable("log_conversion"), "idgoal={$idGoal}"); Piwik_Common::regenerateCacheWebsiteAttributes($idSite); }
/** * Set an access level to a given user for a list of websites ID. * * If access = 'noaccess' the current access (if any) will be deleted. * If access = 'view' or 'admin' the current access level is deleted and updated with the new value. * * @param string $userLogin The user login * @param string $access Access to grant. Must have one of the following value : noaccess, view, admin * @param int|array $idSites The array of idSites on which to apply the access level for the user. * If the value is "all" then we apply the access level to all the websites ID for which the current authentificated user has an 'admin' access. * * @throws Exception if the user doesn't exist * @throws Exception if the access parameter doesn't have a correct value * @throws Exception if any of the given website ID doesn't exist * * @return bool true on success */ public function setUserAccess($userLogin, $access, $idSites) { $this->checkAccessType($access); $this->checkUserExists($userLogin); $this->checkUserIsNotSuperUser($userLogin); if ($userLogin == 'anonymous' && $access == 'admin') { throw new Exception(Piwik_TranslateException("UsersManager_ExceptionAdminAnonymous")); } // in case idSites is null we grant access to all the websites on which the current connected user // has an 'admin' access if ($idSites === 'all') { $idSites = Piwik_SitesManager_API::getInstance()->getSitesIdWithAdminAccess(); } elseif (!is_array($idSites)) { $idSites = Piwik_Site::getIdSitesFromIdSitesString($idSites); } // it is possible to set user access on websites only for the websites admin // basically an admin can give the view or the admin access to any user for the websites he manages Piwik::checkUserHasAdminAccess($idSites); $this->deleteUserAccess($userLogin, $idSites); // delete UserAccess $db = Zend_Registry::get('db'); // if the access is noaccess then we don't save it as this is the default value // when no access are specified if ($access != 'noaccess') { foreach ($idSites as $idsite) { $db->insert(Piwik_Common::prefixTable("access"), array("idsite" => $idsite, "login" => $userLogin, "access" => $access)); } } // we reload the access list which doesn't yet take in consideration this new user access Zend_Registry::get('access')->reloadAccess(); Piwik_Common::deleteTrackerCache(); }
public function deleteFunnel($idSite, $idGoal, $idFunnel) { Piwik::checkUserHasAdminAccess($idSite); Piwik_Query("UPDATE " . Piwik_Common::prefixTable('funnel') . "\n\t\t\t\t\t\t\t\t\t\tSET deleted = 1\n\t\t\t\t\t\t\t\t\t\tWHERE idsite = ? \n\t\t\t\t\t\t\t\t\t\tAND idgoal = ?\n\t\t\t\t\t\t\t\t\t\tAND idfunnel = ?", array($idSite, $idGoal, $idFunnel)); Piwik_Common::regenerateCacheWebsiteAttributes($idSite); }
/** * Soft deletes a given Goal. * Stats data in the archives will still be recorded, but not displayed. * * @param int $idSite * @param int $idGoal * @return void */ public function deleteGoal($idSite, $idGoal) { Piwik::checkUserHasAdminAccess($idSite); Piwik_Query("UPDATE " . Piwik_Common::prefixTable('goal') . "\n\t\t\t\t\t\t\t\t\t\tSET deleted = 1\n\t\t\t\t\t\t\t\t\t\tWHERE idsite = ? \n\t\t\t\t\t\t\t\t\t\t\tAND idgoal = ?", array($idSite, $idGoal)); Piwik_DeleteAllRows(Piwik_Common::prefixTable("log_conversion"), "WHERE idgoal = ?", 100000, array($idGoal)); Piwik_Common::regenerateCacheWebsiteAttributes($idSite); }
/** * Update an existing website. * 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. * * @param int website ID defining the website to edit * @param string website name * @param string|array the website URLs * * @exception if any of the parameter is not correct * * @return bool true on success */ public static function updateSite($idSite, $siteName, $urls = null) { Piwik::checkUserHasAdminAccess($idSite); self::checkName($siteName); // SQL fields to update $bind = array(); if (!is_null($urls)) { $urls = self::cleanParameterUrls($urls); self::checkUrls($urls); self::checkAtLeastOneUrl($urls); $url = $urls[0]; $bind['main_url'] = $url; } $bind['name'] = $siteName; $db = Zend_Registry::get('db'); $db->update(Piwik::prefixTable("site"), $bind, "idsite = {$idSite}"); // we now update the main + alias URLs self::deleteSiteAliasUrls($idSite); if (count($urls) > 1) { $insertedUrls = self::addSiteAliasUrls($idSite, array_slice($urls, 1)); } self::postUpdateWebsite($idSite); }
/** * Update an existing website. * 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. * * @param int website ID defining the website to edit * @param string website name * @param string|array the website URLs * @param string Comma separated list of IPs to exclude from being tracked (allows wildcards) * @param string Timezone * @param string Currency code * @param string Group name where this website belongs * @param string Date at which the statistics for this website will start. Defaults to today's date in YYYY-MM-DD format * * @exception if any of the parameter is not correct * * @return bool true on success */ public function updateSite( $idSite, $siteName, $urls = null, $ecommerce = null, $excludedIps = null, $excludedQueryParameters = null, $timezone = null, $currency = null, $group = null, $startDate = null) { Piwik::checkUserHasAdminAccess($idSite); $idSites = Piwik_SitesManager_API::getInstance()->getSitesId(); if(!in_array($idSite, $idSites)) { throw new Exception("website id = $idSite not found"); } $this->checkName($siteName); // SQL fields to update $bind = array(); if(!is_null($urls)) { $urls = $this->cleanParameterUrls($urls); $this->checkUrls($urls); $this->checkAtLeastOneUrl($urls); $url = $urls[0]; $bind['main_url'] = $url; } if(!is_null($currency)) { $currency = trim($currency); $this->checkValidCurrency($currency); $bind['currency'] = $currency; } if(!is_null($timezone)) { $timezone = trim($timezone); $this->checkValidTimezone($timezone); $bind['timezone'] = $timezone; } if(!is_null($group) && Piwik::isUserIsSuperUser()) { $bind['group'] = trim($group); } if(!is_null($ecommerce)) { $bind['ecommerce'] = (int)(bool)$ecommerce; } if(!is_null($startDate)) { $bind['ts_created'] = Piwik_Date::factory($startDate)->getDatetime(); } $bind['excluded_ips'] = $this->checkAndReturnExcludedIps($excludedIps); $bind['excluded_parameters'] = $this->checkAndReturnExcludedQueryParameters($excludedQueryParameters); $bind['name'] = $siteName; $db = Zend_Registry::get('db'); $db->update(Piwik_Common::prefixTable("site"), $bind, "idsite = $idSite" ); // we now update the main + alias URLs $this->deleteSiteAliasUrls($idSite); if(count($urls) > 1) { $insertedUrls = $this->addSiteAliasUrls($idSite, array_slice($urls,1)); } $this->postUpdateWebsite($idSite); }
/** * When tracking data in the past (using Tracking API), this function * can be used to invalidate reports for the idSites and dates where new data * was added. * DEV: If you call this API, the UI should display the data correctly, but will process * in real time, which could be very slow after large data imports. * After calling this function via REST, you can manually force all data * to be reprocessed by visiting the script as the Super User: * http://example.net/piwik/misc/cron/archive.php?token_auth=$SUPER_USER_TOKEN_AUTH_HERE * REQUIREMENTS: On large piwik setups, you will need in PHP configuration: max_execution_time = 0 * We recommend to use an hourly schedule of the script at misc/cron/archive.php * More information: http://piwik.org/setup-auto-archiving/ * * @param string $idSites Comma separated list of idSite that have had data imported for the specified dates * @param string $dates Comma separated list of dates to invalidate for all these websites * @return array */ public function invalidateArchivedReports($idSites, $dates) { $idSites = Piwik_Site::getIdSitesFromIdSitesString($idSites); if (empty($idSites)) { throw new Exception("Specify a value for &idSites= as a comma separated list of website IDs, for which your token_auth has 'admin' permission"); } Piwik::checkUserHasAdminAccess($idSites); // Ensure the specified dates are valid $toInvalidate = $invalidDates = array(); $dates = explode(',', $dates); $dates = array_unique($dates); foreach ($dates as $theDate) { try { $date = Piwik_Date::factory($theDate); } catch (Exception $e) { $invalidDates[] = $theDate; continue; } if ($date->toString() == $theDate) { $toInvalidate[] = $date; } else { $invalidDates[] = $theDate; } } // Lookup archive tables $tables = Piwik::getTablesInstalled(); $archiveTables = Piwik::getTablesArchivesInstalled(); // If using the feature "Delete logs older than N days"... $logsAreDeletedBeforeThisDate = Piwik_Config::getInstance()->Deletelogs['delete_logs_schedule_lowest_interval']; $logsDeleteEnabled = Piwik_Config::getInstance()->Deletelogs['delete_logs_enable']; $minimumDateWithLogs = false; if ($logsDeleteEnabled && $logsAreDeletedBeforeThisDate) { $minimumDateWithLogs = Piwik_Date::factory('today')->subDay($logsAreDeletedBeforeThisDate); } // Given the list of dates, process which tables they should be deleted from $minDate = false; $warningDates = $processedDates = array(); /* @var $date Piwik_Date */ foreach ($toInvalidate as $date) { // we should only delete reports for dates that are more recent than N days if ($minimumDateWithLogs && $date->isEarlier($minimumDateWithLogs)) { $warningDates[] = $date->toString(); } else { $processedDates[] = $date->toString(); } $month = $date->toString('Y_m'); // For a given date, we must invalidate in the monthly archive table $datesByMonth[$month][] = $date->toString(); // But also the year stored in January $year = $date->toString('Y_01'); $datesByMonth[$year][] = $date->toString(); // but also weeks overlapping several months stored in the month where the week is starting /* @var $week Piwik_Period_Week */ $week = Piwik_Period::factory('week', $date); $week = $week->getDateStart()->toString('Y_m'); $datesByMonth[$week][] = $date->toString(); // Keep track of the minimum date for each website if ($minDate === false || $date->isEarlier($minDate)) { $minDate = $date; } } // In each table, invalidate day/week/month/year containing this date $sqlIdSites = implode(",", $idSites); foreach ($archiveTables as $table) { // Extract Y_m from table name $suffix = str_replace(array('archive_numeric_', 'archive_blob_'), '', Piwik_Common::unprefixTable($table)); if (!isset($datesByMonth[$suffix])) { continue; } // Dates which are to be deleted from this table $datesToDeleteInTable = $datesByMonth[$suffix]; // Build one statement to delete all dates from the given table $sql = $bind = array(); $datesToDeleteInTable = array_unique($datesToDeleteInTable); foreach ($datesToDeleteInTable as $dateToDelete) { $sql[] = '(date1 <= ? AND ? <= date2)'; $bind[] = $dateToDelete; $bind[] = $dateToDelete; } $sql = implode(" OR ", $sql); $query = "DELETE FROM {$table} " . " WHERE ( {$sql} ) " . " AND idsite IN (" . $sqlIdSites . ")"; Piwik_Query($query, $bind); // var_dump($query);var_dump($bind); } // Update piwik_site.ts_created $query = "UPDATE " . Piwik_Common::prefixTable("site") . " SET ts_created = ?" . " WHERE idsite IN ( {$sqlIdSites} )\n\t\t\t\t\tAND ts_created > ?"; $minDateSql = $minDate->subDay(1)->getDatetime(); $bind = array($minDateSql, $minDateSql); Piwik_Query($query, $bind); // var_dump($query);var_dump($bind); // Force to re-process data for these websites in the next archive.php cron run $invalidatedIdSites = Piwik_CoreAdminHome_API::getWebsiteIdsToInvalidate(); $invalidatedIdSites = array_merge($invalidatedIdSites, $idSites); $invalidatedIdSites = array_unique($invalidatedIdSites); $invalidatedIdSites = array_values($invalidatedIdSites); Piwik_SetOption(self::OPTION_INVALIDATED_IDSITES, serialize($invalidatedIdSites)); Piwik_Site::clearCache(); $output = array(); // output logs if ($warningDates) { $output[] = 'Warning: the following Dates have not been invalidated, because they are earlier than your Log Deletion limit: ' . implode(", ", $warningDates) . "\n The last day with logs is " . $minimumDateWithLogs . ". " . "\n Please disable 'Delete old Logs' or set it to a higher deletion threshold (eg. 180 days or 365 years).'."; } $output[] = "Success. The following dates were invalidated successfully: " . implode(", ", $processedDates); return $output; }