update Piwik to version 2.16 (fixes #91)

This commit is contained in:
oliver 2016-04-10 18:55:57 +02:00
commit d885a4baa9
5833 changed files with 418860 additions and 226988 deletions

View file

@ -5,7 +5,7 @@ require_once '../../libs/PiwikTracker/PiwikTracker.php';
PiwikTracker::$URL = 'http://localhost/trunk/';
$piwikTracker = new PiwikTracker($idSite = 1);
// You can manually set the Visitor details (resolution, time, plugins)
// You can manually set the Visitor details (resolution, time, plugins)
// See all other ->set* functions available in the PiwikTracker class
$piwikTracker->setResolution(1600, 1400);

View file

@ -8,17 +8,18 @@ define('PIWIK_ENABLE_DISPATCH', false);
define('PIWIK_ENABLE_ERROR_HANDLER', false);
define('PIWIK_ENABLE_SESSION_START', false);
// if you prefer not to include 'index.php', you must also define here PIWIK_DOCUMENT_ROOT
// and include "libs/upgradephp/upgrade.php" and "core/Loader.php"
require_once PIWIK_INCLUDE_PATH . "/index.php";
require_once PIWIK_INCLUDE_PATH . "/core/API/Request.php";
$environment = new \Piwik\Application\Environment(null);
$environment->init();
FrontController::getInstance()->init();
// This inits the API Request with the specified parameters
$request = new Request('
module=API
&method=UserSettings.getResolution
&method=Resolution.getResolution
&idSite=7
&date=yesterday
&period=week

View file

@ -1,7 +1,7 @@
<?php
exit; // REMOVE this line to run the script
// this token is used to authenticate your API request.
// this token is used to authenticate your API request.
// You can get the token on the API page inside your Piwik interface
$token_auth = 'anonymous';
@ -20,11 +20,11 @@ if (!$content) {
print("Error, content fetched = " . $fetched);
}
print("<h1>Keywords for the last month</h1>");
print("<h1>Keywords for the last month</h1>\n");
foreach ($content as $row) {
$keyword = htmlspecialchars(html_entity_decode(urldecode($row['label']), ENT_QUOTES), ENT_QUOTES);
$hits = $row['nb_visits'];
print("<b>$keyword</b> ($hits hits)<br>");
print("<b>$keyword</b> ($hits hits)<br>\n");
}

View file

@ -1,39 +0,0 @@
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
use Piwik\Config;
use Piwik\FrontController;
error_reporting(E_ALL | E_NOTICE);
define('PIWIK_DOCUMENT_ROOT', dirname(__FILE__) == '/' ? '' : dirname(__FILE__) . '/../..');
if (file_exists(PIWIK_DOCUMENT_ROOT . '/bootstrap.php')) {
require_once PIWIK_DOCUMENT_ROOT . '/bootstrap.php';
}
if (!defined('PIWIK_USER_PATH')) {
define('PIWIK_USER_PATH', PIWIK_DOCUMENT_ROOT);
}
if (!defined('PIWIK_INCLUDE_PATH')) {
define('PIWIK_INCLUDE_PATH', PIWIK_DOCUMENT_ROOT);
}
ignore_user_abort(true);
set_time_limit(0);
@date_default_timezone_set('UTC');
require_once PIWIK_INCLUDE_PATH . '/libs/upgradephp/upgrade.php';
require_once PIWIK_INCLUDE_PATH . '/core/testMinimumPhpVersion.php';
require_once PIWIK_INCLUDE_PATH . '/core/Loader.php';
$GLOBALS['PIWIK_TRACKER_DEBUG'] = false;
define('PIWIK_ENABLE_DISPATCH', false);
Config::getInstance()->log['log_writers'][] = 'screen';
Config::getInstance()->log['log_level'] = 'VERBOSE';
Config::getInstance()->log['string_message_format'] = "%message%";
FrontController::getInstance()->init();

View file

@ -2,10 +2,8 @@ Count the download for 'latest.zip' on the 20th March
# cat access.log | grep "20/Mar" | grep "latest.zip" | awk '{print $1}' | sort | uniq | wc -l
Value to be compared with the one given by Piwik in Actions > Downloads
Count the no of hits by referrers, excluding piwik.org as a referer
# cat /var/log/apache2/access.log | awk '{print $11}' | grep -vE "(^"-"$|/dev.piwik.org|/piwik.org)" | sort | uniq -c | sort -rn | head -n20

234
www/analytics/misc/others/geoipUpdateRows.php Executable file → Normal file
View file

@ -1,233 +1,5 @@
<?php
use Piwik\Common;
use Piwik\Config;
use Piwik\Db;
use Piwik\FrontController;
use Piwik\IP;
use Piwik\Log;
use Piwik\Piwik;
use Piwik\Plugins\UserCountry\LocationProvider\GeoIp\Pecl;
use Piwik\Plugins\UserCountry\LocationProvider;
use Piwik\Plugins\UserCountry\LocationProvider\GeoIp\Php;
require_once './cli-script-bootstrap.php';
ini_set("memory_limit", "512M");
$query = "SELECT count(*) FROM " . Common::prefixTable('log_visit');
$count = Db::fetchOne($query);
// when script run via browser, check for Super User & output html page to do conversion via AJAX
if (!Common::isPhpCliMode()) {
try {
Piwik::checkUserHasSuperUserAccess();
} catch (Exception $e) {
Log::error('[error] You must be logged in as Super User to run this script. Please login in to Piwik and refresh this page.');
exit;
}
// the 'start' query param will be supplied by the AJAX requests, so if it's not there, the
// user is viewing the page in the browser.
if (Common::getRequestVar('start', false) === false) {
// output HTML page that runs update via AJAX
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<script type="text/javascript" src="../../libs/jquery/jquery.js"></script>
<script type="text/javascript">
(function ($) {
var count = <?php echo $count; ?>;
var doIteration = function (start) {
if (start >= count) {
return;
}
var end = Math.min(start + 100, count);
$.ajax({
type: 'POST',
url: 'geoipUpdateRows.php',
data: {
start: start,
end: end
},
async: true,
error: function (xhr, status, error) {
$('body')
.append(xhr.responseText)
.append('<div style="color:red"><strong>An error occured!</strong></div>');
},
success: function (response) {
doIteration(end);
$('body').append(response);
var body = $('body')[0];
body.scrollTop = body.scrollHeight;
}
});
};
doIteration(0);
}(jQuery));
</script>
</head>
<body>
</body>
</html>
<?php
exit;
} else {
$start = Common::getRequestVar('start', 0, 'int');
$end = min($count, Common::getRequestVar('end', $count, 'int'));
$limit = $end - $start;
}
} else // command line
{
$start = 0;
$end = $count;
$limit = 1000;
}
function geoipUpdateError($message)
{
Log::error($message);
if (!Common::isPhpCliMode()) {
@header('HTTP/1.1 500 Internal Server Error', $replace = true, $responseCode = 500);
}
exit;
}
// only display notes if on command line (where start will == 0 for that part of script) or on
// first AJAX call by browser
$displayNotes = $start == 0;
// try getting the pecl location provider
$provider = new Pecl();
if (!$provider->isAvailable()) {
if ($displayNotes) {
Log::info("[note] The GeoIP PECL extension is not installed.");
}
$provider = null;
} else {
$workingOrError = $provider->isWorking();
if ($workingOrError !== true) {
if ($displayNotes) {
Log::info("[note] The GeoIP PECL extension is broken: $workingOrError");
}
if (Common::isPhpCliMode()) {
Log::info("[note] Make sure your command line PHP is configured to use the PECL extension.");
}
$provider = null;
}
}
// use php api if pecl extension cannot be used
if (is_null($provider)) {
if ($displayNotes) {
Log::info("[note] Falling back to PHP API. This may become too slow for you. If so, you can read this link on how to install the PECL extension: http://piwik.org/faq/how-to/#faq_164");
}
$provider = new Php();
if (!$provider->isAvailable()) {
if ($displayNotes) {
Log::info("[note] The GeoIP PHP API is not available. This means you do not have a GeoIP location database in your ./misc directory. The database must be named either GeoIP.dat or GeoIPCity.dat based on the type of database it is.");
}
$provider = null;
} else {
$workingOrError = $provider->isWorking();
if ($workingOrError !== true) {
if ($displayNotes) {
Log::info("[note] The GeoIP PHP API is broken: $workingOrError");
}
$provider = null;
}
}
}
if (is_null($provider)) {
geoipUpdateError("\n[error] There is no location provider that can be used with this script. Only the GeoIP PECL module or the GeoIP PHP API can be used at present. Please install and configure one of these first.");
}
$info = $provider->getInfo();
if ($displayNotes) {
Log::info("[note] Found working provider: {$info['id']}");
}
// perform update
$logVisitFieldsToUpdate = array('location_country' => LocationProvider::COUNTRY_CODE_KEY,
'location_region' => LocationProvider::REGION_CODE_KEY,
'location_city' => LocationProvider::CITY_NAME_KEY,
'location_latitude' => LocationProvider::LATITUDE_KEY,
'location_longitude' => LocationProvider::LONGITUDE_KEY);
if ($displayNotes) {
Log::info("\n$count rows to process in " . Common::prefixTable('log_visit')
. " and " . Common::prefixTable('log_conversion') . "...");
}
flush();
for (; $start < $end; $start += $limit) {
$rows = Db::fetchAll("SELECT idvisit, location_ip, " . implode(',', array_keys($logVisitFieldsToUpdate)) . "
FROM " . Common::prefixTable('log_visit') . "
LIMIT $start, $limit");
if (!count($rows)) {
continue;
}
foreach ($rows as $i => $row) {
$fieldsToSet = array();
foreach ($logVisitFieldsToUpdate as $field => $ignore) {
if (empty($fieldsToSet[$field])) {
$fieldsToSet[] = $field;
}
}
// skip if it already has a location
if (empty($fieldsToSet)) {
continue;
}
$ip = IP::N2P($row['location_ip']);
$location = $provider->getLocation(array('ip' => $ip));
if (!empty($location[LocationProvider::COUNTRY_CODE_KEY])) {
$location[LocationProvider::COUNTRY_CODE_KEY] =
strtolower($location[LocationProvider::COUNTRY_CODE_KEY]);
}
$row['location_country'] = strtolower($row['location_country']);
$columnsToSet = array();
$bind = array();
foreach ($logVisitFieldsToUpdate as $column => $locationKey) {
if (!empty($location[$locationKey])
&& $location[$locationKey] != $row[$column]
) {
$columnsToSet[] = $column . ' = ?';
$bind[] = $location[$locationKey];
}
}
if (empty($columnsToSet)) {
continue;
}
$bind[] = $row['idvisit'];
// update log_visit
$sql = "UPDATE " . Common::prefixTable('log_visit') . "
SET " . implode(', ', $columnsToSet) . "
WHERE idvisit = ?";
Db::query($sql, $bind);
// update log_conversion
$sql = "UPDATE " . Common::prefixTable('log_conversion') . "
SET " . implode(', ', $columnsToSet) . "
WHERE idvisit = ?";
Db::query($sql, $bind);
}
Log::info(round($start * 100 / $count) . "% done...");
flush();
}
if ($start >= $count) {
Log::info("100% done!");
Log::info("");
Log::info("[note] Now that you've geolocated your old visits, you need to force your reports to be re-processed. See this FAQ entry: http://piwik.org/faq/how-to/#faq_59");
}
echo "This script has been removed, instead use the 'usercountry:attribute' command.\n";
echo "For example, run 'php /path/to/piwik/console usercountry:attribute 2012-01-01,2013-01-01'.\n";
echo "To learn more about the new command, run 'php /path/to/piwik/console help usercountry:attribute'.\n";

View file

@ -1,159 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<code_scheme name="Piwik-codestyle">
<option name="LINE_SEPARATOR" value="&#10;" />
<option name="RIGHT_MARGIN" value="160" />
<PHPCodeStyleSettings>
<option name="ALIGN_KEY_VALUE_PAIRS" value="true" />
<option name="LOWER_CASE_BOOLEAN_CONST" value="true" />
<option name="LOWER_CASE_NULL_CONST" value="true" />
</PHPCodeStyleSettings>
<XML>
<option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" />
</XML>
<codeStyleSettings language="JavaScript">
<option name="ALIGN_MULTILINE_PARAMETERS" value="false" />
<option name="KEEP_SIMPLE_BLOCKS_IN_ONE_LINE" value="true" />
<option name="KEEP_SIMPLE_METHODS_IN_ONE_LINE" value="true" />
</codeStyleSettings>
<codeStyleSettings language="PHP">
<option name="ALIGN_MULTILINE_ARRAY_INITIALIZER_EXPRESSION" value="true" />
<arrangement>
<groups>
<group>
<type>DEPENDENT_METHODS</type>
<order>BREADTH_FIRST</order>
</group>
</groups>
<rules>
<rule>
<match>
<CONST />
</match>
</rule>
<rule>
<match>
<AND>
<FIELD />
<PUBLIC />
<STATIC />
</AND>
</match>
</rule>
<rule>
<match>
<AND>
<FIELD />
<PROTECTED />
<STATIC />
</AND>
</match>
</rule>
<rule>
<match>
<AND>
<FIELD />
<PRIVATE />
<STATIC />
</AND>
</match>
</rule>
<rule>
<match>
<AND>
<FIELD />
<PUBLIC />
</AND>
</match>
</rule>
<rule>
<match>
<AND>
<FIELD />
<PROTECTED />
</AND>
</match>
</rule>
<rule>
<match>
<AND>
<FIELD />
<PRIVATE />
</AND>
</match>
</rule>
<rule>
<match>
<CONSTRUCTOR />
</match>
</rule>
<rule>
<match>
<AND>
<METHOD />
<PUBLIC />
<STATIC />
</AND>
</match>
</rule>
<rule>
<match>
<AND>
<METHOD />
<PROTECTED />
<STATIC />
</AND>
</match>
</rule>
<rule>
<match>
<AND>
<METHOD />
<PRIVATE />
<STATIC />
</AND>
</match>
</rule>
<rule>
<match>
<AND>
<METHOD />
<PUBLIC />
</AND>
</match>
</rule>
<rule>
<match>
<AND>
<METHOD />
<PROTECTED />
</AND>
</match>
</rule>
<rule>
<match>
<AND>
<METHOD />
<PRIVATE />
</AND>
</match>
</rule>
<rule>
<match>
<TRAIT />
</match>
</rule>
<rule>
<match>
<INTERFACE />
</match>
</rule>
<rule>
<match>
<CLASS />
</match>
</rule>
</rules>
</arrangement>
</codeStyleSettings>
</code_scheme>

View file

@ -1,21 +0,0 @@
Phpstorm has an awesome feature called "Reformat code" which reformats all PHP code to follow a particular selected coding style.
Piwik uses PSR coding standard for php source code. We use a slightly customized PSR style
(because the default PSR style in Phpstorm results in some unwanted changes).
Steps:
* Use latest Phpstorm
* Copy this Piwik_codestyle.xml file in your ~/.WebIde60/config/codestyles/
* If you use Windows or Mac see which path to copy at: http://intellij-support.jetbrains.com/entries/23358108
* To automatically link to the file in Piwik:
`$ ln -s ~/dev/piwik-master/misc/others/phpstorm-codestyles/Piwik_codestyle.xml ~/.WebIde70/config/codestyles/Piwik_codestyle.xml`
* Restart PhpStorm.
* Select this coding in Settings>Code style.
Phpstorm can also be configured to apply the style automatically before commit.
You are now writing code that respects Piwik coding standards. Enjoy!
Reference: http://piwik.org/participate/coding-standards/

View file

@ -1,27 +0,0 @@
<?php
// Script that creates 100 websites, then outputs a IMG that records a pageview in each website
// Used initially to test how to handle cookies for this use case (see http://dev.piwik.org/trac/ticket/409)
use Piwik\Common;
use Piwik\FrontController;
use Piwik\Piwik;
use Piwik\Plugins\SitesManager\API;
exit;
define('PIWIK_INCLUDE_PATH', '../..');
define('PIWIK_ENABLE_DISPATCH', false);
define('PIWIK_ENABLE_ERROR_HANDLER', false);
define('PIWIK_ENABLE_SESSION_START', false);
require_once PIWIK_INCLUDE_PATH . "/index.php";
require_once PIWIK_INCLUDE_PATH . "/core/API/Request.php";
require_once PIWIK_INCLUDE_PATH . "/libs/PiwikTracker/PiwikTracker.php";
FrontController::getInstance()->init();
Piwik::setUserHasSuperUserAccess();
$count = 100;
for ($i = 0; $i <= $count; $i++) {
$id = API::getInstance()->addSite(Common::getRandomString(), 'http://piwik.org');
$t = new PiwikTracker($id, 'http://localhost/trunk/piwik.php');
echo $id . " <img width=100 height=10 border=1 src='" . $t->getUrlTrackPageView('title') . "'><br/>";
}

View file

@ -1,154 +0,0 @@
<?php
use Piwik\Common;
use Piwik\Config;
use Piwik\FrontController;
use Piwik\Log;
define('PIWIK_INCLUDE_PATH', realpath(dirname(__FILE__) . "/../.."));
define('PIWIK_ENABLE_DISPATCH', false);
define('PIWIK_ENABLE_ERROR_HANDLER', false);
define('PIWIK_ENABLE_SESSION_START', false);
require_once PIWIK_INCLUDE_PATH . "/index.php";
require_once PIWIK_INCLUDE_PATH . "/core/API/Request.php";
require_once PIWIK_INCLUDE_PATH . "/libs/PiwikTracker/PiwikTracker.php";
FrontController::getInstance()->init();
// SECURITY: DO NOT DELETE THIS LINE!
if (!Common::isPhpCliMode()) {
die("ERROR: Must be executed in CLI");
}
$process = new Piwik_StressTests_CopyLogs;
$process->init();
$process->run();
//$process->delete();
class Piwik_StressTests_CopyLogs
{
function init()
{
$config = Config::getInstance();
$config->log['log_only_when_debug_parameter'] = 0;
$config->log['log_writers'] = array('screen');
$config->log['log_level'] = 'VERBOSE';
}
function run()
{
// Copy all visits in date range into TODAY
$startDate = '2011-08-12';
$endDate = '2011-08-12';
$this->log("Starting...");
$db = \Zend_Registry::get('db');
$initial = $this->getVisitsToday();
$this->log(" Visits today so far: " . $initial);
$initialActions = $this->getActionsToday();
$this->log(" Actions today: " . $initialActions);
$initialPurchasedItems = $this->getConversionItemsToday();
$this->log(" Purchased items today: " . $initialPurchasedItems);
$initialConversions = $this->getConversionsToday();
$this->log(" Conversions today: " . $initialConversions);
$this->log(" Now copying visits between '$startDate' and '$endDate'...");
$sql = "INSERT INTO " . Common::prefixTable('log_visit') . " (`idsite`, `idvisitor`, `visitor_localtime`, `visitor_returning`, `visitor_count_visits`, `visit_first_action_time`, `visit_last_action_time`, `visit_exit_idaction_url`, `visit_exit_idaction_name`, `visit_entry_idaction_url`, `visit_entry_idaction_name`, `visit_total_actions`, `visit_total_time`, `visit_goal_converted`, `visit_goal_buyer`, `referer_type`, `referer_name`, `referer_url`, `referer_keyword`, `config_id`, `config_os`, `config_browser_name`, `config_browser_version`, `config_resolution`, `config_pdf`, `config_flash`, `config_java`, `config_director`, `config_quicktime`, `config_realplayer`, `config_windowsmedia`, `config_gears`, `config_silverlight`, `config_cookie`, `location_ip`, `location_browser_lang`, `location_country`, `location_provider`, `custom_var_k1`, `custom_var_v1`, `custom_var_k2`, `custom_var_v2`, `custom_var_k3`, `custom_var_v3`, `custom_var_k4`, `custom_var_v4`, `custom_var_k5`, `custom_var_v5`, `visitor_days_since_last`, `visitor_days_since_order`, `visitor_days_since_first`)
SELECT `idsite`, `idvisitor`, `visitor_localtime`, `visitor_returning`, `visitor_count_visits`, CONCAT(CURRENT_DATE() , \" \", FLOOR(RAND()*24) , \":\",FLOOR(RAND()*60),\":\",FLOOR(RAND()*60)), CONCAT(CURRENT_DATE() , \" \", FLOOR(RAND()*24) , \":\",FLOOR(RAND()*60),\":\",FLOOR(RAND()*60)), `visit_exit_idaction_url`, `visit_exit_idaction_name`, `visit_entry_idaction_url`, `visit_entry_idaction_name`, `visit_total_actions`, `visit_total_time`, `visit_goal_converted`, `visit_goal_buyer`, `referer_type`, `referer_name`, `referer_url`, `referer_keyword`, `config_id`, `config_os`, `config_browser_name`, `config_browser_version`, `config_resolution`, `config_pdf`, `config_flash`, `config_java`, `config_director`, `config_quicktime`, `config_realplayer`, `config_windowsmedia`, `config_gears`, `config_silverlight`, `config_cookie`, `location_ip`, `location_browser_lang`, `location_country`, `location_provider`, `custom_var_k1`, `custom_var_v1`, `custom_var_k2`, `custom_var_v2`, `custom_var_k3`, `custom_var_v3`, `custom_var_k4`, `custom_var_v4`, `custom_var_k5`, `custom_var_v5`, `visitor_days_since_last`, `visitor_days_since_order`, `visitor_days_since_first`
FROM `" . Common::prefixTable('log_visit') . "`
WHERE idsite >= 1 AND date(visit_last_action_time) between '$startDate' and '$endDate' ;";
$result = $db->query($sql);
$this->log(" Copying actions...");
$sql = "INSERT INTO " . Common::prefixTable('log_link_visit_action') . " (`idsite`, `idvisitor`, `server_time`, `idvisit`, `idaction_url`, `idaction_url_ref`, `idaction_name`, `idaction_name_ref`, `time_spent_ref_action`, `custom_var_k1`, `custom_var_v1`, `custom_var_k2`, `custom_var_v2`, `custom_var_k3`, `custom_var_v3`, `custom_var_k4`, `custom_var_v4`, `custom_var_k5`, `custom_var_v5`)
SELECT `idsite`, `idvisitor`, CONCAT(CURRENT_DATE() , \" \", FLOOR(RAND()*24) , \":\",FLOOR(RAND()*60),\":\",FLOOR(RAND()*60)), `idvisit`, `idaction_url`, `idaction_url_ref`, `idaction_name`, `idaction_name_ref`, `time_spent_ref_action`, `custom_var_k1`, `custom_var_v1`, `custom_var_k2`, `custom_var_v2`, `custom_var_k3`, `custom_var_v3`, `custom_var_k4`, `custom_var_v4`, `custom_var_k5`, `custom_var_v5`
FROM `" . Common::prefixTable('log_link_visit_action') . "`
WHERE idsite >= 1 AND date(server_time) between '$startDate' and '$endDate'
;"; // LIMIT 1000000
$result = $db->query($sql);
$this->log(" Copying conversions...");
$sql = "INSERT IGNORE INTO `" . Common::prefixTable('log_conversion') . "` (`idvisit`, `idsite`, `visitor_days_since_first`, `visitor_days_since_order`, `visitor_count_visits`, `idvisitor`, `server_time`, `idaction_url`, `idlink_va`, `referer_visit_server_date`, `referer_type`, `referer_name`, `referer_keyword`, `visitor_returning`, `location_country`, `url`, `idgoal`, `revenue`, `buster`, `idorder`, `custom_var_k1`, `custom_var_v1`, `custom_var_k2`, `custom_var_v2`, `custom_var_k3`, `custom_var_v3`, `custom_var_k4`, `custom_var_v4`, `custom_var_k5`, `custom_var_v5`, `items`, `revenue_subtotal`, `revenue_tax`, `revenue_shipping`, `revenue_discount`)
SELECT `idvisit`, `idsite`, `visitor_days_since_first`, `visitor_days_since_order`, `visitor_count_visits`, `idvisitor`, CONCAT(CURRENT_DATE() , \" \", FLOOR(RAND()*24) , \":\",FLOOR(RAND()*60),\":\",FLOOR(RAND()*60)), `idaction_url`, `idlink_va`, `referer_visit_server_date`, `referer_type`, `referer_name`, `referer_keyword`, `visitor_returning`, `location_country`, `url`, `idgoal`, `revenue`, FLOOR(`buster` * RAND()), CONCAT(`idorder`,SUBSTRING(MD5(RAND()) FROM 1 FOR 9)) , `custom_var_k1`, `custom_var_v1`, `custom_var_k2`, `custom_var_v2`, `custom_var_k3`, `custom_var_v3`, `custom_var_k4`, `custom_var_v4`, `custom_var_k5`, `custom_var_v5`, `items`, `revenue_subtotal`, `revenue_tax`, `revenue_shipping`, `revenue_discount`
FROM `" . Common::prefixTable('log_conversion') . "`
WHERE idsite >= 1 AND date(server_time) between '$startDate' and '$endDate' ;";
$result = $db->query($sql);
$this->log(" Copying purchased items...");
$sql = "INSERT INTO `" . Common::prefixTable('log_conversion_item') . "` (`idsite`, `idvisitor`, `server_time`, `idvisit`, `idorder`, `idaction_sku`, `idaction_name`, `idaction_category`, `price`, `quantity`, `deleted`)
SELECT `idsite`, `idvisitor`, CONCAT(CURRENT_DATE() , \" \", TIME(`server_time`)), `idvisit`, CONCAT(`idorder`,SUBSTRING(MD5(RAND()) FROM 1 FOR 9)) , `idaction_sku`, `idaction_name`, `idaction_category`, `price`, `quantity`, `deleted`
FROM `" . Common::prefixTable('log_conversion_item') . "`
WHERE idsite >= 1 AND date(server_time) between '$startDate' and '$endDate' ;";
$result = $db->query($sql);
$now = $this->getVisitsToday();
$actions = $this->getActionsToday();
$purchasedItems = $this->getConversionItemsToday();
$conversions = $this->getConversionsToday();
$this->log(" -------------------------------------");
$this->log(" Today visits after import: " . $now);
$this->log(" Actions: " . $actions);
$this->log(" Purchased items: " . $purchasedItems);
$this->log(" Conversions: " . $conversions);
$this->log(" - New visits created: " . ($now - $initial));
$this->log(" - Actions created: " . ($actions - $initialActions));
$this->log(" - New conversions created: " . ($conversions - $initialConversions));
$this->log(" - New purchased items created: " . ($purchasedItems - $initialPurchasedItems));
$this->log("done");
}
function delete()
{
$this->log("Deleting logs for today...");
$db = \Zend_Registry::get('db');
$sql = "DELETE FROM " . Common::prefixTable('log_visit') . "
WHERE date(visit_last_action_time) = CURRENT_DATE();";
$db->query($sql);
foreach (array('log_link_visit_action', 'log_conversion', 'log_conversion_item') as $table) {
$sql = "DELETE FROM " . Common::prefixTable($table) . "
WHERE date(server_time) = CURRENT_DATE();";
$db->query($sql);
}
$tablesToOptimize = array(
Common::prefixTable('log_link_visit_action'),
Common::prefixTable('log_conversion'),
Common::prefixTable('log_conversion_item'),
Common::prefixTable('log_visit')
);
\Piwik\Db::optimizeTables($tablesToOptimize);
$this->log("done");
}
function log($m)
{
Log::info($m);
}
function getVisitsToday()
{
$sql = "SELECT count(*) FROM `" . Common::prefixTable('log_visit') . "` WHERE idsite >= 1 AND DATE(`visit_last_action_time`) = CURRENT_DATE;";
return \Zend_Registry::get('db')->fetchOne($sql);
}
function getConversionItemsToday($table = 'log_conversion_item')
{
$sql = "SELECT count(*) FROM `" . Common::prefixTable($table) . "` WHERE idsite >= 1 AND DATE(`server_time`) = CURRENT_DATE;";
return \Zend_Registry::get('db')->fetchOne($sql);
}
function getConversionsToday()
{
return $this->getConversionItemsToday($table = "log_conversion");
}
function getActionsToday()
{
$sql = "SELECT count(*) FROM `" . Common::prefixTable('log_link_visit_action') . "` WHERE idsite >= 1 AND DATE(`server_time`) = CURRENT_DATE;";
return \Zend_Registry::get('db')->fetchOne($sql);
}
}

View file

@ -12,11 +12,11 @@ $trackingURL = Piwik_getUrlTrackPageView($idSite = 16, $customTitle = 'This titl
<script type="text/javascript">
var _paq = _paq || [];
(function() {
var u=(("https:" == document.location.protocol) ? "https" : "http") + "://localhost/piwik-master/";
var u="//localhost/piwik-master/";
_paq.push(["setTrackerUrl", u+"piwik.php"]);
_paq.push(["setSiteId", "16"]);
var d=document, g=d.createElement("script"), s=d.getElementsByTagName("script")[0]; g.type="text/javascript";
g.defer=true; g.async=true; g.src=u+"js/piwik.js"; s.parentNode.insertBefore(g,s);
var d=document, g=d.createElement("script"), s=d.getElementsByTagName("script")[0];
g.type="text/javascript"; g.async=true; g.defer=true; g.src=u+"piwik.js"; s.parentNode.insertBefore(g,s);
})();
</script>
<!-- End Piwik Code -->

View file

@ -1,11 +1,14 @@
<?php
exit; // Remove this line before using the script
// How to remove the piwik/ directory if it does not work in FTP?
// 1) Download and upload this file to your webserver
// 2) Put this file in the folder that contains the piwik/ directory (above the piwik/ directory)
// 2) Remove the 2nd line (the "exit;")
// 3) Put this file in the folder that contains the piwik/ directory (above the piwik/ directory)
// For example if the piwik/ folder is at http://your-site/piwik/ you put the file in http://your-site/uninstall-delete-piwik-directory.php
// 3) Go with your browser to http://your-site/uninstall-delete-piwik-directory.php
// 4) The folder http://your-site/piwik/ should now be deleted!
// We hope you enjoyed Piwik. If you have any feedback why you stopped using Piwik,
// 4) Go with your browser to http://your-site/uninstall-delete-piwik-directory.php
// 5) The folder http://your-site/piwik/ should now be deleted!
// We hope you enjoyed Piwik. If you have any feedback why you stopped using Piwik,
// please let us know at hello@piwik.org - we are interested by your experience
function unlinkRecursive($dir)
{