Remove User_Adapter

This commit is contained in:
Nicolas Le Goff
2013-11-05 17:38:27 +01:00
parent 171390f7c8
commit c156f842c7
231 changed files with 3918 additions and 2986 deletions

View File

@@ -10,6 +10,7 @@
*/
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Model\Entities\User;
class ACL implements cache_cacheableInterface
{
@@ -59,7 +60,7 @@ class ACL implements cache_cacheableInterface
*
* @var Array
*/
protected $_global_rights = [
protected $_global_rights = array(
'taskmanager' => false,
'manageusers' => false,
'order' => false,
@@ -80,7 +81,7 @@ class ACL implements cache_cacheableInterface
'bas_chupub' => false,
'candwnldpreview' => true,
'candwnldhd' => true
];
);
/**
*
@@ -138,20 +139,20 @@ class ACL implements cache_cacheableInterface
return false;
}
public function grant_hd_on(record_adapter $record, User_Adapter $pusher, $action)
public function grant_hd_on(record_adapter $record, User $pusher, $action)
{
$sql = 'REPLACE INTO records_rights
(id, usr_id, sbas_id, record_id, document, `case`, pusher_usr_id)
VALUES
(null, :usr_id, :sbas_id, :record_id, 1, :case, :pusher)';
$params = [
':usr_id' => $this->user->get_id()
$params = array(
':usr_id' => $this->user->getId()
, ':sbas_id' => $record->get_sbas_id()
, ':record_id' => $record->get_record_id()
, ':case' => $action
, ':pusher' => $pusher->get_id()
];
, ':pusher' => $pusher->getId()
);
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params);
@@ -162,20 +163,20 @@ class ACL implements cache_cacheableInterface
return $this;
}
public function grant_preview_on(record_adapter $record, User_Adapter $pusher, $action)
public function grant_preview_on(record_adapter $record, User $pusher, $action)
{
$sql = 'REPLACE INTO records_rights
(id, usr_id, sbas_id, record_id, preview, `case`, pusher_usr_id)
VALUES
(null, :usr_id, :sbas_id, :record_id, 1, :case, :pusher)';
$params = [
':usr_id' => $this->user->get_id()
$params = array(
':usr_id' => $this->user->getId()
, ':sbas_id' => $record->get_sbas_id()
, ':record_id' => $record->get_record_id()
, ':case' => $action
, ':pusher' => $pusher->get_id()
];
, ':pusher' => $pusher->getId()
);
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params);
@@ -272,7 +273,7 @@ class ACL implements cache_cacheableInterface
return $this;
}
$sbas_ids = [];
$sbas_ids = array();
foreach ($base_ids as $base_id) {
$sbas_ids[] = phrasea::sbasFromBas($this->app, $base_id);
@@ -280,10 +281,10 @@ class ACL implements cache_cacheableInterface
$sbas_ids = array_unique($sbas_ids);
$sbas_rights = ['bas_manage', 'bas_modify_struct', 'bas_modif_th', 'bas_chupub'];
$sbas_rights = array('bas_manage', 'bas_modify_struct', 'bas_modif_th', 'bas_chupub');
$sbas_to_acces = [];
$rights_to_give = [];
$sbas_to_acces = array();
$rights_to_give = array();
foreach ($this->app['acl']->get($template_user)->get_granted_sbas() as $databox) {
$sbas_id = $databox->get_sbas_id();
@@ -308,27 +309,27 @@ class ACL implements cache_cacheableInterface
$this->update_rights_to_sbas($sbas_id, $rights);
}
$bas_rights = ['canputinalbum', 'candwnldhd'
$bas_rights = array('canputinalbum', 'candwnldhd'
, 'candwnldpreview', 'cancmd'
, 'canadmin', 'actif', 'canreport', 'canpush'
, 'canaddrecord', 'canmodifrecord', 'candeleterecord'
, 'chgstatus', 'imgtools'
, 'manage', 'modify_struct'
, 'nowatermark', 'order_master'
];
);
$bas_to_acces = $masks_to_give = $rights_to_give = [];
$bas_to_acces = $masks_to_give = $rights_to_give = array();
/**
* map masks (and+xor) of template to masks to apply to user on base
* (and_and, and_or, xor_and, xor_or)
*/
$sbmap = [
'00' => ['aa' => '1', 'ao' => '0', 'xa' => '1', 'xo' => '0'],
'01' => ['aa' => '1', 'ao' => '0', 'xa' => '1', 'xo' => '0'],
'10' => ['aa' => '1', 'ao' => '1', 'xa' => '0', 'xo' => '0'],
'11' => ['aa' => '1', 'ao' => '1', 'xa' => '1', 'xo' => '1']
];
$sbmap = array(
'00' => array('aa' => '1', 'ao' => '0', 'xa' => '1', 'xo' => '0'),
'01' => array('aa' => '1', 'ao' => '0', 'xa' => '1', 'xo' => '0'),
'10' => array('aa' => '1', 'ao' => '1', 'xa' => '0', 'xo' => '0'),
'11' => array('aa' => '1', 'ao' => '1', 'xa' => '1', 'xo' => '1')
);
foreach ($this->app['acl']->get($template_user)->get_granted_base() as $collection) {
$base_id = $collection->get_base_id();
@@ -362,7 +363,7 @@ class ACL implements cache_cacheableInterface
. decbin($mask_xor)
, -32
);
$m = ['aa' => '', 'ao' => '', 'xa' => '', 'xo' => ''];
$m = array('aa' => '', 'ao' => '', 'xa' => '', 'xo' => '');
for ($i = 0; $i < 32; $i++) {
$ax = $mand[$i] . $mxor[$i];
@@ -371,12 +372,12 @@ class ACL implements cache_cacheableInterface
}
}
$masks_to_give[$base_id] = [
$masks_to_give[$base_id] = array(
'aa' => $m['aa']
, 'ao' => $m['ao']
, 'xa' => $m['xa']
, 'xo' => $m['xo']
];
);
}
$this->give_access_to_base($bas_to_acces);
@@ -448,7 +449,7 @@ class ACL implements cache_cacheableInterface
*/
public function get_cache_key($option = null)
{
return '_ACL_' . $this->user->get_id() . ($option ? '_' . $option : '');
return '_ACL_' . $this->user->getId() . ($option ? '_' . $option : '');
}
/**
@@ -669,10 +670,10 @@ class ACL implements cache_cacheableInterface
* @param array|null $sbas_ids Optionnal sbas_id to restrict the query on
* @return array An array of collection
*/
public function get_granted_base(Array $rights = [], array $sbas_ids = null)
public function get_granted_base(Array $rights = array(), array $sbas_ids = null)
{
$this->load_rights_bas();
$ret = [];
$ret = array();
foreach ($this->app['phraseanet.appbox']->get_databoxes() as $databox) {
if ($sbas_ids && !in_array($databox->get_sbas_id(), $sbas_ids)) {
@@ -716,16 +717,16 @@ class ACL implements cache_cacheableInterface
* @param Array $rights
* @return Array
*/
public function get_granted_sbas($rights = [])
public function get_granted_sbas($rights = array())
{
if (is_string($rights))
$rights = [$rights];
$rights = array($rights);
assert(is_array($rights));
$this->load_rights_sbas();
$ret = [];
$ret = array();
foreach ($this->_rights_sbas as $sbas_id => $datas) {
$continue = false;
@@ -761,10 +762,10 @@ class ACL implements cache_cacheableInterface
$sql = 'UPDATE usr SET create_db = :create_db WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([
$stmt->execute(array(
':create_db' => $boolean ? '1' : '0',
':usr_id' => $this->user->get_id()
]);
':usr_id' => $this->user->getId()
));
$stmt->closeCursor();
$this->delete_data_from_cache(self::CACHE_IS_ADMIN);
@@ -799,13 +800,13 @@ class ACL implements cache_cacheableInterface
FROM records_rights WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_id' => $this->user->get_id()]);
$stmt->execute(array(':usr_id' => $this->user->getId()));
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
unset($stmt);
$this->_rights_records_preview = [];
$this->_rights_records_document = [];
$this->_rights_records_preview = array();
$this->_rights_records_document = array();
foreach ($rs as $row) {
$currentid = $row["sbas_id"] . "_" . $row["record_id"];
@@ -814,10 +815,10 @@ class ACL implements cache_cacheableInterface
$this->_rights_records_preview[$currentid] = $currentid;
}
$datas = [
$datas = array(
'preview' => $this->_rights_records_preview
, 'document' => $this->_rights_records_document
];
);
$this->set_data_to_cache($datas, self::CACHE_RIGHTS_RECORDS);
@@ -841,7 +842,7 @@ class ACL implements cache_cacheableInterface
FROM usr WHERE usr_id = :usr_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_id' => $this->user->get_id()]);
$stmt->execute(array(':usr_id' => $this->user->getId()));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
unset($stmt);
@@ -878,11 +879,11 @@ class ACL implements cache_cacheableInterface
AND sbas.sbas_id = sbasusr.sbas_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_id' => $this->user->get_id()]);
$stmt->execute(array(':usr_id' => $this->user->getId()));
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$this->_rights_sbas = [];
$this->_rights_sbas = array();
$this->_global_rights['bas_modif_th'] = false;
$this->_global_rights['bas_modify_struct'] = false;
@@ -939,11 +940,11 @@ class ACL implements cache_cacheableInterface
AND s.sbas_id = b.sbas_id ';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_id' => $this->user->get_id()]);
$stmt->execute(array(':usr_id' => $this->user->getId()));
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$this->_rights_bas = $this->_limited = [];
$this->_rights_bas = $this->_limited = array();
$this->_global_rights['manageusers'] = false;
$this->_global_rights['coll_manage'] = false;
@@ -1000,10 +1001,10 @@ class ACL implements cache_cacheableInterface
if ($row['time_limited'] == '1'
&& ($row['limited_from'] !== '' || $row['limited_to'] !== '')) {
$this->_limited[$row['base_id']] = [
$this->_limited[$row['base_id']] = array(
'dmin' => $row['limited_from'] ? new DateTime($row['limited_from']) : null
, 'dmax' => $row['limited_to'] ? new DateTime($row['limited_to']) : null
];
);
}
$this->_rights_bas[$row['base_id']]['imgtools']
@@ -1116,10 +1117,10 @@ class ACL implements cache_cacheableInterface
$sql_del = 'DELETE FROM basusr WHERE base_id = :base_id AND usr_id = :usr_id';
$stmt_del = $this->app['phraseanet.appbox']->get_connection()->prepare($sql_del);
$usr_id = $this->user->get_id();
$usr_id = $this->user->getId();
foreach ($base_ids as $base_id) {
if (!$stmt_del->execute([':base_id' => $base_id, ':usr_id' => $usr_id])) {
if (!$stmt_del->execute(array(':base_id' => $base_id, ':usr_id' => $usr_id))) {
throw new Exception('Error while deleteing some rights');
}
}
@@ -1138,13 +1139,13 @@ class ACL implements cache_cacheableInterface
$sql_ins = 'INSERT INTO basusr (id, base_id, usr_id, actif)
VALUES (null, :base_id, :usr_id, "1")';
$stmt_ins = $this->app['phraseanet.appbox']->get_connection()->prepare($sql_ins);
$usr_id = $this->user->get_id();
$to_update = [];
$usr_id = $this->user->getId();
$to_update = array();
$this->load_rights_bas();
foreach ($base_ids as $base_id) {
if (!isset($this->_rights_bas[$base_id])) {
$stmt_ins->execute([':base_id' => $base_id, ':usr_id' => $usr_id]);
$stmt_ins->execute(array(':base_id' => $base_id, ':usr_id' => $usr_id));
} elseif ($this->_rights_bas[$base_id]['actif'] === false) {
$to_update[] = $base_id;
}
@@ -1155,7 +1156,7 @@ class ACL implements cache_cacheableInterface
WHERE usr_id = :usr_id AND base_id = :base_id';
$stmt_upd = $this->app['phraseanet.appbox']->get_connection()->prepare($sql_upd);
foreach ($to_update as $base_id) {
$stmt_upd->execute([':usr_id' => $usr_id, ':base_id' => $base_id]);
$stmt_upd->execute(array(':usr_id' => $usr_id, ':base_id' => $base_id));
}
$stmt_upd->closeCursor();
@@ -1175,11 +1176,11 @@ class ACL implements cache_cacheableInterface
$sql_ins = 'INSERT INTO sbasusr (sbasusr_id, sbas_id, usr_id) VALUES (null, :sbas_id, :usr_id)';
$stmt_ins = $this->app['phraseanet.appbox']->get_connection()->prepare($sql_ins);
$usr_id = $this->user->get_id();
$usr_id = $this->user->getId();
foreach ($sbas_ids as $sbas_id) {
if (!$this->has_access_to_sbas($sbas_id))
$stmt_ins->execute([':sbas_id' => $sbas_id, ':usr_id' => $usr_id]);
$stmt_ins->execute(array(':sbas_id' => $sbas_id, ':usr_id' => $usr_id));
}
$this->delete_data_from_cache(self::CACHE_RIGHTS_SBAS);
@@ -1198,12 +1199,12 @@ class ACL implements cache_cacheableInterface
{
if (!$this->has_access_to_base($base_id) && (!isset($rights['actif']) || $rights['actif'] == '1')) {
$this->give_access_to_base([$base_id]);
$this->give_access_to_base(array($base_id));
}
$sql_up = "UPDATE basusr SET ";
$sql_args = $params = [];
$sql_args = $params = array();
foreach ($rights as $right => $v) {
$sql_args[] = " " . $right . " = :" . $right;
switch ($right) {
@@ -1221,14 +1222,14 @@ class ACL implements cache_cacheableInterface
return $this;
}
$usr_id = $this->user->get_id();
$usr_id = $this->user->getId();
$sql_up .= implode(', ', $sql_args) . ' WHERE base_id = :base_id
AND usr_id = :usr_id';
$params = array_merge(
$params
, [':base_id' => $base_id, ':usr_id' => $usr_id]
, array(':base_id' => $base_id, ':usr_id' => $usr_id)
);
$stmt_up = $this->app['phraseanet.appbox']->get_connection()->prepare($sql_up);
@@ -1252,8 +1253,8 @@ class ACL implements cache_cacheableInterface
(SELECT distinct sbas_id FROM basusr bu, bas b
WHERE usr_id = :usr_id_2 AND b.base_id = bu.base_id)';
$usr_id = $this->user->get_id();
$params = [':usr_id_1' => $usr_id, ':usr_id_2' => $usr_id];
$usr_id = $this->user->getId();
$params = array(':usr_id_1' => $usr_id, ':usr_id_2' => $usr_id);
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params);
@@ -1273,13 +1274,13 @@ class ACL implements cache_cacheableInterface
public function update_rights_to_sbas($sbas_id, $rights)
{
if (!$this->has_access_to_sbas($sbas_id))
$this->give_access_to_sbas([$sbas_id]);
$this->give_access_to_sbas(array($sbas_id));
$sql_up = "UPDATE sbasusr SET ";
$sql_args = [];
$usr_id = $this->user->get_id();
$params = [':sbas_id' => $sbas_id, ':usr_id' => $usr_id];
$sql_args = array();
$usr_id = $this->user->getId();
$params = array(':sbas_id' => $sbas_id, ':usr_id' => $usr_id);
foreach ($rights as $right => $v) {
$sql_args[] = " " . $right . " = :" . $right;
@@ -1315,7 +1316,7 @@ class ACL implements cache_cacheableInterface
WHERE usr_id = :usr_id AND base_id = :base_id ';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_id' => $this->user->get_id(), ':base_id' => $base_id]);
$stmt->execute(array(':usr_id' => $this->user->getId(), ':base_id' => $base_id));
$stmt->closeCursor();
unset($stmt);
@@ -1331,13 +1332,13 @@ class ACL implements cache_cacheableInterface
AND usr_id = :usr_id
AND MONTH(lastconn) != MONTH(NOW()) AND restrict_dwnld = 1';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_id' => $this->user->get_id()]);
$stmt->execute(array(':usr_id' => $this->user->getId()));
$stmt->closeCursor();
$sql = "UPDATE basusr SET lastconn=now()
WHERE usr_id = :usr_id AND actif = 1";
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_id' => $this->user->get_id()]);
$stmt->execute(array(':usr_id' => $this->user->getId()));
$stmt->closeCursor();
unset($stmt);
@@ -1359,12 +1360,12 @@ class ACL implements cache_cacheableInterface
SET remain_dwnld = :restes, restrict_dwnld = 1, month_dwnld_max = :droits
WHERE usr_id = :usr_id AND base_id = :base_id ';
$params = [
':usr_id' => $this->user->get_id(),
$params = array(
':usr_id' => $this->user->getId(),
':base_id' => $base_id,
':restes' => $restes,
':droits' => $droits
];
);
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params);
@@ -1381,10 +1382,10 @@ class ACL implements cache_cacheableInterface
$sql = 'SELECT * FROM basusr
WHERE base_id = :base_from AND usr_id = :usr_id';
$params = [
$params = array(
':base_from' => $base_id_from,
':usr_id' => $this->user->get_id()
];
':usr_id' => $this->user->getId()
);
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params);
@@ -1395,12 +1396,12 @@ class ACL implements cache_cacheableInterface
return $this;
}
$this->give_access_to_base([$base_id_dest]);
$this->give_access_to_base(array($base_id_dest));
$rights = [
$rights = array(
'mask_and' => $row['mask_and'],
'mask_xor' => $row['mask_xor'],
];
);
if ($row['canputinalbum'])
$rights['canputinalbum'] = true;
@@ -1470,7 +1471,7 @@ class ACL implements cache_cacheableInterface
foreach ($this->get_granted_base([], [$databox->get_sbas_id()]) as $collection) {
$stmt->execute([
':site_id' => $this->app['conf']->get(['main', 'key']),
':usr_id' => $this->user->get_id(),
':usr_id' => $this->user->getId(),
':coll_id' => $collection->get_coll_id(),
':mask_and' => $this->get_mask_and($collection->get_base_id()),
':mask_xor' => $this->get_mask_xor($collection->get_base_id()),
@@ -1496,7 +1497,7 @@ class ACL implements cache_cacheableInterface
{
$sql = 'DELETE FROM collusr WHERE usr_id = :usr_id AND site = :site';
$params = [
':usr_id' => $this->user->get_id()
':usr_id' => $this->user->getId()
, ':site' => $this->app['conf']->get(['main', 'key'])
];
$stmt = $databox->get_connection()->prepare($sql);
@@ -1508,13 +1509,13 @@ class ACL implements cache_cacheableInterface
public function set_masks_on_base($base_id, $and_and, $and_or, $xor_and, $xor_or)
{
$vhex = [];
$datas = [
$vhex = array();
$datas = array(
'and_and' => $and_and,
'and_or' => $and_or,
'xor_and' => $xor_and,
'xor_or' => $xor_or
];
);
foreach ($datas as $name => $f) {
$vhex[$name] = "0x";
@@ -1536,7 +1537,7 @@ class ACL implements cache_cacheableInterface
WHERE usr_id = :usr_id and base_id = :base_id";
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':base_id' => $base_id, ':usr_id' => $this->user->get_id()]);
$stmt->execute(array(':base_id' => $base_id, ':usr_id' => $this->user->getId()));
$stmt->closeCursor();
unset($stmt);
@@ -1589,12 +1590,12 @@ class ACL implements cache_cacheableInterface
WHERE base_id = :base_id AND usr_id = :usr_id';
}
$params = [
':usr_id' => $this->user->get_id()
$params = array(
':usr_id' => $this->user->getId()
, ':base_id' => $base_id
, 'limited_from' => ($limit_from ? $limit_from->format(DATE_ISO8601) : null)
, 'limited_to' => ($limit_to ? $limit_to->format(DATE_ISO8601) : null)
];
);
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
@@ -1616,11 +1617,11 @@ class ACL implements cache_cacheableInterface
{
$sql = 'SELECT base_id FROM basusr WHERE order_master="1" AND usr_id= :usr_id ';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':usr_id' => $this->user->get_id()]);
$stmt->execute(array(':usr_id' => $this->user->getId()));
$rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
$stmt->closeCursor();
$collections = [];
$collections = array();
foreach ($rs as $row) {
$collections[] = \collection::get_from_base_id($this->app, $row['base_id']);
@@ -1643,11 +1644,11 @@ class ACL implements cache_cacheableInterface
WHERE usr_id = :usr_id AND base_id = :base_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([
$stmt->execute(array(
':master' => $bool ? 1 : 0,
':usr_id' => $this->user->get_id(),
':usr_id' => $this->user->getId(),
':base_id' => $collection->get_base_id()
]);
));
$stmt->closeCursor();
return $this;