PageRenderTime 39ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/ezdb/classes/ezdbtool.php

https://github.com/aurelienRT1/ezpublish
PHP | 97 lines | 46 code | 6 blank | 45 comment | 8 complexity | 23ad0ee85443ebc259afd05f2a68c147 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
  1. <?php
  2. //
  3. // Definition of eZDBTool class
  4. //
  5. // Created on: <11-Dec-2002 15:07:25 amos>
  6. //
  7. // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
  8. // SOFTWARE NAME: eZ Publish
  9. // SOFTWARE RELEASE: 4.1.x
  10. // COPYRIGHT NOTICE: Copyright (C) 1999-2010 eZ Systems AS
  11. // SOFTWARE LICENSE: GNU General Public License v2.0
  12. // NOTICE: >
  13. // This program is free software; you can redistribute it and/or
  14. // modify it under the terms of version 2.0 of the GNU General
  15. // Public License as published by the Free Software Foundation.
  16. //
  17. // This program is distributed in the hope that it will be useful,
  18. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. // GNU General Public License for more details.
  21. //
  22. // You should have received a copy of version 2.0 of the GNU General
  23. // Public License along with this program; if not, write to the Free
  24. // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  25. // MA 02110-1301, USA.
  26. //
  27. //
  28. // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
  29. //
  30. /*! \file
  31. */
  32. /*!
  33. \class eZDBTool ezdbtool.php
  34. \brief The class eZDBTool does
  35. */
  36. class eZDBTool
  37. {
  38. /*!
  39. \return true if the database does not contain any relation objects.
  40. \note If db is not specified it will use eZDB::instance()
  41. */
  42. static function isEmpty( $db )
  43. {
  44. if ( $db === null )
  45. $db = eZDB::instance();
  46. $relationTypeMask = $db->supportedRelationTypeMask();
  47. $count = $db->relationCounts( $relationTypeMask );
  48. return $count == 0;
  49. }
  50. /*!
  51. Tries to remove all relation types from the database.
  52. \note If db is not specified it will use eZDB::instance()
  53. */
  54. static function cleanup( $db )
  55. {
  56. if ( $db === null )
  57. $db = eZDB::instance();
  58. $relationTypes = $db->supportedRelationTypes();
  59. $result = true;
  60. $defaultRegexp = "#^ez|tmp_notification_rule_s#";
  61. foreach ( $relationTypes as $relationType )
  62. {
  63. $relationItems = $db->relationList( $relationType );
  64. // This is the default regexp, unless the db driver provides one
  65. $matchRegexp = null;
  66. if ( method_exists( $db, 'relationMatchRegexp' ) )
  67. {
  68. $matchRegexp = $db->relationMatchRegexp( $relationType );
  69. }
  70. if ( $matchRegexp === null )
  71. $matchRegexp = $defaultRegexp;
  72. foreach ( $relationItems as $relationItem )
  73. {
  74. // skip relations that shouldn't be touched
  75. if ( $matchRegexp !== false and
  76. !preg_match( $matchRegexp, $relationItem ) )
  77. continue;
  78. if ( !$db->removeRelation( $relationItem, $relationType ) )
  79. {
  80. $result = false;
  81. break;
  82. }
  83. }
  84. if ( !$result )
  85. break;
  86. }
  87. return $result;
  88. }
  89. }
  90. ?>