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

@ -1,6 +1,6 @@
<?php
/**
* Piwik - Open source web analytics
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
@ -22,10 +22,18 @@ use Piwik\Piwik;
* Existing Permissions are listed given a login via "getSitesAccessFromUser", or a website ID via "getUsersAccessFromSite",
* or you can list all users and websites for a given permission via "getUsersSitesFromAccess". Permissions are set and updated
* via the method "setUserAccess".
* See also the documentation about <a href='http://piwik.org/docs/manage-users/' target='_blank'>Managing Users</a> in Piwik.
* See also the documentation about <a href='http://piwik.org/docs/manage-users/' rel='noreferrer' target='_blank'>Managing Users</a> in Piwik.
*/
class Model
{
private static $rawPrefix = 'user';
private $table;
public function __construct()
{
$this->table = Common::prefixTable(self::$rawPrefix);
}
/**
* Returns the list of all the users
*
@ -39,13 +47,12 @@ class Model
if (!empty($userLogins)) {
$where = 'WHERE login IN (' . Common::getSqlStringFieldsArray($userLogins) . ')';
$bind = $userLogins;
$bind = $userLogins;
}
$users = Db::get()->fetchAll("SELECT *
FROM " . Common::prefixTable("user") . "
$where
ORDER BY login ASC", $bind);
$users = $this->getDb()->fetchAll("SELECT * FROM " . $this->table . "
$where
ORDER BY login ASC", $bind);
return $users;
}
@ -57,23 +64,21 @@ class Model
*/
public function getUsersLogin()
{
$users = Db::get()->fetchAll("SELECT login
FROM " . Common::prefixTable("user") . "
ORDER BY login ASC");
$users = $this->getDb()->fetchAll("SELECT login FROM " . $this->table . " ORDER BY login ASC");
$return = array();
foreach ($users as $login) {
$return[] = $login['login'];
}
return $return;
}
public function getUsersSitesFromAccess($access)
{
$users = Db::get()->fetchAll("SELECT login,idsite
FROM " . Common::prefixTable("access")
. " WHERE access = ?
ORDER BY login, idsite", $access);
$users = $this->getDb()->fetchAll("SELECT login,idsite FROM " . Common::prefixTable("access")
. " WHERE access = ?
ORDER BY login, idsite", $access);
$return = array();
foreach ($users as $user) {
@ -85,9 +90,8 @@ class Model
public function getUsersAccessFromSite($idSite)
{
$users = Db::get()->fetchAll("SELECT login,access
FROM " . Common::prefixTable("access")
. " WHERE idsite = ?", $idSite);
$users = $this->getDb()->fetchAll("SELECT login,access FROM " . Common::prefixTable("access")
. " WHERE idsite = ?", $idSite);
$return = array();
foreach ($users as $user) {
@ -99,9 +103,9 @@ class Model
public function getUsersLoginWithSiteAccess($idSite, $access)
{
$users = Db::get()->fetchAll("SELECT login
FROM " . Common::prefixTable("access")
. " WHERE idsite = ? AND access = ?", array($idSite, $access));
$users = $this->getDb()->fetchAll("SELECT login
FROM " . Common::prefixTable("access")
. " WHERE idsite = ? AND access = ?", array($idSite, $access));
$logins = array();
foreach ($users as $user) {
@ -129,9 +133,8 @@ class Model
*/
public function getSitesAccessFromUser($userLogin)
{
$users = Db::get()->fetchAll("SELECT idsite,access
FROM " . Common::prefixTable("access")
. " WHERE login = ?", $userLogin);
$users = $this->getDb()->fetchAll("SELECT idsite,access FROM " . Common::prefixTable("access")
. " WHERE login = ?", $userLogin);
$return = array();
foreach ($users as $user) {
@ -146,23 +149,30 @@ class Model
public function getUser($userLogin)
{
return Db::get()->fetchRow("SELECT *
FROM " . Common::prefixTable("user")
. " WHERE login = ?", $userLogin);
$db = $this->getDb();
$matchedUsers = $db->fetchAll("SELECT * FROM " . $this->table . " WHERE login = ?", $userLogin);
// for BC in 2.15 LTS, if there is a user w/ an exact match to the requested login, return that user.
// this is done since before this change, login was case sensitive. until 3.0, we want to maintain
// this behavior.
foreach ($matchedUsers as $user) {
if ($user['login'] == $userLogin) {
return $user;
}
}
return reset($matchedUsers);
}
public function getUserByEmail($userEmail)
{
return Db::get()->fetchRow("SELECT *
FROM " . Common::prefixTable("user")
. " WHERE email = ?", $userEmail);
return $this->getDb()->fetchRow("SELECT * FROM " . $this->table . " WHERE email = ?", $userEmail);
}
public function getUserByTokenAuth($tokenAuth)
{
return Db::get()->fetchRow('SELECT *
FROM ' . Common::prefixTable('user') . '
WHERE token_auth = ?', $tokenAuth);
return $this->getDb()->fetchRow('SELECT * FROM ' . $this->table . ' WHERE token_auth = ?', $tokenAuth);
}
public function addUser($userLogin, $passwordTransformed, $email, $alias, $tokenAuth, $dateRegistered)
@ -177,12 +187,12 @@ class Model
'superuser_access' => 0
);
Db::get()->insert(Common::prefixTable("user"), $user);
$this->getDb()->insert($this->table, $user);
}
public function setSuperUserAccess($userLogin, $hasSuperUserAccess)
{
Db::get()->update(Common::prefixTable("user"),
$this->getDb()->update($this->table,
array(
'superuser_access' => $hasSuperUserAccess ? 1 : 0
),
@ -190,19 +200,24 @@ class Model
);
}
/**
* Note that this returns the token_auth which is as private as the password!
*
* @return array[] containing login, email and token_auth
*/
public function getUsersHavingSuperUserAccess()
{
$users = Db::get()->fetchAll("SELECT login, email
FROM " . Common::prefixTable("user") . "
WHERE superuser_access = 1
ORDER BY date_registered ASC");
$users = $this->getDb()->fetchAll("SELECT login, email, token_auth
FROM " . Common::prefixTable("user") . "
WHERE superuser_access = 1
ORDER BY date_registered ASC");
return $users;
}
public function updateUser($userLogin, $password, $email, $alias, $tokenAuth)
{
Db::get()->update(Common::prefixTable("user"),
$this->getDb()->update($this->table,
array(
'password' => $password,
'alias' => $alias,
@ -215,24 +230,22 @@ class Model
public function userExists($userLogin)
{
$count = Db::get()->fetchOne("SELECT count(*)
FROM " . Common::prefixTable("user") . "
WHERE login = ?", $userLogin);
$count = $this->getDb()->fetchOne("SELECT count(*) FROM " . $this->table . " WHERE login = ?", $userLogin);
return $count != 0;
}
public function userEmailExists($userEmail)
{
$count = Db::get()->fetchOne("SELECT count(*)
FROM " . Common::prefixTable("user") . "
WHERE email = ?", $userEmail);
$count = $this->getDb()->fetchOne("SELECT count(*) FROM " . $this->table . " WHERE email = ?", $userEmail);
return $count != 0;
}
public function addUserAccess($userLogin, $access, $idSites)
{
foreach ($idSites as $idsite) {
Db::get()->insert(Common::prefixTable("access"),
$this->getDb()->insert(Common::prefixTable("access"),
array("idsite" => $idsite,
"login" => $userLogin,
"access" => $access)
@ -242,7 +255,7 @@ class Model
public function deleteUserOnly($userLogin)
{
Db::get()->query("DELETE FROM " . Common::prefixTable("user") . " WHERE login = ?", $userLogin);
$this->getDb()->query("DELETE FROM " . $this->table . " WHERE login = ?", $userLogin);
/**
* Triggered after a user has been deleted.
@ -258,12 +271,12 @@ class Model
public function deleteUserAccess($userLogin, $idSites = null)
{
if (is_null($idSites)) {
Db::get()->query("DELETE FROM " . Common::prefixTable("access") .
$this->getDb()->query("DELETE FROM " . Common::prefixTable("access") .
" WHERE login = ?",
array($userLogin));
} else {
foreach ($idSites as $idsite) {
Db::get()->query("DELETE FROM " . Common::prefixTable("access") .
$this->getDb()->query("DELETE FROM " . Common::prefixTable("access") .
" WHERE idsite = ? AND login = ?",
array($idsite, $userLogin)
);
@ -271,4 +284,9 @@ class Model
}
}
private function getDb()
{
return Db::get();
}
}