forked from commerceguys/commerce_kickstart
-
Notifications
You must be signed in to change notification settings - Fork 1
/
commerce_kickstart.install
1276 lines (1163 loc) · 42.7 KB
/
commerce_kickstart.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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* @file
* Installation code for Commerce Kickstart.
*/
/**
* Implements hook_install_tasks().
*/
function commerce_kickstart_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();
$current_task = variable_get('install_task', 'done');
$install_demo_store = variable_get('commerce_kickstart_demo_store', FALSE);
$tasks['commerce_kickstart_configure_store_form'] = array(
'display_name' => st('Configure store'),
'type' => 'form',
);
$tasks['commerce_kickstart_install_additional_modules'] = array(
'display_name' => $install_demo_store ? st('Install demo store') : st('Install additional functionality'),
'type' => 'batch',
// Show this task only after the Kickstart steps have bene reached.
'display' => strpos($current_task, 'commerce_kickstart_') !== FALSE,
'dfp_settings' => array(
'dfp_unit' => 'Kickstart_Install_2',
),
);
$tasks['commerce_kickstart_import_content'] = array(
'display_name' => st('Import content'),
'type' => 'batch',
// Show this task only after the Kickstart steps have bene reached.
'display' => strpos($current_task, 'commerce_kickstart_') !== FALSE,
'dfp_settings' => array(
'dfp_unit' => 'Kickstart_Install_3',
),
);
return $tasks;
}
/**
* Implements hook_install_tasks_alter().
*/
function commerce_kickstart_install_tasks_alter(&$tasks, $install_state) {
$tasks['install_finished']['function'] = 'commerce_kickstart_install_finished';
$tasks['install_select_profile']['display'] = FALSE;
$tasks['install_select_locale']['display'] = FALSE;
$tasks['install_select_locale']['run'] = INSTALL_TASK_SKIP;
$tasks['install_profile_modules']['display_name'] = st('Install Commerce Kickstart 2');
// The "Welcome" screen needs to come after the first two steps
// (profile and language selection), despite the fact that they are disabled.
$new_task['install_welcome'] = array(
'display' => TRUE,
'display_name' => st('Welcome'),
'type' => 'form',
'run' => isset($install_state['parameters']['welcome']) ? INSTALL_TASK_SKIP : INSTALL_TASK_RUN_IF_REACHED,
);
$old_tasks = $tasks;
$tasks = array_slice($old_tasks, 0, 2) + $new_task + array_slice($old_tasks, 2);
// Set the installation theme.
_commerce_kickstart_set_theme('commerce_kickstart_admin');
// Add the DFP javascript if needed.
if (!empty($install_state['parameters']['use_dfp'])) {
// Test if the current task is a batch task.
if (isset($tasks[$install_state['active_task']]['type']) && $tasks[$install_state['active_task']]['type'] == 'batch') {
if (!isset($tasks[$install_state['active_task']]['dfp_settings'])) {
$tasks[$install_state['active_task']]['dfp_settings'] = array();
}
// Default to Kickstart_Install dfp unit.
$tasks[$install_state['active_task']]['dfp_settings'] += array(
'dfp_unit' => 'Kickstart_Install',
);
drupal_add_js(array(
'dfp' => $tasks[$install_state['active_task']]['dfp_settings'],
), 'setting');
$prefix = (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') ? 'https://' : 'http://';
drupal_add_js($prefix . 'www.googletagservices.com/tag/js/gpt.js');
drupal_add_js(drupal_get_path('profile', 'commerce_kickstart') . '/js/commerce_kickstart.js');
}
}
}
/**
* Force-set a theme at any point during the execution of the request.
*
* Drupal doesn't give us the option to set the theme during the installation
* process and forces enable the maintenance theme too early in the request
* for us to modify it in a clean way.
*/
function _commerce_kickstart_set_theme($target_theme) {
if ($GLOBALS['theme'] != $target_theme) {
unset($GLOBALS['theme']);
drupal_static_reset();
$GLOBALS['conf']['maintenance_theme'] = $target_theme;
_drupal_maintenance_theme();
}
}
/**
* Task callback: shows the welcome screen.
*/
function install_welcome($form, &$form_state, &$install_state) {
drupal_set_title(st('Welcome to Commerce Kickstart 2'));
$message = '<p>' . st('Thank you for choosing Commerce Kickstart, a product offered by Commerce Guys.') . '</p>';
$eula = '<p>' . st('While we have a rather long, boring Privacy Policy just like any other technology company, here is a short summary of some key items we feel are important:') . '</p>';
$items = array();
$dfp_link = l("Google's DoubleClick for Publishers (\"DFP\")", "http://www.google.com/dfp/info/sb/index.html", array('attributes' => array('target' => '_blank')));
$items[] = st("Commerce Kickstart makes use of !dfp;", array('!dfp' => $dfp_link));
$items[] = st('We use DFP to show you content relevant to Drupal Commerce at various points and places in Commerce Kickstart, including during installation;');
$items[] = st('DFP is a third-party technology. It uses audience management tags which collect and use certain data;');
$items[] = st('Commerce Guys does not collect any personally identifiable information;');
$items[] = st('If at any time after installation you do not want us to utilize DFP through Commerce Kickstart, you can easily opt out of it;');
$eula .= theme('item_list', array('items' => $items));
$eula_link = l('Privacy Policy and User Agreement', 'https://marketplace.commerceguys.com/privacy/commerce-kickstart', array('attributes' => array('target' => '_blank')));
$eula .= '<p>' . st('That is it for the main points. The full !policy can be viewed on our website. Thank you again for choosing Commerce Kickstart!', array('!policy' => $eula_link)) . '</p>';
$form = array();
$form['welcome_message'] = array(
'#markup' => $message,
);
$form['eula'] = array(
'#prefix' => '<div id="eula-installation-welcome">',
'#markup' => $eula,
);
$form['eula-accept'] = array(
'#title' => st('Privacy Policy and User Agreement'),
'#title_display' => 'invisible',
'#type' => 'radios',
'#default_value' => 1,
'#options' => array(
1 => st('I agree to the Privacy Policy and User Agreement'),
0 => st('I want to opt out and disable content from Commerce Guys'),
),
'#suffix' => '</div>',
);
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => st("Let's Get Started!"),
'#weight' => 10,
);
return $form;
}
function install_welcome_submit($form, &$form_state) {
global $install_state;
$install_state['parameters']['welcome'] = 'done';
$install_state['parameters']['locale'] = 'en';
$install_state['parameters']['use_dfp'] = $form_state['values']['eula-accept'];
}
/**
* Task callback: returns the form allowing the user to add example store content on install.
*/
function commerce_kickstart_configure_store_form() {
include_once DRUPAL_ROOT . '/includes/iso.inc';
drupal_set_title(st('Configure store'));
$form['country'] = array(
'#type' => 'fieldset',
'#title' => st('Country'),
);
$form['country']['country_list'] = array(
'#title' => t('Default store country'),
'#description' => t('Services specific to the selected country will be installed if they exist.'),
'#options' => _country_get_predefined_list(),
'#type' => 'select',
'#default_value' => variable_get('site_default_country'),
// This field is not required when installing through drush.
'#required' => !drupal_is_cli(),
);
// Prepare all the options for sample content.
$options = array(
'1' => st('Yes'),
'0' => st('No'),
);
$form['functionality'] = array(
'#type' => 'fieldset',
'#title' => st('Functionality'),
);
$form['functionality']['install_demo_store'] = array(
'#type' => 'radios',
'#title' => st('Do you want to install the demo store?'),
'#description' => st('Shows you everything Commerce Kickstart can do. Includes a custom theme, sample content and products.'),
'#options' => $options,
'#default_value' => '1',
);
$form['functionality']['notice'] = array(
'#type' => 'item',
'#markup' => '<p>' . t('<strong>Important</strong>: Once installed, products type cannot be deleted. Not recommended for development.') . '</p>',
'#attributes' => array(
'style' => 'clear: both;',
),
'#states' => array(
'visible' => array(
':input[name="install_demo_store"]' => array('value' => '1'),
),
),
);
$form['localization'] = array(
'#type' => 'fieldset',
'#title' => st('Localization'),
);
$form['localization']['install_localization'] = array(
'#type' => 'radios',
'#title' => st('Do you want to be able to translate the interface of your store?'),
'#options' => $options,
'#default_value' => '0',
);
$options_selection = array(
'anonymous_checkout' => 'Allow checkout for <strong>anonymous users</strong>.',
'merchandising' => 'Additional <strong>blocks</strong> for featuring specific content.',
'slideshow' => 'Frontpage <strong>slideshow</strong>.',
'menus' => 'Custom <strong>admin menu</strong> designed for store owners.',
'blog' => '<strong>Blog</strong> functionality.',
'social' => '<strong>Social</strong> logins and links for sharing products via social networks.',
'zoom_cloud' => '<strong>Zoom & Gallery</strong> mode for products.',
);
$form['functionality']['extras'] = array(
'#type' => 'checkboxes',
'#options' => $options_selection,
'#title' => t("Install additional functionality"),
'#states' => array(
'visible' => array(
':input[name="install_demo_store"]' => array('value' => '0'),
),
),
);
// Build a currency options list from all defined currencies.
$options = array();
foreach (commerce_currencies(FALSE, TRUE) as $currency_code => $currency) {
$options[$currency_code] = t('@code - !name', array(
'@code' => $currency['code'],
'@symbol' => $currency['symbol'],
'!name' => $currency['name']
));
if (!empty($currency['symbol'])) {
$options[$currency_code] .= ' - ' . check_plain($currency['symbol']);
}
}
$form['commerce_default_currency_wrapper'] = array(
'#type' => 'fieldset',
'#title' => st('Currency'),
);
$form['commerce_default_currency_wrapper']['commerce_default_currency'] = array(
'#type' => 'select',
'#title' => t('Default store currency'),
'#options' => $options,
'#default_value' => commerce_default_currency(),
);
// Prepare all the options for sample content.
$options = array(
'none' => st("No sample tax rate."),
'us' => st('US - Sales taxes displayed in checkout'),
'europe' => st('European - Inclusive tax rates (VAT)'),
);
$form['commerce_kickstart_tax_wrapper'] = array(
'#type' => 'fieldset',
'#title' => st('Tax Rate'),
);
$form['commerce_kickstart_tax_wrapper']['commerce_kickstart_choose_tax_country'] = array(
'#type' => 'radios',
'#title' => st('Tax rate examples'),
'#description' => st('Example tax rates will be created in this style.'),
'#options' => $options,
'#default_value' => key($options),
);
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => st('Create and Finish'),
'#weight' => 15,
);
return $form;
}
/**
* Submit callback: creates the requested sample content.
*/
function commerce_kickstart_configure_store_form_submit(&$form, &$form_state) {
variable_set('commerce_kickstart_store_country', $form_state['values']['country_list']);
variable_set('commerce_kickstart_demo_store', $form_state['values']['install_demo_store']);
variable_set('commerce_kickstart_localization', $form_state['values']['install_localization']);
variable_set('commerce_kickstart_selected_extras', $form_state['values']['extras']);
variable_set('commerce_kickstart_choose_tax_country', $form_state['values']['commerce_kickstart_choose_tax_country']);
variable_set('commerce_default_currency', $form_state['values']['commerce_default_currency']);
variable_set('commerce_enabled_currencies', array($form_state['values']['commerce_default_currency'] => $form_state['values']['commerce_default_currency']));
// Kickstart features rebuild themselves in their hook_enable() hooks, disable
// features_modules_enabled() until the end of install.
variable_set('features_rebuild_on_module_install', FALSE);
}
/**
* Task callback: uses Batch API to import modules based on user selection.
* Installs all demo store modules if requested, or any modules providing
* additional functionality to the base install.
*
* Any modules providing custom blocks should be enabled here, and not before
* (as an install profile dependency), because the themes are setup during
* commerce_kickstart_install(), which means region assignment can only happen
* after that.
*/
function commerce_kickstart_install_additional_modules() {
global $install_state;
$install_demo_store = variable_get('commerce_kickstart_demo_store', FALSE);
if ($install_demo_store) {
$modules = array(
'commerce_kickstart_reset',
'commerce_kickstart_block',
'commerce_kickstart_user',
'commerce_checkout_redirect',
'commerce_kickstart_social',
'commerce_kickstart_product',
'commerce_kickstart_product_ui',
'commerce_kickstart_blog',
'commerce_kickstart_slideshow',
'commerce_kickstart_merchandising',
'commerce_kickstart_menus',
'commerce_kickstart_search',
'commerce_kickstart_taxonomy',
);
}
else {
$modules = array(
'commerce_kickstart_block',
'commerce_kickstart_user',
'commerce_kickstart_lite_product',
'commerce_kickstart_product_ui',
'commerce_kickstart_search',
'commerce_kickstart_taxonomy',
);
$selected_extras = variable_get('commerce_kickstart_selected_extras', array());
if (empty($selected_extras['anonymous_checkout'])) {
$modules[] = 'commerce_checkout_redirect';
}
if (!empty($selected_extras['merchandising'])) {
$modules[] = 'commerce_kickstart_merchandising';
}
if (!empty($selected_extras['slideshow'])) {
$modules[] = 'commerce_kickstart_slideshow';
}
if (!empty($selected_extras['menus'])) {
$modules[] = 'commerce_kickstart_menus';
}
if (!empty($selected_extras['blog'])) {
$modules[] = 'commerce_kickstart_blog';
}
if (!empty($selected_extras['social'])) {
$modules[] = 'commerce_kickstart_social';
}
if (!empty($selected_extras['zoom_cloud'])) {
variable_set('commerce_kickstart_product_zoom_enabled', TRUE);
}
}
$install_localization = variable_get('commerce_kickstart_localization', FALSE);
if ($install_localization) {
$modules[] = 'locale';
$modules[] = 'variable';
$modules[] = 'i18n';
$modules[] = 'i18n_field';
}
$store_country = variable_get('commerce_kickstart_store_country', 'US');
// Enable Payleap and Paypal for North America.
if (in_array($store_country, array('CA', 'US'))) {
$modules[] = 'commerce_payleap';
$modules[] = 'commerce_payflow';
$modules[] = 'commerce_paypal_ec';
}
// Enable the commerce_kickstart_dfp module.
if ($install_state['parameters']['use_dfp']) {
$modules[] = 'commerce_kickstart_dfp';
}
// Resolve the dependencies now, so that module_enable() doesn't need
// to do it later for each individual module (which kills performance).
$files = system_rebuild_module_data();
$modules_sorted = array();
foreach ($modules as $module) {
if ($files[$module]->requires) {
// Create a list of dependencies that haven't been installed yet.
$dependencies = array_keys($files[$module]->requires);
$dependencies = array_filter($dependencies, '_commerce_kickstart_filter_dependencies');
// Add them to the module list.
$modules = array_merge($modules, $dependencies);
}
}
$modules = array_unique($modules);
foreach ($modules as $module) {
$modules_sorted[$module] = $files[$module]->sort;
}
arsort($modules_sorted);
$operations = array();
// Enable and set as default the correct theme.
$theme = $install_demo_store ? 'commerce_kickstart_theme' : 'omega_kickstart';
$operations[] = array('_commerce_kickstart_enable_theme', array($theme));
// Enable the selected modules.
foreach ($modules_sorted as $module => $weight) {
$operations[] = array('_commerce_kickstart_enable_module', array($module, $files[$module]->info['name']));
}
if ($install_localization) {
$operations[] = array('_commerce_kickstart_setup_localization', array(t('Configured localization.')));
}
$operations[] = array('_commerce_kickstart_flush_caches', array(t('Flushed caches.')));
$batch = array(
'title' => $install_demo_store ? t('Installing demo store') : t('Installing additional functionality'),
'operations' => $operations,
'file' => drupal_get_path('profile', 'commerce_kickstart') . '/commerce_kickstart.install_callbacks.inc',
);
return $batch;
}
/**
* array_filter() callback used to filter out already installed dependencies.
*/
function _commerce_kickstart_filter_dependencies($dependency) {
return !module_exists($dependency);
}
/**
* Task callback: return a batch API array with the products to be imported.
*/
function commerce_kickstart_import_content() {
// Fixes problems when the CSV files used for importing have been created
// on a Mac, by forcing PHP to detect the appropriate line endings.
ini_set("auto_detect_line_endings", TRUE);
$operations = array();
$operations[] = array('_commerce_kickstart_example_taxes', array(t('Setting up taxes.')));
$install_demo_store = variable_get('commerce_kickstart_demo_store', FALSE);
$operations[] = array('_commerce_kickstart_taxonomy_menu', array(t('Setting up menus.')));
// Run all available migrations.
$migrations = migrate_migrations();
foreach ($migrations as $machine_name => $migration) {
$operations[] = array('_commerce_kickstart_import', array($machine_name, t('Importing content.')));
}
if ($install_demo_store) {
$operations[] = array('_commerce_kickstart_example_user', array(t('Setting up users.')));
}
// Perform post-import tasks.
$operations[] = array('_commerce_kickstart_post_import', array(t('Completing setup.')));
$batch = array(
'title' => t('Importing content'),
'operations' => $operations,
'file' => drupal_get_path('profile', 'commerce_kickstart') . '/commerce_kickstart.install_callbacks.inc',
);
return $batch;
}
/**
* 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_kickstart_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');
// Restore features behavior.
variable_set('features_rebuild_on_module_install', TRUE);
// There is an issue with Features and menu_links when profile installed
// through Drush. We need to revert the menu_links and autosku patterns.
if (drupal_is_cli()) {
$feature_install_fix = array(
// Fix AutoSKU
'commerce_kickstart_product' => array('commerce_autosku_patterns'),
// Fences has issues in Features
'commerce_kickstart_blog' => array('field_instance'),
'commerce_kickstart_merchandising' => array('field_instance'),
);
features_revert($feature_install_fix);
// Fix Menu Links
$features_menu_link_fix = array(
'commerce_kickstart_block',
'commerce_kickstart_social',
'commerce_kickstart_user',
);
foreach ($features_menu_link_fix as $module) {
if ($menu_links = features_get_default('menu_links', $module)) {
menu_links_features_rebuild_ordered($menu_links, TRUE);
}
}
}
// 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.
// Will also trigger indexing of profile-supplied content or feeds.
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);
// Migrate adds its messages under the wrong type, see #1659150.
drupal_get_messages('ok', TRUE);
// If we don't install drupal using Drush, redirect the user to the front
// page.
if (!drupal_is_cli()) {
if (module_exists('overlay')) {
// Special case when no clean urls.
$fragment = empty($GLOBALS['conf']['clean_url']) ? urlencode('?q=admin/help/getting-started') : 'admin/help/getting-started';
drupal_goto('', array('fragment' => 'overlay=' . $fragment));
}
else {
drupal_goto('admin/help/getting-started');
}
}
}
}
/**
* Implements hook_install().
*/
function commerce_kickstart_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);
// Enable the admin theme.
$admin_theme = 'commerce_kickstart_admin';
theme_enable(array($admin_theme));
variable_set('admin_theme', $admin_theme);
variable_set('node_admin_theme', '1');
// 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 = 2;
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();
// Update the menu router information.
menu_rebuild();
// Set Mimemail.
variable_set('mimemail_format', 'full_html');
// Set checkout progress.
variable_set('commerce_checkout_progress_link', 0);
variable_set('commerce_checkout_progress_list_type', 'ol');
variable_set('commerce_checkout_progress_block_pages', array_keys(commerce_checkout_pages()));
// Configure Chosen.
variable_set('chosen_jquery_selector', '.view-filters .views-exposed-form select');
variable_set('chosen_minimum_single', 'Always Apply');
variable_set('chosen_minimum_multiple', 'Always Apply');
variable_set('chosen_minimum_width', 200);
variable_set('chosen_search_contains', TRUE);
// Create the default Search API server.
$values = array(
'machine_name' => 'frontend',
'name' => 'Frontend',
'description' => '',
'class' => 'search_api_db_service',
'options' => array(
'database' => 'default:default',
'min_chars' => 3,
),
);
search_api_server_insert($values);
// Enable automatic title replacement for node and commerce product bundles.
foreach (array('node', 'commerce_product') as $entity_type) {
$title_settings = array(
'auto_attach' => array(
'title' => 'title',
),
'hide_label' => array(
'entity' => 'entity',
'page' => 0,
),
);
variable_set('title_' . $entity_type, $title_settings);
}
// Disable migrate autoregistration.
variable_set('migrate_disable_autoregistration', TRUE);
// Check DFP User Agreement.
variable_set('commerce_kickstart_dfp_eula', TRUE);
// Creating needed fields
$field_image = array(
'active' => 1,
'cardinality' => 1,
'deleted' => 0,
'entity_types' => array(),
'field_name' => 'field_image',
'foreign keys' => array(
'fid' => array(
'columns' => array(
'fid' => 'fid',
),
'table' => 'file_managed',
),
),
'indexes' => array(
'fid' => array(
0 => 'fid',
),
),
'locked' => 0,
'module' => 'image',
'settings' => array(
'default_image' => 0,
'uri_scheme' => 'public',
),
'translatable' => 1,
'type' => 'image',
);
field_create_field($field_image);
}
/**
* Disables the passed modules by removing their entries from the system table.
*
* Used for modules that have already disappeared from the filesystem.
* Implemented in order to avoid the core issue described in #1081266.
*
* @param $modules
* The modules to disable.
*/
function _commerce_kickstart_disable_modules($modules) {
// Disable the removed modules.
db_update('system')
->fields(array('status' => 0))
->condition('name', $modules)
->condition('type', 'module')
->execute();
}
/**
* Implements hook_update_dependencies().
*/
function commerce_kickstart_update_dependencies() {
$deps = array();
$deps['commerce_kickstart'][7200] = array(
'rules' => 7210,
'rules' => 7211,
'rules' => 7212,
'rules' => 7213,
);
$deps['commerce_kickstart'][7212] = array(
'rules' => 7210,
'rules' => 7211,
'rules' => 7212,
'rules' => 7213,
);
if (module_exists('commerce_discount')) {
$deps['commerce_kickstart'][7213] = array(
'commerce_discount' => 7101,
'commerce_discount' => 7102,
);
}
$deps['commerce_kickstart'][7214] = array(
'rules' => 7210,
'rules' => 7211,
'rules' => 7212,
'rules' => 7213,
);
if (module_exists('commerce_discount')) {
$deps['commerce_kickstart'][7219] = array(
'commerce_discount' => 7104,
);
}
return $deps;
}
/**
* Update the admin theme from "Commerce Kickstart Admin Theme" to "Shiny".
*/
function commerce_kickstart_update_7200() {
// Enable the new theme.
theme_enable(array('shiny'));
variable_set('admin_theme', 'shiny');
drupal_static_reset();
_block_rehash('shiny');
// Disable all blocks in the content region except "Main page content".
db_update('block')
->fields(array('region' => '-1'))
->condition('theme', 'shiny')
->condition('region', 'content')
->condition(db_and()
->condition('module', 'system', '<>')
->condition('delta', 'main', '<>')
)
->execute();
// Move help to the correct region.
db_update('block')
->fields(array('region' => 'help'))
->condition('module', 'system')
->condition('delta', 'help')
->condition('theme', 'shiny')
->execute();
// Disable the old theme.
theme_disable(array('commerce_kickstart_admin'));
}
/**
* Flush caches and rebuild features.
*/
function commerce_kickstart_update_7201() {
// install_task wasn't set properly on older installs, which affects
// feature rebuilding.
variable_set('install_task', 'done');
// Only non-overridden indexes get processed in 7202, no reason to do a
// cache clear this early otherwise.
$index = search_api_index_load('product_display');
if (!empty($index) && !$index->hasStatus(ENTITY_OVERRIDDEN)) {
entity_property_info_cache_clear();
drupal_flush_all_caches();
}
}
/**
* Update Search API integration to work with Commerce 1.4
*/
function commerce_kickstart_update_7202() {
// The price property has changed. A reindex is necessary.
drupal_load('module', 'search_api');
$index = search_api_index_load('product_display');
if (!empty($index) && !$index->hasStatus(ENTITY_OVERRIDDEN)) {
// Refresh the list of blocks and enable the new Price facet block.
$default_theme = variable_get('theme_default', 'omega_kickstart');
drupal_static_reset();
_block_rehash($default_theme);
db_update('block')
->fields(array('region' => 'sidebar_first', 'status' => 1, 'weight' => -1))
->condition('module', 'facetapi')
->condition('delta', 'TFVaQKSORCPdrULxfXDnLQZ40xH0Nper')
->condition('theme', $default_theme)
->execute();
$index->clear();
search_api_index_items($index, 100);
}
else {
// The index is overridden and can't be modified, so point the user
// to the documentation page.
return '<strong style="color: red">' . t('Important: To complete the update process, please visit http://drupal.org/node/1819842 and follow the instructions.') . '</strong>';
}
}
/**
* Remove the old price sort.
*/
function commerce_kickstart_update_7203() {
$sorts = entity_load('search_api_sort', FALSE, array('field' => 'field_product_commerce_price_amount_float_asc'));
if (!empty($sorts)) {
$sort = reset($sorts);
$sort->delete();
}
}
/**
* Enable the commerce_backoffice_content module.
*/
function commerce_kickstart_update_7204() {
_commerce_kickstart_disable_modules('commerce_kickstart_content_ui');
drupal_flush_all_caches();
module_enable(array('commerce_backoffice_content'));
}
/**
* Replace the collection view by a view based on the product display index.
*/
function commerce_kickstart_update_7205(&$sandbox) {
$install_demo_store = variable_get('commerce_kickstart_demo_store', FALSE);
// Batching the update
if (!isset($sandbox['progress'])) {
$sandbox['progress'] = 1;
$sandbox['max'] = 6;
}
if ($sandbox['progress'] == 1) {
// Enable commerce_kickstart_taxonomy.
module_enable(array('commerce_kickstart_taxonomy'));
menu_rebuild();
$sandbox['progress']++;
}
elseif ($sandbox['progress'] == 2) {
// Disable the old taxonomy/term/% view.
$view = views_get_view('collection_taxonomy_term');
if (isset($view->disabled) && $view->disabled === FALSE) {
views_export_status($view, TRUE);
}
$default_theme = variable_get('theme_default', 'omega_kickstart');
// Set the facets blocks only visibile on the "all products" view.
db_update('block')
->fields(array('pages' => 'products', 'visibility' => BLOCK_VISIBILITY_LISTED))
->condition('module', array('facetapi', 'search_api_sorts'))
->condition('theme', $default_theme)
->execute();
$sandbox['progress']++;
}
elseif ($sandbox['progress'] == 3) {
// Set up taxonomy main menu..
if ($install_demo_store) {
$vocabulary_machine_name = 'collection';
}
else {
$vocabulary_machine_name = 'product_category';
}
if (($collection = taxonomy_vocabulary_machine_name_load($vocabulary_machine_name)) && module_exists('taxonomy_menu')) {
drupal_load('module', 'taxonomy_menu');
$variable_name = _taxonomy_menu_build_variable('vocab_menu', $collection->vid);
variable_set($variable_name, 'main-menu');
$variable_name = _taxonomy_menu_build_variable('path', $collection->vid);
variable_set($variable_name, 'commerce_kickstart_taxonomy_term_path');
// Remove the previous menu entries.
_taxonomy_menu_delete_all($collection->vid);
// Taxonomy menu links
$terms = taxonomy_get_tree($collection->vid, 0, 1);
// Loop through $terms to process each term.
foreach ($terms as $term) {
$args = array(
'term' => $term,
'menu_name' => 'main-menu',
);
$mlid = taxonomy_menu_handler('insert', $args);
}
}
$sandbox['progress']++;
}
elseif ($sandbox['progress'] == 4) {
// Add fields to the index (Needed for the new view).
drupal_load('module', 'search_api');
$index = search_api_index_load('product_display');
if (!empty($index)) {
$indexed_fields = $index->getFields();
$options = $index->options;
if ($index->hasStatus(ENTITY_OVERRIDDEN)) {
$options['fields'] += array(
'status' => array(
'type' => 'integer',
),
);
if ($install_demo_store) {
$options['fields'] += array(
'field_category:name' => array(