ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilDbSetup Class Reference

Class ilDbSetup. More...

+ Collaboration diagram for ilDbSetup:

Public Member Functions

 createDatabase ($a_collation)
 
 provideGlobalDB ()
 
 revokeGlobalDB ()
 
 installDatabase ()
 
 isDatabaseExisting ()
 
 isConnectable ($keep_connection=false)
 
 isDatabaseConnectable ()
 
 isDatabaseInstalled ()
 
 getClient ()
 
 setClient ($client)
 
 getStatus ()
 
 setStatus ($status)
 
 getSqlDumpFile ()
 
 setSqlDumpFile ($sql_dump_file)
 
 dropTables ()
 
 getIlDBInterface ()
 
 setIlDBInterface ($ilDBInterface)
 

Static Public Member Functions

static getInstanceForClient (\ilClient $client)
 
static getInstanceForNewClient ($client_name, $dbname, $host='localhost', $username='root', $password='', $type=ilDBConstants::TYPE_PDO_MYSQL_INNODB)
 

Data Fields

const STATUS_OK = 1
 
const STATUS_FAILURE = 2
 

Protected Member Functions

 __construct (\ilClient $client)
 ilDbSetup constructor. More...
 
 getline ($fp, $delim)
 
 readDump ()
 legacy version of readdump More...
 
 readDumpSmall ()
 legacy version of readdump More...
 
 readDumpUltraSmall ()
 
 canDatabaseBeInstalled ()
 

Protected Attributes

 $client
 
 $status = self::STATUS_FAILURE
 
 $ilDBInterface
 
 $sql_dump_file = './setup/sql/ilias3.sql'
 

Static Protected Attributes

static $instances = array()
 

Detailed Description

Class ilDbSetup.

Author
Fabian Schmid fs@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch

Definition at line 10 of file class.ilDbSetup.php.

Constructor & Destructor Documentation

◆ __construct()

ilDbSetup::__construct ( \ilClient  $client)
protected

ilDbSetup constructor.

Parameters
\ilClient$client

Definition at line 41 of file class.ilDbSetup.php.

References $client, ilClient\getDbType(), and ilDBInterface\initFromIniFile().

41  {
42  $this->client = $client;
43  $this->ilDBInterface = ilDBWrapperFactory::getWrapper($client->getDbType());
44  $this->ilDBInterface->initFromIniFile($this->client->ini);
45  }
initFromIniFile($tmpClientIniFile=null)
Interface ilDBInterface.
+ Here is the call graph for this function:

Member Function Documentation

◆ canDatabaseBeInstalled()

ilDbSetup::canDatabaseBeInstalled ( )
protected
Returns
bool

Definition at line 326 of file class.ilDbSetup.php.

References isDatabaseConnectable(), and isDatabaseInstalled().

Referenced by installDatabase().

326  {
327  $connectable = $this->isDatabaseConnectable();
328  $installed = $this->isDatabaseInstalled();
329 
330  return ($connectable && !$installed);
331  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createDatabase()

ilDbSetup::createDatabase (   $a_collation)
Parameters
$a_collation
Returns
bool|mixed

Definition at line 92 of file class.ilDbSetup.php.

References ilDBInterface\connect(), ilDBInterface\createDatabase(), getClient(), ilDBInterface\getDBType(), ilDBInterface\initFromIniFile(), isConnectable(), ilDBConstants\TYPE_GALERA, ilDBConstants\TYPE_INNODB, ilDBConstants\TYPE_MYSQL, ilDBConstants\TYPE_PDO_MYSQL_INNODB, ilDBConstants\TYPE_PDO_MYSQL_MYISAM, and ilDBConstants\TYPE_PDO_POSTGRE.

92  {
93  if ($this->isConnectable()) {
94  switch ($this->ilDBInterface->getDBType()) {
101  $clientIniFile = $this->client->ini;
102 
103  if (!$this->ilDBInterface->createDatabase($clientIniFile->readVariable("db", "name"), 'utf8', $a_collation)) {
104  return false;
105  }
106  $this->ilDBInterface->initFromIniFile($this->getClient()->ini);
107 
108  return $this->ilDBInterface->connect();
109  break;
110  }
111  }
112 
113  return false;
114  }
initFromIniFile($tmpClientIniFile=null)
connect($return_false_on_error=false)
isConnectable($keep_connection=false)
Interface ilDBInterface.
createDatabase($a_name, $a_charset="utf8", $a_collation="")
getDBType()
Get DSN.
+ Here is the call graph for this function:

◆ dropTables()

ilDbSetup::dropTables ( )

Definition at line 382 of file class.ilDbSetup.php.

References ilDBInterface\listTables(), and ilDBInterface\manipulate().

382  {
383  foreach ($this->ilDBInterface->listTables() as $table) {
384  $this->ilDBInterface->manipulate('DROP TABLE ' . $table);
385  }
386  }
Interface ilDBInterface.
manipulate($query)
+ Here is the call graph for this function:

◆ getClient()

ilDbSetup::getClient ( )
Returns
ilClient

Definition at line 337 of file class.ilDbSetup.php.

References $client.

Referenced by createDatabase(), and installDatabase().

337  {
338  return $this->client;
339  }
+ Here is the caller graph for this function:

◆ getIlDBInterface()

ilDbSetup::getIlDBInterface ( )
Returns

Definition at line 392 of file class.ilDbSetup.php.

References $ilDBInterface.

392  {
393  return $this->ilDBInterface;
394  }

◆ getInstanceForClient()

static ilDbSetup::getInstanceForClient ( \ilClient  $client)
static
Parameters
\ilClient$client
Returns
ilDbSetup

Definition at line 52 of file class.ilDbSetup.php.

References $client, and ilClient\getId().

Referenced by ilClient\getDBSetup().

52  {
53  if (empty(self::$instances[$client->getId()])) {
54  self::$instances[$client->getId()] = new self($client);
55  }
56 
57  return self::$instances[$client->getId()];
58  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getInstanceForNewClient()

static ilDbSetup::getInstanceForNewClient (   $client_name,
  $dbname,
  $host = 'localhost',
  $username = 'root',
  $password = '',
  $type = ilDBConstants::TYPE_PDO_MYSQL_INNODB 
)
static
Parameters
$client_name
$dbname
string$host
string$username
string$password
string$type
Returns

Definition at line 70 of file class.ilDbSetup.php.

70  {
71  require_once('./setup/classes/class.ilClient.php');
72  require_once('./Services/Init/classes/class.ilIniFile.php');
73  require_once('./setup/classes/class.ilDBConnections.php');
74 
75  $ilClient = new ilClient($client_name, new ilDBConnections());
76  $ilClient->init();
77  $ilClient->setDbHost($host);
78  $ilClient->setDbName($dbname);
79  $ilClient->setDbUser($username);
80  $ilClient->setDbPass($password);
81  $ilClient->setDbType($type);
82  $ilClient->writeIni();
83 
84  return self::getInstanceForClient($ilClient);
85  }
Administrates DB connections in setup.
Client Management.

◆ getline()

ilDbSetup::getline (   $fp,
  $delim 
)
protected
Parameters
$fp
$delim
Returns
string

Definition at line 141 of file class.ilDbSetup.php.

References $result.

Referenced by readDump().

141  {
142  $result = "";
143  while (!feof($fp)) {
144  $tmp = fgetc($fp);
145  if ($tmp == $delim) {
146  return $result;
147  }
148  $result .= $tmp;
149  }
150 
151  return $result;
152  }
$result
+ Here is the caller graph for this function:

◆ getSqlDumpFile()

ilDbSetup::getSqlDumpFile ( )
Returns
string

Definition at line 369 of file class.ilDbSetup.php.

References $sql_dump_file.

Referenced by readDump(), readDumpSmall(), and readDumpUltraSmall().

369  {
370  return $this->sql_dump_file;
371  }
+ Here is the caller graph for this function:

◆ getStatus()

ilDbSetup::getStatus ( )
Returns
mixed

Definition at line 353 of file class.ilDbSetup.php.

References $status.

353  {
354  return $this->status;
355  }

◆ installDatabase()

ilDbSetup::installDatabase ( )
Returns
bool

Definition at line 221 of file class.ilDbSetup.php.

References canDatabaseBeInstalled(), ilDBInterface\connect(), getClient(), ilDBInterface\getDBType(), provideGlobalDB(), readDumpUltraSmall(), ilDBConstants\TYPE_GALERA, ilDBConstants\TYPE_INNODB, ilDBConstants\TYPE_MYSQL, ilDBConstants\TYPE_ORACLE, ilDBConstants\TYPE_PDO_MYSQL_INNODB, ilDBConstants\TYPE_PDO_MYSQL_MYISAM, ilDBConstants\TYPE_PDO_POSTGRE, and ilDBConstants\TYPE_POSTGRES.

221  {
222  if ($this->canDatabaseBeInstalled()) {
223  $this->provideGlobalDB();
224  switch ($this->ilDBInterface->getDBType()) {
227  $this->ilDBInterface->connect();
228  //$this->dropTables();
229  //$this->readDump();
230  $this->readDumpUltraSmall();
231  $this->getClient()->db_installed = true;
232 
233  return true;
234 
235  break;
242  include_once("./setup/sql/ilDBTemplate.php");
243  setupILIASDatabase();
244 
245  return true;
246  break;
247  }
248  }
249 
250  return false;
251  }
connect($return_false_on_error=false)
Interface ilDBInterface.
getDBType()
Get DSN.
+ Here is the call graph for this function:

◆ isConnectable()

ilDbSetup::isConnectable (   $keep_connection = false)
Returns
bool|mixed

Definition at line 272 of file class.ilDbSetup.php.

References ilDBInterface\connect(), ilDBInterface\getDBType(), provideGlobalDB(), and ilDBConstants\TYPE_ORACLE.

Referenced by createDatabase(), isDatabaseConnectable(), and isDatabaseExisting().

272  {
273  switch ($this->ilDBInterface->getDBType()) {
274  default:
275  try {
276  $connect = $this->ilDBInterface->connect();
277  } catch (PDOException $e) {
278  $connect = ($e->getCode() == 1049);
279  }
280  break;
282  $connect = $this->ilDBInterface->connect(true);
283  break;
284  }
285  if ($keep_connection && $connect) {
286  $this->provideGlobalDB();
287  }
288 
289  if (!$connect) {
290  $this->client->setError('Database can\'t be reached. Please check the credentials and if database exists');
291  }
292 
293  return $connect;
294  }
connect($return_false_on_error=false)
Interface ilDBInterface.
getDBType()
Get DSN.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isDatabaseConnectable()

ilDbSetup::isDatabaseConnectable ( )
Returns
bool

Definition at line 300 of file class.ilDbSetup.php.

References ilDBInterface\connect(), and isConnectable().

Referenced by canDatabaseBeInstalled(), and isDatabaseExisting().

300  {
301  if (!$this->isConnectable()) {
302  return false;
303  }
304 
305  return $this->ilDBInterface->connect(true);
306  }
connect($return_false_on_error=false)
isConnectable($keep_connection=false)
Interface ilDBInterface.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isDatabaseExisting()

ilDbSetup::isDatabaseExisting ( )
Returns
bool

Definition at line 257 of file class.ilDbSetup.php.

References isConnectable(), and isDatabaseConnectable().

Referenced by isDatabaseInstalled().

257  {
258  if (!$this->isConnectable()) {
259  return false;
260  }
261  if (!$this->isDatabaseConnectable()) {
262  return false;
263  }
264 
265  return true;
266  }
isConnectable($keep_connection=false)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isDatabaseInstalled()

ilDbSetup::isDatabaseInstalled ( )
Returns
bool

Definition at line 312 of file class.ilDbSetup.php.

References $target, array, isDatabaseExisting(), and ilDBInterface\listTables().

Referenced by canDatabaseBeInstalled().

312  {
313  if (!$this->isDatabaseExisting()) {
314  return false;
315  }
316 
317  $target = array( 'usr_data', 'object_data', 'object_reference' );
318 
319  return count(array_intersect($this->ilDBInterface->listTables(), $target)) == count($target);
320  }
Interface ilDBInterface.
Create styles array
The data for the language used.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ provideGlobalDB()

ilDbSetup::provideGlobalDB ( )

Definition at line 117 of file class.ilDbSetup.php.

References $DIC, $GLOBALS, and $ilDBInterface.

Referenced by installDatabase(), and isConnectable().

117  {
118  global $DIC;
119 
120  if($DIC->offsetExists('ilDB')) {
121  $DIC->offsetUnset('ilDB');
122  }
123 
124  $GLOBALS["ilDB"] = $this->ilDBInterface;
125  $DIC["ilDB"] = $this->ilDBInterface;
126  $this->client->db = $this->ilDBInterface; // TODO ugly and dirty, but ilClient requires it
127  }
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
global $DIC
+ Here is the caller graph for this function:

◆ readDump()

ilDbSetup::readDump ( )
protected

legacy version of readdump

Deprecated:
use readDumpUltraSmall
Returns
bool

Definition at line 160 of file class.ilDbSetup.php.

References $r, getline(), getSqlDumpFile(), and ilDBInterface\query().

160  {
161  $fp = fopen($this->getSqlDumpFile(), 'r');
162  $q = '';
163  while (!feof($fp)) {
164  $line = trim($this->getline($fp, "\n"));
165 
166  if ($line != "" && substr($line, 0, 1) != "#" && substr($line, 0, 1) != "-") {
167  if (substr($line, - 1) == ";") {
168  //query is complete
169  $q .= " " . substr($line, 0, - 1);
170  try {
171  $r = $this->ilDBInterface->query($q);
172  } catch (ilDatabaseException $e) {
173  return false;
174  }
175 
176  unset($q);
177  unset($line);
178  } else {
179  $q .= " " . $line;
180  }
181  }
182  }
183 
184  fclose($fp);
185  }
Class ilDatabaseException.
Interface ilDBInterface.
$r
Definition: example_031.php:79
getline($fp, $delim)
query($query)
+ Here is the call graph for this function:

◆ readDumpSmall()

ilDbSetup::readDumpSmall ( )
protected

legacy version of readdump

Deprecated:
use readDumpUltraSmall
Returns
bool

Definition at line 193 of file class.ilDbSetup.php.

References getSqlDumpFile(), and ilDBInterface\manipulate().

193  {
194  $sql = file_get_contents($this->getSqlDumpFile());
195  $lines = explode(';', $sql);
196  foreach ($lines as $line) {
197  if (strlen($line) > 0) {
198  $this->ilDBInterface->manipulate($line);
199  }
200  }
201 
202  return true;
203  }
Interface ilDBInterface.
manipulate($query)
+ Here is the call graph for this function:

◆ readDumpUltraSmall()

ilDbSetup::readDumpUltraSmall ( )
protected
Returns
bool

Definition at line 209 of file class.ilDbSetup.php.

References ilDBInterface\execute(), getSqlDumpFile(), and ilDBInterface\prepareManip().

Referenced by installDatabase().

209  {
210  $sql = file_get_contents($this->getSqlDumpFile());
211  $re = $this->ilDBInterface->prepareManip($sql);
212  $this->ilDBInterface->execute($re);
213 
214  return true;
215  }
prepareManip($a_query, $a_types=null)
execute($stmt, $data=array())
Interface ilDBInterface.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ revokeGlobalDB()

ilDbSetup::revokeGlobalDB ( )

Definition at line 130 of file class.ilDbSetup.php.

References $GLOBALS.

130  {
131  $GLOBALS["ilDB"] = null;
132  $this->client->db = null; // TODO ugly and dirty, but ilClient requires it
133  }
$GLOBALS['loaded']
Global hash that tracks already loaded includes.

◆ setClient()

ilDbSetup::setClient (   $client)
Parameters
ilClient$client

Definition at line 345 of file class.ilDbSetup.php.

References $client.

345  {
346  $this->client = $client;
347  }

◆ setIlDBInterface()

ilDbSetup::setIlDBInterface (   $ilDBInterface)
Parameters
\ilDBInterface$ilDBInterface

Definition at line 400 of file class.ilDbSetup.php.

References $ilDBInterface.

400  {
401  $this->ilDBInterface = $ilDBInterface;
402  }
Interface ilDBInterface.

◆ setSqlDumpFile()

ilDbSetup::setSqlDumpFile (   $sql_dump_file)
Parameters
string$sql_dump_file

Definition at line 377 of file class.ilDbSetup.php.

References $sql_dump_file.

377  {
378  $this->sql_dump_file = $sql_dump_file;
379  }

◆ setStatus()

ilDbSetup::setStatus (   $status)
Parameters
mixed$status

Definition at line 361 of file class.ilDbSetup.php.

References $status.

361  {
362  $this->status = $status;
363  }

Field Documentation

◆ $client

ilDbSetup::$client
protected

Definition at line 17 of file class.ilDbSetup.php.

Referenced by __construct(), getClient(), getInstanceForClient(), and setClient().

◆ $ilDBInterface

ilDbSetup::$ilDBInterface
protected

Definition at line 29 of file class.ilDbSetup.php.

Referenced by getIlDBInterface(), provideGlobalDB(), and setIlDBInterface().

◆ $instances

ilDbSetup::$instances = array()
staticprotected

Definition at line 25 of file class.ilDbSetup.php.

◆ $sql_dump_file

ilDbSetup::$sql_dump_file = './setup/sql/ilias3.sql'
protected

Definition at line 33 of file class.ilDbSetup.php.

Referenced by getSqlDumpFile(), and setSqlDumpFile().

◆ $status

ilDbSetup::$status = self::STATUS_FAILURE
protected

Definition at line 21 of file class.ilDbSetup.php.

Referenced by getStatus(), and setStatus().

◆ STATUS_FAILURE

const ilDbSetup::STATUS_FAILURE = 2

Definition at line 13 of file class.ilDbSetup.php.

◆ STATUS_OK

const ilDbSetup::STATUS_OK = 1

Definition at line 12 of file class.ilDbSetup.php.


The documentation for this class was generated from the following file: