00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 include_once( 'lib/ezdb/classes/ezdb.php' );
00041
00042 class eZDBTool
00043 {
00044
00045
00046
00047 function eZDBTool()
00048 {
00049 }
00050
00051
00052
00053
00054
00055 function isEmpty( &$db )
00056 {
00057 if ( $db === null )
00058 $db =& eZDB::instance();
00059 $relationTypeMask = $db->supportedRelationTypeMask();
00060 $count = $db->relationCounts( $relationTypeMask );
00061 return $count == 0;
00062 }
00063
00064
00065
00066
00067
00068 function cleanup( &$db )
00069 {
00070 if ( $db === null )
00071 $db =& eZDB::instance();
00072 $relationTypes = $db->supportedRelationTypes();
00073 $result = true;
00074 $defaultRegexp = "#^ez|tmp_notification_rule_s#";
00075 foreach ( $relationTypes as $relationType )
00076 {
00077 $relationItems = $db->relationList( $relationType );
00078
00079 $matchRegexp = null;
00080 if ( method_exists( $db, 'relationMatchRegexp' ) )
00081 {
00082 $matchRegexp = $db->relationMatchRegexp( $relationType );
00083 }
00084 if ( $matchRegexp === null )
00085 $matchRegexp = $defaultRegexp;
00086 foreach ( $relationItems as $relationItem )
00087 {
00088
00089 if ( $matchRegexp !== false and
00090 !preg_match( $matchRegexp, $relationItem ) )
00091 continue;
00092
00093 if ( !$db->removeRelation( $relationItem, $relationType ) )
00094 {
00095 $result = false;
00096 break;
00097 }
00098 }
00099 if ( !$result )
00100 break;
00101 }
00102 return $result;
00103 }
00104 }
00105
00106 ?>