作者:dorelljame
项目:piwi
public function setUp()
{
parent::setUp();
PiwikCache::flushAll();
Translate::loadAllTranslations();
$this->api = API::getInstance();
}
作者:bossrabbi
项目:piwi
/**
* @return \Piwik\Cache\Lazy
*/
private static function getCache()
{
if (is_null(self::$cache)) {
self::$cache = PiwikCache::getLazyCache();
}
return self::$cache;
}
作者:bossrabbi
项目:piwi
/**
* @return array names of plugins that have been loaded
*/
public function loadTrackerPlugins()
{
$cacheId = 'PluginsTracker';
$cache = Cache::getEagerCache();
if ($cache->contains($cacheId)) {
$pluginsTracker = $cache->fetch($cacheId);
} else {
$this->unloadPlugins();
$this->loadActivatedPlugins();
$pluginsTracker = array();
foreach ($this->loadedPlugins as $pluginName => $plugin) {
if ($this->isTrackerPlugin($plugin)) {
$pluginsTracker[] = $pluginName;
}
}
if (!empty($pluginsTracker)) {
$cache->save($cacheId, $pluginsTracker);
}
}
if (empty($pluginsTracker)) {
$this->unloadPlugins();
return array();
}
$pluginsTracker = array_diff($pluginsTracker, $this->getTrackerPluginsNotToLoad());
$this->doNotLoadAlwaysActivatedPlugins();
$this->loadPlugins($pluginsTracker);
// we could simply unload all plugins first before loading plugins but this way it is much faster
// since we won't have to create each plugin again and we won't have to parse each plugin metadata file
// again etc
$this->makeSureOnlyActivatedPluginsAreLoaded();
return $pluginsTracker;
}
作者:dorelljame
项目:piwi
public function test_onSiteDeleted_shouldClearSiteCache()
{
$cache = Cache::getLazyCache();
$cache->save($this->siteId, 'testcontent');
$this->manager->onSiteDeleted($this->siteId);
$this->assertFalse($cache->contains($this->siteId));
}
作者:FluentDevelopmen
项目:piwi
/**
* Called on Core install, update, plugin enable/disable
* Will clear all cache that could be affected by the change in configuration being made
*/
public static function deleteAllCacheOnUpdate($pluginName = false)
{
AssetManager::getInstance()->removeMergedAssets($pluginName);
View::clearCompiledTemplates();
TrackerCache::deleteTrackerCache();
PiwikCache::flushAll();
self::clearPhpCaches();
}
作者:cem
项目:piwi
public function test_isUsedInAtLeastOneSite_shouldCache()
{
$key = '1.month.' . $this->date;
$cache = Cache::getTransientCache();
$this->assertFalse($cache->contains($key));
$this->userId->isUsedInAtLeastOneSite($idSites = array(1), 'day', $this->date);
$this->assertTrue($cache->contains($key));
$this->assertFalse($cache->fetch($key));
}
作者:CaptainShar
项目:SSAD_Projec
private function isUsedInSiteCached($idSite, $period, $date)
{
$cache = Cache::getTransientCache();
$key = sprintf('%d.%s.%s', $idSite, $period, $date);
if (!$cache->contains($key)) {
$result = $this->isUsedInSite($idSite, $period, $date);
$cache->save($key, $result);
}
return $cache->fetch($key);
}
作者:JoeHor
项目:piwi
/**
* Returns list of search engines by URL
*
* @return array Array of ( URL => array( searchEngineName, keywordParameter, path, charset ) )
*/
public function getDefinitions()
{
$cache = Cache::getEagerCache();
$cacheId = 'Social-' . self::OPTION_STORAGE_NAME;
if ($cache->contains($cacheId)) {
$list = $cache->fetch($cacheId);
} else {
$list = $this->loadDefinitions();
$cache->save($cacheId, $list);
}
return $list;
}
作者:Govanif
项目:piwi
private function getSpammerListFromCache()
{
$cache = Cache::getEagerCache();
$cacheId = 'ReferrerSpamFilter-' . self::OPTION_STORAGE_NAME;
if ($cache->contains($cacheId)) {
$list = $cache->fetch($cacheId);
} else {
$list = $this->loadSpammerList();
$cache->save($cacheId, $list);
}
return $list;
}
作者:mgou-ne
项目:piwi
public function test_getEagerCache_shouldPersistOnceEventWasTriggered()
{
$storageId = 'eagercache-test-ui';
$cache = Cache::getEagerCache();
$cache->save('test', 'mycontent');
// make sure something was changed, otherwise it won't save anything
/** @var Cache\Backend $backend */
$backend = StaticContainer::get('Piwik\\Cache\\Backend');
$this->assertFalse($backend->doContains($storageId));
Piwik::postEvent('Request.dispatch.end');
// should trigger save
$this->assertTrue($backend->doContains($storageId));
}
作者:bossrabbi
项目:piwi
/**
* Returns all language codes the transifex project is available for
*
* @return array
* @throws AuthenticationFailedException
* @throws Exception
*/
public function getAvailableLanguageCodes()
{
$cache = Cache::getTransientCache();
$cacheId = 'transifex_languagescodes_' . $this->projectSlug;
$languageCodes = $cache->fetch($cacheId);
if (empty($languageCodes)) {
$apiData = $this->getApiResults('project/' . $this->projectSlug . '/languages');
foreach ($apiData as $languageData) {
$languageCodes[] = $languageData->language_code;
}
$cache->save($cacheId, $languageCodes);
}
return $languageCodes;
}
作者:piwi
项目:piwi
/**
* Returns a list of all available reports. Even not enabled reports will be returned. They will be already sorted
* depending on the order and category of the report.
* @return \Piwik\Plugin\Report[]
* @api
*/
public function getAllReports()
{
$reports = $this->getAllReportClasses();
$cacheId = CacheId::languageAware('Reports' . md5(implode('', $reports)));
$cache = PiwikCache::getTransientCache();
if (!$cache->contains($cacheId)) {
$instances = array();
/**
* Triggered to add new reports that cannot be picked up automatically by the platform.
* This is useful if the plugin allows a user to create reports / dimensions dynamically. For example
* CustomDimensions or CustomVariables. There are a variable number of dimensions in this case and it
* wouldn't be really possible to create a report file for one of these dimensions as it is not known
* how many Custom Dimensions will exist.
*
* **Example**
*
* public function addReport(&$reports)
* {
* $reports[] = new MyCustomReport();
* }
*
* @param Report[] $reports An array of reports
*/
Piwik::postEvent('Report.addReports', array(&$instances));
foreach ($reports as $report) {
$instances[] = new $report();
}
/**
* Triggered to filter / restrict reports.
*
* **Example**
*
* public function filterReports(&$reports)
* {
* foreach ($reports as $index => $report) {
* if ($report->getCategory() === 'Actions') {}
* unset($reports[$index]); // remove all reports having this action
* }
* }
* }
*
* @param Report[] $reports An array of reports
*/
Piwik::postEvent('Report.filterReports', array(&$instances));
usort($instances, array($this, 'sort'));
$cache->save($cacheId, $instances);
}
return $cache->fetch($cacheId);
}
作者:hichni
项目:piwi
/**
* Setup the database and create the base tables for all tests
*/
public function setUp()
{
parent::setUp();
static::$fixture->extraDefinitions = array_merge(static::provideContainerConfigBeforeClass(), $this->provideContainerConfig());
static::$fixture->createEnvironmentInstance();
Db::createDatabaseObject();
Fixture::loadAllPlugins(new TestingEnvironmentVariables(), get_class($this), self::$fixture->extraPluginsToLoad);
Access::getInstance()->setSuperUserAccess(true);
if (!empty(self::$tableData)) {
self::restoreDbTables(self::$tableData);
}
PiwikCache::getEagerCache()->flushAll();
PiwikCache::getTransientCache()->flushAll();
MenuAbstract::clearMenus();
}
作者:andrzejewsk
项目:plugin-CustomAlert
public function setUp()
{
parent::setUp();
// make sure templates will be found
Plugin\Manager::getInstance()->loadPlugin('CustomAlerts');
Plugin\Manager::getInstance()->loadPlugin('Morpheus');
if (class_exists('\\Piwik\\Cache\\PluginAwareStaticCache')) {
\Piwik\Cache\PluginAwareStaticCache::clearAll();
// TODO remove this one
} else {
PiwikCache::flushAll();
}
Translate::loadAllTranslations();
$this->controller = new CustomController();
}
作者:FluentDevelopmen
项目:piwi
public function test_flushAll_shouldActuallyFlushAllCaches()
{
$cache1 = Cache::getTransientCache();
$cache2 = Cache::getLazyCache();
$cache3 = Cache::getEagerCache();
$cache1->save('test1', 'content');
$cache2->save('test2', 'content');
$cache3->save('test3', 'content');
$this->assertTrue($cache1->contains('test1'));
$this->assertTrue($cache2->contains('test2'));
$this->assertTrue($cache3->contains('test3'));
Cache::flushAll();
$this->assertFalse($cache1->contains('test1'));
$this->assertFalse($cache2->contains('test2'));
$this->assertFalse($cache3->contains('test3'));
}
作者:cem
项目:piwi
private function getSpammerListFromCache()
{
$cache = Cache::getEagerCache();
$cacheId = 'ReferrerSpamFilter-' . self::OPTION_STORAGE_NAME;
if ($cache->contains($cacheId)) {
$list = $cache->fetch($cacheId);
} else {
$list = $this->loadSpammerList();
$cache->save($cacheId, $list);
}
if (!is_array($list)) {
Common::printDebug('Warning: could not read list of spammers from cache.');
return array();
}
return $list;
}
作者:FluentDevelopmen
项目:piwi
/**
* Returns all registered visualization classes. Uses the 'Visualization.getAvailable'
* event to retrieve visualizations.
*
* @return array Array mapping visualization IDs with their associated visualization classes.
* @throws \Exception If a visualization class does not exist or if a duplicate visualization ID
* is found.
* @return array
*/
public static function getAvailableViewDataTables()
{
$cache = Cache::getTransientCache();
$cacheId = 'ViewDataTable.getAvailableViewDataTables';
$dataTables = $cache->fetch($cacheId);
if (!empty($dataTables)) {
return $dataTables;
}
$klassToExtend = '\\Piwik\\Plugin\\ViewDataTable';
/** @var string[] $visualizations */
$visualizations = PluginManager::getInstance()->findMultipleComponents('Visualizations', $klassToExtend);
/**
* Triggered when gathering all available DataTable visualizations.
*
* Plugins that want to expose new DataTable visualizations should subscribe to
* this event and add visualization class names to the incoming array.
*
* **Example**
*
* public function addViewDataTable(&$visualizations)
* {
* $visualizations[] = 'Piwik\\Plugins\\MyPlugin\\MyVisualization';
* }
*
* @param array &$visualizations The array of all available visualizations.
* @ignore
* @deprecated since 2.5.0 Place visualization in a "Visualizations" directory instead.
*/
Piwik::postEvent('ViewDataTable.addViewDataTable', array(&$visualizations));
$result = array();
foreach ($visualizations as $viz) {
if (!class_exists($viz)) {
throw new \Exception("Invalid visualization class '{$viz}' found in Visualization.getAvailableVisualizations.");
}
if (!is_subclass_of($viz, $klassToExtend)) {
throw new \Exception("ViewDataTable class '{$viz}' does not extend Plugin/ViewDataTable");
}
$vizId = $viz::getViewDataTableId();
if (isset($result[$vizId])) {
throw new \Exception("ViewDataTable ID '{$vizId}' is already in use!");
}
$result[$vizId] = $viz;
}
$cache->save($cacheId, $result);
return $result;
}
作者:piwi
项目:piwi
/**
* Returns all registered visualization classes. Uses the 'Visualization.getAvailable'
* event to retrieve visualizations.
*
* @return array Array mapping visualization IDs with their associated visualization classes.
* @throws \Exception If a visualization class does not exist or if a duplicate visualization ID
* is found.
* @return array
*/
public static function getAvailableViewDataTables()
{
$cache = Cache::getTransientCache();
$cacheId = 'ViewDataTable.getAvailableViewDataTables';
$dataTables = $cache->fetch($cacheId);
if (!empty($dataTables)) {
return $dataTables;
}
$klassToExtend = '\\Piwik\\Plugin\\ViewDataTable';
/** @var string[] $visualizations */
$visualizations = PluginManager::getInstance()->findMultipleComponents('Visualizations', $klassToExtend);
$result = array();
foreach ($visualizations as $viz) {
if (!class_exists($viz)) {
throw new \Exception("Invalid visualization class '{$viz}' found in Visualization.getAvailableVisualizations.");
}
if (!is_subclass_of($viz, $klassToExtend)) {
throw new \Exception("ViewDataTable class '{$viz}' does not extend Plugin/ViewDataTable");
}
$vizId = $viz::getViewDataTableId();
if (isset($result[$vizId])) {
throw new \Exception("ViewDataTable ID '{$vizId}' is already in use!");
}
$result[$vizId] = $viz;
}
/**
* Triggered to filter available DataTable visualizations.
*
* Plugins that want to disable certain visualizations should subscribe to
* this event and remove visualizations from the incoming array.
*
* **Example**
*
* public function filterViewDataTable(&$visualizations)
* {
* unset($visualizations[HtmlTable::ID]);
* }
*
* @param array &$visualizations An array of all available visualizations indexed by visualization ID.
* @since Piwik 3.0.0
*/
Piwik::postEvent('ViewDataTable.filterViewDataTable', array(&$result));
$cache->save($cacheId, $result);
return $result;
}
作者:dorelljame
项目:piwi
public function test_getIdSitesToArchiveWhenNoVisits_CanBeUsedToTriggerArchiving_EvenIfSiteHasNoVisits()
{
// add our mock archiver instance
// TODO: should use a dummy plugin that is activated for this test explicitly, but that can be tricky, especially in the future
PluginsArchiver::$archivers['VisitsSummary'] = 'Piwik\\Tests\\Integration\\ArchiveWithNoVisitsTest_MockArchiver';
// initiate archiving w/o adding the event and make sure no methods are called
VisitsSummaryAPI::getInstance()->get($idSite = 1, 'week', '2012-01-01');
$this->assertEmpty(ArchiveWithNoVisitsTest_MockArchiver::$methodsCalled);
// mark our only site as should archive when no visits
$eventDispatcher = $this->getEventDispatcher();
$eventDispatcher->addObserver('Archiving.getIdSitesToArchiveWhenNoVisits', function (&$idSites) {
$idSites[] = 1;
});
Cache::getTransientCache()->flushAll();
// initiate archiving and make sure both aggregate methods are called correctly
VisitsSummaryAPI::getInstance()->get($idSite = 1, 'week', '2012-01-10');
$expectedMethodCalls = array('aggregateDayReport', 'aggregateDayReport', 'aggregateDayReport', 'aggregateDayReport', 'aggregateDayReport', 'aggregateDayReport', 'aggregateDayReport', 'aggregateMultipleReports');
$this->assertEquals($expectedMethodCalls, ArchiveWithNoVisitsTest_MockArchiver::$methodsCalled);
}
作者:FluentDevelopmen
项目:piwi
private function buildCache()
{
return Cache::getLazyCache();
}