2 //==============================================================================
3 // Name: JPDBDELCLASS.PHP
4 // Description: Deletes a class from the documentation DB
6 // Author: johanp@aditus.nu
7 // Version: $Id: jpdbdelclass.php,v 1.3 2002/06/05 22:39:14 aditus Exp $
10 // Copyright (C) 2002 Johan Persson
12 //==============================================================================
15 include ("de_utils.php");
17 DEFINE("DELDB_OVERRIDE_REFCHK",1);
18 DEFINE("DELDB_OVERRIDE_EXTCHK",2);
22 function RemoveDBCLass($aDB) {
26 function Run($aProjname,$aClass,$aFlags=0) {
28 // Get some info about this class
29 $q = 'SELECT * FROM tbl_class_'.$aProjname.' WHERE fld_name='."'$aClass'";
30 $res = $this->iDB->Query($q);
31 if( $res->NumRows() == 0 ) {
32 Utils::Error("Can't find class '$aClass' in DB.");
36 $class = $res->Fetch();
38 // As a safety check we don't allow deleting classes who's
39 // methods are referenced by the method references in other classes.
41 $q = "SELECT DISTINCT CONCAT(c.fld_name,'::<b>',b.fld_name,'</b>()') as fld_name
42 FROM tbl_method_".$aProjname." as a,tbl_method_".$aProjname." as b,tbl_class_".$aProjname." as c
43 WHERE a.fld_classidx=".$class['fld_key']." AND
44 c.fld_key = b.fld_classidx AND
45 (b.fld_methref1=a.fld_key OR
46 b.fld_methref2=a.fld_key OR
47 b.fld_methref3=a.fld_key OR
48 b.fld_methref4=a.fld_key OR
49 b.fld_methref5=a.fld_key)
51 $res = $this->iDB->Query($q);
53 if( $n > 0 && !($aFlags & DELDB_OVERRIDE_REFCHK)) {
57 $s .= $row['fld_name'];
58 if( $n > 1 ) $s .= ",<br> ";
61 Utils::Error("Can't delete class '$aClass' since it's methods are referenced by:<br>$s<p>");
65 // As another safety check we don't allow deleting classes which
66 // are superclasses to some other classes in the DB
68 $q = 'SELECT fld_name FROM tbl_class_'.$aProjname.' WHERE fld_parentname='."'$aClass'";
69 $res = $this->iDB->Query($q);
71 if( $n > 0 && !($aFlags & DELDB_OVERRIDE_EXTCHK) ) {
75 $s .= "CLASS ".$row['fld_name'];
76 if( $n > 1 ) $s .= ",<br> ";
79 Utils::Error("Can't delete class '$aClass' since it is inherited by:<br>$s<p>");
83 // Checks are done. Point of no return. Now really delete class
85 // Start by deleting all methods in this class
86 $q = "DELETE FROM tbl_method_".$aProjname." WHERE fld_classidx=".$class['fld_key'];
87 $this->iDB->Query($q);
89 // .. and all instance variables
90 $q = "DELETE FROM tbl_classvars_".$aProjname." WHERE fld_classidx=".$class['fld_key'];
91 $this->iDB->Query($q);
94 $q = "DELETE FROM tbl_class_".$aProjname." WHERE fld_name='".$aClass."'";
95 $this->iDB->Query($q);
104 var $iProjname,$iProjidx;
107 global $HTTP_COOKIE_VARS;
108 $this->iDB = DBFactory::InitDB();
110 $this->iProjname = strtok(@$HTTP_COOKIE_VARS['ddda_project'],':');
111 if( $this->iProjname != '' ) {
112 $this->iProjidx = strtok(':');
115 die('No project specified.');
118 function Run($aClass,$aFlags=0) {
119 $dbremove = new RemoveDBClass($this->iDB);
120 if( $dbremove->Run($this->iProjname,$aClass,$aFlags) )
121 echo "Class <b>$aClass</b> has been removed from JpGraph Database.";
123 Utils::Error("Can't remove class <b>$aClass</b> from JpGRaph Database.");
128 //==========================================================================
129 // Script entry point
130 // Read URL argument and create Driver
131 //==========================================================================
132 if( !isset($HTTP_GET_VARS['class']) )
133 Utils::Error("Must specify class to remove from db. Use syntax class=<class-name>");
135 $class = urldecode($HTTP_GET_VARS['class']);
137 $driver = new Driver();
138 $driver->Run($class);