Created
July 21, 2009 09:04
-
-
Save perifer/151216 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function sbm_upgrade_install() { | |
// Install modules that were enabled on the D5 site and should be enabled | |
// here too. Make sure that dependent modules are listed after dependencies. | |
drupal_install_modules(array( | |
'content', | |
'optionwidgets', | |
'text', | |
'content_copy', | |
'emfield', | |
'emthumb', | |
'emvideo', | |
'fieldgroup', | |
'filefield', | |
'imagefield', | |
'nodereference', | |
'userreference', | |
'number', | |
'excerpt', | |
'faq', | |
'imce', | |
'token', | |
'pathauto', | |
'sbm', | |
'sbm_product', | |
'sbm_product_tip', | |
'sbm_basket', | |
'sbm_blog', | |
'sbm_service', | |
'views', | |
)); | |
// Enable modules new to the D6 site. | |
drupal_install_modules(array( | |
'linkimagefield', | |
'cobalt', | |
'sbm_utils', | |
'node_clone', | |
'tradedoubler', | |
'imageapi_gd', | |
'imagecache', | |
'imagecache_action_cover', | |
'clone', | |
'domain', | |
'domain_conf', | |
'domain_theme', | |
'install_profile_api', //Only used at this upgrade | |
)); | |
} | |
/* Seperate update script for everything else since functions for enabled | |
* modules doesn't seem to be availabe, e.g linkimagefield. | |
*/ | |
function sbm_upgrade_update_1() { | |
$ret = array(); | |
// Change Produktinformation to multiple textfields. | |
module_load_include('inc', 'content', 'includes/content.crud'); | |
$existing_fields = content_field_instance_read(array('field_name' => 'field_produktinformation')); | |
if (!empty($existing_fields)) { | |
foreach ($existing_fields as $field) { | |
$field['multiple'] = '1'; | |
$field['widget']['size'] = '60'; | |
$field['widget']['type'] = 'text_textfield'; | |
content_field_instance_update($field); | |
} | |
} | |
// List the nodes that need manual editing. | |
$result = db_query("SELECT nid FROM {content_field_produktinformation} WHERE field_produktinformation_value IS NOT NULL"); | |
$links = array(); | |
while ($node = db_fetch_object($result)) { | |
$links[] = l('Node ' . $node->nid, 'node/' . $node->nid, array('attributes' => array('target' => '_blank'))); | |
} | |
drupal_set_message(t("Please update the product description for the following nodes: !links.<br/>You most likely want to use this text:<br/>Starthjälp<br/>Hjälp på plats<br/>Låsöppning<br/>Hjälp vid bränslestopp<br/>Bärgning till verkstad<br/>Hjälp vid punktering<br/>500 kr i kontantersättning", array('!links' => implode(', ', $links)))); | |
// Update imagefield settings. | |
$image_fields = array('field_top_image', 'field_list_shot', 'field_product_shot', 'field_better_buy', 'field_bild', 'field_framsidesbild', 'field_right_push_image'); | |
foreach ($image_fields as $field_name) { | |
$existing_fields = content_field_instance_read(array('field_name' => $field_name)); | |
if (!empty($existing_fields)) { | |
foreach ($existing_fields as $field) { | |
$field['widget']['file_extensions'] = 'jpg jpeg png gif'; | |
// Product shots should be linkable. | |
if ($field_name == 'field_product_shot') { | |
$field['widget']['type'] = 'linkimagefield_widget'; | |
$field['widget']['module'] = 'linkimagefield'; | |
} | |
content_field_instance_update($field); | |
} | |
} | |
} | |
// Convert the Produktkategori CCK field to a vocabulary | |
install_include(array('taxonomy')); | |
$prod_voc_name = 'Produktkategori'; | |
if (!install_taxonomy_get_vid($prod_voc_name)) { | |
$prod_vid = install_taxonomy_add_vocabulary($prod_voc_name, array('sbm_product' => 1)); | |
// Create the vocabulary + taxonomy. | |
$terms = array('Bil', 'Båt', 'Cykel', 'Moped', 'Motorcykel', 'Skoter'); | |
$terms = array_fill_keys($terms, ''); | |
foreach ($terms as $name => $array) { | |
// Save the tid to the array. | |
$terms[$name] = install_taxonomy_add_term($prod_vid, $name); | |
} | |
// Assign the new terms to all product nodes | |
$result = db_query("SELECT nid, vid, field_product_category_value AS name FROM {content_type_sbm_product} WHERE field_product_category_value IS NOT NULL"); | |
while ($node = db_fetch_object($result)) { | |
db_query('DELETE FROM {term_node} WHERE vid = %d AND tid = %d', $node->vid, $terms[$node->name]); | |
db_query('INSERT INTO {term_node} (nid, tid, vid) VALUES (%d, %d, %d)', $node->nid, $terms[$node->name], $node->vid); | |
} | |
// Delete the CCK field | |
$existing_fields = content_field_instance_read(array('field_name' => 'field_product_category')); | |
if (!empty($existing_fields)) { | |
foreach ($existing_fields as $field) { | |
content_field_instance_delete($field['field_name'], $field['type_name']); | |
} | |
} | |
} | |
// Copy data from Tradedoubler CCK field to the new tradedoubler module | |
$result = db_query("SELECT nid, vid, field_tradedoubler_event_id_value AS tradedoubler_event_id FROM {content_type_sbm_product} WHERE field_tradedoubler_event_id_value IS NOT NULL"); | |
while ($node = db_fetch_object($result)) { | |
db_query('DELETE FROM {tradedoubler} WHERE vid = %d', $node->vid); | |
tradedoubler_set_event_id($node); | |
} | |
// Delete the Tradedoubler CCK field. | |
$existing_fields = content_field_instance_read(array('field_name' => 'field_tradedoubler_event_id')); | |
if (!empty($existing_fields)) { | |
foreach ($existing_fields as $field) { | |
content_field_instance_delete($field['field_name'], $field['type_name']); | |
} | |
} | |
// Save tradeoubler settings. | |
variable_set('tradedoubler_organization', '1316130'); | |
variable_set('tradedoubler_checksum_code', '1452'); | |
variable_set('tradedoubler_sbm_product', 1); | |
// Enable and configurate domain access. | |
$domains = array( | |
array('bilcert.sbmfordon.se', 'Bilcert'), | |
array('gjensidige.sbmfordon.se', 'Gjensidige'), | |
array('if.sbmfordon.se', 'If Försäkringar'), | |
array('lansforsakringar.sbmfordon.se', 'Länsförsäkringar'), | |
array('renaultforsakringar.sbmfordon.se', 'Renaultförsäkringar'), | |
array('saluansvar.sbmfordon.se', 'Saluansvar'), | |
array('volvia.sbmfordon.se', 'Volvia'), | |
); | |
foreach ($domains as $key => $domain) { | |
db_query("DELETE FROM {domain} WHERE subdomain = '%s'", $domain[0]); | |
db_query("INSERT INTO {domain} (domain_id, subdomain, sitename, scheme, valid) VALUES (%d, '%s', '%s', 'http', '1')", $key + 1, $domain[0], $domain[1]); | |
} | |
drupal_set_message(t('Remember to add "include \'./sites/default/modules/domain/settings.inc\';" to your settings.php file')); | |
// Copy data from price and product_code CCK field to the new sbm_product variant table. | |
// We don't accout for different revisisons (vid) since they are not used on | |
// the old site and there is no revision support for variants. | |
$result = db_query("SELECT nid, vid, field_price_value AS price, field_product_code_value AS pcode FROM {content_type_sbm_product}"); | |
while ($node = db_fetch_object($result)) { | |
db_query('DELETE FROM {sbm_product_variant} WHERE nid = %d', $node->nid); | |
db_query("INSERT INTO {sbm_product_variant} (nid, product_code, price) VALUES (%d, '%s', %d)", $node->nid, $node->pcode, $node->price); | |
} | |
// Delete the price CCK field. | |
$existing_fields = content_field_instance_read(array('field_name' => 'field_price')); | |
if (!empty($existing_fields)) { | |
foreach ($existing_fields as $field) { | |
content_field_instance_delete($field['field_name'], $field['type_name']); | |
} | |
} | |
// Delete the product_code CCK field. | |
$existing_fields = content_field_instance_read(array('field_name' => 'field_product_code')); | |
if (!empty($existing_fields)) { | |
foreach ($existing_fields as $field) { | |
content_field_instance_delete($field['field_name'], $field['type_name']); | |
} | |
} | |
variable_set('sbm_thank_you_page', _sbm_upgrade_thank_you_text()); | |
variable_set('site_frontpage', SBM_SHOP_URL); | |
variable_set('sbm_basket_preamble', '<p>Det här är din varukorg. Den innehåller !total_count produkter till en summa av !total_amount kr.</p><a href="!shop_url"><strong>Klicka här för att beställa mer</a></strong>'); | |
variable_set('sbm_order_form_preamble', '<p>Fyll i dina uppgifter och klicka på !button_text.<br/><a href="/content/pul-personuppgiftslagen">Läs mer här om hur vi hanterar personuppgifter</a></p>'); | |
variable_set('theme_sbm_main_settings', array( | |
'toggle_logo' => 0, | |
'toggle_name' => 1, | |
'toggle_slogan' => 0, | |
'toggle_mission' => 1, | |
'toggle_node_user_picture' => 0, | |
'toggle_comment_user_picture' => 0, | |
'toggle_search' => 1, | |
'toggle_favicon' => 1, | |
'toggle_primary_links' => 1, | |
'toggle_secondary_links' => 1, | |
'default_logo' => 1, | |
'logo_path' => '', | |
'logo_upload' => '', | |
'default_favicon' => 0, | |
'favicon_path' => 'files/favicon.ico', | |
'favicon_upload' => '', | |
)); | |
// Frontpage blocks. | |
$blocks = array('product_by_category-car', 'product_by_category-motorcycle', 'product_by_category-vehicles', 'product_by_category-otherprod'); | |
$block_options = array('region' => 'content_bottom', 'pages' => 'produkter', 'visibility' => 1); | |
foreach ($blocks as $weight => $delta) { | |
$block_options['weight'] = $weight; | |
sbm_upgrade_install_add_block('views', $delta, 'sbm_main', $block_options); | |
} | |
drupal_set_message(t('Disable install_profile_api module')); | |
// FAQ module | |
path_set_alias('faq', 'kundservice'); | |
db_query("INSERT INTO {vocabulary_node_types} (vid, type) VALUES (1, 'faq')"); | |
variable_set('faq_description', ''); | |
cache_clear_all(); | |
return $ret; | |
} | |
function sbm_upgrade_install_add_block($module, $delta, $theme, $options) { | |
// Merge in defaults. | |
$options += array( | |
'status' => 1, | |
'weight' => 0, | |
'region' => '', | |
'visibility' => 0, | |
'pages' => '', | |
'custom' => 0, | |
'throttle' => 0, | |
'title' => '', | |
); | |
$bid = db_result(db_query("SELECT bid FROM {blocks} WHERE module = '%s' AND delta = '%s' AND theme = '%s'", $module, $delta, $theme)); | |
if ($bid) { | |
db_query("UPDATE {blocks} SET module = '%s', delta = '%s', theme = '%s', status = %d, weight = %d, region = '%s', visibility = %d, pages = '%s', custom = %d, throttle = %d, title = '%s' WHERE bid = %d", | |
$module, $delta, $theme, $options['status'], $options['weight'], $options['region'], $options['visibility'], $options['pages'], $options['custom'], $options['throttle'], $options['title'], $bid); | |
} | |
else { | |
db_query("INSERT INTO {blocks} (module, delta, theme, status, weight, region, visibility, pages, custom, throttle, title) | |
VALUES ('%s', '%s', '%s', %d, %d, '%s', %d, '%s', %d, %d, '%s')", | |
$module, $delta, $theme, $options['status'], $options['weight'], $options['region'], $options['visibility'], $options['pages'], $options['custom'], $options['throttle'], $options['title']); | |
} | |
} | |
# Uncomment to run the upgrade script immediately on /update.php | |
#sbm_upgrade_update_1(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment