-
Notifications
You must be signed in to change notification settings - Fork 0
/
SnoopyBehavioralScoring.php
executable file
·88 lines (76 loc) · 2.95 KB
/
SnoopyBehavioralScoring.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\SnoopyBehavioralScoring;
use Piwik\Common;
use Piwik\Db;
use \Exception;
class SnoopyBehavioralScoring extends \Piwik\Plugin {
private static $table_name = "snoopy";
public function install() {
try {
$sql = "CREATE TABLE IF NOT EXISTS " . Common::prefixTable("snoopy") . " (
id int(11) NOT NULL AUTO_INCREMENT,
idvisitor varchar(45) DEFAULT NULL,
score float DEFAULT NULL,
updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
created_at datetime DEFAULT NULL,
PRIMARY KEY (id),
KEY idvisitor_idx (idvisitor),
KEY id_idvisitor_idx (id,idvisitor)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ";
Db::exec($sql);
$sql = "CREATE TABLE IF NOT EXISTS " . Common::prefixTable("snoopy_visitors") . " (
id int(11) NOT NULL AUTO_INCREMENT,
idvisitor varchar(45) DEFAULT NULL,
custom_1 varchar(255) DEFAULT NULL,
custom_2 varchar(255) DEFAULT NULL,
custom_3 varchar(255) DEFAULT NULL,
custom_4 TEXT DEFAULT NULL,
custom_5 TEXT DEFAULT NULL,
updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
created_at datetime DEFAULT NULL,
PRIMARY KEY (id),
UNIQUE KEY (idvisitor)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ";
Db::exec($sql);
$sql = "CREATE TABLE IF NOT EXISTS " . Common::prefixTable("snoopy_visitors_statuses") . "(
id int(11) NOT NULL AUTO_INCREMENT,
idvisitor varchar(45) DEFAULT NULL,
status varchar(45) DEFAULT NULL,
PRIMARY KEY (id),
UNIQUE KEY idvisitor_uniq (idvisitor)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
Db::exec($sql);
} catch (Exception $e) {
// ignore error if table already exists (1050 code is for 'table already exists')
if (!Db::get()->isErrNo($e, '1050')) {
throw $e;
}
}
}
public function uninstall() {
Db::dropTables(Common::prefixTable("snoopy"));
Db::dropTables(Common::prefixTable("snoopy_visitors"));
Db::dropTables(Common::prefixTable("snoopy_visitors_statuses"));
}
public function activate() {
$this->install();
}
static function getTableName() {
return self::$table_name;
}
public function getStylesheetFiles(&$files) {
$files[] = "plugins/SnoopyBehavioralScoring/stylesheets/style.less";
$files[] = "plugins/SnoopyBehavioralScoring/stylesheets/style.css";
}
public function registerEvents() {
return array(
'AssetManager.getStylesheetFiles' => 'getStylesheetFiles',
);
}
}