You are here

function privatemsg_install in Privatemsg 5.3

Same name and namespace in other branches
  1. 5 privatemsg.install \privatemsg_install()
  2. 6.2 privatemsg.install \privatemsg_install()
  3. 6 privatemsg.install \privatemsg_install()
  4. 7.2 privatemsg.install \privatemsg_install()
  5. 7 privatemsg.install \privatemsg_install()

File

./privatemsg.install, line 3

Code

function privatemsg_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("CREATE TABLE {privatemsg} (\n          id            int unsigned NOT NULL primary key,\n          author        int unsigned NOT NULL,\n          recipient     int unsigned NOT NULL,\n          subject       varchar(255) NOT NULL,\n          message       text NOT NULL,\n          timestamp     int unsigned NOT NULL,\n          newmsg        tinyint unsigned NOT NULL,\n          hostname      varchar(255) NOT NULL,\n          folder        int unsigned NOT NULL DEFAULT 0,\n          author_del    tinyint unsigned NOT NULL DEFAULT 0,\n          recipient_del tinyint unsigned NOT NULL DEFAULT 0,\n          format        int NOT NULL DEFAULT 0,\n          thread        int NOT NULL DEFAULT 0,\n          type          varchar(255) NOT NULL,\n          variables     longtext,\n          key (recipient),\n          key (folder),\n          key(type),\n          key(author)\n        ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
      db_query("CREATE TABLE {privatemsg_folder} (\n          fid           int unsigned NOT NULL primary key,\n          uid           int unsigned NOT NULL,\n          name          varchar(255) NOT NULL\n        ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
      db_query("CREATE TABLE {privatemsg_archive} (\n          id            int unsigned NOT NULL primary key,\n          author        int unsigned NOT NULL,\n          recipient     int unsigned NOT NULL,\n          subject       VARCHAR(64) NOT NULL,\n          message       text NOT NULL,\n          timestamp     int unsigned NOT NULL,\n          hostname      varchar(255) NOT NULL,\n          folder        int unsigned NOT NULL,\n          format        int NOT NULL DEFAULT 0,\n          thread        int NOT NULL DEFAULT 0,\n          key (recipient)\n        ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
      db_query('CREATE TABLE {privatemsg_block_user} (
          author int unsigned NOT NULL,
          recipient int unsigned NOT NULL,
          PRIMARY KEY (author, recipient)
        )  /*!40100 DEFAULT CHARACTER SET utf8 */');
      break;

    /*
                    notification_subject varchar(255) NOT NULL,
              notification_text_body varchar(255) NOT NULL,
              notification_html_body varchar(255) NOT NULL,
              notification_group_text_body varchar(255) NOT NULL,
              notification_group_html_body varchar(255) NOT NULL,
    */
    case 'pgsql':
      db_query("CREATE TABLE {privatemsg} (\n          id            integer NOT NULL,\n          author        integer NOT NULL,\n          recipient     integer NOT NULL,\n          subject       varchar(255) NOT NULL,\n          message       text NOT NULL,\n          timestamp     integer NOT NULL,\n          newmsg        smallint NOT NULL,\n          hostname      varchar(255) NOT NULL,\n          format        smallint NOT NULL DEFAULT 0,\n          folder        integer NOT NULL DEFAULT 0,\n          author_del    smallint NOT NULL DEFAULT 0,\n          recipient_del smallint NOT NULL DEFAULT 0,\n          thread        int NOT NULL DEFAULT 0,\n          type          varchar(255) NOT NULL,\n          variables     text,\n          PRIMARY KEY (id)\n        )");
      db_query("CREATE INDEX {privatemsg_folder_index} ON {privatemsg}(folder)");
      db_query("CREATE INDEX {privatemsg_folder_recipient} ON {privatemsg}(recipient)");
      db_query("CREATE INDEX {privatemsg_folder_type} ON {privatemsg}(type)");
      db_query("CREATE INDEX {privatemsg_folder_author} ON {privatemsg}(author)");
      db_query("CREATE TABLE {privatemsg_folder} (\n          fid           integer NOT NULL,\n          uid           integer NOT NULL,\n          name          varchar(255) not null,\n          PRIMARY KEY (fid)\n        )");
      db_query("CREATE TABLE {privatemsg_archive} (\n          id            integer NOT NULL,\n          author        integer NOT NULL,\n          recipient     integer NOT NULL,\n          subject       varchar(64) NOT NULL,\n          message       text NOT NULL,\n          timestamp     integer NOT NULL,\n          hostname      varchar(255) NOT NULL,\n          format        smallint NOT NULL DEFAULT 0,\n          folder        integer NOT NULL,\n          thread        int NOT NULL DEFAULT 0,\n          PRIMARY KEY (id)\n        )");
      db_query("CREATE INDEX {privatemsg_archive_recipient} ON {privatemsg_archive}(recipient)");
      db_query('CREATE SEQUENCE {privatemsg}_id_seq INCREMENT 1 START 1');
      db_query('CREATE SEQUENCE {privatemsg_folder}_fid_seq INCREMENT 1 START 1');
      db_query('CREATE TABLE {privatemsg_block_user} (
          author int unsigned NOT NULL,
          recipient int unsigned NOT NULL,
          PRIMARY KEY (author, recipient)
        )');
      db_query("create or replace function unix_timestamp(timestamp with time zone)\n        returns int as '\n        declare\n           date alias for \$1;\n           timezero timestamp;\n           offset interval;\n        begin\n           timezero := timestamp ''1970-1-1 00:00'' at time zone ''utc'';\n           offset := date-timezero;\n\n           return (extract(''days'' from offset)*86400+\n                   extract(''hours'' from offset)*3600+\n                   extract(''minutes'' from offset)*60+\n                   extract(''seconds'' from offset))::int;\n        end;\n        ' language 'plpgsql'");
      db_query("create or replace function unix_timestamp(timestamp without time zone)\n        returns int as '\n        declare\n           date alias for \$1;\n           timezero timestamp;\n           offset interval;\n        begin\n           timezero := timestamp ''1970-1-1 00:00'' at time zone ''utc'';\n           offset := date-timezero;\n\n           return (extract(''days'' from offset)*86400+\n                   extract(''hours'' from offset)*3600+\n                   extract(''minutes'' from offset)*60+\n                   extract(''seconds'' from offset))::int;\n        end;\n        ' language 'plpgsql'");
      break;
  }

  // Sent messages folder
  db_query("INSERT INTO {privatemsg_folder} (fid, uid, name) VALUES (1, 0, 'Sent')");
  do {
    $i = db_next_id('{privatemsg_folder}_fid');
  } while ($i < 1);

  // In case this api ever changes to start at zero..
}