|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of eZDBTool class 00004 // 00005 // Created on: <11-Dec-2002 15:07:25 amos> 00006 // 00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00008 // SOFTWARE NAME: eZ Publish 00009 // SOFTWARE RELEASE: 4.0.x 00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS 00011 // SOFTWARE LICENSE: GNU General Public License v2.0 00012 // NOTICE: > 00013 // This program is free software; you can redistribute it and/or 00014 // modify it under the terms of version 2.0 of the GNU General 00015 // Public License as published by the Free Software Foundation. 00016 // 00017 // This program is distributed in the hope that it will be useful, 00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 // GNU General Public License for more details. 00021 // 00022 // You should have received a copy of version 2.0 of the GNU General 00023 // Public License along with this program; if not, write to the Free 00024 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00025 // MA 02110-1301, USA. 00026 // 00027 // 00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00029 // 00030 00031 /*! \file ezdbtool.php 00032 */ 00033 00034 /*! 00035 \class eZDBTool ezdbtool.php 00036 \brief The class eZDBTool does 00037 00038 */ 00039 00040 //include_once( 'lib/ezdb/classes/ezdb.php' ); 00041 00042 class eZDBTool 00043 { 00044 /*! 00045 \return true if the database does not contain any relation objects. 00046 \note If db is not specified it will use eZDB::instance() 00047 */ 00048 static function isEmpty( $db ) 00049 { 00050 if ( $db === null ) 00051 $db = eZDB::instance(); 00052 $relationTypeMask = $db->supportedRelationTypeMask(); 00053 $count = $db->relationCounts( $relationTypeMask ); 00054 return $count == 0; 00055 } 00056 00057 /*! 00058 Tries to remove all relation types from the database. 00059 \note If db is not specified it will use eZDB::instance() 00060 */ 00061 static function cleanup( $db ) 00062 { 00063 if ( $db === null ) 00064 $db = eZDB::instance(); 00065 $relationTypes = $db->supportedRelationTypes(); 00066 $result = true; 00067 $defaultRegexp = "#^ez|tmp_notification_rule_s#"; 00068 foreach ( $relationTypes as $relationType ) 00069 { 00070 $relationItems = $db->relationList( $relationType ); 00071 // This is the default regexp, unless the db driver provides one 00072 $matchRegexp = null; 00073 if ( method_exists( $db, 'relationMatchRegexp' ) ) 00074 { 00075 $matchRegexp = $db->relationMatchRegexp( $relationType ); 00076 } 00077 if ( $matchRegexp === null ) 00078 $matchRegexp = $defaultRegexp; 00079 foreach ( $relationItems as $relationItem ) 00080 { 00081 // skip relations that shouldn't be touched 00082 if ( $matchRegexp !== false and 00083 !preg_match( $matchRegexp, $relationItem ) ) 00084 continue; 00085 00086 if ( !$db->removeRelation( $relationItem, $relationType ) ) 00087 { 00088 $result = false; 00089 break; 00090 } 00091 } 00092 if ( !$result ) 00093 break; 00094 } 00095 return $result; 00096 } 00097 } 00098 00099 ?>