~bellini666/charms/trusty/wordpress/piwik_integration

« back to all changes in this revision

Viewing changes to hooks/analytics-relation-changed

  • Committer: Thiago Bellini
  • Date: 2014-12-10 17:03:41 UTC
  • Revision ID: hackedbellini@async.com.br-20141210170341-2rhb3tugw3zlox5u
Initial analytics relation support with piwik

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
 
 
3
set -xe
 
4
 
 
5
source inc/common
 
6
 
 
7
tmp_file=`mktemp`
 
8
plugin_path=`wp plugin path --path=$wp_install_path`
 
9
piwik_settings_path=$plugin_path/wp-piwik/classes/WP_Piwik_Settings.php
 
10
piwik_logger_path=$plugin_path/wp-piwik/classes/WP_Piwik_Logger_Dummy.php
 
11
 
 
12
wp_content_repo=`config-get wp-content`
 
13
piwik_url=`relation-get url`
 
14
piwik_token=`relation-get token`
 
15
 
 
16
if [ -z "$piwik_url" -o -z "$piwik_token" ]; then
 
17
    echo "url and token not set yet"
 
18
    exit 0
 
19
fi
 
20
 
 
21
cd $wp_install_path
 
22
if wp plugin --path=$wp_install_path | grep wp-piwik; then
 
23
    juju-log "wp-piwik found, skipping installation"
 
24
else
 
25
    if [ -n "$wp_content_repo" ]; then
 
26
        juju-log "The wp-content is versioned. Please install wp-piwik plugin before continuing"
 
27
        exit 1
 
28
    fi
 
29
    wp plugin install wp-piwik --path=$wp_install_path --activate
 
30
fi
 
31
 
 
32
# FIXME: Find a way for, when executing this piece of code, the configuration
 
33
# is is not just saved, but the tracking is added to piwik. This happens when
 
34
# clicking the "Save" button at the plugin settings page.
 
35
cat > $tmp_file <<EOF
 
36
<?php
 
37
 
 
38
/** Absolute path to the WordPress directory. */
 
39
if ( !defined('ABSPATH') )
 
40
        define('ABSPATH', '$wp_install_path' . '/');
 
41
 
 
42
/** Pull in the config information */
 
43
require_once(ABSPATH . 'wp-load.php');
 
44
/** Load the piwik settings and logger files */
 
45
require_once('$piwik_settings_path');
 
46
require_once('$piwik_logger_path');
 
47
 
 
48
\$l = new WP_Piwik_Logger_Dummy('juju_dummy');
 
49
\$s = new WP_Piwik_Settings(\$l);
 
50
 
 
51
\$s->setGlobalOption('piwik_token', '$piwik_token');
 
52
\$s->setOption('piwik_token', '$piwik_token');
 
53
\$s->setGlobalOption('piwik_url', '$piwik_url');
 
54
\$s->setOption('piwik_url', '$piwik_url');
 
55
\$s->setGlobalOption('add_tracking_code', true);
 
56
\$s->setOption('add_tracking_code', true);
 
57
\$s->save();
 
58
 
 
59
EOF
 
60
 
 
61
php $tmp_file