/[drupal]/contributions/modules/provisionator/provisionator_helper.inc
ViewVC logotype

Contents of /contributions/modules/provisionator/provisionator_helper.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download) (as text)
Thu Feb 8 03:28:37 2007 UTC (2 years, 9 months ago) by dnorman
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +1 -1 lines
File MIME type: text/x-php
removed stray legacy call to deleted function. fixed setting files_directory.
1 <?php
2 // custom functions
3
4
5 function copydir($original , $destination) {
6 $file=opendir($original);
7 if (file_exists($destination)){ return 0;}
8 if( !mkdir($destination, fileperms($original)) ) {
9 /* CAN'T CREATE THE DESTINATION directory! BORK APPROPRIATELY! */
10 watchdog('Provisionator', 'Unable to create directory while copying file: '.$destination);
11 }
12 $total = 0;
13 $l = array('.', '..');
14 while ($afile = readdir($file)) {
15 if (!in_array( $afile, $l)){
16 if (is_dir($original."/".$afile)){
17 $total += copydir("$original/$afile", "$destination/$afile");
18 } else {
19 copy("$original/$afile", "$destination/$afile");
20 $total++;
21 }
22 }
23 }
24 return $total;
25 }
26
27 // this method is added because PHP's native file_put_contents() isn't available on all systems.
28 // ideally, this method should test for the existence of file_put_contents() and if available, use that. If not, fall back on fopen()...
29 function compat_file_put_contents($n,$d) {
30 $f=@fopen($n,"w");
31 if (!$f) {
32 return false;
33 } else {
34 fwrite($f,$d);
35 fclose($f);
36 return true;
37 }
38 }
39
40 function provisionator_get_profiles() {
41 $ctr = 0;
42 $path = variable_get('provisionator_profilesdir','');
43
44 if ( $p_dir = @opendir($path) ) {
45 while ( false !== ($p_file = readdir($p_dir)) ) {
46 // add checks for other image file types here, if you like
47 if ( preg_match("/(\.sql)$/", $p_file) ) {
48 $profiles[$ctr] = $p_file;
49 $ctr++;
50 }
51 }
52 closedir($p_dir);
53 return $profiles;
54 } else {
55 return false;
56 }
57 }
58
59
60
61 function provisionator_deploy_site( $sitenode ) {
62 // settings. All of these values should be customizable via admin/settings/provisionator
63 $profilesdir = variable_get('provisionator_profilesdir','');
64 $mysqlbin = variable_get('provisionator_mysqlbin','');
65 $mysqlhost = variable_get('provisionator_mysqlhost','');
66 $mysqluser = variable_get('provisionator_mysqluser','');
67 $mysqlpass = variable_get('provisionator_mysqlpass','');
68 $drupal_site_template_dir = variable_get('provisionator_drupal_site_template_dir', '');
69 $drupal_site_dir_prefix = variable_get('provisionator_drupal_site_dir_prefix', '');
70 $drupal_installed_path = variable_get('provisionator_drupal_installed_path', '');
71 $manifest_filename = variable_get('provisionator_manifest_index_filename', '');
72
73
74 // settings pulled from the provisionatorsite node
75 $shortname = $sitenode->shortname;
76 $profilenumber = $sitenode->profile;
77 $profiles = provisionator_get_profiles();
78 $profile = $profiles[$profilenumber];
79
80
81 // settings pulled from the provisionatorclient node
82 // try to load the client node for the given clientid
83 $client = db_fetch_object(db_query("SELECT dbprefix, symlinkpath, domainprefix, apachetargetdir from {provisionatorclient} where nid = %d", $sitenode->client));
84 $dbprefix = $client->dbprefix;
85 $apache_target_dir = $client->apachetargetdir;
86
87
88 // settings derived from calculating/merging other settings
89 $dbname = $dbprefix.$shortname;
90 $sqlfile = $profilesdir.'/'.$profile;
91
92 // create the database
93 $result = db_query( 'create database '.$dbname );
94
95 // populate the database with the sql template file
96 exec($mysqlbin.' -h '.$mysqlhost.' -u '.$mysqluser.' -p'.$mysqlpass.' '.$dbname.' < '.$sqlfile);
97
98 // convert fullurl to cleaned dot-syntax format
99 $drupal_site_dir_name = str_replace('http://', '', $sitenode->fullurl);
100 $drupal_site_dir_name = str_replace('/', '.', $drupal_site_dir_name);
101
102 // copy the drupal site template directory
103 $drupal_site_dir = $drupal_installed_path.'/sites/'.$drupal_site_dir_name; //$drupal_site_dir_prefix.'.'.$shortname;
104 $filescopied = copydir( $drupal_site_template_dir, $drupal_site_dir);
105
106 // replace values in the new drupal site directory for this site
107 $settingsfilename = $drupal_site_dir.'/settings.php';
108
109 $settingsfilecontents = file_get_contents($settingsfilename);
110 $settingsfilecontents = str_replace('database_name_goes_here', $dbname, $settingsfilecontents);
111 $settingsfilecontents = str_replace('file_directory_path_goes_here', $drupal_site_dir_name, $settingsfilecontents);
112 $settingsfilecontents = str_replace('base_url_goes_here', $sitenode->fullurl, $settingsfilecontents);
113
114 $result = compat_file_put_contents($settingsfilename, $settingsfilecontents);
115
116 // link the sitename into the web document root
117 symlink( $drupal_installed_path, $apache_target_dir.'/'.$shortname);
118
119 //$output .= '<br />'.$sitenode->sitename . ' deployed. yay.';
120 $output .= '<p><a href="'.$sitenode->fullurl.'" target="_blank">'.$sitenode->title.'</a> deployed successfully.</p>';
121
122 watchdog('Provisionator', 'Site deployed: '.$shortname);
123
124
125 drupal_set_message( t( $output) );
126
127 return TRUE;
128 }
129
130
131
132 ?>

  ViewVC Help
Powered by ViewVC 1.1.2