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; // 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('Privacy Policy Summary')); $message = '
' . st('Thank you for choosing Commerce Kickstart, a product offered by Commerce Guys.') . '
'; $eula = '' . 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:') . '
'; $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 .= '' . 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)) . '
'; $form = array(); $form['welcome_message'] = array( '#markup' => $message, ); $form['eula'] = array( '#prefix' => '' . (isset($messages['error']) ? st('Review the messages above before visiting your new site.', array('@url' => url(''))) : st('Visit your new site.', array('@url' => url('')))) . '
'; 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 basic pages 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', 0); 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); } /** * 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, ); $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 '' . t('Important: To complete the update process, please visit http://drupal.org/node/1819842 and follow the instructions.') . ''; } } /** * 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( 'type' => 'string', ), ); } if (!$index->update(array('options' => $options))) { $sandbox['error_message'] = '' . t("Important: We couldn't add the new fields to the index.") . ''; } } // Schedule the reindexing. $index->clear(); search_api_index_items($index, 100); } $sandbox['progress']++; } elseif ($sandbox['progress'] >= 5) { if (empty($sandbox['pathauto'])) { // Delete old pathauto aliases that are now no longer valid. db_delete('url_alias') ->condition('source', db_like('taxonomy/term/') . '%', 'LIKE') ->execute(); $sandbox['pathauto'] = array( 'sandbox' => array(), 'finished' => 0, ); } // Generate new aliases by running the pathauto batch. module_load_include('inc', 'pathauto', 'pathauto.pathauto'); taxonomy_pathauto_bulk_update_batch_process($sandbox['pathauto']); $sandbox['progress'] += $sandbox['pathauto']['finished']; } $sandbox['#finished'] = $sandbox['progress'] / $sandbox['max']; if (!empty($sandbox['error_message'])) { return $sandbox['error_message']; } } /** * Enable the commerce_kickstart_product_ui on the no demo store. */ function commerce_kickstart_update_7206() { if (!variable_get('commerce_kickstart_demo_store', FALSE)) { // Disable the removed lite modules. _commerce_kickstart_disable_modules(array('commerce_kickstart_lite_product_ui', 'commerce_kickstart_lite_product_zoom')); drupal_flush_all_caches(); module_enable(array('commerce_kickstart_product_ui')); } } /** * Enable facetapi blocks + assign them in the sidebar_first region. */ function commerce_kickstart_update_7207() { $default_theme = variable_get('theme_default', 'omega_kickstart'); _block_rehash($default_theme); // Put the facets blocks in the right place. db_update('block') ->fields(array( 'region' => 'sidebar_first', 'pages' => 'products', 'visibility' => BLOCK_VISIBILITY_LISTED, 'status' => (int) '1', )) ->condition('module', 'facetapi') ->condition('delta', '0', '<>') ->condition('theme', $default_theme) ->execute(); } /** * Enable commerce_add_to_cart_confirmation. */ function commerce_kickstart_update_7208() { module_enable(array('commerce_add_to_cart_confirmation')); } /** * Check and remove sorts on non indexed fields. */ function commerce_kickstart_update_7209() { if ($index = search_api_index_load('product_display')) { $fields = $index->options['fields']; $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'search_api_sort') ->propertyCondition('field', array_keys($fields), 'NOT IN'); $results = $query->execute(); if (!empty($results['search_api_sort'])) { entity_delete_multiple('search_api_sort', array_keys($results['search_api_sort'])); } } } /** * Enable automatic title replacement for node and commerce product bundles. */ function commerce_kickstart_update_7210() { 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); } } /** * Enable commerce_message. */ function commerce_kickstart_update_7211() { module_enable(array('commerce_message')); } /** * Disable commerce_kickstart_checkout_redirect. */ function commerce_kickstart_update_7212() { _commerce_kickstart_disable_modules('commerce_kickstart_checkout_redirect'); } /** * Update the admin theme from "Shiny" to "Commerce Kickstart Admin Theme". */ function commerce_kickstart_update_7213() { if (variable_get('admin_theme', 'shiny') == 'shiny') { // Enable the new theme. theme_enable(array('commerce_kickstart_admin')); variable_set('admin_theme', 'commerce_kickstart_admin'); drupal_static_reset(); _block_rehash('commerce_kickstart_admin'); // Disable all blocks in the content region except "Main page content". db_update('block') ->fields(array('region' => '-1')) ->condition('theme', 'commerce_kickstart_admin') ->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', 'commerce_kickstart_admin') ->execute(); // Disable the old theme. theme_disable(array('shiny')); } } /** * Enable the Commerce Guys Marketplace module. */ function commerce_kickstart_update_7214() { module_enable(array('commerceguys_marketplace')); } /** * Disable commerce_kickstart_service_provider. */ function commerce_kickstart_update_7215() { _commerce_kickstart_disable_modules('commerce_kickstart_service_provider'); } /** * Revert body field to text with summary type. */ function commerce_kickstart_update_7216() { if (db_table_exists('field_data_body') && !db_field_exists('field_data_body', 'body_summary')) { // Force field type change. db_update('field_config') ->fields(array('type' => 'text_with_summary')) ->condition('field_name', 'body') ->execute(); // Add summary field to Body field tables. $summary_field = array( 'type' => 'text', 'size' => 'big', 'not null' => FALSE, ); db_add_field('field_data_body', 'body_summary', $summary_field); db_add_field('field_revision_body', 'body_summary', $summary_field); // Revert field components of features with body field features. $modules = array_filter(array('commerce_kickstart_product', 'commerce_kickstart_lite_product', 'commerce_kickstart_blog'), 'module_exists'); $revert = array(); foreach ($modules as $module) { $revert[$module][] = 'field'; } if (!empty($revert)) { features_revert($revert); } } } /** * Enable Inline Conditions (Needed by Commerce Discount). */ function commerce_kickstart_update_7217() { if (module_exists('commerce_discount')) { module_enable(array('inline_conditions')); } } /** * Remove jirafe. */ function commerce_kickstart_update_7218() { _commerce_kickstart_disable_modules(array('jirafe')); variable_del('jirafe_config'); variable_del('jirafe_create_account_link'); } /** * Remove Commerce Kickstart payment example and enable Commerce payment example. */ function commerce_kickstart_update_7219() { _commerce_kickstart_disable_modules(array('commerce_kickstart_payment')); module_enable(array('commerce_payment_example')); }