You are here

views_bulk_operations.install in Views Bulk Operations (VBO) 5

File

views_bulk_operations.install
View source
<?php

function views_bulk_operations_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("CREATE TABLE {vbo_settings} (\n      name varchar(48) NOT NULL,\n      value longtext NOT NULL,\n      PRIMARY KEY (name)\n    ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
      break;
  }
}
function views_bulk_operations_update_1() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("CREATE TABLE {vbo_settings} (\n      name varchar(48) NOT NULL,\n      value longtext NOT NULL,\n      PRIMARY KEY (name)\n    ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
      $ret[] = update_sql("INSERT INTO {vbo_settings} (name, value) SELECT {variable}.name, {variable}.value FROM {variable} WHERE {variable}.name LIKE 'views_bulk_operations%'");
      $ret[] = update_sql("DELETE FROM {variable} WHERE name LIKE 'views_bulk_operations%'");
      break;
  }
  return $ret;
}
function views_bulk_operations_update_2() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("UPDATE {vbo_settings} SET name = REPLACE(name, 'views_bulk_operations_prefs_', '')");
      $ret[] = update_sql("UPDATE {variable} SET name = REPLACE(name, 'views_bulk_operations_queue_', 'vbo_queue_')");
      break;
  }
  return $ret;
}

// Convert vbo_settings from format used in 5.x-1.1 to that used in 5.x-1.2.
function views_bulk_operations_update_3() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $entries = db_query("SELECT * FROM {vbo_settings}");
      $count = 0;
      while ($entry = db_fetch_object($entries)) {
        $new_ops = array();
        $old_ops = unserialize($entry->value);
        foreach ($old_ops as $op) {
          $key = md5($op['callback'] . $op['label']);
          $new_ops[$key] = $op;
        }
        db_query("UPDATE {vbo_settings} SET value = '%s' WHERE name = '%s'", serialize($new_ops), $entry->name);
        $count++;
      }
      break;
  }
  $ret[] = array(
    'success' => true,
    'query' => "Converted {$count} VBO settings.",
  );
  return $ret;
}
function views_bulk_operations_uninstall() {
  db_query("DROP TABLE {vbo_settings}");
  db_query("DELETE FROM {variable} WHERE name LIKE 'vbo_queue_%'");
}