View Single Post
  #8  
Old 19th October 2010, 16:45
ppnl.com ppnl.com is offline
Junior Member
 
Join Date: Oct 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

To adapt ispconfig and use DOMAINNAME, DOMAINID, DOMAINNAMESHORT as prefix for database in order to allow moving databases between clients!

My prefix for database name and database user is:
[DOMAINNAMESHORT][DOMAINID]_

Here DOMAINNAMESHORT will be the first 5 characters of the domain name, and the DOMAINID will be added to make it unique, however not a full list of databases with ONLY numbers!

e.g. for domain.com the database prefix will be domai12_

And because it's based on DOMAIN it allows to move to another client.

INSTRUCTIONS (on own risk)

To support DOMAINID, DOMAINNAME and DOMAINNAMESHORT as prefix modfiy the file /usr/local/ispconfig/interface/web/sites/tools.inc.php and modify replacePrefix and add also a new function getDomainName :

Code:
function replacePrefix($name, $dataRecord) {
  // No input -> no possible output -> go out!
  if ($name=="") return "";
  
  // Array containing keys to search
  $keywordlist=array('CLIENTNAME','CLIENTID','DOMAINID','DOMAINNAME','DOMAINNAMESHORT');
  
  // Try to match the key within the string
  foreach ($keywordlist as $keyword) {
    if (substr_count($name, '['.$keyword.']') > 0) {
      switch ($keyword) {
        case 'CLIENTNAME':
          $name=str_replace('['.$keyword.']', getClientName($dataRecord),$name);
        break;
        case 'CLIENTID':
          $name=str_replace('['.$keyword.']', getClientID($dataRecord),$name);
        break;
        case 'DOMAINID':
          $name=str_replace('['.$keyword.']', $dataRecord['parent_domain_id'],$name);
        break;
        case 'DOMAINNAME':
          $name=str_replace('['.$keyword.']', getDomainName($dataRecord['parent_domain_id']),$name);
        break;
        case 'DOMAINNAMESHORT':
          $name=str_replace('['.$keyword.']', substr(getDomainName($dataRecord['parent_domain_id']),0,5),$name);
        break;
      }
    }
  }
  return $name;
}

function getDomainName($domain_id) {
  global $app;
  $tmp = $app->db->queryOneRecord("SELECT domain FROM web_domain WHERE domain_id = " . $domain_id);

  return $tmp['domain'];
}

To show the dropdown with domains in the database edit form, modify web/sites/templates/database_edit.htm and add between client_group_id and type around line 39:
(copied from ftp_user_edit.htm)

Code:
<div class="ctrlHolder">
    <label for="parent_domain_id">{tmpl_var name='parent_domain_id_txt'}</label>
    <select name="parent_domain_id" id="parent_domain_id" class="selectInput">
                                       {tmpl_var name='parent_domain_id'}
    </select>
  </div>
To define the domain dropdown in the form modify /usr/local/ispconfig/interface/web/sites/form/database.tform.php and add between server_id and type around line 72:
(copied from ftp_user.tform.php)
Code:
'parent_domain_id' => array (
                        'datatype'      => 'INTEGER',
                        'formtype'      => 'SELECT',
                        'default'       => '',
                        'datasource'    => array (      'type'  => 'SQL', 'querystring' => "SELECT domain_id,domain FROM web_domain WHERE type = 'vhost' AND {AUTHSQL} ORDER BY domain",'keyfield'=> 'domain_id','valuefield'=> 'domain'
                                                 ),
                        'value'         => ''
),
Add to the table web_database the field parent_domain_id after server_id with INT unsigned default 0.
Reply With Quote