diff --git a/contemplate.install b/contemplate.install index a9364f3..ea5ead7 100644 --- a/contemplate.install +++ b/contemplate.install @@ -16,20 +16,6 @@ function contemplate_schema() { ), 'description' => t('This tables lists the files that are use as templates'), ); - $schema['contemplate'] = array( - 'fields' => array( - 'type' => array('type' => 'varchar', 'length' => '32', 'not null' => TRUE, 'default' => '', 'description' => t('What node type is this Template for?')), - 'teaser' => array('type' => 'text', 'not null' => TRUE, 'description' => t('tempalte for teaser')), - 'body' => array('type' => 'text', 'not null' => TRUE, 'description' => t('tempalte for body')), - 'rss' => array('type' => 'text', 'not null' => TRUE, 'description' => t('tempalte for rss')), - 'enclosure' => array('type' => 'varchar', 'length' => '128', 'not null' => TRUE, 'description' => t('enclosure information to be used with this node type.')), - 'flags' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 7, 'disp-width' => '10', 'description' => t('bitmask of flags for this node type, which are enables, etc...')) - ), - 'indexes' => array( - 'type' => array('type') - ), - 'description' => t('Store data for Content Templates for each node type, if ther be any.'), - ); return $schema; } @@ -78,6 +64,29 @@ function contemplate_update_6102() { return array(); } +/** + * Migrate to a StrongArm capable storage system, store configuration in variables + * we keep {contemplate_files} as this is updated dynamically to track contemplate template files + * + */ +function contemplate_update_6103() { + + $ret = array(); + + if( db_table_exists('contemplate')) { + $query = db_query("SELECT * FROM {contemplate}"); + + while( $row = db_fetch_array($query) ) { + $type = $row['type']; + variable_set('contemplate_'.$type, $row); + } + + $ret[] = update_sql('DROP TABLE {contemplate}'); + } + + return $ret; +} + function contemplate_uninstall() { drupal_uninstall_schema('contemplate'); drupal_set_message(t('The ConTemplate tables have been removed from the database')); diff --git a/contemplate.module b/contemplate.module index e843e96..9258ea9 100644 --- a/contemplate.module +++ b/contemplate.module @@ -469,13 +469,21 @@ function contemplate_edit_type($type = array()) { * @return array template */ function contemplate_get_template($type) { + //only load each template once per page hit static $types = array(); if (!isset($types[$type])) { + $template = variable_get('contemplate_'.$type, false); + if ( ! $template ) { + $template['flags'] = 0; + } + + $types[$type] = $template; + $types[$type]['type'] = $type; + // first check to see what's stored in the contemplate table - $types[$type] = db_fetch_array(db_query("SELECT * FROM {contemplate} WHERE type = '%s'", $type)); if (empty($types[$type])) { $types[$type] = array('flags' => 0); } @@ -490,6 +498,8 @@ function contemplate_get_template($type) { $types[$type][$field] = $file->contents; $types[$type][$field . '-file'] = $file; $types[$type]['flags'] |= $enable; // if there is a file, the field is always enabled... + } else { + $types[$type][$field . '-file'] = false; } $types[$type][$field . '-enabled'] = $types[$type]['flags'] & $enable ? TRUE : FALSE; } @@ -530,22 +540,21 @@ function contemplate_edit_type_form_submit($form, &$form_state) { function contemplate_save($edit) { $type = $edit['values']['type']; - $teaserfield = !empty($edit['values']['teaserfield']) ? $edit['values']['teaserfield'] : ''; - $bodyfield = !empty($edit['values']['bodyfield']) ? $edit['values']['bodyfield'] : ''; - $rssfield = !empty($edit['values']['rssfield']) ? $edit['values']['rssfield'] : ''; - $enclosure = !empty($edit['values']['enclosure']) ? $edit['values']['enclosure'] : ''; - $flags |= !empty($edit['values']['teaser-enabled']) ? CONTEMPLATE_TEASER_ENABLED : 0; - $flags |= !empty($edit['values']['body-enabled']) ? CONTEMPLATE_BODY_ENABLED : 0; - $flags |= !empty($edit['values']['rss-enabled']) ? CONTEMPLATE_RSS_ENABLED : 0; - - contemplate_delete($type); - $sql = "INSERT INTO {contemplate} (type, teaser, body, rss, enclosure, flags) VALUES ('%s', '%s', '%s', '%s', '%s', %d)"; - return db_query($sql, $type, $teaserfield, $bodyfield, $rssfield, $enclosure, $flags); + + $value['teaser'] = !empty($edit['values']['teaserfield']) ? $edit['values']['teaserfield'] : ''; + $value['body'] = !empty($edit['values']['bodyfield']) ? $edit['values']['bodyfield'] : ''; + $value['rss'] = !empty($edit['values']['rssfield']) ? $edit['values']['rssfield'] : ''; + $value['enclosure'] = !empty($edit['values']['enclosure']) ? $edit['values']['enclosure'] : ''; + $value['flags'] |= !empty($edit['values']['teaser-enabled']) ? CONTEMPLATE_TEASER_ENABLED : 0; + $value['flags'] |= !empty($edit['values']['body-enabled']) ? CONTEMPLATE_BODY_ENABLED : 0; + $value['flags'] |= !empty($edit['values']['rss-enabled']) ? CONTEMPLATE_RSS_ENABLED : 0; + + variable_set('contemplate_'.$type, $value); } function contemplate_delete($type) { - return db_query("DELETE FROM {contemplate} WHERE type='%s'", $type); + variable_del('contemplate_'.$type); } /**