public function database($args) { EStructure::view("header"); if (!isset($args[0])) { echo '<h3>Database</h3>'; echo '<p>If you just copied your ocs-server files to an other server, you would like to reconfigure database.<br> <a href="/admin/steps/step1">CONFIGURE DATABASE</a></p>'; echo '<p>If you have a broken/unconsistent database running, you can attempt resetting your database.<br> <a href="/admin/status/database/reset">RESET DATABASE</a></p>'; echo '<p>If you want to run sanity tests on your database you should install default data.<br> This is not reccomended on production and generally useful only for developers.<br> <a href="/admin/status/database/testdata">INSTALL TEST DATA</a></p>'; } if (isset($args[0])) { echo '<hr>'; if ($args[0] == 'reset') { echo '<h3>Database</h3>'; echo 'Resetting...Done!<br>'; echo 'Are you willing to execute tests? You better <a href="/admin/status/database/testdata">install default data</a>'; echo '<br><a href="/admin/status/database">Back to database panel</a>'; //using ocstest external library in /admin/libs OCSTest::reset_ocs_database(); } else { if ($args[0] == 'testdata') { echo '<p>adding test/password user..........'; $postdata = array("login" => "test", "password" => "password", "email" => "*****@*****.**", "firstname" => "cavolf", "lastname" => "chiappe"); $client = new OCSClient(EConfig::$data["ocs"]["host"]); $check = $client->post("v1/person/add", $postdata); $this->_statuscode_test($check, $client); echo '<a href="/admin/status/database">Back to database panel</a>'; } } } EStructure::view("footer"); }
public static function reset_ocs_database() { EDatabase::q("DROP TABLE IF EXISTS `ocs_apitraffic`;"); EDatabase::q("DROP TABLE IF EXISTS `ocs_comment`;"); EDatabase::q("DROP TABLE IF EXISTS `ocs_content`;"); EDatabase::q("DROP TABLE IF EXISTS `ocs_fan`;"); EDatabase::q("DROP TABLE IF EXISTS `ocs_person`;"); EDatabase::q("DROP TABLE IF EXISTS `ocs_activity`;"); EDatabase::q("DROP TABLE IF EXISTS `ocs_friendship`;"); EDatabase::q("DROP TABLE IF EXISTS `ocs_friendinvitation`;"); OCSTest::install_ocs_database(); }
public function step1($args) { $working = false; $name = EHeaderDataParser::post('name'); $host = EHeaderDataParser::post('host'); $user = EHeaderDataParser::post('user'); $pass = EHeaderDataParser::post('password'); $pass2 = EHeaderDataParser::post('password2'); $notification = ''; $database_path = ELoader::$prev_path . '/config/database.conf.php'; $cf = new EConfigFile(); $cf->set_abs_file($database_path); if (empty($name) and !empty($cf->get('name'))) { $name = $cf->get('name'); } if (empty($host) and !empty($cf->get('host'))) { $host = $cf->get('host'); } if (empty($user) and !empty($cf->get('user'))) { $user = $cf->get('user'); } if (empty($pass) and !empty($cf->get('password'))) { $pass = $pass2 = $cf->get('password'); } if (!empty($name) and !empty($user) and !empty($host) and !empty($pass) and !empty($pass2)) { if ($pass != $pass2) { $this->_error('Warning! Your passwords didn\'t match! Please reinsert them!'); } else { $cf->set('name', $name); $cf->set('user', $user); $cf->set('host', $host); $cf->set('password', $pass); EDatabase::set_db_info($name, $host, $user, $pass); EUtility::hide_output(); // hiding output as mysqli functions are surely outputting something if (!EDatabase::open_session()) { EUtility::show_output(); $notification = $this->_error('Couldn\'t open connection to database! Please check config!'); } else { OCSTest::install_ocs_database(); //execute soft install $out = EUtility::show_output(); if (!empty($out)) { $notification = $this->_error('Something went wrong with install phase! Please check config!'); } else { $notification = $this->_notify('We can connect to database! Database is installed and configuration saved!'); $working = true; $cf->save(); } } } } $data = array(); $data['name'] = $name; $data['user'] = $user; $data['host'] = $host; $data['pass'] = $pass; $data['pass2'] = $pass2; $data['working'] = $working; $data['notification'] = $notification; EStructure::view('wizard/step1', $data); }