Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
RedBeanDatabase.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  *
23  * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  *
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
37  $basePath = Yii::app()->getBasePath();
38  require_once("$basePath/../../redbean/rb.php");
39 
44  Yii::import('application.core.models.ZurmoRedBean');
46  {
47  private static $isSetup = false;
48  private static $databaseType = null;
49 
61  public static function setup($dsn, $username, $password)
62  {
63  assert('is_string($dsn) && $dsn != ""');
64  assert('$username == null || is_string($username) && $username != ""');
65  assert('$password == null || is_string($password)');
66  assert('!self::isSetup()');
67  try
68  {
69  ZurmoRedBean::setup($dsn, $username, $password);
70  static::freeze();
71  if (SHOW_QUERY_DATA)
72  {
73  Yii::app()->performance->setRedBeanQueryLogger(ZurmoRedBeanPluginQueryLogger::
74  getInstanceAndAttach(ZurmoRedBean::$adapter ));
75  }
76 
77  if (defined('REDBEAN_DEBUG_TO_FILE') && REDBEAN_DEBUG_TO_FILE)
78  {
79  $queryLoggerComponent = Yii::createComponent(array(
80  'class' => 'application.core.models.ZurmoRedBeanQueryFileLogger',
81  ));
82  $queryLoggerComponent->init();
83  Yii::app()->setComponent('queryFileLogger', $queryLoggerComponent);
84  ZurmoRedBean::debug(true, Yii::app()->queryFileLogger);
85  }
86  else
87  {
88  ZurmoRedBean::debug(defined('REDBEAN_DEBUG') && REDBEAN_DEBUG);
89  }
90 
91  self::$isSetup = true;
92  self::$databaseType = substr($dsn, 0, strpos($dsn, ':'));
93  }
94  catch (Exception $e)
95  {
96  self::close();
97  throw $e;
98  }
99  assert('static::isSetup()');
100  assert('RedBeanDatabase::isFrozen()');
101  }
102 
106  public static function isSetup()
107  {
108  return self::$isSetup;
109  }
110 
111  public static function close()
112  {
113  // TODO - find out if there is a proper way.
114  ZurmoRedBean::$toolboxes = array();
115  ZurmoRedBean::$toolbox = null;
116  ZurmoRedBean::$redbean = null;
117  ZurmoRedBean::$writer = null;
118  ZurmoRedBean::$adapter = null;
119  ZurmoRedBean::$associationManager = null;
120  ZurmoRedBean::$extAssocManager = null;
121  ZurmoRedBean::$exporter = null;
122  ZurmoRedBean::$tagManager = null;
123  ZurmoRedBean::$currentDB = '';
124  ZurmoRedBean::$f = null;
125  ZurmoRedBean::close();
126  self::$isSetup = false;
127  }
128 
129  public static function getDatabaseType()
130  {
131  return self::$databaseType;
132  }
133 
140  public static function freeze()
141  {
142  ZurmoRedBean::freeze(true);
143  }
144 
148  public static function isFrozen()
149  {
150  return ZurmoRedBean::$redbean !== null && ZurmoRedBean::$redbean->isFrozen();
151  }
152 
157  public static function unfreeze()
158  {
159  ZurmoRedBean::freeze(false);
160  }
161 
167  public static function getDatabaseTypeFromDsnString($dsn)
168  {
169  $databaseType = substr($dsn, 0, strpos($dsn, ':'));
170  if ($databaseType)
171  {
172  return $databaseType;
173  }
174  else
175  {
176  throw new NotSupportedException();
177  }
178  }
179 
186  public static function getDatabaseInfoFromDsnString($dsn)
187  {
188  preg_match("/^([^;]+):host=([^;]+);(?:port=([^;]+);)?dbname=([^;]+)/", $dsn, $matches); // Not Coding Standard
189  if (count($matches) == 5)
190  {
191  if (empty($matches['3']))
192  {
193  $databaseType = $matches['1'];
194  $databasePort = DatabaseCompatibilityUtil::getDatabaseDefaultPort($databaseType);
195  }
196  else
197  {
198  $databasePort = $matches['3'];
199  }
200  $databaseConnectionInfo = array(
201  'databaseType' => $matches['1'],
202  'databaseHost' => $matches['2'],
203  'databasePort' => intval($databasePort),
204  'databaseName' => $matches['4']
205  );
206  return $databaseConnectionInfo;
207  }
208  else
209  {
210  throw new NotSupportedException();
211  }
212  }
213 
223  public static function getDatabaseNameFromDsnString($dsn)
224  {
225  preg_match("/host=([^;]+);(?:port=([^;]+);)?dbname=([^;]+)/", $dsn, $matches); // Not Coding Standard
226  if (count($matches) == 4)
227  {
228  return $matches[3];
229  }
230  else
231  {
232  throw new NotSupportedException();
233  }
234  }
235  }
236 ?>
static setup($dsn, $username, $password)
static getDatabaseInfoFromDsnString($dsn)
static getDatabaseNameFromDsnString($dsn)
static getDatabaseDefaultPort($databaseType= 'mysql')
static getDatabaseTypeFromDsnString($dsn)
Generated on Mon Jul 6 2020 07:10:30
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.