1 filter.install filter_update_1000()

Convert filter formats to configuration.

Related topics

File

core/modules/filter/filter.install, line 25
Install, update, and uninstall functions for the Filter module.

Code

function filter_update_1000() {
  if (!db_table_exists('filter_format')) {
    return;
  }

  $result = db_query('SELECT format, name, cache, status, weight FROM {filter_format}', array(), array('fetch' => PDO::FETCH_ASSOC));
  foreach ($result as $format) {
    $format_name = $format['format'];

    // Add user roles.
    $format['roles'] = array_keys(user_roles(FALSE, 'use text format ' . $format['format']));

    // Retrieve and prepare all filters.
    $filters = db_query('SELECT name, module, status, weight, settings FROM {filter} WHERE format = :format ORDER BY weight, module, name', array(':format' => $format_name), array('fetch' => PDO::FETCH_ASSOC))->fetchAllAssoc('name');
    foreach ($filters as $name => &$filter) {
      // The filter name is used as key only.
      unset($filter['name']);
      if ($filter['settings']) {
        $filter['settings'] = unserialize($filter['settings']);
      }
    }
    $format['filters'] = $filters;

    // Save the config object.
    $config = config('filter.format.' . $format_name);
    $config->setData($format);
    $config->save();
  }

  db_drop_table('filter_format');
  db_drop_table('filter');
}