You are here

function filebrowser_update_6200 in Filebrowser 7.3

Same name and namespace in other branches
  1. 6.2 filebrowser.install \filebrowser_update_6200()
  2. 7.4 filebrowser.install \filebrowser_update_6200()
  3. 7.2 filebrowser.install \filebrowser_update_6200()

File

./filebrowser.install, line 156
filbrowser installation file.

Code

function filebrowser_update_6200() {
  $ret = array();

  // Add new fields
  db_add_field($ret, 'filebrowser', 'nid', array(
    'type' => 'int',
    'unsigned' => TRUE,
    'not NULL' => TRUE,
  ));
  db_add_field($ret, 'filebrowser', 'file_blacklist', array(
    'type' => 'varchar',
    'length' => '255',
    'not NULL' => TRUE,
  ));

  // Change existing fields
  db_change_field($ret, 'filebrowser', 'location', 'file_path', array(
    'type' => 'varchar',
    'length' => '255',
    'not NULL' => TRUE,
  ));
  db_drop_primary_key($ret, 'filebrowser');
  db_change_field($ret, 'filebrowser', 'can_explore', 'explore_subdirs', array(
    'type' => 'int',
    'size' => 'tiny',
    'not NULL' => TRUE,
    'disp-width' => '1',
  ));

  // Grab all existing filebrowser data
  $qry = db_query('SELECT file_path, path, explore_subdirs FROM {filebrowser}');
  $new_nodes = array();
  while ($node = db_fetch_object($qry)) {
    $new_nodes[] = $node;
  }

  // Clear out the filebrowser data
  // This is necessary so that we can use node_save() which will automatically
  // call filebrowser_save() for us.
  $ret[] = update_sql('TRUNCATE TABLE {filebrowser}');

  // We need to add the primary key after we've truncated the table, otherwise
  // it'll fail on duplicate keys if multiple directory listings have been
  // created.
  db_add_primary_key($ret, 'filebrowser', array(
    'nid',
  ));

  // Attach these nodes to the default administrator account
  $user = user_load(array(
    'uid' => 1,
  ));

  // Reinsert our directory listing nodes
  foreach ($new_nodes as $node) {
    $node->type = 'dir_listing';
    $node->uid = 1;
    $node->name = $user->name;
    $node->file_blacklist = '';
    node_save($node);
  }

  // Drop unneeded fields
  db_drop_field($ret, 'filebrowser', 'path');
  return $ret;
}