| 1 | #===========================================================================
|
|---|
| 2 | # Description
|
|---|
| 3 | # This powershell script will automatically run Piwik archiving for whatever
|
|---|
| 4 | # frequency you set it up to run, it is recommended that is be every 1 hour
|
|---|
| 5 | # or 3600 seconds.
|
|---|
| 6 |
|
|---|
| 7 | # It automatically fetches the Super User token_auth
|
|---|
| 8 | # and triggers the archiving for all websites for all periods.
|
|---|
| 9 | # This ensures that all reports are pre-computed and Piwik renders very fast.
|
|---|
| 10 |
|
|---|
| 11 | # Documentation
|
|---|
| 12 | # Please check the documentation on http://piwik.org/docs/setup-auto-archiving/
|
|---|
| 13 |
|
|---|
| 14 | # Optimization for high traffic websites
|
|---|
| 15 | # You may want to override the following settings in config/config.ini.php:
|
|---|
| 16 | # See documentation of the fields in your piwik/config/config.ini.php
|
|---|
| 17 | #
|
|---|
| 18 | # [General]
|
|---|
| 19 | # time_before_archive_considered_outdated = 3600
|
|---|
| 20 | # enable_browser_archiving_triggering = false
|
|---|
| 21 | #
|
|---|
| 22 | #===========================================================================
|
|---|
| 23 | $PHP_INI = "C:\Program Files\EasyPHP-5.3.2i\apache\php.ini"
|
|---|
| 24 | $BINS = @("php5.exe", "php.exe")
|
|---|
| 25 |
|
|---|
| 26 | foreach($phpTestBin in $BINS)
|
|---|
| 27 | {
|
|---|
| 28 | if(Get-Command $phpTestBin -ea SilentlyContinue)
|
|---|
| 29 | {
|
|---|
| 30 | $PHP_BIN = Get-Command $phpTestBin|Select-Object -ExpandProperty Definition
|
|---|
| 31 | break
|
|---|
| 32 | }
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | if(($PHP_BIN -eq $null) -or !(Test-Path $PHP_BIN -ea SilentlyContinue))
|
|---|
| 36 | {
|
|---|
| 37 | Write-Host "php binary not found. Make sure php5 or php exists in PATH."
|
|---|
| 38 | Exit 1
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | $PIWIK_SCRIPT_FOLDER = Split-Path -parent $MyInvocation.MyCommand.Definition
|
|---|
| 42 | $PIWIK_PATH="$PIWIK_SCRIPT_FOLDER\..\..\index.php"
|
|---|
| 43 | $PIWIK_CONFIG="$PIWIK_SCRIPT_FOLDER\..\..\config/config.ini.php"
|
|---|
| 44 |
|
|---|
| 45 | Function Parse-IniFile ($file) {
|
|---|
| 46 | $ini = @{}
|
|---|
| 47 | switch -regex -file $file {
|
|---|
| 48 | "^\[(.+)\]$" {
|
|---|
| 49 | $section = $matches[1].Trim()
|
|---|
| 50 | $ini[$section] = @{}
|
|---|
| 51 | }
|
|---|
| 52 | "(.+)=(.+)" {
|
|---|
| 53 | $name,$value = $matches[1..2]
|
|---|
| 54 | $name = $name.Trim()
|
|---|
| 55 | $value = $value.Trim()
|
|---|
| 56 | $ini[$section][$name] = $value
|
|---|
| 57 | }
|
|---|
| 58 | }
|
|---|
| 59 | $ini
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | $CONFIG = Parse-IniFile $PIWIK_CONFIG
|
|---|
| 63 | $PIWIK_SUPERUSER=$CONFIG["superuser"]["login"].Replace('"', '')
|
|---|
| 64 | $PIWIK_SUPERUSER_MD5_PASSWORD=$CONFIG["superuser"]["password"].Replace('"', '')
|
|---|
| 65 |
|
|---|
| 66 | $TOKEN_AUTH= & $PHP_BIN -c $PHP_INI "$PIWIK_PATH" "--" "module=API&method=UsersManager.getTokenAuth&userLogin=$PIWIK_SUPERUSER&md5Password=$PIWIK_SUPERUSER_MD5_PASSWORD&format=php&serialize=0"
|
|---|
| 67 |
|
|---|
| 68 | $ID_SITES= & $PHP_BIN -c $PHP_INI "$PIWIK_PATH" "--" "module=API&method=SitesManager.getAllSitesId&token_auth=$TOKEN_AUTH&format=csv&convertToUnicode=0"
|
|---|
| 69 |
|
|---|
| 70 | Write-Host "Starting Piwik archiving..."
|
|---|
| 71 |
|
|---|
| 72 | foreach($ID_SITE in $ID_SITES)
|
|---|
| 73 | {
|
|---|
| 74 | if($ID_SITE -match "^\d+$")
|
|---|
| 75 | {
|
|---|
| 76 | foreach($period in @("day","week","year"))
|
|---|
| 77 | {
|
|---|
| 78 | Write-Host ""
|
|---|
| 79 | Write-Host "Archiving period = $period for idsite = $ID_SITE..."
|
|---|
| 80 | & $PHP_BIN -c $PHP_INI "$PIWIK_PATH" "--" "module=API&method=VisitsSummary.getVisits&idSite=$ID_SITE&period=$period&date=last52&format=xml&token_auth=$TOKEN_AUTH"
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | Write-Host ""
|
|---|
| 84 | Write-Host "Archiving for idsite = $ID_SITE done!"
|
|---|
| 85 | }
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | Write-Host "Piwik archiving finished." |
|---|