ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 getNewInstanceForClient (\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, and ilClient\getDbType().

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

Member Function Documentation

◆ canDatabaseBeInstalled()

ilDbSetup::canDatabaseBeInstalled ( )
protected
Returns
bool

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

References isDatabaseConnectable(), and isDatabaseInstalled().

Referenced by installDatabase().

346  {
347  $connectable = $this->isDatabaseConnectable();
348  $installed = $this->isDatabaseInstalled();
349 
350  return ($connectable && !$installed);
351  }
+ 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 103 of file class.ilDbSetup.php.

References getClient(), 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.

104  {
105  if ($this->isConnectable()) {
106  switch ($this->ilDBInterface->getDBType()) {
113  $clientIniFile = $this->client->ini;
114 
115  if (!$this->ilDBInterface->createDatabase($clientIniFile->readVariable("db", "name"), 'utf8', $a_collation)) {
116  return false;
117  }
118  $this->ilDBInterface->initFromIniFile($this->getClient()->ini);
119 
120  return $this->ilDBInterface->connect();
121  break;
122  }
123  }
124 
125  return false;
126  }
isConnectable($keep_connection=false)
+ Here is the call graph for this function:

◆ dropTables()

ilDbSetup::dropTables ( )

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

References $table.

409  {
410  foreach ($this->ilDBInterface->listTables() as $table) {
411  $this->ilDBInterface->manipulate('DROP TABLE ' . $table);
412  }
413  }
if(empty($password)) $table
Definition: pwgen.php:24

◆ getClient()

ilDbSetup::getClient ( )
Returns
ilClient

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

References $client.

Referenced by createDatabase(), and installDatabase().

358  {
359  return $this->client;
360  }
+ Here is the caller graph for this function:

◆ getIlDBInterface()

ilDbSetup::getIlDBInterface ( )
Returns

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

References $ilDBInterface.

420  {
421  return $this->ilDBInterface;
422  }

◆ 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().

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:

◆ 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 80 of file class.ilDbSetup.php.

References $password, and $type.

81  {
82  require_once('./setup/classes/class.ilClient.php');
83  require_once('./Services/Init/classes/class.ilIniFile.php');
84  require_once('./setup/classes/class.ilDBConnections.php');
85 
86  $ilClient = new ilClient($client_name, new ilDBConnections());
87  $ilClient->init();
88  $ilClient->setDbHost($host);
89  $ilClient->setDbName($dbname);
90  $ilClient->setDbUser($username);
91  $ilClient->setDbPass($password);
92  $ilClient->setDbType($type);
93  $ilClient->writeIni();
94 
95  return self::getInstanceForClient($ilClient);
96  }
Administrates DB connections in setup.
$type
$password
Definition: cron.php:14
Client Management.

◆ getline()

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

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

References $result.

Referenced by readDump().

156  {
157  $result = "";
158  while (!feof($fp)) {
159  $tmp = fgetc($fp);
160  if ($tmp == $delim) {
161  return $result;
162  }
163  $result .= $tmp;
164  }
165 
166  return $result;
167  }
$result
+ Here is the caller graph for this function:

◆ getNewInstanceForClient()

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

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

References $client.

Referenced by ilClient\getDBSetup().

66  : \ilDbSetup
67  {
68  return new self($client);
69  }
Class ilDbSetup.
+ Here is the caller graph for this function:

◆ getSqlDumpFile()

ilDbSetup::getSqlDumpFile ( )
Returns
string

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

References $sql_dump_file.

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

394  {
395  return $this->sql_dump_file;
396  }
+ Here is the caller graph for this function:

◆ getStatus()

ilDbSetup::getStatus ( )
Returns
mixed

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

References $status.

376  {
377  return $this->status;
378  }

◆ installDatabase()

ilDbSetup::installDatabase ( )
Returns
bool

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

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

240  {
241  if ($this->canDatabaseBeInstalled()) {
242  $this->provideGlobalDB();
243  switch ($this->ilDBInterface->getDBType()) {
246  $this->ilDBInterface->connect();
247  //$this->dropTables();
248  //$this->readDump();
249  $this->readDumpUltraSmall();
250  $this->getClient()->db_installed = true;
251 
252  return true;
253 
254  break;
260  include_once("./setup/sql/ilDBTemplate.php");
261  setupILIASDatabase();
262 
263  return true;
264  break;
265  }
266  }
267 
268  return false;
269  }
+ Here is the call graph for this function:

◆ isConnectable()

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

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

References provideGlobalDB().

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

292  {
293  switch ($this->ilDBInterface->getDBType()) {
294  default:
295  try {
296  $connect = $this->ilDBInterface->connect();
297  } catch (PDOException $e) {
298  $connect = ($e->getCode() == 1049);
299  }
300  break;
301  }
302  if ($keep_connection && $connect) {
303  $this->provideGlobalDB();
304  }
305 
306  if (!$connect) {
307  $this->client->setError('Database can\'t be reached. Please check the credentials and if database exists');
308  }
309 
310  return $connect;
311  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isDatabaseConnectable()

ilDbSetup::isDatabaseConnectable ( )
Returns
bool

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

References isConnectable().

Referenced by canDatabaseBeInstalled(), and isDatabaseExisting().

318  {
319  if (!$this->isConnectable()) {
320  return false;
321  }
322 
323  return $this->ilDBInterface->connect(true);
324  }
isConnectable($keep_connection=false)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isDatabaseExisting()

ilDbSetup::isDatabaseExisting ( )
Returns
bool

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

References isConnectable(), and isDatabaseConnectable().

Referenced by isDatabaseInstalled().

276  {
277  if (!$this->isConnectable()) {
278  return false;
279  }
280  if (!$this->isDatabaseConnectable()) {
281  return false;
282  }
283 
284  return true;
285  }
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 330 of file class.ilDbSetup.php.

References $target, and isDatabaseExisting().

Referenced by canDatabaseBeInstalled().

331  {
332  if (!$this->isDatabaseExisting()) {
333  return false;
334  }
335 
336  $target = array( 'usr_data', 'object_data', 'object_reference' );
337 
338  return count(array_intersect($this->ilDBInterface->listTables(), $target)) == count($target);
339  }
$target
Definition: test.php:19
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ provideGlobalDB()

ilDbSetup::provideGlobalDB ( )

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

References $DIC, $GLOBALS, and $ilDBInterface.

Referenced by installDatabase(), and isConnectable().

130  {
131  global $DIC;
132 
133  if ($DIC->offsetExists('ilDB')) {
134  $DIC->offsetUnset('ilDB');
135  }
136 
137  $GLOBALS["ilDB"] = $this->ilDBInterface;
138  $DIC["ilDB"] = $this->ilDBInterface;
139  $this->client->db = $this->ilDBInterface; // TODO ugly and dirty, but ilClient requires it
140  }
global $DIC
Definition: saml.php:7
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
+ Here is the caller graph for this function:

◆ readDump()

ilDbSetup::readDump ( )
protected

legacy version of readdump

Deprecated:
use readDumpUltraSmall
Returns
bool

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

References $r, getline(), and getSqlDumpFile().

176  {
177  $fp = fopen($this->getSqlDumpFile(), 'r');
178  $q = '';
179  while (!feof($fp)) {
180  $line = trim($this->getline($fp, "\n"));
181 
182  if ($line != "" && substr($line, 0, 1) != "#" && substr($line, 0, 1) != "-") {
183  if (substr($line, -1) == ";") {
184  //query is complete
185  $q .= " " . substr($line, 0, -1);
186  try {
187  $r = $this->ilDBInterface->query($q);
188  } catch (ilDatabaseException $e) {
189  return false;
190  }
191 
192  unset($q);
193  unset($line);
194  } else {
195  $q .= " " . $line;
196  }
197  }
198  }
199 
200  fclose($fp);
201  }
Class ilDatabaseException.
$r
Definition: example_031.php:79
getline($fp, $delim)
+ Here is the call graph for this function:

◆ readDumpSmall()

ilDbSetup::readDumpSmall ( )
protected

legacy version of readdump

Deprecated:
use readDumpUltraSmall
Returns
bool

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

References getSqlDumpFile().

210  {
211  $sql = file_get_contents($this->getSqlDumpFile());
212  $lines = explode(';', $sql);
213  foreach ($lines as $line) {
214  if (strlen($line) > 0) {
215  $this->ilDBInterface->manipulate($line);
216  }
217  }
218 
219  return true;
220  }
+ Here is the call graph for this function:

◆ readDumpUltraSmall()

ilDbSetup::readDumpUltraSmall ( )
protected
Returns
bool

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

References getSqlDumpFile().

Referenced by installDatabase().

227  {
228  $sql = file_get_contents($this->getSqlDumpFile());
229  $re = $this->ilDBInterface->prepareManip($sql);
230  $this->ilDBInterface->execute($re);
231 
232  return true;
233  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ revokeGlobalDB()

ilDbSetup::revokeGlobalDB ( )

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

References $GLOBALS.

144  {
145  $GLOBALS["ilDB"] = null;
146  $this->client->db = null; // TODO ugly and dirty, but ilClient requires it
147  }
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.

◆ setClient()

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

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

References $client.

367  {
368  $this->client = $client;
369  }

◆ setIlDBInterface()

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

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

References $ilDBInterface.

429  {
430  $this->ilDBInterface = $ilDBInterface;
431  }

◆ setSqlDumpFile()

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

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

References $sql_dump_file.

403  {
404  $this->sql_dump_file = $sql_dump_file;
405  }

◆ setStatus()

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

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

References $status.

385  {
386  $this->status = $status;
387  }

Field Documentation

◆ $client

ilDbSetup::$client
protected

◆ $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: