abstractdatabase.php 1.4 KB

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