本文整理汇总了PHP中Piwik_SetOption函数的典型用法代码示例。如果您正苦于以下问题:PHP Piwik_SetOption函数的具体用法?PHP Piwik_SetOption怎么用?PHP Piwik_SetOption使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Piwik_SetOption函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: check
/**
* Check for a newer version
*/
public static function check()
{
$lastTimeChecked = Piwik_GetOption(self::LAST_TIME_CHECKED);
if($lastTimeChecked === false
|| time() - self::CHECK_INTERVAL > $lastTimeChecked )
{
$parameters = array(
'piwik_version' => Piwik_Version::VERSION,
'php_version' => phpversion(),
'url' => Piwik_Url::getCurrentUrlWithoutQueryString(),
'trigger' => Piwik_Common::getRequestVar('module','','string'),
);
$url = self::PIWIK_HOST . "?" . http_build_query($parameters, '', '&');
$timeout = self::SOCKET_TIMEOUT;
try {
$latestVersion = Piwik::sendHttpRequest($url, $timeout);
Piwik_SetOption(self::LATEST_VERSION, $latestVersion);
} catch(Exception $e) {
// e.g., disable_functions = fsockopen; allow_url_open = Off
Piwik_SetOption(self::LATEST_VERSION, '');
}
Piwik_SetOption(self::LAST_TIME_CHECKED, time(), $autoload = 1);
}
}
示例2: check
/**
* Check for a newer version
*
* @param bool $force Force check
*/
public static function check($force = false)
{
$lastTimeChecked = Piwik_GetOption(self::LAST_TIME_CHECKED);
if($force || $lastTimeChecked === false
|| time() - self::CHECK_INTERVAL > $lastTimeChecked )
{
// set the time checked first, so that parallel Piwik requests don't all trigger the http requests
Piwik_SetOption(self::LAST_TIME_CHECKED, time(), $autoload = 1);
$parameters = array(
'piwik_version' => Piwik_Version::VERSION,
'php_version' => PHP_VERSION,
'url' => Piwik_Url::getCurrentUrlWithoutQueryString(),
'trigger' => Piwik_Common::getRequestVar('module','','string'),
'timezone' => Piwik_SitesManager_API::getInstance()->getDefaultTimezone(),
);
$url = Zend_Registry::get('config')->General->api_service_url;
$url .= '/1.0/getLatestVersion/';
$url .= '?' . http_build_query($parameters, '', '&');
$timeout = self::SOCKET_TIMEOUT;
try {
$latestVersion = Piwik_Http::sendHttpRequest($url, $timeout);
Piwik_SetOption(self::LATEST_VERSION, $latestVersion);
} catch(Exception $e) {
// e.g., disable_functions = fsockopen; allow_url_open = Off
Piwik_SetOption(self::LATEST_VERSION, '');
}
}
}
示例3: cacheDataByArchiveNameReports
/**
* Caches the intermediate DataTables used in the getIndividualReportsSummary and
* getIndividualMetricsSummary reports in the option table.
*/
public function cacheDataByArchiveNameReports()
{
$api = Piwik_DBStats_API::getInstance();
$api->getIndividualReportsSummary(true);
$api->getIndividualMetricsSummary(true);
$now = Piwik_Date::now()->getLocalized("%longYear%, %shortMonth% %day%");
Piwik_SetOption(self::TIME_OF_LAST_TASK_RUN_OPTION, $now);
}
示例4: recordComponentSuccessfullyUpdated
/**
* Record version of successfully completed component update
*
* @param string $name
* @param string $version
*/
public function recordComponentSuccessfullyUpdated($name, $version)
{
try {
Piwik_SetOption('version_' . $name, $version, $autoload = 1);
} catch (Exception $e) {
// case when the option table is not yet created (before 0.2.10)
}
}
示例5: runTasks
static public function runTasks()
{
// Gets the array where rescheduled timetables are stored
$option = Piwik_GetOption(self::TIMETABLE_OPTION_STRING);
$timetable = self::getTimetableFromOption($option);
if($timetable === false) {
return;
}
if(isset($GLOBALS['PIWIK_TRACKER_DEBUG_FORCE_SCHEDULED_TASKS']) && $GLOBALS['PIWIK_TRACKER_DEBUG_FORCE_SCHEDULED_TASKS'])
{
$timetable = array();
}
// Collects tasks
Piwik_PostEvent(self::GET_TASKS_EVENT, $tasks);
$return = array();
// Loop through each task
foreach ($tasks as $task)
{
$scheduledTime = $task->getScheduledTime();
$className = $task->getClassName();
$methodName = $task->getMethodName();
$fullyQualifiedMethodName = get_class($className) . '.' . $methodName;
/*
* Task has to be executed if :
* - it is the first time, ie. rescheduledTime is not set
* - that task has already been executed and the current system time is greater than the
* rescheduled time.
*/
if ( !isset($timetable[$fullyQualifiedMethodName])
|| (isset($timetable[$fullyQualifiedMethodName])
&& time() >= $timetable[$fullyQualifiedMethodName]) )
{
// Updates the rescheduled time
$timetable[$fullyQualifiedMethodName] = $scheduledTime->getRescheduledTime();
Piwik_SetOption(self::TIMETABLE_OPTION_STRING, serialize($timetable));
// Run the task
try {
$timer = new Piwik_Timer;
call_user_func ( array($className,$methodName) );
$message = $timer->__toString();
} catch(Exception $e) {
$message = 'ERROR: '.$e->getMessage();
}
$return[] = array('task' => $fullyQualifiedMethodName, 'output' => $message);
}
}
return $return;
}
示例6: runTasks
/**
* runTasks collects tasks defined within piwik plugins, runs them if they are scheduled and reschedules
* the tasks that have been executed.
*
* @return array
*/
public static function runTasks()
{
// Gets the array where rescheduled timetables are stored
$option = Piwik_GetOption(self::TIMETABLE_OPTION_STRING);
$timetable = self::getTimetableFromOption($option);
if ($timetable === false) {
return;
}
$forceScheduledTasks = false;
if (isset($GLOBALS['PIWIK_TRACKER_DEBUG_FORCE_SCHEDULED_TASKS']) && $GLOBALS['PIWIK_TRACKER_DEBUG_FORCE_SCHEDULED_TASKS'] || DEBUG_FORCE_SCHEDULED_TASKS) {
$forceScheduledTasks = true;
$timetable = array();
}
// Collects tasks
Piwik_PostEvent(self::GET_TASKS_EVENT, $tasks);
$return = array();
// for every priority level, starting with the highest and concluding with the lowest
for ($priority = Piwik_ScheduledTask::HIGHEST_PRIORITY; $priority <= Piwik_ScheduledTask::LOWEST_PRIORITY; ++$priority) {
// Loop through each task
foreach ($tasks as $task) {
// if the task does not have the current priority level, don't execute it yet
if ($task->getPriority() != $priority) {
continue;
}
$scheduledTime = $task->getScheduledTime();
$className = $task->getClassName();
$methodName = $task->getMethodName();
$fullyQualifiedMethodName = get_class($className) . '.' . $methodName;
/*
* Task has to be executed if :
* - it is the first time, ie. rescheduledTime is not set
* - that task has already been executed and the current system time is greater than the
* rescheduled time.
*/
if (!isset($timetable[$fullyQualifiedMethodName]) || isset($timetable[$fullyQualifiedMethodName]) && time() >= $timetable[$fullyQualifiedMethodName] || $forceScheduledTasks) {
// Updates the rescheduled time
$timetable[$fullyQualifiedMethodName] = $scheduledTime->getRescheduledTime();
Piwik_SetOption(self::TIMETABLE_OPTION_STRING, serialize($timetable));
self::$running = true;
// Run the task
try {
$timer = new Piwik_Timer();
call_user_func(array($className, $methodName));
$message = $timer->__toString();
} catch (Exception $e) {
$message = 'ERROR: ' . $e->getMessage();
}
self::$running = false;
$return[] = array('task' => $fullyQualifiedMethodName, 'output' => $message);
}
}
}
return $return;
}
示例7: deleteLogTables
function deleteLogTables()
{
$deleteSettings = Piwik_Config::getInstance()->Deletelogs;
//Make sure, log deletion is enabled
if ($deleteSettings['delete_logs_enable'] == 0) {
return;
}
//Log deletion may not run until it is once rescheduled (initial run). This is the only way to guarantee the calculated next scheduled deletion time.
$initialDelete = Piwik_GetOption(self::OPTION_LAST_DELETE_PIWIK_LOGS_INITIAL);
if (empty($initialDelete)) {
Piwik_SetOption(self::OPTION_LAST_DELETE_PIWIK_LOGS_INITIAL, 1);
return;
}
//Make sure, log purging is allowed to run now
$lastDelete = Piwik_GetOption(self::OPTION_LAST_DELETE_PIWIK_LOGS);
$deleteIntervalSeconds = $this->getDeleteIntervalInSeconds($deleteSettings['delete_logs_schedule_lowest_interval']);
if ($lastDelete === false || $lastDelete !== false && (int) $lastDelete + $deleteIntervalSeconds <= time()) {
$maxIdVisit = $this->getDeleteIdVisitOffset($deleteSettings['delete_logs_older_than']);
$logTables = $this->getDeleteTableLogTables();
//set lastDelete time to today
$date = Piwik_Date::factory("today");
$lastDeleteDate = $date->getTimestamp();
/*
* Tell the DB that log deletion has run BEFORE deletion is executed;
* If deletion / table optimization exceeds execution time, other tasks maybe prevented of being executed every time,
* when the schedule is triggered.
*/
Piwik_SetOption(self::OPTION_LAST_DELETE_PIWIK_LOGS, $lastDeleteDate);
//Break if no ID was found (nothing to delete for given period)
if (empty($maxIdVisit)) {
return;
}
foreach ($logTables as $logTable) {
$this->deleteRowsFromTable($logTable, $maxIdVisit, $deleteSettings['delete_max_rows_per_run'] * self::DELETE_MAX_ROWS_MULTIPLICATOR);
}
//optimize table overhead after deletion
$query = "OPTIMIZE TABLE " . implode(",", $logTables);
Piwik_Query($query);
}
}
示例8: test_RunAllTests
public function test_RunAllTests()
{
parent::test_RunAllTests();
if (Test_Integration::$apiTestingLevel != Test_Integration::NO_API_TESTING) {
$this->_checkExpectedRowsInArchiveTable();
// Force Purge to happen again this table (since it was called at end of archiving)
Piwik_SetOption(Piwik_ArchiveProcessing_Period::FLAG_TABLE_PURGED . Piwik_Common::prefixTable('archive_blob_2010_12'), '2010-01-01');
Piwik_SetOption(Piwik_ArchiveProcessing_Period::FLAG_TABLE_PURGED . Piwik_Common::prefixTable('archive_blob_2011_01'), '2010-01-01');
foreach (array('archive_numeric_2010_12', 'archive_blob_2010_12', 'archive_numeric_2011_01', 'archive_blob_2011_01') as $table) {
// INSERT some ERROR records.
// We use period=range since the test below is restricted to these
Piwik_Query(" INSERT INTO `" . Piwik_Common::prefixTable($table) . "` (`idarchive` ,`name` ,`idsite` ,`date1` ,`date2` ,`period` ,`ts_archived` ,`value`)\n\t\t\t\t\tVALUES (10000, 'done', '1', '2010-12-06', '2010-12-06', '" . Piwik::$idPeriods['range'] . "', '2010-12-06' , '" . Piwik_ArchiveProcessing::DONE_ERROR . "'), \n\t\t\t\t\t\t\t(20000, 'doneX', '2', '2012-07-06', '2012-07-06', '" . Piwik::$idPeriods['range'] . "', '' , '" . Piwik_ArchiveProcessing::DONE_ERROR . "')");
}
// We've added error rows which should fail the following test
$this->_checkExpectedRowsInArchiveTable($expectPass = false);
// Test Scheduled tasks Table Optimize, and Delete old reports
Piwik_CoreAdminHome::purgeOutdatedArchives();
Piwik_CoreAdminHome::optimizeArchiveTable();
// Check that only the good reports were not deleted:
$this->_checkExpectedRowsInArchiveTable();
}
}
开发者ID:nnnnathann,项目名称:piwik,代码行数:22,代码来源:OneVisitorOneWebsite_SeveralDaysDateRange_ArchivingTests.test.php
示例9: check
/**
* Check for a newer version
*
* @param bool $force Force check
*/
public static function check($force = false)
{
$lastTimeChecked = Piwik_GetOption(self::LAST_TIME_CHECKED);
if ($force || $lastTimeChecked === false || time() - self::CHECK_INTERVAL > $lastTimeChecked) {
// set the time checked first, so that parallel Piwik requests don't all trigger the http requests
Piwik_SetOption(self::LAST_TIME_CHECKED, time(), $autoload = 1);
$parameters = array('piwik_version' => Piwik_Version::VERSION, 'php_version' => PHP_VERSION, 'url' => Piwik_Url::getCurrentUrlWithoutQueryString(), 'trigger' => Piwik_Common::getRequestVar('module', '', 'string'), 'timezone' => Piwik_SitesManager_API::getInstance()->getDefaultTimezone());
$url = Piwik_Config::getInstance()->General['api_service_url'] . '/1.0/getLatestVersion/' . '?' . http_build_query($parameters, '', '&');
$timeout = self::SOCKET_TIMEOUT;
if (@Piwik_Config::getInstance()->Debug['allow_upgrades_to_beta']) {
$url = 'http://builds.piwik.org/LATEST_BETA';
}
try {
$latestVersion = Piwik_Http::sendHttpRequest($url, $timeout);
if (!preg_match('~^[0-9][0-9a-zA-Z_.-]*$~D', $latestVersion)) {
$latestVersion = '';
}
} catch (Exception $e) {
// e.g., disable_functions = fsockopen; allow_url_open = Off
$latestVersion = '';
}
Piwik_SetOption(self::LATEST_VERSION, $latestVersion);
}
}
示例10: setUpBeforeClass
public static function setUpBeforeClass()
{
$dbName = false;
if (!empty($GLOBALS['PIWIK_BENCHMARK_DATABASE'])) {
$dbName = $GLOBALS['PIWIK_BENCHMARK_DATABASE'];
}
// connect to database
self::createTestConfig();
self::connectWithoutDatabase();
// create specified fixture (global var not set, use default no-data fixture (see end of this file))
if (empty($GLOBALS['PIWIK_BENCHMARK_FIXTURE'])) {
$fixtureName = 'Piwik_Test_Fixture_EmptyOneSite';
} else {
$fixtureName = 'Piwik_Test_Fixture_' . $GLOBALS['PIWIK_BENCHMARK_FIXTURE'];
}
self::$fixture = new $fixtureName();
// figure out if the desired fixture has already been setup, and if not empty the database
$installedFixture = false;
try {
if (isset(self::$fixture->tablesPrefix)) {
Piwik_Config::getInstance()->database['tables_prefix'] = self::$fixture->tablesPrefix;
Piwik_Common::$cachedTablePrefix = null;
}
Piwik_Query("USE " . $dbName);
$installedFixture = Piwik_GetOption('benchmark_fixture_name');
} catch (Exception $ex) {
// ignore
}
$createEmptyDatabase = $fixtureName != $installedFixture;
parent::setUpBeforeClass($dbName, $createEmptyDatabase, $createConfig = false);
// if we created an empty database, setup the fixture
if ($createEmptyDatabase) {
self::$fixture->setUp();
Piwik_SetOption('benchmark_fixture_name', $fixtureName);
}
}
示例11: test_deleteLike
public function test_deleteLike()
{
// empty table, expect false (i.e., not found)
$this->assertTrue(Piwik_GetOption('anonymous_defaultReport') === false);
$this->assertTrue(Piwik_GetOption('admin_defaultReport') === false);
$this->assertTrue(Piwik_GetOption('visitor_defaultReport') === false);
// insert guard - to test unescaped underscore
Piwik_SetOption('adefaultReport', '0', true);
$this->assertTrue(Piwik_GetOption('adefaultReport') === '0');
// populate table, expect '1'
Piwik_SetOption('anonymous_defaultReport', '1', true);
Piwik_Option::getInstance()->deleteLike('\\_defaultReport');
$this->assertTrue(Piwik_Option::getInstance()->get('anonymous_defaultReport') === '1');
$this->assertTrue(Piwik_GetOption('adefaultReport') === '0');
// populate table, expect '2'
Piwik_SetOption('admin_defaultReport', '2', false);
Piwik_Option::getInstance()->deleteLike('\\_defaultReport');
$this->assertTrue(Piwik_Option::getInstance()->get('admin_defaultReport') === '2');
$this->assertTrue(Piwik_GetOption('adefaultReport') === '0');
// populate table, expect '3'
Piwik_SetOption('visitor_defaultReport', '3', false);
Piwik_Option::getInstance()->deleteLike('\\_defaultReport');
$this->assertTrue(Piwik_Option::getInstance()->get('visitor_defaultReport') === '3');
$this->assertTrue(Piwik_GetOption('adefaultReport') === '0');
// delete with non-matching value, expect '1'
Piwik_Option::getInstance()->deleteLike('%\\_defaultReport', '4');
$this->assertTrue(Piwik_Option::getInstance()->get('anonymous_defaultReport') === '1');
$this->assertTrue(Piwik_GetOption('adefaultReport') === '0');
// delete with matching pattern, expect false
Piwik_Option::getInstance()->deleteLike('%\\_defaultReport', '1');
$this->assertTrue(Piwik_Option::getInstance()->get('anonymous_defaultReport') === false);
$this->assertTrue(Piwik_GetOption('adefaultReport') === '0');
// this shouldn't have been deleted, expect '2' and '3'
$this->assertTrue(Piwik_Option::getInstance()->get('admin_defaultReport') === '2');
$this->assertTrue(Piwik_Option::getInstance()->get('visitor_defaultReport') === '3');
$this->assertTrue(Piwik_GetOption('adefaultReport') === '0');
// deleted, expect false (except for the guard)
Piwik_Option::getInstance()->deleteLike('%\\_defaultReport');
$this->assertTrue(Piwik_Option::getInstance()->get('admin_defaultReport') === false);
$this->assertTrue(Piwik_Option::getInstance()->get('visitor_defaultReport') === false);
// unescaped backslash (single quotes)
Piwik_Option::getInstance()->deleteLike('%\\_defaultReport');
$this->assertTrue(Piwik_GetOption('adefaultReport') === '0');
// escaped backslash (single quotes)
Piwik_Option::getInstance()->deleteLike('%\\_defaultReport');
$this->assertTrue(Piwik_GetOption('adefaultReport') === '0');
// unescaped backslash (double quotes)
Piwik_Option::getInstance()->deleteLike("%\\_defaultReport");
$this->assertTrue(Piwik_GetOption('adefaultReport') === '0');
// escaped backslash (double quotes)
Piwik_Option::getInstance()->deleteLike("%\\_defaultReport");
$this->assertTrue(Piwik_GetOption('adefaultReport') === '0');
}
示例12: getRowCountsByArchiveName
/**
* Utility function. Gets row count of a set of tables grouped by the 'name' column.
* This is the implementation of the getRowCountsAndSizeBy... functions.
*/
private function getRowCountsByArchiveName($statuses, $getRowSizeMethod, $forceCache = false, $otherSelects = array(), $otherDataTableColumns = array())
{
$extraCols = '';
if (!empty($otherSelects)) {
$extraCols = ', ' . implode(', ', $otherSelects);
}
$cols = array_merge(array('row_count'), $otherDataTableColumns);
$dataTable = new Piwik_DataTable();
foreach ($statuses as $status) {
$dataTableOptionName = $this->getCachedOptionName($status['Name'], 'byArchiveName');
// if option exists && !$forceCache, use the cached data, otherwise create the
$cachedData = Piwik_GetOption($dataTableOptionName);
if ($cachedData !== false && !$forceCache) {
$table = new Piwik_DataTable();
$table->addRowsFromSerializedArray($cachedData);
} else {
// otherwise, create data table & cache it
$sql = "SELECT name as 'label', COUNT(*) as 'row_count'{$extraCols} FROM {$status['Name']} GROUP BY name";
$table = new Piwik_DataTable();
$table->addRowsFromSimpleArray(Piwik_FetchAll($sql));
$reduceArchiveRowName = array($this, 'reduceArchiveRowName');
$table->filter('GroupBy', array('label', $reduceArchiveRowName));
$serializedTables = $table->getSerialized();
$serializedTable = reset($serializedTables);
Piwik_SetOption($dataTableOptionName, $serializedTable);
}
// add estimated_size column
$getEstimatedSize = array($this, $getRowSizeMethod);
$table->filter('ColumnCallbackAddColumn', array($cols, 'estimated_size', $getEstimatedSize, array($status)));
$dataTable->addDataTable($table);
destroy($table);
}
return $dataTable;
}
示例13: setCurrentProvider
/**
* Sets the provider to use when tracking.
*
* @param string $providerId The ID of the provider to use.
* @return Piwik_UserCountry_LocationProvider The new current provider.
* @throws Exception If the provider ID is invalid.
*/
public static function setCurrentProvider($providerId)
{
$provider = self::getProviderById($providerId);
if ($provider === false) {
throw new Exception("Invalid provider ID '{$providerId}'. The provider either does not exist or is not available");
}
Piwik_SetOption(self::CURRENT_PROVIDER_OPTION_NAME, $providerId);
return $provider;
}
示例14: setDefaultTimezone
/**
* Sets the default timezone that will be used when creating websites
*
* @param string $defaultTimezone Timezone string eg. Europe/Paris or UTC+8
* @return bool
*/
public function setDefaultTimezone($defaultTimezone)
{
Piwik::checkUserIsSuperUser();
$this->checkValidTimezone($defaultTimezone);
Piwik_SetOption(self::OPTION_DEFAULT_TIMEZONE, $defaultTimezone);
return true;
}
示例15: setBrowserTriggerArchiving
public static function setBrowserTriggerArchiving($enabled)
{
if (!is_bool($enabled)) {
throw new Exception('Browser trigger archiving must be set to true or false.');
}
Piwik_SetOption(self::OPTION_BROWSER_TRIGGER_ARCHIVING, (int) $enabled, $autoload = true);
Piwik_Common::clearCacheGeneral();
}