abstractdatabase.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace OC\Setup;
  3. abstract class AbstractDatabase {
  4. /**
  5. * @var \OC_L10N
  6. */
  7. protected $trans;
  8. protected $dbDefinitionFile;
  9. protected $dbuser;
  10. protected $dbpassword;
  11. protected $dbname;
  12. protected $dbhost;
  13. protected $tableprefix;
  14. public function __construct($trans, $dbDefinitionFile) {
  15. $this->trans = $trans;
  16. $this->dbDefinitionFile = $dbDefinitionFile;
  17. }
  18. public function validate($config) {
  19. $errors = array();
  20. if(empty($config['dbuser'])) {
  21. $errors[] = $this->trans->t("%s enter the database username.", array($this->dbprettyname));
  22. }
  23. if(empty($config['dbname'])) {
  24. $errors[] = $this->trans->t("%s enter the database name.", array($this->dbprettyname));
  25. }
  26. if(substr_count($config['dbname'], '.') >= 1) {
  27. $errors[] = $this->trans->t("%s you may not use dots in the database name", array($this->dbprettyname));
  28. }
  29. return $errors;
  30. }
  31. public function initialize($config) {
  32. $dbuser = $config['dbuser'];
  33. $dbpass = $config['dbpass'];
  34. $dbname = $config['dbname'];
  35. $dbhost = !empty($config['dbhost']) ? $config['dbhost'] : 'localhost';
  36. $dbtableprefix = isset($config['dbtableprefix']) ? $config['dbtableprefix'] : 'oc_';
  37. \OC_Config::setValue('dbname', $dbname);
  38. \OC_Config::setValue('dbhost', $dbhost);
  39. \OC_Config::setValue('dbtableprefix', $dbtableprefix);
  40. $this->dbuser = $dbuser;
  41. $this->dbpassword = $dbpass;
  42. $this->dbname = $dbname;
  43. $this->dbhost = $dbhost;
  44. $this->tableprefix = $dbtableprefix;
  45. }
  46. }