Beispiel #1
0
 /**
  * @dataProvider getCommonTestData
  * @group Core
  * @group Segment
  */
 public function testCommon($segment, $expected)
 {
     $select = 'log_visit.idvisit';
     $from = 'log_visit';
     $expected = array('sql' => '
             SELECT
                 log_visit.idvisit
             FROM
                 ' . Piwik_Common::prefixTable('log_visit') . ' AS log_visit
             WHERE
                 ' . $expected['where'], 'bind' => $expected['bind']);
     $segment = new Piwik_Segment($segment, $idSites = array());
     $sql = $segment->getSelectQuery($select, $from, false);
     $this->assertEquals($this->_filterWhitsSpaces($expected), $this->_filterWhitsSpaces($sql));
     // calling twice should give same results
     $sql = $segment->getSelectQuery($select, array($from));
     $this->assertEquals($this->_filterWhitsSpaces($expected), $this->_filterWhitsSpaces($sql));
     $this->assertEquals(32, strlen($segment->getHash()));
 }
Beispiel #2
0
    public function test_common()
    {
        $tests = array('country==France' => array('where' => ' log_visit.location_country = ? ', 'bind' => array('France')), 'country==a\\,==' => array('where' => ' log_visit.location_country = ? ', 'bind' => array('a,==')), 'country==a;visitorType!=returning;visitorType==new' => array('where' => ' log_visit.location_country = ? AND log_visit.visitor_returning <> ? AND log_visit.visitor_returning = ? ', 'bind' => array('a', '1', '0')), 'referrerType==search,referrerType==direct' => array('where' => ' (log_visit.referer_type = ? OR log_visit.referer_type = ? )', 'bind' => array(Piwik_Common::REFERER_TYPE_SEARCH_ENGINE, Piwik_Common::REFERER_TYPE_DIRECT_ENTRY)));
        foreach ($tests as $segment => $expected) {
            $select = 'log_visit.idvisit';
            $from = 'log_visit';
            $expected = array('sql' => '
			SELECT
				log_visit.idvisit
			FROM
				' . Piwik_Common::prefixTable('log_visit') . ' AS log_visit
			WHERE
				' . $expected['where'], 'bind' => $expected['bind']);
            $segment = new Piwik_Segment($segment, $idSites = array());
            $sql = $segment->getSelectQuery($select, $from, false);
            $this->assertEqual($sql, $expected, var_export($sql, true));
            // calling twice should give same results
            $sql = $segment->getSelectQuery($select, array($from));
            $this->assertEqual($sql, $expected, var_export($sql, true));
            $this->assertEqual(strlen($segment->getHash()), 32);
        }
    }
Beispiel #3
0
 /**
  * Generate advisory lock name
  *
  * @param int $idsite
  * @param Piwik_Period $period
  * @return string
  */
 public static function getArchiveProcessingLockName($idsite, $period, Piwik_Segment $segment)
 {
     $config = Zend_Registry::get('config');
     $lockName = 'piwik.' . $config->database->dbname . '.' . $config->database->tables_prefix . '/' . $idsite . '/' . (!$segment->isEmpty() ? $segment->getHash() . '/' : '') . $period->getId() . '/' . $period->getDateStart()->toString('Y-m-d') . ',' . $period->getDateEnd()->toString('Y-m-d');
     return $lockName . '/' . md5($lockName . $config->superuser->salt);
 }
Beispiel #4
0
 /**
  * Returns the name of the archive field used to tell the status of an archive, (ie,
  * whether the archive was created successfully or not).
  *
  * @param Piwik_Segment $segment
  * @param Piwik_Period $period
  * @param string $requestedReport
  * @param bool $flagArchiveAsAllPlugins
  * @return string
  */
 public static function getDoneStringFlagFor($segment, $period, $requestedReport, $flagArchiveAsAllPlugins = false)
 {
     $segmentHash = $segment->getHash();
     if (!self::shouldProcessReportsAllPluginsFor($segment, $period)) {
         $pluginProcessed = self::getPluginBeingProcessed($requestedReport);
         if (!Piwik_PluginsManager::getInstance()->isPluginLoaded($pluginProcessed) || $flagArchiveAsAllPlugins) {
             $pluginProcessed = 'all';
         }
         $segmentHash .= '.' . $pluginProcessed;
     }
     return 'done' . $segmentHash;
 }
Beispiel #5
0
 /**
  * Generate advisory lock name
  *
  * @param int            $idsite
  * @param Piwik_Period   $period
  * @param Piwik_Segment  $segment
  * @return string
  */
 protected function getProcessingLockName($idsite, $period, $segment)
 {
     $config = Config::getInstance();
     $lockName = 'piwik.' . $config->database['dbname'] . '.' . $config->database['tables_prefix'] . '/' . $idsite . '/' . (!$segment->isEmpty() ? $segment->getHash() . '/' : '') . $period->getId() . '/' . $period->getDateStart()->toString('Y-m-d') . ',' . $period->getDateEnd()->toString('Y-m-d');
     $return = $lockName . '/' . md5($lockName . SettingsPiwik::getSalt());
     return $return;
 }
 /**
  * Generate advisory lock name
  *
  * @param int $idsite
  * @param Piwik_Period $period
  * @return string
  */
 public static function getArchiveProcessingLockName($idsite, $period, Piwik_Segment $segment)
 {
     $config = Piwik_Config::getInstance();
     $lockName = 'piwik.' . $config->database['dbname'] . '.' . $config->database['tables_prefix'] . '/' . $idsite . '/' . (!$segment->isEmpty() ? $segment->getHash() . '/' : '') . $period->getId() . '/' . $period->getDateStart()->toString('Y-m-d') . ',' . $period->getDateEnd()->toString('Y-m-d');
     return $lockName . '/' . md5($lockName . $config->superuser['salt']);
 }