You are here

function mail_edit_update_6000 in Mail Editor 6

Do one of two things to install on D6: -- If this is an upgrade from a 5.x-1.x installation: The D5 {mail_edit} table cannot be migrated to D6, so we move it away and do a full install. Modules that have used Mail Editor under D5 can pick up their old records from {mail_edit_D5}. -- If we already have an early 6.x-1.x installation, then fix the schema.

File

./mail_edit.install, line 117
Install, update and uninstall functions for the Mail Editor module.

Code

function mail_edit_update_6000() {
  $ret = array();
  if (db_table_exists('mail_edit') && !db_table_exists('mail_edit_registry')) {

    // We have a D5 installation and need to move the old table out of the way.
    db_rename_table($ret, 'mail_edit', 'mail_edit_d5');
    if ($ret[0]['success']) {
      watchdog('mail_edit', 'The %mail_edit table has been renamed to %mail_edit_d5.', array(
        '%mail_edit' => '{mail_edit}',
        '%mail_edit_d5' => '{mail_edit_d5}',
      ), WATCHDOG_NOTICE);
    }

    // Now install the D6 schema as of update_6000.
    $schema['mail_edit'] = array(
      'description' => '',
      'fields' => array(
        'description' => array(
          'type' => 'varchar',
          'length' => '255',
          'not null' => TRUE,
          'description' => '',
        ),
        'subject' => array(
          'type' => 'varchar',
          'length' => '255',
          'not null' => TRUE,
          'description' => '',
        ),
        'id' => array(
          'type' => 'varchar',
          'length' => '255',
          'not null' => TRUE,
          'description' => '',
        ),
        'language' => array(
          'type' => 'varchar',
          'length' => '10',
          'not null' => TRUE,
          'description' => '',
        ),
        'body' => array(
          'type' => 'text',
          'size' => 'normal',
          'description' => '',
        ),
      ),
      'primary key' => array(
        'id',
        'language',
      ),
      'indexes' => array(
        'language' => array(
          'language',
        ),
      ),
    );
    $schema['mail_edit_registry'] = array(
      'description' => '',
      'fields' => array(
        'id' => array(
          'type' => 'varchar',
          'length' => '255',
          'not null' => TRUE,
          'description' => '',
        ),
        'module' => array(
          'type' => 'varchar',
          'length' => '255',
          'not null' => TRUE,
          'description' => '',
        ),
        'mailkey' => array(
          'type' => 'varchar',
          'length' => '255',
          'not null' => TRUE,
          'description' => '',
        ),
        'description' => array(
          'type' => 'varchar',
          'length' => '255',
          'not null' => TRUE,
          'description' => '',
        ),
      ),
      'primary key' => array(
        'id',
      ),
    );
    db_create_table($ret, 'mail_edit', $schema['mail_edit']);
    db_create_table($ret, 'mail_edit_registry', $schema['mail_edit_registry']);
  }
  else {

    // Fix the schema of the 2008-Oct-08 snapshot release.
    db_drop_index($ret, 'mail_edit', '`unique entry`');
    db_drop_index($ret, 'mail_edit', '`id`');
    db_add_primary_key($ret, 'mail_edit', array(
      'id',
      'language',
    ));
    db_add_primary_key($ret, 'mail_edit_registry', array(
      'id',
    ));
  }
  return $ret;
}