Domain Prefix tables, lightweight version

Public

This will duplicate defined tables for the current domain, and use them instead of the normal ones

</> CopyGet raw version
php
  1. /**
  2.  * Implements hook_domain_bootstrap_full().
  3.  */
  4. function mymodule_domain_bootstrap_full($domain) {
  5. global $databases;
  6.  
  7. // Define the prefix
  8. $prefix = 'domain_' . $domain['domain_id'] . '_';
  9.  
  10. // Define tables to (copy and) load dynamically, modify at you ease
  11. $tables = array('block', 'block_custom', 'menu_links', 'cache_menu');
  12.  
  13. foreach ($tables as $table) {
  14. $new_table = $prefix . $table;
  15. // If the table for the domain does not exists, duplicate the normal one
  16. if (!db_table_exists($new_table)) {
  17. // Copy structure
  18. db_query("CREATE TABLE $new_table LIKE $table");
  19. // Copy data
  20. db_query("INSERT $new_table SELECT * from $table"); // Comment this line if you don't want data to be copied
  21. }
  22. $databases['default']['default']['prefix'][$table] = $prefix;
  23. }
  24.  
  25. // This resets our current database connection with prefixes
  26. Database::closeConnection();
  27. Database::parseConnectionInfo();
  28. }
  29.  
  30. /**
  31.  * Implements hook_enable().
  32.  */
  33. function mymodule_blocks_enable() {
  34. domain_bootstrap_register();
  35. }