-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaddgrant.php
executable file
·69 lines (59 loc) · 2.02 KB
/
addgrant.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
#!/usr/bin/env php
<?php
/**
* Tine 2.0 add grant script
* - This script adds a defined grant for all containers of a group in an application
*
* @package HelperScripts
* @license http://www.gnu.org/licenses/agpl.html AGPL Version 3
* @author Philipp Schuele <p.schuele@metaways.de>
* @copyright Copyright (c) 2010 Metaways Infosystems GmbH (http://www.metaways.de)
* @version $Id$
*
*/
if (php_sapi_name() != 'cli') {
die('not allowed!');
}
// db info
$host = 'host';
$user = 'user';
$pass = 'pass';
$db = 'db';
// values
$containerTable = 'tine20_container';
$aclTable = 'tine20_container_acl';
$grant = 'deleteGrant';
$accountId = 'f68dbbc2b4ad4e823423962f2b1a2e78ea1703e4';
$accountType = 'group';
$appId = '3584703dcd783a3427a1d9a2cf0352327a6d4ca7';
$link = mysql_connect($host, $user, $pass)
or die("No connection: " . mysql_error());
mysql_select_db($db) or die("Could not select DB.");
// get all containers where this group has access
$query = 'SELECT DISTINCT container.id FROM `' . $containerTable . '` as container left join ' . $aclTable . ' as acl on container.id = acl.container_id '
. 'WHERE application_id = \'' . $appId . '\' and account_id = \'' . $accountId . '\' and account_type = \'' . $accountType . '\'';
$result = mysql_query($query) or die("\n" . mysql_error());
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
$lines[] = $line;
}
//print_r($lines);
echo 'Adding ' . count($lines) . ' new grants for ' . $accountType . ' ' . $accountId;
foreach($lines as $line) {
$id = sha1(mt_rand(). microtime());
$query = "
INSERT INTO $aclTable
(`id` ,
`container_id` ,
`account_type` ,
`account_id` ,
`account_grant`
) VALUES (
'$id', '" . $line['id'] . "', '$accountType', '$accountId', '$grant')";
//echo $query;
$result = mysql_query($query) or die("\n" . mysql_error() . "\n");
if ($result) {
echo ".";
}
}
echo " done.\n";
mysql_close($link);