Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
destroyFamily.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Delete family document and its documents
8  *
9  * @subpackage
10  */
11 /**
12  */
13 global $action;
14 
15 include_once ("FDL/Lib.Attr.php");
16 include_once ("FDL/Class.DocFam.php");
17 
18 $usage = new ApiUsage();
19 $usage->setDefinitionText("Delete family document and its documents");
20 $docid = $usage->addRequiredParameter("famid", "special docid");
21 $force = $usage->addHiddenParameter("force", "force without transaction");
22 
23 $transaction = $usage->addEmptyParameter("transaction", "abort deletion if one of query failed");
24 if (!$force) {
26 } else {
27  $force = ($force == "yes");
28 }
29 $usage->verify();
30 
32 $appl->Set("FDL", $core);
33 
34 $dbaccess = $appl->dbaccess;
35 if ($dbaccess == "") {
36  $action->exitError("Database not found : appl->dbaccess");
37 }
38 
39 if (($docid !== 0) && (!is_numeric($docid))) {
40  $odocid = $docid;
42  if (!$docid) {
43  $action->exitError(sprintf(_("family %s not found") . "\n", $odocid));
44  }
45 }
46 
48 
49 function destroyFamily($dbaccess, $idfam, $force = false)
50 {
51  global $action;
52 
53  $tdoc = getTDoc($dbaccess, $idfam);
54  if ($tdoc) {
55  $resid = $tdoc["id"];
56  $resname = $tdoc["name"];
57  print "Destroying [" . $tdoc["title"] . "(" . $tdoc["name"] . ")]\n";
58  $dbid = getDbId($dbaccess);
59  $tsql = array();
60  if (!$force) $tsql[] = "BEGIN;";
61  $tsql+= array(
62  sprintf("DELETE FROM fld WHERE childid IN (SELECT id FROM doc%d);", $resid) ,
63  sprintf("DELETE FROM doc%d;", $resid) ,
64  sprintf("DELETE FROM docname WHERE name = %s;", pg_escape_literal($resname)) ,
65  sprintf("DELETE FROM docfrom WHERE fromid = %d;", $resid) ,
66  sprintf("DELETE FROM docattr WHERE docid = %d;", $resid) ,
67  sprintf("DELETE FROM docfam WHERE id = %d;", $resid) ,
68  sprintf("DROP VIEW IF EXISTS family.%s;", pg_escape_identifier(strtolower($resname))) ,
69  sprintf("DROP TABLE IF EXISTS doc%d;", $resid) ,
70  sprintf("DROP SEQUENCE IF EXISTS seq_doc%d;", $resid)
71  );
72  if (!$force) $tsql[] = "COMMIT;";
73  $fdlgen = sprintf("FDLGEN/Class.Doc%d.php", $tdoc["id"]);
74  if (file_exists($fdlgen) && is_file($fdlgen)) {
75  if (!unlink($fdlgen)) {
76  $action->exitError("Could not delete file '%s'.", $fdlgen);
77  } else {
78  printf("Deleted file '%s'.\n", $fdlgen);
79  }
80  }
81  $res = "";
82  foreach ($tsql as $sql) {
83  print "$sql\n";
84  $res = @pg_query($dbid, $sql);
85  if (!$res) {
86  print pg_last_error() . "\n";
87  if (!$force) break;
88  }
89  }
90  if ($res) printf("Family %s (id : %d) is destroyed.\n", $tdoc["name"], $tdoc["id"]);
91  } else {
92  $action->exitError("cannot destroy $idfam\n");
93  }
94 }
$tdoc
getTDoc($dbaccess, $id, $sqlfilters=array(), $result=array())
destroyFamily($dbaccess, $idfam, $force=false)
$transaction
$appl
$docid
$usage
$force
getFamIdFromName($dbaccess, $name)
print
Definition: checklist.php:49
$dbaccess
global $action
Verify arguments for wsh programs.
$core
Definition: chgpasswd.php:33
← centre documentaire © anakeen