You are here

function uc_catalog_install in Ubercart 5

Same name and namespace in other branches
  1. 8.4 uc_catalog/uc_catalog.install \uc_catalog_install()
  2. 6.2 uc_catalog/uc_catalog.install \uc_catalog_install()

File

uc_catalog/uc_catalog.install, line 3

Code

function uc_catalog_install() {
  $t = get_t();

  //Find possible Product Catalog vocabulary.
  $result = db_query("SELECT vid FROM {vocabulary} WHERE name = 'Product Catalog'");
  if ($vocab = db_fetch_object($result)) {
    $vid = $vocab->vid;
  }
  else {

    //If none, create one.
    $vid = db_next_id('{vocabulary}_vid');
    db_query("INSERT INTO {vocabulary} (vid, name, description, help, relations, hierarchy, multiple, required, tags, module, weight)\n      VALUES (%d, '%s', '', '%s', 0, 2, 1, 0, 0, 'uc_catalog', 0)", $vid, $t('Catalog'), $t('Hold Ctrl while clicking to select multiple categories.'));
    db_query("INSERT INTO {vocabulary_node_types} (vid, type) VALUES (%d, 'product')", $vid);
  }
  variable_set('uc_catalog_vid', $vid);
  variable_set('uc_catalog_name', $t('Catalog'));
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':

      // Initially allow everyone to view the catalog.
      db_query("UPDATE {permission} SET perm = CONCAT_WS(', ', perm, 'view catalog')");
      db_query("CREATE TABLE IF NOT EXISTS {uc_catalog_images} (\n        `fid` int(10) unsigned NOT NULL default '0',\n        `tid` int(10) unsigned NOT NULL default '0',\n        `filename` varchar(255) NOT NULL default '',\n        `filepath` varchar(255) NOT NULL default '',\n        `filemime` varchar(255) NOT NULL default '',\n        `filesize` int(10) unsigned NOT NULL default '0',\n        PRIMARY KEY  (`fid`)\n      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ;");
      break;
    case 'pgsql':

      // Initially allow everyone to view the catalog.
      db_query("UPDATE {permission} SET perm = perm || ', view catalog'");

      // There will be an error if the table already exists, but this should be OK.
      db_query("CREATE TABLE {uc_catalog_images} (\n        fid int_unsigned NOT NULL default 0,\n        tid int_unsigned NOT NULL default 0,\n        filename varchar(255) NOT NULL default '',\n        filepath varchar(255) NOT NULL default '',\n        filemime varchar(255) NOT NULL default '',\n        filesize int_unsigned NOT NULL default 0,\n        PRIMARY KEY  (fid)\n      );");
      break;
  }
}