/** * Check database settings * @return void */ public function checkDatabase() { $mode = $this->settings->get('installmode'); /* get an instance of xPDO using the install settings */ $xpdo = $this->install->getConnection($mode); if (!is_object($xpdo) || !$xpdo instanceof xPDO) { $this->end($this->install->lexicon('xpdo_err_ins')); } /* try to get a connection to the actual database */ $dbExists = $xpdo->connect(); if (!$dbExists) { if ($mode == modInstall::MODE_NEW && $xpdo->getManager()) { /* otherwise try to create the database */ $dbExists = $xpdo->manager->createSourceContainer(array('dbname' => $this->settings->get('dbase'), 'host' => $this->settings->get('database_server')), $this->settings->get('database_user'), $this->settings->get('database_password'), array('charset' => $this->settings->get('database_connection_charset'), 'collation' => $this->settings->get('database_collation'))); if (!$dbExists) { $this->end($this->install->lexicon('db_err_create_database')); } else { $xpdo = $this->install->getConnection($mode); if (!is_object($xpdo) || !$xpdo instanceof xPDO) { $this->end($this->install->lexicon('xpdo_err_ins')); } } } elseif ($mode == modInstall::MODE_NEW) { $this->end($this->install->lexicon('db_err_connect_server')); } } if (!$xpdo->connect()) { $this->end($this->install->lexicon('db_err_connect')); } /* test table prefix */ if ($mode == modInstall::MODE_NEW || $mode == modInstall::MODE_UPGRADE_REVO_ADVANCED) { $count = null; $database = $this->settings->get('dbase'); $prefix = $this->settings->get('table_prefix'); $stmt = $xpdo->query($this->install->driver->testTablePrefix($database, $prefix)); if ($stmt) { $row = $stmt->fetch(PDO::FETCH_ASSOC); if ($row) { $count = (int) $row['ct']; } $stmt->closeCursor(); } if ($mode == modInstall::MODE_NEW && $count !== null) { $this->end($this->install->lexicon('test_table_prefix_inuse')); } elseif ($mode == modInstall::MODE_UPGRADE_REVO_ADVANCED && $count === null) { $this->end($this->install->lexicon('test_table_prefix_nf')); } } }
/** * Check connection to database, as well as table prefix */ protected function _checkDatabase() { /* connect to the database */ $this->title('dbase_connection', $this->install->lexicon('test_db_check')); $xpdo = $this->install->getConnection(); if (!$xpdo || !$xpdo->connect()) { if ($this->mode > modInstall::MODE_NEW) { $this->fail($this->install->lexicon('dbase_connection'), $this->install->lexicon('test_db_failed'), $this->install->lexicon('test_db_check_conn')); } else { $this->warn($this->install->lexicon('dbase_connection'), $this->install->lexicon('test_db_failed'), $this->install->lexicon('test_db_setup_create')); } } else { $this->pass('dbase_connection'); } }