Multi-leveled multi-site on Drupal 7 - drupal

is there an opportunity to make multi-leveled (by hierarchy) multi-site support within drupal's native multi-site solution?
Here's the example:
--example.com
----yyy.example.com (blocks&content shared between it's parent and the same level domains)
------xxx.yyy.example.com (blocks&content shared between it's parent and the same level domains)
----zzz.example.com
----aaa.example.com
------bbb.aaa.example.com and so on...
thanks.

You have to do each multi site one-by-one, and you have to set different database prefixes for each multi-site (you can change that in sites/{multisite_name}/settings.php). So build your multi-sites like this:
1) Build example.com
2) Build example.com/yyy multi-site site. (with prefix 'prefix_xxx_')
3) Build example.com/xxxyyy multi site site. (with prefix 'prefix_xxxyyy_')
and so on...
After ask your web hosting service admin to redirect:
1) example.com/yyy to yyy.example.com
2) example.com/xxxyyy to xxx.yyy.example.com
and so on...
The shared database tables you should specify manually one-by-one at the sites/{multisite_name}/settings.php file like this:
$db_prefix = array(
'default' => 'prefix_xxx_',
'users' => 'prefix_xxxyyy_',
'sessions' => 'prefix_xxxyyy_',
'role' => 'prefix_xxxyyy_',
'authmap' => 'prefix_xxxyyy_',
'sequences' => 'prefix_xxxyyy_',
);

Related

Best technique for creating sample content on Drupal 9 programatically within module

I have created a drupal 9 custom module with new content types and fields. I would like to create a sample node when the module is installed.
What is considered the best method for creating a sample node programatically?
I looked at using migrate and migrate_tools and building YAML files. This is promising but have issues with current versions of drush 10.6 and migrate 5. It looks like there is a fix in dev, but I wondered what everyone else does. My preference is to not depend on a module, unless there are compelling reasons (like easy maintenance of test cases or sample data)
thanks
You have to use a hook:
When you install the module, use this hook hook_install
When you update the module, use this hook hook_update_N
In the hook, you have to implements the correct logic:
$node = Node::create([
'type' => 'article',
'title' => 'Druplicon test',
'field_image' => [
'target_id' => $file->id(),
'alt' => 'Hello world',
'title' => 'Goodbye world'
],
]);
$node->save();

Integrate Smarty Site with Drupal site

I am currently working on a site which is on smarty based.The name of the site is http://example.com
I built a new folder in the root path and installed droupon (which is a component of drupal for buying or creating any deal) on the folder.The site url is http://example.com/coupon
Now I want to integrate or merge this two sites.So that when a registered user access example.com then he can access the example.com/coupon with his session user id.
But this is the problem.
Is this really possible to pass data from smarty based site (example.com) to drupal site example.com/coupon ?
Please help me.
I would write at module in Drupal that looks at $_SESSION and creates and/or login the user at the Drupal-site. Perhaps the rules module can do that work, but you will probably need to implement a rules-hook to grab the relevant session data as input to the rules component.
Here are a few lines of code that do some of the work but you need to implement hook_menu aswell to register an entrypoint for the integration.
//register user
$passwd = user_password();
$edit = array(
'name' => $_SESSION['username'],
'pass' => $passwd,
'mail' => $_SESSION['email'],
'init' => $_SESSION['email'],
'status' => 1,
'access' => REQUEST_TIME,
);
$uu = drupal_anonymous_user();
$u = user_save($uu, $edit);
//Login
global $user;
$user = user_load($u->uid);
$login_array = array ('name' => $username);
user_login_finalize($login_array);
However, Im not sure this is the best way to go about it. Sharing data in the same session-namespace between 2 different applications will probably lead to errors on both sides. Is it not better to implement the whole site in Drupal from the beginning?

Different lighttpd rewrite rules in subirectory

I'm having a few issues getting rewrite rules for a specific subdirectroy (different from the webroot) and I'm at a loss as to where to put them.
/var/www/ (webroot containing WordPress)
/var/www/subdirectory (containing other app which requires it's own rewrite rules)
The below rules I for WordPress which is in the webroot dir (/var/www, or http://mywebsite.com):
$HTTP["host"] =~ "mywebsite.com" {
url.rewrite-final = (
# Exclude some directories from rewriting
"^/(wp-admin|wp-includes|wp-content|gallery2)/(.*)" => "$0",
# Exclude .php files at root from rewriting
"^/(.*.php)" => "$0",
# Handle permalinks and feeds
"^/(.*)$" => "/index.php/$1"
)
}
Then I have a second app that sits in a subdirectory of the webroot (/var/www/subdirectory, or http://mywebsite.com/subdirectory) with the following rules:
url.rewrite = (
"(index.php|test.php|favicon.ico)" => "/$1",
"(css|files|img|js)/(.*)" => "/$1/$2",
"^([^\?]*)(\?(.+))?$" => "/index.php?url=$1&$3",
)
What I need is for the 1st set of rewrite rules above applied to everything except the other directories in the #Excluded rule above (as well as /subdirectory) then the 2nd set of rules applied to only /subdirectory
I got the first set of rules for WordPress from a blog somewhere online any may well be not exactly what I need (in regards to matching "mywebsite.com" and could probably be simplified).
I've Googled myself out trying multiple variations (mostly just stabbing in the dark guided by random forum posts that are slightly related), but I just can't wrap my head round it.
So how would I go about having the 2nd set of rules applied to the subdirectory while maintaining the Wordpress rules for the root?
Note: I have no access to subdomains (that would be too easy).
I am not quite sure what you want to express - I will explain what your current ruleset does.
do not use this, user rewrite-once instead
url.rewrite = (
you keep map any index.php and test.php (even foo-test.php) back to the webroot
"(index.php|test.php|favicon.ico)" => "/$1",
you rewrite any subfolder or files containing css,files,tmp or js in it's url back to the webroot
"(css|files|img|js)/(.*)" => "/$1/$2",
now this matches anything in the your webroot (no subdirs!) and keeps get requests
"^([^\?]*)(\?(.+))?$" => "/index.php?url=$1&$3",
)
Update
This should do it (untested)
url.rewrite-once = (
"^/subdir/(?:index.php|test.php|favicon.ico)" => "$0",
"^/subdir/(?:.+/)?(css|files|img|js)/(.*)" => "/subdir/$1/$2", #update #2
"^/subdir/(?:/(?:.+/))?([^\?]*)(?:\?(.+))?$" => "/subdir/index.php?url=$1&$2",
"^/(wp-admin|wp-includes|wp-content|gallery2)/(.*)" => "$0",
"^/(.*.php)" => "$0",
"^/(.*)$" => "/index.php/$1"
)

Drupal sharing content between two websites

I am farmiar with building drupal sites but not sure what the best way to implement this scenario. I have two domain names mydomain.com and mydomain2.com. I need to have a conten type with some fields in. i.e.
ContentType
Field - Title
Field - Body
Field - Picture
Field - Price
I want both sites to use the same data for the custom conten type. So you enter the data on one site and it will be updated on both.
mydomain.com will show the follwoing infromation from the content type.
ContentType
Field - Title
Field - Body
Field - Picture
mydomain2.com will show all the data.
mydomain.com and mydomain2.com will have diffent look nd feel. And each domain may use some diffent modules. mydomain2.com will be using ubercart and mydomain.com will not.
Would I use mutlisite here and somehow sharte the tables. Use one instance of drupal and do the rest with theming? Use features and context?
Any help would be apreciated.
After doing some research this may be what I need http://drupal.org/project/domain. A case study can be found at http://drupal.org/node/369398.
Still wondering if there are otherways so not acepting this as the answer yet.
You just need to share tables between the sites.
You can share specific tables (best done in logicaly groups) accross Drupal 7 installs by adding something like this to your settings.php file:
$my_db_users = 'drupal_users.shared_';
$my_db_content = 'drupal_content.shared_';
$databases['default']['default'] = array(
'driver' => 'mysql',
'database' => 'defaultdatabase',
'username' => 'databaseuser',
'password' => 'databasepassword',
'host' => '127.0.0.1',
'port' => 3066,
'prefix' => array(
'default' => 'default_',
'users' => $my_db_users,
'sessions' => $my_db_users,
'role' => $my_db_users,
'authmap' => $my_db_users,
'node' => $my_db_content,
'node_revisions' => $my_db_content,
'node_type' => $my_db_content,
),
'collation' => 'utf8_general_ci',
);
In the above instance, we set variables that point to different databases for certain groups of tables. So in the above example, we need three databases: defaultdatabase, drupal_users, and drupal_content.
Then in the array, we set the default table prefix 'default' => 'default_', and that says: "store all tables, unless otherwise specified, in defaultdatabase and make their table prefix default_." We're also saying: "store all users, sessions, roles, and user-role mappings (authmap) in the database drupal_users with the table prefix shared_." And lastly, we're saying: "store all node types, nodes, and their revisions in the database drupal_content with the table prefix shared_."
With great power comes great responsibility:
You will completely hose your install if you don't keep logical groups of tables together.
What are logical groups of tables? Well, probably any table with the prefix node_ in your current install should probably be moved to the shared database. Most well structured modules (say node_access) will have their table name's prefixed with something logical. Based on your modules, ensure you keep groups of tables in the right place (in the default database for site-specific data, or in another database for shared data.)
Add a little bling:
I did a similar install where the users and roles were shared, but NOT the authmap. To what end?
Well, if you do this, you could have the same users and groups accross a large network of sites while still allowing users different permissions on different sites. On one site you may be an editor, but on another you'd be an author.
The Domain module looks good (although I haven't used it). It may be overkill for your needs.
If you want something very simple you can create a module which sets the global $custom_theme in hook_init() depending on the domain.
For me, if this was a critical portion of the site, I would create a custom module. There are a few guides out there to create node_types through modules. I happen to like this one.
That way, you have a basic structure of your data in a custom table and then can customize the call for displaying the data to either include the price column or not.
Again, some may see this as too much work but if you aren't familiar with Drupal module development, this is a great way to learn. If you are familiar, it should be quick and simple.

Drupal PHP pages without having a DB Query?

I'm working on a site where there will be several admin pages that have intense logic in them. Let's take an example. I want a page that lists certain nodes and allows you to add or remove them, or do other actions on them.
Now, I can create a normal page in Drupal and select the input filter as "php code" and then just add the following line:
<?php executeTheCodeThatDoesEverythingForThisPage(); ?>
And I can put this method in a module.
However, this is not ideal, as a DB call is still made to find out what method must be called. I want to:
Entirely skip the DB call
Have a folder, e.g. pages, that stores all my custom pages, e.g. aboutus.php, mystuff.php
Still have access to all the drupal functions in this file
Anybody know how I can do this?
<<-- EDITED -->>
If I can't skip the DB query, can someone tell me the best way to include data from a static php file? Is there a module for this, or should I just add the following code:
include_once "myFile.php";
To include files, you need to look at the menu system, in particular page callbacks:
http://drupal.org/node/146172
Supposing that the myFile.php file is copied in the directory containing the module itself, you could use code similar to the following one.
function mymodule_menu() {
$items['mymodule_path'] = array(
'page callback' => 'mymodule_path_output',
'access arguments' => array('access content'),
);
return $items;
}
function mymodule_path_output() {
module_load_include('php', 'mymodule', 'myFile');
// …
}
The implementation of hook_menu() I used is minimal; see the documentation for more information about the hook.

Resources