Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1683 lines
76 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <?php
  2. use \Friendica\Core\Config;
  3. require_once("boot.php");
  4. require_once("include/text.php");
  5. define('NEW_UPDATE_ROUTINE_VERSION', 1171);
  6. /*
  7. * send the email and do what is needed to do on update fails
  8. *
  9. * @param update_id (int) number of failed update
  10. * @param error_message (str) error message
  11. */
  12. function update_fail($update_id, $error_message){
  13. //send the administrators an e-mail
  14. $admin_mail_list = "'".implode("','", array_map(dbesc, explode(",", str_replace(" ", "", $a->config['admin_email']))))."'";
  15. $adminlist = q("SELECT uid, language, email FROM user WHERE email IN (%s)",
  16. $admin_mail_list
  17. );
  18. // No valid result?
  19. if (!dbm::is_result($adminlist)) {
  20. logger(sprintf('Cannot notify administrators about update_id=%d, error_message=%s', $update_id, $error_message), LOGGER_WARNING);
  21. // Don't continue
  22. return;
  23. }
  24. // every admin could had different language
  25. foreach ($adminlist as $admin) {
  26. $lang = (($admin['language'])?$admin['language']:'en');
  27. push_lang($lang);
  28. $preamble = deindent(t("
  29. The friendica developers released update %s recently,
  30. but when I tried to install it, something went terribly wrong.
  31. This needs to be fixed soon and I can't do it alone. Please contact a
  32. friendica developer if you can not help me on your own. My database might be invalid."));
  33. $body = t("The error message is\n[pre]%s[/pre]");
  34. $preamble = sprintf($preamble, $update_id);
  35. $body = sprintf($body, $error_message);
  36. notification(array(
  37. 'type' => "SYSTEM_EMAIL",
  38. 'to_email' => $admin['email'],
  39. 'preamble' => $preamble,
  40. 'body' => $body,
  41. 'language' => $lang,
  42. ));
  43. }
  44. /*
  45. $email_tpl = get_intltext_template("update_fail_eml.tpl");
  46. $email_msg = replace_macros($email_tpl, array(
  47. '$sitename' => $a->config['sitename'],
  48. '$siteurl' => App::get_baseurl(),
  49. '$update' => DB_UPDATE_VERSION,
  50. '$error' => sprintf(t('Update %s failed. See error logs.'), DB_UPDATE_VERSION)
  51. ));
  52. $subject=sprintf(t('Update Error at %s'), App::get_baseurl());
  53. require_once('include/email.php');
  54. $subject = email_header_encode($subject,'UTF-8');
  55. mail($a->config['admin_email'], $subject, $email_msg,
  56. 'From: ' . 'Administrator' . '@' . $_SERVER['SERVER_NAME']."\n"
  57. .'Content-type: text/plain; charset=UTF-8'."\n"
  58. .'Content-transfer-encoding: 8bit');
  59. */
  60. //try the logger
  61. logger("CRITICAL: Database structure update failed: ".$retval);
  62. }
  63. function table_structure($table) {
  64. $structures = q("DESCRIBE `%s`", $table);
  65. $indexes = q("SHOW INDEX FROM `%s`", $table);
  66. $fielddata = array();
  67. $indexdata = array();
  68. if (dbm::is_result($indexes))
  69. foreach ($indexes AS $index) {
  70. if ($index["Index_type"] == "FULLTEXT") {
  71. continue;
  72. }
  73. if ($index['Key_name'] != 'PRIMARY' && $index['Non_unique'] == '0' && !isset($indexdata[$index["Key_name"]])) {
  74. $indexdata[$index["Key_name"]] = array('UNIQUE');
  75. }
  76. $column = $index["Column_name"];
  77. // On utf8mb4 a varchar index can only have a length of 191
  78. // To avoid the need to add this to every index definition we just ignore it here.
  79. // Exception are primary indexes
  80. // Since there are some combindex primary indexes we use the limit of 180 here.
  81. if (($index["Sub_part"] != "") AND (($index["Sub_part"] < 180) OR ($index["Key_name"] == "PRIMARY"))) {
  82. $column .= "(".$index["Sub_part"].")";
  83. }
  84. $indexdata[$index["Key_name"]][] = $column;
  85. }
  86. if (dbm::is_result($structures)) {
  87. foreach ($structures AS $field) {
  88. $fielddata[$field["Field"]]["type"] = $field["Type"];
  89. if ($field["Null"] == "NO") {
  90. $fielddata[$field["Field"]]["not null"] = true;
  91. }
  92. if (isset($field["Default"])) {
  93. $fielddata[$field["Field"]]["default"] = $field["Default"];
  94. }
  95. if ($field["Extra"] != "") {
  96. $fielddata[$field["Field"]]["extra"] = $field["Extra"];
  97. }
  98. if ($field["Key"] == "PRI") {
  99. $fielddata[$field["Field"]]["primary"] = true;
  100. }
  101. }
  102. }
  103. return(array("fields"=>$fielddata, "indexes"=>$indexdata));
  104. }
  105. function print_structure($database, $charset) {
  106. echo "-- ------------------------------------------\n";
  107. echo "-- ".FRIENDICA_PLATFORM." ".FRIENDICA_VERSION." (".FRIENDICA_CODENAME,")\n";
  108. echo "-- DB_UPDATE_VERSION ".DB_UPDATE_VERSION."\n";
  109. echo "-- ------------------------------------------\n\n\n";
  110. foreach ($database AS $name => $structure) {
  111. echo "--\n";
  112. echo "-- TABLE $name\n";
  113. echo "--\n";
  114. db_create_table($name, $structure['fields'], $charset, true, false, $structure["indexes"]);
  115. echo "\n";
  116. }
  117. }
  118. function update_structure($verbose, $action, $tables=null, $definition=null) {
  119. global $a, $db;
  120. if ($action) {
  121. Config::set('system', 'maintenance', 1);
  122. Config::set('system', 'maintenance_reason', 'Database update');
  123. }
  124. if (isset($a->config["system"]["db_charset"])) {
  125. $charset = $a->config["system"]["db_charset"];
  126. } else {
  127. $charset = "utf8";
  128. }
  129. $errors = false;
  130. logger('updating structure', LOGGER_DEBUG);
  131. // Get the current structure
  132. $database = array();
  133. if (is_null($tables)) {
  134. $tables = q("SHOW TABLES");
  135. }
  136. foreach ($tables AS $table) {
  137. $table = current($table);
  138. logger(sprintf('updating structure for table %s ...', $table), LOGGER_DEBUG);
  139. $database[$table] = table_structure($table);
  140. }
  141. // Get the definition
  142. if (is_null($definition)) {
  143. $definition = db_definition($charset);
  144. }
  145. // MySQL >= 5.7.4 doesn't support the IGNORE keyword in ALTER TABLE statements
  146. if ((version_compare($db->server_info(), '5.7.4') >= 0) AND
  147. !(strpos($db->server_info(), 'MariaDB') !== false)) {
  148. $ignore = '';
  149. } else {
  150. $ignore = ' IGNORE';
  151. }
  152. // Compare it
  153. foreach ($definition AS $name => $structure) {
  154. $is_new_table = False;
  155. $group_by = "";
  156. $sql3 = "";
  157. if (!isset($database[$name])) {
  158. $r = db_create_table($name, $structure["fields"], $charset, $verbose, $action, $structure['indexes']);
  159. if (!dbm::is_result($r)) {
  160. $errors .= t('Errors encountered creating database tables.').$name.EOL;
  161. }
  162. $is_new_table = True;
  163. } else {
  164. $is_unique = false;
  165. $temp_name = $name;
  166. foreach ($structure["indexes"] AS $indexname => $fieldnames) {
  167. if (isset($database[$name]["indexes"][$indexname])) {
  168. $current_index_definition = implode(",",$database[$name]["indexes"][$indexname]);
  169. } else {
  170. $current_index_definition = "__NOT_SET__";
  171. }
  172. $new_index_definition = implode(",",$fieldnames);
  173. if ($current_index_definition != $new_index_definition) {
  174. if ($fieldnames[0] == "UNIQUE") {
  175. $is_unique = true;
  176. if ($ignore == "") {
  177. $temp_name = "temp-".$name;
  178. }
  179. }
  180. }
  181. }
  182. /*
  183. * Drop the index if it isn't present in the definition
  184. * or the definition differ from current status
  185. * and index name doesn't start with "local_"
  186. */
  187. foreach ($database[$name]["indexes"] as $indexname => $fieldnames) {
  188. $current_index_definition = implode(",",$fieldnames);
  189. if (isset($structure["indexes"][$indexname])) {
  190. $new_index_definition = implode(",",$structure["indexes"][$indexname]);
  191. } else {
  192. $new_index_definition = "__NOT_SET__";
  193. }
  194. if ($current_index_definition != $new_index_definition && substr($indexname, 0, 6) != 'local_') {
  195. $sql2=db_drop_index($indexname);
  196. if ($sql3 == "") {
  197. $sql3 = "ALTER".$ignore." TABLE `".$temp_name."` ".$sql2;
  198. } else {
  199. $sql3 .= ", ".$sql2;
  200. }
  201. }
  202. }
  203. // Compare the field structure field by field
  204. foreach ($structure["fields"] AS $fieldname => $parameters) {
  205. if (!isset($database[$name]["fields"][$fieldname])) {
  206. $sql2=db_add_table_field($fieldname, $parameters);
  207. if ($sql3 == "") {
  208. $sql3 = "ALTER" . $ignore . " TABLE `".$temp_name."` ".$sql2;
  209. } else {
  210. $sql3 .= ", ".$sql2;
  211. }
  212. } else {
  213. // Compare the field definition
  214. $current_field_definition = implode(",",$database[$name]["fields"][$fieldname]);
  215. $new_field_definition = implode(",",$parameters);
  216. if ($current_field_definition != $new_field_definition) {
  217. $sql2=db_modify_table_field($fieldname, $parameters);
  218. if ($sql3 == "") {
  219. $sql3 = "ALTER" . $ignore . " TABLE `".$temp_name."` ".$sql2;
  220. } else {
  221. $sql3 .= ", ".$sql2;
  222. }
  223. }
  224. }
  225. }
  226. }
  227. /*
  228. * Create the index if the index don't exists in database
  229. * or the definition differ from the current status.
  230. * Don't create keys if table is new
  231. */
  232. if (!$is_new_table) {
  233. foreach ($structure["indexes"] AS $indexname => $fieldnames) {
  234. if (isset($database[$name]["indexes"][$indexname])) {
  235. $current_index_definition = implode(",",$database[$name]["indexes"][$indexname]);
  236. } else {
  237. $current_index_definition = "__NOT_SET__";
  238. }
  239. $new_index_definition = implode(",",$fieldnames);
  240. if ($current_index_definition != $new_index_definition) {
  241. $sql2 = db_create_index($indexname, $fieldnames);
  242. // Fetch the "group by" fields for unique indexes
  243. if ($fieldnames[0] == "UNIQUE") {
  244. $group_by = db_group_by($indexname, $fieldnames);
  245. }
  246. if ($sql2 != "") {
  247. if ($sql3 == "")
  248. $sql3 = "ALTER" . $ignore . " TABLE `".$temp_name."` ".$sql2;
  249. else
  250. $sql3 .= ", ".$sql2;
  251. }
  252. }
  253. }
  254. }
  255. if ($sql3 != "") {
  256. $sql3 .= ";";
  257. if ($verbose) {
  258. // Ensure index conversion to unique removes duplicates
  259. if ($is_unique) {
  260. if ($ignore != "") {
  261. echo "SET session old_alter_table=1;\n";
  262. } else {
  263. echo "CREATE TABLE `".$temp_name."` LIKE `".$name."`;\n";
  264. }
  265. }
  266. echo $sql3."\n";
  267. if ($is_unique) {
  268. if ($ignore != "") {
  269. echo "SET session old_alter_table=0;\n";
  270. } else {
  271. echo "INSERT INTO `".$temp_name."` SELECT * FROM `".$name."`".$group_by.";\n";
  272. echo "DROP TABLE `".$name."`;\n";
  273. echo "RENAME TABLE `".$temp_name."` TO `".$name."`;\n";
  274. }
  275. }
  276. }
  277. if ($action) {
  278. // Ensure index conversion to unique removes duplicates
  279. if ($is_unique) {
  280. if ($ignore != "") {
  281. $db->q("SET session old_alter_table=1;");
  282. } else {
  283. $r = $db->q("CREATE TABLE `".$temp_name."` LIKE `".$name."`;");
  284. if (!dbm::is_result($r)) {
  285. $errors .= t('Errors encountered performing database changes.').$sql3.EOL;
  286. return $errors;
  287. }
  288. }
  289. }
  290. $r = @$db->q($sql3);
  291. if (!dbm::is_result($r))
  292. $errors .= t('Errors encountered performing database changes.').$sql3.EOL;
  293. if ($is_unique) {
  294. if ($ignore != "") {
  295. $db->q("SET session old_alter_table=0;");
  296. } else {
  297. $r = $db->q("INSERT INTO `".$temp_name."` SELECT * FROM `".$name."`".$group_by.";");
  298. if (!dbm::is_result($r)) {
  299. $errors .= t('Errors encountered performing database changes.').$sql3.EOL;
  300. return $errors;
  301. }
  302. $r = $db->q("DROP TABLE `".$name."`;");
  303. if (!dbm::is_result($r)) {
  304. $errors .= t('Errors encountered performing database changes.').$sql3.EOL;
  305. return $errors;
  306. }
  307. $r = $db->q("RENAME TABLE `".$temp_name."` TO `".$name."`;");
  308. if (!dbm::is_result($r)) {
  309. $errors .= t('Errors encountered performing database changes.').$sql3.EOL;
  310. return $errors;
  311. }
  312. }
  313. }
  314. }
  315. }
  316. }
  317. if ($action) {
  318. Config::set('system', 'maintenance', 0);
  319. Config::set('system', 'maintenance_reason', '');
  320. }
  321. return $errors;
  322. }
  323. function db_field_command($parameters, $create = true) {
  324. $fieldstruct = $parameters["type"];
  325. if ($parameters["not null"])
  326. $fieldstruct .= " NOT NULL";
  327. if (isset($parameters["default"])){
  328. if (strpos(strtolower($parameters["type"]),"int")!==false) {
  329. $fieldstruct .= " DEFAULT ".$parameters["default"];
  330. } else {
  331. $fieldstruct .= " DEFAULT '".$parameters["default"]."'";
  332. }
  333. }
  334. if ($parameters["extra"] != "")
  335. $fieldstruct .= " ".$parameters["extra"];
  336. /*if (($parameters["primary"] != "") AND $create)
  337. $fieldstruct .= " PRIMARY KEY";*/
  338. return($fieldstruct);
  339. }
  340. function db_create_table($name, $fields, $charset, $verbose, $action, $indexes=null) {
  341. global $a, $db;
  342. $r = true;
  343. $sql = "";
  344. $sql_rows = array();
  345. $primary_keys = array();
  346. foreach($fields AS $fieldname => $field) {
  347. $sql_rows[] = "`".dbesc($fieldname)."` ".db_field_command($field);
  348. if (x($field,'primary') and $field['primary']!=''){
  349. $primary_keys[] = $fieldname;
  350. }
  351. }
  352. if (!is_null($indexes)) {
  353. foreach ($indexes AS $indexname => $fieldnames) {
  354. $sql_index = db_create_index($indexname, $fieldnames, "");
  355. if (!is_null($sql_index)) $sql_rows[] = $sql_index;
  356. }
  357. }
  358. $sql = implode(",\n\t", $sql_rows);
  359. $sql = sprintf("CREATE TABLE IF NOT EXISTS `%s` (\n\t", dbesc($name)).$sql."\n) DEFAULT CHARSET=".$charset;
  360. if ($verbose)
  361. echo $sql.";\n";
  362. if ($action)
  363. $r = @$db->q($sql);
  364. return $r;
  365. }
  366. function db_add_table_field($fieldname, $parameters) {
  367. $sql = sprintf("ADD `%s` %s", dbesc($fieldname), db_field_command($parameters));
  368. return($sql);
  369. }
  370. function db_modify_table_field($fieldname, $parameters) {
  371. $sql = sprintf("MODIFY `%s` %s", dbesc($fieldname), db_field_command($parameters, false));
  372. return($sql);
  373. }
  374. function db_drop_index($indexname) {
  375. $sql = sprintf("DROP INDEX `%s`", dbesc($indexname));
  376. return($sql);
  377. }
  378. function db_create_index($indexname, $fieldnames, $method="ADD") {
  379. $method = strtoupper(trim($method));
  380. if ($method!="" && $method!="ADD") {
  381. throw new Exception("Invalid parameter 'method' in db_create_index(): '$method'");
  382. killme();
  383. }
  384. if ($fieldnames[0] == "UNIQUE") {
  385. array_shift($fieldnames);
  386. $method .= ' UNIQUE';
  387. }
  388. $names = "";
  389. foreach ($fieldnames AS $fieldname) {
  390. if ($names != "")
  391. $names .= ",";
  392. if (preg_match('|(.+)\((\d+)\)|', $fieldname, $matches)) {
  393. $names .= "`".dbesc($matches[1])."`(".intval($matches[2]).")";
  394. } else {
  395. $names .= "`".dbesc($fieldname)."`";
  396. }
  397. }
  398. if ($indexname == "PRIMARY") {
  399. return sprintf("%s PRIMARY KEY(%s)", $method, $names);
  400. }
  401. $sql = sprintf("%s INDEX `%s` (%s)", $method, dbesc($indexname), $names);
  402. return($sql);
  403. }
  404. function db_group_by($indexname, $fieldnames) {
  405. if ($fieldnames[0] != "UNIQUE") {
  406. return "";
  407. }
  408. array_shift($fieldnames);
  409. $names = "";
  410. foreach ($fieldnames AS $fieldname) {
  411. if ($names != "")
  412. $names .= ",";
  413. if (preg_match('|(.+)\((\d+)\)|', $fieldname, $matches)) {
  414. $names .= "`".dbesc($matches[1])."`";
  415. } else {
  416. $names .= "`".dbesc($fieldname)."`";
  417. }
  418. }
  419. $sql = sprintf(" GROUP BY %s", $names);
  420. return $sql;
  421. }
  422. function db_index_suffix($charset, $reduce = 0) {
  423. if ($charset != "utf8mb4") {
  424. return "";
  425. }
  426. // On utf8mb4 indexes can only have a length of 191
  427. $indexlength = 191 - $reduce;
  428. return "(".$indexlength.")";
  429. }
  430. function db_definition($charset) {
  431. $database = array();
  432. $database["addon"] = array(
  433. "fields" => array(
  434. "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
  435. "name" => array("type" => "varchar(190)", "not null" => "1", "default" => ""),
  436. "version" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  437. "installed" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
  438. "hidden" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
  439. "timestamp" => array("type" => "bigint(20)", "not null" => "1", "default" => "0"),
  440. "plugin_admin" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
  441. ),
  442. "indexes" => array(
  443. "PRIMARY" => array("id"),
  444. "name" => array("UNIQUE", "name"),
  445. )
  446. );
  447. $database["attach"] = array(
  448. "fields" => array(
  449. "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
  450. "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
  451. "hash" => array("type" => "varchar(64)", "not null" => "1", "default" => ""),
  452. "filename" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  453. "filetype" => array("type" => "varchar(64)", "not null" => "1", "default" => ""),
  454. "filesize" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
  455. "data" => array("type" => "longblob", "not null" => "1"),
  456. "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
  457. "edited" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
  458. "allow_cid" => array("type" => "mediumtext"),
  459. "allow_gid" => array("type" => "mediumtext"),
  460. "deny_cid" => array("type" => "mediumtext"),
  461. "deny_gid" => array("type" => "mediumtext"),
  462. ),
  463. "indexes" => array(
  464. "PRIMARY" => array("id"),
  465. )
  466. );
  467. $database["auth_codes"] = array(
  468. "fields" => array(
  469. "id" => array("type" => "varchar(40)", "not null" => "1", "primary" => "1"),
  470. "client_id" => array("type" => "varchar(20)", "not null" => "1", "default" => ""),
  471. "redirect_uri" => array("type" => "varchar(200)", "not null" => "1", "default" => ""),
  472. "expires" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
  473. "scope" => array("type" => "varchar(250)", "not null" => "1", "default" => ""),
  474. ),
  475. "indexes" => array(
  476. "PRIMARY" => array("id"),
  477. )
  478. );
  479. $database["cache"] = array(
  480. "fields" => array(
  481. "k" => array("type" => "varbinary(255)", "not null" => "1", "primary" => "1"),
  482. "v" => array("type" => "mediumtext"),
  483. "expire_mode" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
  484. "updated" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
  485. ),
  486. "indexes" => array(
  487. "PRIMARY" => array("k"),
  488. "expire_mode_updated" => array("expire_mode", "updated"),
  489. )
  490. );
  491. $database["challenge"] = array(
  492. "fields" => array(
  493. "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
  494. "challenge" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  495. "dfrn-id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  496. "expire" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
  497. "type" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  498. "last_update" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  499. ),
  500. "indexes" => array(
  501. "PRIMARY" => array("id"),
  502. )
  503. );
  504. $database["clients"] = array(
  505. "fields" => array(
  506. "client_id" => array("type" => "varchar(20)", "not null" => "1", "primary" => "1"),
  507. "pw" => array("type" => "varchar(20)", "not null" => "1", "default" => ""),
  508. "redirect_uri" => array("type" => "varchar(200)", "not null" => "1", "default" => ""),
  509. "name" => array("type" => "text"),
  510. "icon" => array("type" => "text"),
  511. "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
  512. ),
  513. "indexes" => array(
  514. "PRIMARY" => array("client_id"),
  515. )
  516. );
  517. $database["config"] = array(
  518. "fields" => array(
  519. "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
  520. "cat" => array("type" => "varbinary(255)", "not null" => "1", "default" => ""),
  521. "k" => array("type" => "varbinary(255)", "not null" => "1", "default" => ""),
  522. "v" => array("type" => "mediumtext"),
  523. ),
  524. "indexes" => array(
  525. "PRIMARY" => array("id"),
  526. "cat_k" => array("UNIQUE", "cat", "k"),
  527. )
  528. );
  529. $database["contact"] = array(
  530. "fields" => array(
  531. "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
  532. "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
  533. "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
  534. "self" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
  535. "remote_self" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
  536. "rel" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
  537. "duplex" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
  538. "network" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  539. "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  540. "nick" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  541. "location" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  542. "about" => array("type" => "text"),
  543. "keywords" => array("type" => "text"),
  544. "gender" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
  545. "xmpp" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  546. "attag" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  547. "avatar" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  548. "photo" => array("type" => "text"),
  549. "thumb" => array("type" => "text"),
  550. "micro" => array("type" => "text"),
  551. "site-pubkey" => array("type" => "text"),
  552. "issued-id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  553. "dfrn-id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  554. "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  555. "nurl" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  556. "addr" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  557. "alias" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  558. "pubkey" => array("type" => "text"),
  559. "prvkey" => array("type" => "text"),
  560. "batch" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  561. "request" => array("type" => "text"),
  562. "notify" => array("type" => "text"),
  563. "poll" => array("type" => "text"),
  564. "confirm" => array("type" => "text"),
  565. "poco" => array("type" => "text"),
  566. "aes_allow" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
  567. "ret-aes" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
  568. "usehub" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
  569. "subhub" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
  570. "hub-verify" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  571. "last-update" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
  572. "success_update" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
  573. "failure_update" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
  574. "name-date" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
  575. "uri-date" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
  576. "avatar-date" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
  577. "term-date" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
  578. "last-item" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
  579. "priority" => array("type" => "tinyint(3)", "not null" => "1", "default" => "0"),
  580. "blocked" => array("type" => "tinyint(1)", "not null" => "1", "default" => "1"),
  581. "readonly" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
  582. "writable" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
  583. "forum" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
  584. "prv" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
  585. "contact-type" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
  586. "hidden" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
  587. "archive" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
  588. "pending" => array("type" => "tinyint(1)", "not null" => "1", "default" => "1"),
  589. "rating" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
  590. "reason" => array("type" => "text"),
  591. "closeness" => array("type" => "tinyint(2)", "not null" => "1", "default" => "99"),
  592. "info" => array("type" => "mediumtext"),
  593. "profile-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
  594. "bdyear" => array("type" => "varchar(4)", "not null" => "1", "default" => ""),
  595. "bd" => array("type" => "date", "not null" => "1", "default" => "0000-00-00"),
  596. "notify_new_posts" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
  597. "fetch_further_information" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
  598. "ffi_keyword_blacklist" => array("type" => "text"),
  599. ),
  600. "indexes" => array(
  601. "PRIMARY" => array("id"),
  602. "uid_name" => array("uid", "name"),
  603. "self_uid" => array("self", "uid"),
  604. "alias_uid" => array("alias(32)", "uid"),
  605. "pending_uid" => array("pending", "uid"),
  606. "blocked_uid" => array("blocked", "uid"),
  607. "uid_rel_network_poll" => array("uid", "rel", "network", "poll(64)", "archive"),
  608. "uid_network_batch" => array("uid", "network", "batch(64)"),
  609. "addr_uid" => array("addr(32)", "uid"),
  610. "nurl_uid" => array("nurl(32)", "uid"),
  611. "nick_uid" => array("nick(32)", "uid"),
  612. "dfrn-id" => array("dfrn-id"),
  613. "issued-id" => array("issued-id"),
  614. )
  615. );
  616. $database["conv"] = array(
  617. "fields" => array(
  618. "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
  619. "guid" => array("type" => "varchar(64)", "not null" => "1", "default" => ""),
  620. "recips" => array("type" => "text"),
  621. "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
  622. "creator" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  623. "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
  624. "updated" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
  625. "subject" => array("type" => "text"),
  626. ),
  627. "indexes" => array(
  628. "PRIMARY" => array("id"),
  629. "uid" => array("uid"),
  630. )
  631. );
  632. $database["event"] = array(
  633. "fields" => array(
  634. "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
  635. "guid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  636. "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
  637. "cid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
  638. "uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  639. "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
  640. "edited" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
  641. "start" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
  642. "finish" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
  643. "summary" => array("type" => "text"),
  644. "desc" => array("type" => "text"),
  645. "location" => array("type" => "text"),
  646. "type" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  647. "nofinish" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
  648. "adjust" => array("type" => "tinyint(1)", "not null" => "1", "default" => "1"),
  649. "ignore" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "0"),
  650. "allow_cid" => array("type" => "mediumtext"),
  651. "allow_gid" => array("type" => "mediumtext"),
  652. "deny_cid" => array("type" => "mediumtext"),
  653. "deny_gid" => array("type" => "mediumtext"),
  654. ),
  655. "indexes" => array(
  656. "PRIMARY" => array("id"),
  657. "uid_start" => array("uid", "start"),
  658. )
  659. );
  660. $database["fcontact"] = array(
  661. "fields" => array(
  662. "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
  663. "guid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  664. "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  665. "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  666. "photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  667. "request" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  668. "nick" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  669. "addr" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  670. "batch" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  671. "notify" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  672. "poll" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  673. "confirm" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  674. "priority" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
  675. "network" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
  676. "alias" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  677. "pubkey" => array("type" => "text"),
  678. "updated" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
  679. ),
  680. "indexes" => array(
  681. "PRIMARY" => array("id"),
  682. "addr" => array("addr(32)"),
  683. "url" => array("url"),
  684. )
  685. );
  686. $database["ffinder"] = array(
  687. "fields" => array(
  688. "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
  689. "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
  690. "cid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
  691. "fid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
  692. ),
  693. "indexes" => array(
  694. "PRIMARY" => array("id"),
  695. )
  696. );
  697. $database["fserver"] = array(
  698. "fields" => array(
  699. "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
  700. "server" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  701. "posturl" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  702. "key" => array("type" => "text"),
  703. ),
  704. "indexes" => array(
  705. "PRIMARY" => array("id"),
  706. "server" => array("server(32)"),
  707. )
  708. );
  709. $database["fsuggest"] = array(
  710. "fields" => array(
  711. "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
  712. "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
  713. "cid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
  714. "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  715. "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  716. "request" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  717. "photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  718. "note" => array("type" => "text"),
  719. "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
  720. ),
  721. "indexes" => array(
  722. "PRIMARY" => array("id"),
  723. )
  724. );
  725. $database["gcign"] = array(
  726. "fields" => array(
  727. "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
  728. "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
  729. "gcid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
  730. ),
  731. "indexes" => array(
  732. "PRIMARY" => array("id"),
  733. "uid" => array("uid"),
  734. "gcid" => array("gcid"),
  735. )
  736. );
  737. $database["gcontact"] = array(
  738. "fields" => array(
  739. "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
  740. "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  741. "nick" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  742. "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  743. "nurl" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  744. "photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  745. "connect" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  746. "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
  747. "updated" => array("type" => "datetime", "default" => NULL_DATE),
  748. "last_contact" => array("type" => "datetime", "default" => NULL_DATE),
  749. "last_failure" => array("type" => "datetime", "default" => NULL_DATE),
  750. "location" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  751. "about" => array("type" => "text"),
  752. "keywords" => array("type" => "text"),
  753. "gender" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
  754. "birthday" => array("type" => "varchar(32)", "not null" => "1", "default" => "0000-00-00"),
  755. "community" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
  756. "contact-type" => array("type" => "tinyint(1)", "not null" => "1", "default" => "-1"),
  757. "hide" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
  758. "nsfw" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
  759. "network" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  760. "addr" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  761. "notify" => array("type" => "text"),
  762. "alias" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  763. "generation" => array("type" => "tinyint(3)", "not null" => "1", "default" => "0"),
  764. "server_url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  765. ),
  766. "indexes" => array(
  767. "PRIMARY" => array("id"),
  768. "nurl" => array("nurl(64)"),
  769. "name" => array("name(64)"),
  770. "nick" => array("nick(32)"),
  771. "addr" => array("addr(64)"),
  772. "hide_network_updated" => array("hide", "network", "updated"),
  773. "updated" => array("updated"),
  774. )
  775. );
  776. $database["glink"] = array(
  777. "fields" => array(
  778. "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
  779. "cid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
  780. "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
  781. "gcid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
  782. "zcid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
  783. "updated" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
  784. ),
  785. "indexes" => array(
  786. "PRIMARY" => array("id"),
  787. "cid_uid_gcid_zcid" => array("UNIQUE", "cid","uid","gcid","zcid"),
  788. "gcid" => array("gcid"),
  789. )
  790. );
  791. $database["group"] = array(
  792. "fields" => array(
  793. "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
  794. "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
  795. "visible" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
  796. "deleted" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
  797. "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  798. ),
  799. "indexes" => array(
  800. "PRIMARY" => array("id"),
  801. "uid" => array("uid"),
  802. )
  803. );
  804. $database["group_member"] = array(
  805. "fields" => array(
  806. "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
  807. "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
  808. "gid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
  809. "contact-id" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
  810. ),
  811. "indexes" => array(
  812. "PRIMARY" => array("id"),
  813. "contactid" => array("contact-id"),
  814. "gid_contactid" => array("gid", "contact-id"),
  815. "uid_gid_contactid" => array("UNIQUE", "uid", "gid", "contact-id"),
  816. )
  817. );
  818. $database["gserver"] = array(
  819. "fields" => array(
  820. "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
  821. "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  822. "nurl" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  823. "version" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  824. "site_name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  825. "info" => array("type" => "text"),
  826. "register_policy" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
  827. "poco" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  828. "noscrape" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  829. "network" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
  830. "platform" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  831. "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
  832. "last_poco_query" => array("type" => "datetime", "default" => NULL_DATE),
  833. "last_contact" => array("type" => "datetime", "default" => NULL_DATE),
  834. "last_failure" => array("type" => "datetime", "default" => NULL_DATE),
  835. ),
  836. "indexes" => array(
  837. "PRIMARY" => array("id"),
  838. "nurl" => array("nurl(32)"),
  839. )
  840. );
  841. $database["hook"] = array(
  842. "fields" => array(
  843. "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
  844. "hook" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  845. "file" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  846. "function" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
  847. "priority" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
  848. ),
  849. "indexes" => array(
  850. "PRIMARY" => array("id"),
  851. "hook_file_function" => array("UNIQUE", "hook(50)","file(80)","function(60)"),
  852. )
  853. );
  854. $database["intro"] = array(
  855. "fields" => array(
  856. "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
  857. "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
  858. "fid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
  859. "contact-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
  860. "knowyou"