-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommerce_downloads.install
253 lines (221 loc) · 8.12 KB
/
commerce_downloads.install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
<?php
/**
* @file
* Installation code for commerce_downloads.
*/
/**
* Implements hook_install_tasks().
*/
function commerce_downloads_install_tasks() {
// Increase maximum function nesting level to prevent install errors.
$max_nesting_level = ini_get('xdebug.max_nesting_level');
if ($max_nesting_level > 0 && $max_nesting_level <= '200') {
ini_set('xdebug.max_nesting_level', 200);
}
// Remove any status messages that might have been set. They are unneeded.
drupal_get_messages('status', TRUE);
$tasks = array();
// $tasks['fakedin_import_content'] = array(
// 'display_name' => st('Import content'),
// 'type' => 'batch',
// 'display' => TRUE,
// );
$tasks['commerce_downloads_install_theme'] = array(
'display_name' => st('Install Theme Settings'),
'type' => 'normal',
'display' => TRUE,
);
return $tasks;
}
/**
* Implements hook_install_tasks_alter().
*/
function commerce_downloads_install_tasks_alter(&$tasks, $install_state) {
$tasks['install_finished']['function'] = 'commerce_downloads_install_finished';
$tasks['install_select_profile']['display'] = FALSE;
}
/**
* Theme install task
*/
function commerce_downloads_install_theme() {
// Enable the admin theme.
$admin_theme = 'shiny';
$theme = 'bootstrap';
theme_enable(array($admin_theme, $theme));
variable_set('admin_theme', $admin_theme);
variable_set('node_admin_theme', '1');
// Enable the front-end theme.
variable_set('theme_default', $theme);
// JQuery Update Settings
variable_set('jquery_update_jquery_version', '1.8');
variable_set('jquery_update_jquery_admin_version', '1.7');
}
/**
* Implements hook_install().
*/
function commerce_downloads_install() {
// Add text formats.
$filtered_html_format = array(
'format' => 'filtered_html',
'name' => 'Filtered HTML',
'weight' => 0,
'filters' => array(
// URL filter.
'filter_url' => array(
'weight' => 0,
'status' => 1,
),
// HTML filter.
'filter_html' => array(
'weight' => 1,
'status' => 1,
),
// Line break filter.
'filter_autop' => array(
'weight' => 2,
'status' => 1,
),
// HTML corrector filter.
'filter_htmlcorrector' => array(
'weight' => 10,
'status' => 1,
),
),
);
$filtered_html_format = (object) $filtered_html_format;
filter_format_save($filtered_html_format);
$full_html_format = array(
'format' => 'full_html',
'name' => 'Full HTML',
'weight' => 1,
'filters' => array(
// URL filter.
'filter_url' => array(
'weight' => 0,
'status' => 1,
),
// Line break filter.
'filter_autop' => array(
'weight' => 1,
'status' => 1,
),
// HTML corrector filter.
'filter_htmlcorrector' => array(
'weight' => 10,
'status' => 1,
),
),
);
$full_html_format = (object) $full_html_format;
filter_format_save($full_html_format);
// Insert default pre-defined node types into the database.
$types = array(
array(
'type' => 'page',
'name' => st('Basic page'),
'base' => 'node_content',
'description' => st("Use <em>basic pages</em> for your static content, such as an 'About us' page."),
'custom' => 1,
'modified' => 1,
'locked' => 0,
),
);
foreach ($types as $type) {
$type = node_type_set_defaults($type);
node_type_save($type);
node_add_body_field($type);
}
// "Basic page" configuration.
variable_set('node_options_page', array('status'));
variable_set('comment_page', COMMENT_NODE_HIDDEN);
variable_set('node_submitted_page', FALSE);
variable_set('pathauto_node_page_pattern', '[node:title]');
// Enable default permissions for system roles.
$filtered_html_permission = filter_permission_name($filtered_html_format);
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access content', 'access comments', 'access checkout', 'view own commerce_order entities', 'view any commerce_product entity', $filtered_html_permission));
user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array('access content', 'access comments', 'access checkout', 'view own commerce_order entities', 'view any commerce_product entity', 'post comments', 'skip comment approval', $filtered_html_permission));
// Create a default role for site administrators, with all available permissions assigned.
$admin_role = new stdClass();
$admin_role->name = 'administrator';
$admin_role->weight = 10;
user_role_save($admin_role);
user_role_grant_permissions($admin_role->rid, array_keys(module_invoke_all('permission')));
// Set this as the administrator role.
variable_set('user_admin_role', $admin_role->rid);
// Assign user 1 the "administrator" role.
db_insert('users_roles')
->fields(array('uid' => 1, 'rid' => $admin_role->rid))
->execute();
// Create a default commerce_downloads role for subscribers.
$admin_role = new stdClass();
$admin_role->name = 'commerce_downloads';
$admin_role->weight = 2;
user_role_save($admin_role);
// Disable Views' Advanced Help module nag message until it's production ready.
variable_set('views_hide_help_message', TRUE);
// If Admin Menu is installed, collapse the module fieldsets.
variable_set('admin_menu_tweak_modules', TRUE);
// Configure Mimemail.
variable_set('mimemail_format', 'full_html');
// Add a shortcut set for store administration.
$set = new stdClass;
$set->title = st('Store administration');
$set->links = array(
array('link_path' => 'admin/commerce/products/add', 'link_title' => st('Add product')),
array('link_path' => 'admin/commerce/products', 'link_title' => st('View products')),
array('link_path' => 'admin/commerce/orders', 'link_title' => st('View orders')),
array('link_path' => 'admin/commerce/config', 'link_title' => st('Configure store')),
);
shortcut_set_save($set);
// Apply the shortcut set to the first user.
shortcut_set_assign_user($set, (object) array('uid' => 1));
// Update the menu router information.
menu_rebuild();
}
/**
* Custom installation task; perform final steps and redirect the user to the new site if there are no errors.
*
* @param $install_state
* An array of information about the current installation state.
*
* @return
* A message informing the user about errors if there was some.
*/
function commerce_downloads_install_finished(&$install_state) {
drupal_set_title(st('@drupal installation complete', array('@drupal' => drupal_install_profile_distribution_name())), PASS_THROUGH);
$messages = drupal_set_message();
// Remember the profile which was used.
variable_set('install_profile', drupal_get_profile());
variable_set('install_task', 'done');
// Flush all caches to ensure that any full bootstraps during the installer
// do not leave stale cached data, and that any content types or other items
// registered by the install profile are registered correctly.
drupal_flush_all_caches();
// Install profiles are always loaded last
db_update('system')
->fields(array('weight' => 1000))
->condition('type', 'module')
->condition('name', drupal_get_profile())
->execute();
// Cache a fully-built schema.
drupal_get_schema(NULL, TRUE);
// Run cron to populate update status tables (if available) so that users
// will be warned if they've installed an out of date Drupal version.
drupal_cron_run();
if (isset($messages['error'])) {
$output = '<p>' . (isset($messages['error']) ? st('Review the messages above before visiting <a href="@url">your new site</a>.', array('@url' => url(''))) : st('<a href="@url">Visit your new site</a>.', array('@url' => url('')))) . '</p>';
return $output;
}
else {
// Since any module can add a drupal_set_message, this can bug the user
// when we redirect him to the front page. For a better user experience,
// remove all the message that are only "notifications" message.
drupal_get_messages('status', TRUE);
drupal_get_messages('completed', TRUE);
// If we don't install drupal using Drush, redirect the user to the front
// page.
if (!drupal_is_cli()) {
drupal_goto('<front>');
}
}
}