You are here

class hostingService_db_mysql in Hosting 7.3

Same name and namespace in other branches
  1. 6.2 db_server/hosting_db_server.service.inc \hostingService_db_mysql
  2. 7.4 db_server/hosting_db_server.service.inc \hostingService_db_mysql

A MySQL specific db service implementation class.

Hierarchy

Expanded class hierarchy of hostingService_db_mysql

File

db_server/hosting_db_server.service.inc, line 17
Provide the hosting serivce classes for database integration.

View source
class hostingService_db_mysql extends hostingService_db {
  public $type = 'mysql';
  public $name = 'MySQL';
  public $has_port = TRUE;
  function default_port() {
    return 3306;
  }
  function form(&$form) {
    parent::form($form);
    $form['db_user'] = array(
      '#type' => 'textfield',
      '#required' => !empty($this->available),
      '#title' => t('Username'),
      '#description' => t('The user that will be used to create new mysql users and databases for new sites.'),
      '#size' => 40,
      '#default_value' => isset($this->db_user) ? $this->db_user : NULL,
      '#maxlength' => 64,
      '#weight' => 5,
    );
    $passwd_description = '';
    if (isset($this->db_passwd)) {
      $passwd_description = t('<strong>You have already set a password for this database server.</strong><br />');
    }
    $form['db_passwd'] = array(
      '#type' => 'password_confirm',
      '#required' => FALSE,
      '#description' => $passwd_description . t('The password for the user that will be used to create new mysql users and databases for new sites'),
      '#size' => 30,
      '#weight' => 10,
    );
  }
  function insert() {
    parent::insert();
    $id = db_insert('hosting_db_server')
      ->fields(array(
      'vid' => $this->server->vid,
      'nid' => $this->server->nid,
      'db_user' => $this->db_user,
      'db_passwd' => $this->db_passwd,
    ))
      ->execute();
  }
  function update() {
    if (!empty($this->db_passwd)) {
      parent::update();
    }
    else {

      // only do the parent's update routine.
      parent::delete_revision();
      parent::insert();
    }
  }
  function delete_revision() {
    parent::delete_revision();
    db_delete('hosting_db_server')
      ->condition('vid', $this->server->vid)
      ->execute();
  }
  function delete() {
    parent::delete();
    db_delete('hosting_db_server')
      ->condition('nid', $this->server->nid)
      ->execute();
  }
  function load() {
    parent::load();
    $this
      ->mergeData('SELECT db_user, db_passwd FROM {hosting_db_server} WHERE vid = :vid', array(
      ':vid' => $this->server->vid,
    ));
  }
  function view(&$render) {
    parent::view($render);
    $render['db_user'] = array(
      '#type' => 'item',
      '#title' => t('Database user'),
      '#markup' => filter_xss($this->db_user),
      '#weight' => 1,
    );
    if (empty($this->db_passwd)) {
      $markup = t('None');
    }
    else {
      $markup = t('Saved');
    }
    $render['db_passwd'] = array(
      '#type' => 'item',
      '#title' => t('Database password'),
      '#markup' => $markup,
      '#weight' => 2,
    );
  }
  public function context_options($task_type, $ref_type, &$task) {
    parent::context_options($task_type, $ref_type, $task);

    // Provide context_options for verification and writing out to an alias
    $task->context_options['master_db'] = 'mysql' . '://' . urlencode($this->db_user) . ':' . urlencode($this->db_passwd) . '@' . $this->server->title;
  }
  public function context_import($context) {
    parent::context_import($context);
    $matches = array();
    preg_match("+^mysql://(.*):(.*)@.*\$+", stripslashes($context->master_db), $matches);
    $this->db_user = urldecode($matches[1]);
    $this->db_passwd = urldecode($matches[2]);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
hostingService::$available public property
hostingService::$has_restart_cmd protected property 5
hostingService::$server public property
hostingService::$server_node public property
hostingService::default_restart_cmd public function 5
hostingService::getName public function Returns human readable name for this service.
hostingService::has_port public function 3
hostingService::has_restart_cmd public function 5
hostingService::mergeData protected function
hostingService::save public function
hostingService::setValues public function
hostingService::validate public function 2
hostingService::__construct function
hostingService_db::$service public property Overrides hostingService::$service
hostingService_db_mysql::$has_port public property Overrides hostingService::$has_port
hostingService_db_mysql::$name public property Overrides hostingService::$name
hostingService_db_mysql::$type public property Overrides hostingService::$type
hostingService_db_mysql::context_import public function Overrides hostingService::context_import
hostingService_db_mysql::context_options public function Overrides hostingService::context_options
hostingService_db_mysql::default_port function Overrides hostingService::default_port
hostingService_db_mysql::delete function Overrides hostingService::delete
hostingService_db_mysql::delete_revision function Overrides hostingService::delete_revision
hostingService_db_mysql::form function Overrides hostingService::form
hostingService_db_mysql::insert function Overrides hostingService::insert
hostingService_db_mysql::load function Overrides hostingService::load
hostingService_db_mysql::update function Overrides hostingService::update
hostingService_db_mysql::view function Overrides hostingService::view