You are here

function textimage_update_4 in Textimage 5.2

Same name and namespace in other branches
  1. 6.2 textimage.install \textimage_update_4()

File

./textimage.install, line 213

Code

function textimage_update_4() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("ALTER TABLE {textimage_preset} ADD COLUMN description MEDIUMTEXT NOT NULL");
      break;
    case 'pgsql':
      db_add_column($ret = array(), 'textimage_preset', 'dsecription', 'text', array(
        'not null' => TRUE,
        'default' => '',
      ));
      break;
  }
  include_once drupal_get_path('module', 'textimage') . '/textimage_admin.inc';
  $presets = textimage_get_presets();
  foreach ($presets as $preset) {

    // Update font settings.
    if (!isset($preset->settings['font'])) {
      $preset->settings['font'] = array(
        'file' => $preset->settings['text']['font'],
        'size' => $preset->settings['text']['size'],
        'color' => array(
          'hex' => $preset->settings['text']['color'],
          'opacity' => 100,
        ),
      );
      unset($preset->settings['text']['font']);
      unset($preset->settings['text']['size']);
      unset($preset->settings['text']['color']);
    }

    // Update margin settings
    if (!isset($preset->settings['text']['margin'])) {
      $preset->settings['text']['margin'] = array(
        'top' => $preset->settings['text']['margin_top'],
        'right' => $preset->settings['text']['margin_right'],
        'bottom' => $preset->settings['text']['margin_bottom'],
        'left' => $preset->settings['text']['margin_left'],
      );
      unset($preset->settings['text']['margin_top']);
      unset($preset->settings['text']['margin_right']);
      unset($preset->settings['text']['margin_bottom']);
      unset($preset->settings['text']['margin_left']);
    }

    // Update stroke settings.
    if (!isset($preset->settings['text']['stroke'])) {
      $preset->settings['text']['stroke'] = array(
        'width' => $preset->settings['text']['stroke_width'],
        'color' => $preset->settings['text']['stroke_color'],
      );
      unset($preset->settings['text']['stroke_width']);
      unset($preset->settings['text']['stroke_color']);
    }

    // Update Preview text.
    if (!isset($preset->settings['preview']['text']['default'])) {
      $preset->settings['preview']['text']['default'] = $preset->settings['preview']['text'];
      unset($preset->settings['preview']['text']);
    }

    // Update description.
    if (isset($preset->settings['description'])) {
      $preset->description = $preset->settings['description'];
      unset($preset->settings['description']);
    }
    _textimage_preset_update($preset->pid, $preset->name, $preset->description, $preset->settings);
  }
  return $ret;
}