Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
migr_sql2.0.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5  * @package FDL
6 */
7 /**
8  * Generated Header (not documented yet)
9  *
10  * @author Anakeen 2000
11  * @version $Id: migr_sql2.0.php,v 1.4 2005/06/28 08:37:46 eric Exp $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  * @subpackage
15  */
16 /**
17  */
18 // refreah for a classname
19 // use this only if you have changed title attributes
20 include_once ("FDL/Class.Doc.php");
21 include_once ("FDL/Class.DocFam.php");
22 
23 function migrTables()
24 {
25 
26  $appl = new Application();
27  $appl->Set("FDL", $core);
28 
29  $dbaccess = $appl->GetParam("FREEDOM_DB");
30  if ($dbaccess == "") {
31  print "Database not found : param FREEDOM_DB";
32  exit;
33  }
34 
35  $query = new QueryDb($dbaccess, "Doc");
36  $query->AddQuery("doctype='C'");
37  $query->order_by = "fromid";
38 
39  $table1 = $query->Query();
40 
41  $docf = new DocFam($dbaccess);
42 
43  if ($query->nb > 0) {
44 
46  $fields = implode(",", $doc->fields);
47  //-------------------------
48  // first part sql familly table
49  //print $docf->sqlcreate;
50  //print "insert into docfam ($fields) select * from only doc where doctype='C';\n";
51  //print "delete from only doc where doctype='C';\n";
52  //-------------------------
53  // second part sql table
54  while (list($k, $v) = each($table1)) {
55  $qattr = new QueryDb($dbaccess, "DocAttr");
56  $qattr->AddQuery("docid=" . $v->id);
57  $qattr->AddQuery("visibility != 'F'");
58  $qattr->AddQuery("visibility != 'M'");
59  $lattr = $qattr->Query();
60  if (!$lattr) $lattr = array();
61  $attr = array();
62  while (list($ka, $va) = each($lattr)) {
63  $attr[] = "$va->id text";
64  }
65  $sattr = implode(",", $attr);
66  if ($v->fromid == 0) {
67  //print "create table doc{$v->id} ($sattr) inherits (doc);\n";
68 
69  } else {
70  //print "create table doc{$v->id} ($sattr) inherits (doc{$v->fromid});\n";
71 
72  }
73  // print "create unique index doc_pkey{$v->id} on doc{$v->id}(id);\n";
74  print "insert into doc{$v->id} ($fields) select * from only doc where fromid = {$v->id} and doctype !='C';\n";
75  print "delete from only doc where fromid = {$v->id} and doctype !='C';\n";
76  reset($lattr);
77  $attr = array();
78  // with all attributes
79  $qattr = new QueryDb($dbaccess, "DocAttr");
80  $qattr->AddQuery("visibility != 'M'");
81  $qattr->AddQuery("type != 'frame'");
82  $sql_cond_doc = GetSqlCond(array_merge($v->GetFathersDoc() , $v->id) , "docid");
83  $qattr->AddQuery($sql_cond_doc);
84  $lattr = $qattr->Query();
85  if (!$lattr) $lattr = array();
86  while (list($ka, $va) = each($lattr)) {
87  print "update doc{$v->id} set {$va->id} = docvalue.value from docvalue where docvalue.docid=doc{$v->id}.id and attrid='{$va->id}';\n";
88  }
89  }
90  }
91 }
92 //---------------------------------------------------------------------------------------------
93 function migrPerm()
94 {
95  //---------------------------------------------------------------------------------------------
96  include_once ("FDL/Class.PDir.php");
97  include_once ("FDL/Class.PDoc.php");
98  include_once ("FDL/Class.PDocSearch.php");
99  include_once ("FDL/Class.WDocIncident.php");
100  include_once ("FDL/Class.WDocPropo.php");
101 
102  $appl = new Application();
103  $appl->Set("FDL", $core);
104 
105  $dbaccess = $appl->GetParam("FREEDOM_DB");
106  if ($dbaccess == "") {
107  print "Database not found : param FREEDOM_DB";
108  exit;
109  }
110 
111  include_once ("Class.ControlObject.php");
112 
113  include_once ("Class.ObjectPermission.php");
114 
115  include_once ("FDL/Class.DocPerm.php");
116 
117  $query = new QueryDb($dbaccess, "ControlObject");
118 
119  $table1 = $query->Query();
120 
121  if ($query->nb > 0) {
122 
123  $qacl = new QueryDb($dbaccess, "Acl");
124  $tacl = $qacl->Query();
125 
126  while (list($k, $v) = each($tacl)) {
127  $aclToName[$v->id] = $v->name;
128  }
129 
130  $qapp = new QueryDb($dbaccess, "Application");
131  $tapp = $qapp->Query(0, 0, "TABLE");
132 
133  while (list($k, $v) = each($tapp)) {
134  $ClassApps[$v["id"]] = $v["name"];
135  }
136 
137  while (list($k, $v) = each($table1)) {
138 
139  $qp = new QueryDb($dbaccess, "ObjectPermission");
140  $qp->AddQuery("id_obj=" . $v->id_obj);
141  $qp->AddQuery("ids_acl is not null");
142  $lp = $qp->Query();
143  if (count($lp > 0)) {
144 
145  $class = $ClassApps[$v->id_class];
146  $doc = new $class();
147 
148  print $v->description . "\n";
149 
150  while (list($kp, $pdoc) = each($lp)) {
151  if ($pdoc->isAffected()) {
152  $pdoc->GetPrivileges();
153  $dp = new Docperm($dbaccess, array(
154  $pdoc->id_obj,
155  $pdoc->id_user
156  ));
157  $dp->UnSetControl();
158  while (list($ku, $upp) = each($pdoc->upprivileges)) {
159  $pos = $doc->dacls[$aclToName[$upp]]["pos"];
160  $dp->SetControlP($pos);
161  }
162  while (list($ku, $upn) = each($pdoc->unprivileges)) {
163  $pos = $doc->dacls[$aclToName[$upn]]["pos"];
164  $dp->SetControlN($pos);
165  }
166 
167  $dp->Add();
168  }
169  }
170  }
171  }
172  }
173 }
174 
175 $table = (GetHttpVars("table", "no") == "yes"); //
176 $perm = (GetHttpVars("perm", "no") == "yes"); //
177 if ($table) migrTables();
178 if ($perm) migrPerm();
179 ?>
← centre documentaire © anakeen - published under CC License - Dynacase