ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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().

42  {
43  $this->client = $client;
44  $this->ilDBInterface = ilDBWrapperFactory::getWrapper($client->getDbType());
45  $this->ilDBInterface->initFromIniFile($this->client->ini);
46  }
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 341 of file class.ilDbSetup.php.

References isDatabaseConnectable(), and isDatabaseInstalled().

Referenced by installDatabase().

342  {
343  $connectable = $this->isDatabaseConnectable();
344  $installed = $this->isDatabaseInstalled();
345 
346  return ($connectable && !$installed);
347  }
+ 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 95 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.

96  {
97  if ($this->isConnectable()) {
98  switch ($this->ilDBInterface->getDBType()) {
105  $clientIniFile = $this->client->ini;
106 
107  if (!$this->ilDBInterface->createDatabase($clientIniFile->readVariable("db", "name"), 'utf8', $a_collation)) {
108  return false;
109  }
110  $this->ilDBInterface->initFromIniFile($this->getClient()->ini);
111 
112  return $this->ilDBInterface->connect();
113  break;
114  }
115  }
116 
117  return false;
118  }
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 404 of file class.ilDbSetup.php.

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

405  {
406  foreach ($this->ilDBInterface->listTables() as $table) {
407  $this->ilDBInterface->manipulate('DROP TABLE ' . $table);
408  }
409  }
Interface ilDBInterface.
if(empty($password)) $table
Definition: pwgen.php:24
manipulate($query)
Run a (write) Query on the database.
+ Here is the call graph for this function:

◆ getClient()

ilDbSetup::getClient ( )
Returns
ilClient

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

References $client.

Referenced by createDatabase(), and installDatabase().

354  {
355  return $this->client;
356  }
+ Here is the caller graph for this function:

◆ getIlDBInterface()

ilDbSetup::getIlDBInterface ( )
Returns

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

References $ilDBInterface.

416  {
417  return $this->ilDBInterface;
418  }

◆ getInstanceForClient()

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

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

References $client, and ilClient\getId().

Referenced by ilClient\getDBSetup().

54  {
55  if (empty(self::$instances[$client->getId()])) {
56  self::$instances[$client->getId()] = new self($client);
57  }
58 
59  return self::$instances[$client->getId()];
60  }
+ 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 72 of file class.ilDbSetup.php.

References $password, and $type.

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

◆ getline()

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

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

References $result.

Referenced by readDump().

148  {
149  $result = "";
150  while (!feof($fp)) {
151  $tmp = fgetc($fp);
152  if ($tmp == $delim) {
153  return $result;
154  }
155  $result .= $tmp;
156  }
157 
158  return $result;
159  }
$result
+ Here is the caller graph for this function:

◆ getSqlDumpFile()

ilDbSetup::getSqlDumpFile ( )
Returns
string

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

References $sql_dump_file.

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

390  {
391  return $this->sql_dump_file;
392  }
+ Here is the caller graph for this function:

◆ getStatus()

ilDbSetup::getStatus ( )
Returns
mixed

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

References $status.

372  {
373  return $this->status;
374  }

◆ installDatabase()

ilDbSetup::installDatabase ( )
Returns
bool

Definition at line 231 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.

232  {
233  if ($this->canDatabaseBeInstalled()) {
234  $this->provideGlobalDB();
235  switch ($this->ilDBInterface->getDBType()) {
238  $this->ilDBInterface->connect();
239  //$this->dropTables();
240  //$this->readDump();
241  $this->readDumpUltraSmall();
242  $this->getClient()->db_installed = true;
243 
244  return true;
245 
246  break;
253  include_once("./setup/sql/ilDBTemplate.php");
254  setupILIASDatabase();
255 
256  return true;
257  break;
258  }
259  }
260 
261  return false;
262  }
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 284 of file class.ilDbSetup.php.

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

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

285  {
286  switch ($this->ilDBInterface->getDBType()) {
287  default:
288  try {
289  $connect = $this->ilDBInterface->connect();
290  } catch (PDOException $e) {
291  $connect = ($e->getCode() == 1049);
292  }
293  break;
295  $connect = $this->ilDBInterface->connect(true);
296  break;
297  }
298  if ($keep_connection && $connect) {
299  $this->provideGlobalDB();
300  }
301 
302  if (!$connect) {
303  $this->client->setError('Database can\'t be reached. Please check the credentials and if database exists');
304  }
305 
306  return $connect;
307  }
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 313 of file class.ilDbSetup.php.

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

Referenced by canDatabaseBeInstalled(), and isDatabaseExisting().

314  {
315  if (!$this->isConnectable()) {
316  return false;
317  }
318 
319  return $this->ilDBInterface->connect(true);
320  }
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 268 of file class.ilDbSetup.php.

References isConnectable(), and isDatabaseConnectable().

Referenced by isDatabaseInstalled().

269  {
270  if (!$this->isConnectable()) {
271  return false;
272  }
273  if (!$this->isDatabaseConnectable()) {
274  return false;
275  }
276 
277  return true;
278  }
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 326 of file class.ilDbSetup.php.

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

Referenced by canDatabaseBeInstalled().

327  {
328  if (!$this->isDatabaseExisting()) {
329  return false;
330  }
331 
332  $target = array( 'usr_data', 'object_data', 'object_reference' );
333 
334  return count(array_intersect($this->ilDBInterface->listTables(), $target)) == count($target);
335  }
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 121 of file class.ilDbSetup.php.

References $DIC, $GLOBALS, and $ilDBInterface.

Referenced by installDatabase(), and isConnectable().

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

◆ readDump()

ilDbSetup::readDump ( )
protected

legacy version of readdump

Deprecated:
use readDumpUltraSmall
Returns
bool

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

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

168  {
169  $fp = fopen($this->getSqlDumpFile(), 'r');
170  $q = '';
171  while (!feof($fp)) {
172  $line = trim($this->getline($fp, "\n"));
173 
174  if ($line != "" && substr($line, 0, 1) != "#" && substr($line, 0, 1) != "-") {
175  if (substr($line, -1) == ";") {
176  //query is complete
177  $q .= " " . substr($line, 0, -1);
178  try {
179  $r = $this->ilDBInterface->query($q);
180  } catch (ilDatabaseException $e) {
181  return false;
182  }
183 
184  unset($q);
185  unset($line);
186  } else {
187  $q .= " " . $line;
188  }
189  }
190  }
191 
192  fclose($fp);
193  }
Class ilDatabaseException.
Interface ilDBInterface.
$r
Definition: example_031.php:79
getline($fp, $delim)
query($query)
Run a (read-only) Query on the database.
+ Here is the call graph for this function:

◆ readDumpSmall()

ilDbSetup::readDumpSmall ( )
protected

legacy version of readdump

Deprecated:
use readDumpUltraSmall
Returns
bool

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

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

202  {
203  $sql = file_get_contents($this->getSqlDumpFile());
204  $lines = explode(';', $sql);
205  foreach ($lines as $line) {
206  if (strlen($line) > 0) {
207  $this->ilDBInterface->manipulate($line);
208  }
209  }
210 
211  return true;
212  }
Interface ilDBInterface.
manipulate($query)
Run a (write) Query on the database.
+ Here is the call graph for this function:

◆ readDumpUltraSmall()

ilDbSetup::readDumpUltraSmall ( )
protected
Returns
bool

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

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

Referenced by installDatabase().

219  {
220  $sql = file_get_contents($this->getSqlDumpFile());
221  $re = $this->ilDBInterface->prepareManip($sql);
222  $this->ilDBInterface->execute($re);
223 
224  return true;
225  }
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 135 of file class.ilDbSetup.php.

References $GLOBALS.

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

◆ setClient()

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

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

References $client.

363  {
364  $this->client = $client;
365  }

◆ setIlDBInterface()

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

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

References $ilDBInterface.

425  {
426  $this->ilDBInterface = $ilDBInterface;
427  }
Interface ilDBInterface.

◆ setSqlDumpFile()

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

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

References $sql_dump_file.

399  {
400  $this->sql_dump_file = $sql_dump_file;
401  }

◆ setStatus()

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

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

References $status.

381  {
382  $this->status = $status;
383  }

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: