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.

update.php 51KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725
  1. <?php
  2. define( 'UPDATE_VERSION' , 1191 );
  3. /**
  4. *
  5. * update.php - automatic system update
  6. *
  7. * Automatically update database schemas and any other development changes such that
  8. * copying the latest files from the source code repository will always perform a clean
  9. * and painless upgrade.
  10. *
  11. * Each function in this file is named update_nnnn() where nnnn is an increasing number
  12. * which began counting at 1000.
  13. *
  14. * At the top of the file "boot.php" is a define for DB_UPDATE_VERSION. Any time there is a change
  15. * to the database schema or one which requires an upgrade path from the existing application,
  16. * the DB_UPDATE_VERSION and the UPDATE_VERSION at the top of this file are incremented.
  17. *
  18. * The current DB_UPDATE_VERSION is stored in the config area of the database. If the application starts up
  19. * and DB_UPDATE_VERSION is greater than the last stored build number, we will process every update function
  20. * in order from the currently stored value to the new DB_UPDATE_VERSION. This is expected to bring the system
  21. * up to current without requiring re-installation or manual intervention.
  22. *
  23. * Once the upgrade functions have completed, the current DB_UPDATE_VERSION is stored as the current value.
  24. * The DB_UPDATE_VERSION will always be one greater than the last numbered script in this file.
  25. *
  26. * If you change the database schema, the following are required:
  27. * 1. Update the file include/dbstructure.php to match the new schema.
  28. * 2. If there is a need for a post procession, update this file by adding a new function at the end with the number of the current DB_UPDATE_VERSION.
  29. * This function should perform some post procession steps but no database updates.
  30. * 3. Increment the DB_UPDATE_VERSION in boot.php *AND* the UPDATE_VERSION in this file to match it
  31. * 4. TEST the upgrade prior to checkin and filing a pull request.
  32. *
  33. * IMPORTANT!
  34. * NEVER do a database change anymore in the update functions! Only do this in the file include/dbstructure.php!
  35. */
  36. function update_1000() {
  37. q("ALTER TABLE `item` DROP `like`, DROP `dislike` ");
  38. q("ALTER TABLE `item` ADD `verb` CHAR( 255 ) NOT NULL AFTER `body` ,
  39. ADD `object-type` CHAR( 255 ) NOT NULL AFTER `verb` ,
  40. ADD `object` TEXT NOT NULL AFTER `object-type` ");
  41. q("ALTER TABLE `intro` ADD `duplex` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `knowyou` ");
  42. q("ALTER TABLE `contact` ADD `duplex` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `rel` ");
  43. q("ALTER TABLE `contact` CHANGE `issued-pubkey` `issued-pubkey` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL");
  44. q("ALTER TABLE `contact` ADD `term-date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `avatar-date`");
  45. }
  46. function update_1001() {
  47. q("ALTER TABLE `item` ADD `wall` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `type` ");
  48. q("ALTER TABLE `item` ADD INDEX ( `wall` )");
  49. }
  50. function update_1002() {
  51. q("ALTER TABLE `item` ADD `gravity` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `wall` ");
  52. }
  53. function update_1003() {
  54. q("ALTER TABLE `contact` DROP `issued-pubkey` , DROP `ret-id` , DROP `ret-pubkey` ");
  55. q("ALTER TABLE `contact` ADD `usehub` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `ret-aes`");
  56. q("ALTER TABLE `contact` ADD `hub-verify` CHAR( 255 ) NOT NULL AFTER `usehub`");
  57. q("ALTER TABLE `contact` ADD INDEX ( `uid` ) , ADD INDEX ( `self` ), ADD INDEX ( `issued-id` ), ADD INDEX ( `dfrn-id` )");
  58. q("ALTER TABLE `contact` ADD INDEX ( `blocked` ), ADD INDEX ( `readonly` )");
  59. }
  60. function update_1004() {
  61. q("ALTER TABLE `contact` ADD `subhub` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `usehub`");
  62. }
  63. function update_1005() {
  64. q("ALTER TABLE `user` ADD `spubkey` TEXT NOT NULL AFTER `prvkey` ,
  65. ADD `sprvkey` TEXT NOT NULL AFTER `spubkey`");
  66. }
  67. function update_1006() {
  68. // create 's' keys for everybody that does not have one
  69. $r = q("SELECT * FROM `user` WHERE `spubkey` = '' ");
  70. if(count($r)) {
  71. foreach($r as $rr) {
  72. $sres=openssl_pkey_new(array('encrypt_key' => false ));
  73. $sprvkey = '';
  74. openssl_pkey_export($sres, $sprvkey);
  75. $spkey = openssl_pkey_get_details($sres);
  76. $spubkey = $spkey["key"];
  77. $r = q("UPDATE `user` SET `spubkey` = '%s', `sprvkey` = '%s'
  78. WHERE `uid` = %d",
  79. dbesc($spubkey),
  80. dbesc($sprvkey),
  81. intval($rr['uid'])
  82. );
  83. }
  84. }
  85. }
  86. function update_1007() {
  87. q("ALTER TABLE `user` ADD `page-flags` INT NOT NULL DEFAULT '0' AFTER `notify-flags`");
  88. q("ALTER TABLE `user` ADD INDEX ( `nickname` )");
  89. }
  90. function update_1008() {
  91. q("ALTER TABLE `profile` ADD `with` TEXT NOT NULL AFTER `marital` ");
  92. }
  93. function update_1009() {
  94. q("ALTER TABLE `user` ADD `allow_location` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `default-location` ");
  95. }
  96. function update_1010() {
  97. q("ALTER TABLE `contact` ADD `lrdd` CHAR( 255 ) NOT NULL AFTER `url` ");
  98. }
  99. function update_1011() {
  100. q("ALTER TABLE `contact` ADD `nick` CHAR( 255 ) NOT NULL AFTER `name` ");
  101. $r = q("SELECT * FROM `contact` WHERE 1");
  102. if(count($r)) {
  103. foreach($r as $rr) {
  104. q("UPDATE `contact` SET `nick` = '%s' WHERE `id` = %d",
  105. dbesc(basename($rr['url'])),
  106. intval($rr['id'])
  107. );
  108. }
  109. }
  110. }
  111. function update_1012() {
  112. q("ALTER TABLE `item` ADD `inform` MEDIUMTEXT NOT NULL AFTER `tag` ");
  113. }
  114. function update_1013() {
  115. q("ALTER TABLE `item` ADD `target-type` CHAR( 255 ) NOT NULL
  116. AFTER `object` , ADD `target` TEXT NOT NULL AFTER `target-type`");
  117. }
  118. function update_1014() {
  119. require_once('include/Photo.php');
  120. q("ALTER TABLE `contact` ADD `micro` TEXT NOT NULL AFTER `thumb` ");
  121. $r = q("SELECT * FROM `photo` WHERE `scale` = 4");
  122. if(count($r)) {
  123. foreach($r as $rr) {
  124. $ph = new Photo($rr['data']);
  125. if($ph->is_valid()) {
  126. $ph->scaleImage(48);
  127. $ph->store($rr['uid'],$rr['contact-id'],$rr['resource-id'],$rr['filename'],$rr['album'],6,(($rr['profile']) ? 1 : 0));
  128. }
  129. }
  130. }
  131. $r = q("SELECT * FROM `contact` WHERE 1");
  132. if(count($r)) {
  133. foreach($r as $rr) {
  134. if(stristr($rr['thumb'],'avatar'))
  135. q("UPDATE `contact` SET `micro` = '%s' WHERE `id` = %d",
  136. dbesc(str_replace('avatar','micro',$rr['thumb'])),
  137. intval($rr['id']));
  138. else
  139. q("UPDATE `contact` SET `micro` = '%s' WHERE `id` = %d",
  140. dbesc(str_replace('5.jpg','6.jpg',$rr['thumb'])),
  141. intval($rr['id']));
  142. }
  143. }
  144. }
  145. function update_1015() {
  146. q("ALTER TABLE `item` CHANGE `body` `body` mediumtext NOT NULL");
  147. }
  148. function update_1016() {
  149. q("ALTER TABLE `user` ADD `openid` CHAR( 255 ) NOT NULL AFTER `email` ");
  150. }
  151. function update_1017() {
  152. q(" CREATE TABLE IF NOT EXISTS `clients` (
  153. `client_id` VARCHAR( 20 ) NOT NULL ,
  154. `pw` VARCHAR( 20 ) NOT NULL ,
  155. `redirect_uri` VARCHAR( 200 ) NOT NULL ,
  156. PRIMARY KEY ( `client_id` )
  157. ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
  158. q(" CREATE TABLE IF NOT EXISTS `tokens` (
  159. `id` VARCHAR( 40 ) NOT NULL ,
  160. `client_id` VARCHAR( 20 ) NOT NULL ,
  161. `expires` INT NOT NULL ,
  162. `scope` VARCHAR( 200 ) NOT NULL ,
  163. PRIMARY KEY ( `id` )
  164. ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
  165. q("CREATE TABLE IF NOT EXISTS `auth_codes` (
  166. `id` VARCHAR( 40 ) NOT NULL ,
  167. `client_id` VARCHAR( 20 ) NOT NULL ,
  168. `redirect_uri` VARCHAR( 200 ) NOT NULL ,
  169. `expires` INT NOT NULL ,
  170. `scope` VARCHAR( 250 ) NOT NULL ,
  171. PRIMARY KEY ( `id` )
  172. ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
  173. }
  174. function update_1018() {
  175. q("CREATE TABLE IF NOT EXISTS `queue` (
  176. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  177. `cid` INT NOT NULL ,
  178. `created` DATETIME NOT NULL ,
  179. `last` DATETIME NOT NULL ,
  180. `content` MEDIUMTEXT NOT NULL
  181. ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
  182. }
  183. function update_1019() {
  184. q("ALTER TABLE `mail` DROP `delivered`");
  185. q("ALTER TABLE `profile` ADD `showwith` TINYINT(1) NOT NULL DEFAULT '0' AFTER `marital` ");
  186. }
  187. function update_1020() {
  188. q("ALTER TABLE `profile` DROP `showwith`");
  189. q("ALTER TABLE `item` ADD `thr-parent` CHAR( 255 ) NOT NULL AFTER `parent-uri` ");
  190. }
  191. function update_1021() {
  192. q("ALTER TABLE `profile_check` ADD `sec` CHAR( 255 ) NOT NULL AFTER `dfrn_id` ");
  193. q("ALTER TABLE `profile_check` ADD `cid` INT(10) unsigned NOT NULL DEFAULT '0' AFTER `uid`");
  194. q("ALTER TABLE `item` ADD `private` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `deny_gid` ");
  195. }
  196. function update_1022() {
  197. q("CREATE TABLE `pconfig` (
  198. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  199. `uid` INT NOT NULL DEFAULT '0',
  200. `cat` CHAR( 255 ) NOT NULL ,
  201. `k` CHAR( 255 ) NOT NULL ,
  202. `v` MEDIUMTEXT NOT NULL
  203. ) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci ");
  204. }
  205. function update_1023() {
  206. q("ALTER TABLE `user` ADD `register_date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `timezone` ,
  207. ADD `login_date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `register_date` ");
  208. }
  209. function update_1024() {
  210. q("ALTER TABLE `profile` ADD `keywords` TEXT NOT NULL AFTER `religion` ");
  211. }
  212. function update_1025() {
  213. q("ALTER TABLE `user` ADD `maxreq` int(11) NOT NULL DEFAULT '10' AFTER `pwdreset` ");
  214. }
  215. function update_1026() {
  216. q("CREATE TABLE IF NOT EXISTS `hook` (
  217. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  218. `hook` CHAR( 255 ) NOT NULL ,
  219. `file` CHAR( 255 ) NOT NULL ,
  220. `function` CHAR( 255 ) NOT NULL
  221. ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
  222. }
  223. function update_1027() {
  224. q("CREATE TABLE IF NOT EXISTS `addon` (
  225. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  226. `name` CHAR( 255 ) NOT NULL ,
  227. `version` CHAR( 255 ) NOT NULL ,
  228. `installed` TINYINT( 1 ) NOT NULL DEFAULT '0'
  229. ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
  230. }
  231. function update_1028() {
  232. q("ALTER TABLE `user` ADD `openidserver` text NOT NULL AFTER `deny_gid` ");
  233. }
  234. function update_1029() {
  235. q("ALTER TABLE `contact` ADD `info` MEDIUMTEXT NOT NULL AFTER `reason` ");
  236. }
  237. function update_1030() {
  238. q("ALTER TABLE `contact` ADD `bdyear` CHAR( 4 ) NOT NULL COMMENT 'birthday notify flag' AFTER `profile-id` ");
  239. q("CREATE TABLE IF NOT EXISTS `event` (
  240. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  241. `uid` INT NOT NULL ,
  242. `cid` INT NOT NULL ,
  243. `created` DATETIME NOT NULL ,
  244. `edited` DATETIME NOT NULL ,
  245. `start` DATETIME NOT NULL ,
  246. `finish` DATETIME NOT NULL ,
  247. `desc` TEXT NOT NULL ,
  248. `location` TEXT NOT NULL ,
  249. `type` CHAR( 255 ) NOT NULL ,
  250. `adjust` TINYINT( 1 ) NOT NULL DEFAULT '1',
  251. `allow_cid` MEDIUMTEXT NOT NULL ,
  252. `allow_gid` MEDIUMTEXT NOT NULL ,
  253. `deny_cid` MEDIUMTEXT NOT NULL ,
  254. `deny_gid` MEDIUMTEXT NOT NULL
  255. ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
  256. }
  257. function update_1031() {
  258. // Repair any bad links that slipped into the item table
  259. $r = q("SELECT `id`, `object` FROM `item` WHERE `object` != '' ");
  260. if($r && count($r)) {
  261. foreach($r as $rr) {
  262. if(strstr($rr['object'],'type=&quot;http')) {
  263. q("UPDATE `item` SET `object` = '%s' WHERE `id` = %d",
  264. dbesc(str_replace('type=&quot;http','href=&quot;http',$rr['object'])),
  265. intval($rr['id'])
  266. );
  267. }
  268. }
  269. }
  270. }
  271. function update_1032() {
  272. q("ALTER TABLE `profile` ADD `pdesc` CHAR( 255 ) NOT NULL AFTER `name` ");
  273. }
  274. function update_1033() {
  275. q("CREATE TABLE IF NOT EXISTS `cache` (
  276. `k` CHAR( 255 ) NOT NULL PRIMARY KEY ,
  277. `v` TEXT NOT NULL,
  278. `updated` DATETIME NOT NULL
  279. ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
  280. }
  281. function update_1034() {
  282. // If you have any of these parent-less posts they can cause problems, and
  283. // we need to delete them. You can't see them anyway.
  284. // Legitimate items will usually get re-created on the next
  285. // pull from the hub.
  286. // But don't get rid of a post that may have just come in
  287. // and may not yet have the parent id set.
  288. q("DELETE FROM `item` WHERE `parent` = 0 AND `created` < UTC_TIMESTAMP() - INTERVAL 2 MINUTE");
  289. }
  290. function update_1035() {
  291. q("ALTER TABLE `contact` ADD `success_update` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `last-update` ");
  292. }
  293. function update_1036() {
  294. $r = dbq("SELECT * FROM `contact` WHERE `network` = 'dfrn' && `photo` LIKE '%include/photo%' ");
  295. if(count($r)) {
  296. foreach($r as $rr) {
  297. q("UPDATE `contact` SET `photo` = '%s', `thumb` = '%s', `micro` = '%s' WHERE `id` = %d",
  298. dbesc(str_replace('include/photo','photo',$rr['photo'])),
  299. dbesc(str_replace('include/photo','photo',$rr['thumb'])),
  300. dbesc(str_replace('include/photo','photo',$rr['micro'])),
  301. intval($rr['id']));
  302. }
  303. }
  304. }
  305. function update_1037() {
  306. q("ALTER TABLE `contact` CHANGE `lrdd` `alias` CHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ");
  307. }
  308. function update_1038() {
  309. q("ALTER TABLE `item` ADD `plink` CHAR( 255 ) NOT NULL AFTER `target` ");
  310. }
  311. function update_1039() {
  312. q("ALTER TABLE `addon` ADD `timestamp` BIGINT NOT NULL DEFAULT '0'");
  313. }
  314. function update_1040() {
  315. q("CREATE TABLE IF NOT EXISTS `fcontact` (
  316. `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  317. `url` CHAR( 255 ) NOT NULL ,
  318. `name` CHAR( 255 ) NOT NULL ,
  319. `photo` CHAR( 255 ) NOT NULL
  320. ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
  321. q("CREATE TABLE IF NOT EXISTS `ffinder` (
  322. `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  323. `uid` INT UNSIGNED NOT NULL ,
  324. `cid` INT UNSIGNED NOT NULL ,
  325. `fid` INT UNSIGNED NOT NULL
  326. ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
  327. }
  328. function update_1041() {
  329. q("ALTER TABLE `profile` CHANGE `keywords` `prv_keywords` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ");
  330. q("ALTER TABLE `profile` ADD `pub_keywords` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL AFTER `religion` ");
  331. }
  332. function update_1042() {
  333. q("ALTER TABLE `user` ADD `expire` INT UNSIGNED NOT NULL DEFAULT '0' AFTER `maxreq` ");
  334. }
  335. function update_1043() {
  336. q("ALTER TABLE `user` ADD `blockwall` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `blocked` ");
  337. }
  338. function update_1044() {
  339. q("ALTER TABLE `profile` ADD FULLTEXT ( `pub_keywords` ) ");
  340. q("ALTER TABLE `profile` ADD FULLTEXT ( `prv_keywords` ) ");
  341. }
  342. function update_1045() {
  343. q("ALTER TABLE `user` ADD `language` CHAR( 16 ) NOT NULL DEFAULT 'en' AFTER `timezone` ");
  344. }
  345. function update_1046() {
  346. q("ALTER TABLE `item` ADD `attach` MEDIUMTEXT NOT NULL AFTER `tag` ");
  347. }
  348. function update_1047() {
  349. q("ALTER TABLE `contact` ADD `writable` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `readonly` ");
  350. }
  351. function update_1048() {
  352. q("UPDATE `contact` SET `writable` = 1 WHERE `network` = 'stat' AND `notify` != '' ");
  353. }
  354. function update_1049() {
  355. q("CREATE TABLE `mailacct` (
  356. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  357. `uid` INT NOT NULL,
  358. `server` CHAR( 255 ) NOT NULL ,
  359. `user` CHAR( 255 ) NOT NULL ,
  360. `pass` CHAR( 255 ) NOT NULL ,
  361. `reply_to` CHAR( 255 ) NOT NULL ,
  362. `last_check` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'
  363. ) ENGINE = MYISAM ");
  364. }
  365. function update_1050() {
  366. q("CREATE TABLE `attach` (
  367. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  368. `uid` INT NOT NULL ,
  369. `filetype` CHAR( 64 ) NOT NULL ,
  370. `filesize` INT NOT NULL ,
  371. `data` LONGBLOB NOT NULL ,
  372. `created` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
  373. `edited` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
  374. `allow_cid` MEDIUMTEXT NOT NULL ,
  375. `allow_gid` MEDIUMTEXT NOT NULL ,
  376. `deny_cid` MEDIUMTEXT NOT NULL ,
  377. `deny_gid` MEDIUMTEXT NOT NULL
  378. ) ENGINE = MYISAM ");
  379. }
  380. function update_1051() {
  381. q("ALTER TABLE `mailacct` ADD `port` INT NOT NULL AFTER `server` ,
  382. ADD `ssltype` CHAR( 16 ) NOT NULL AFTER `port` ,
  383. ADD `mailbox` CHAR( 255 ) NOT NULL AFTER `ssltype` ");
  384. q("ALTER TABLE `contact` ADD `addr` CHAR( 255 ) NOT NULL AFTER `url` ");
  385. }
  386. function update_1052() {
  387. q("ALTER TABLE `mailacct` CHANGE `pass` `pass` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL");
  388. q("ALTER TABLE `mailacct` ADD `pubmail` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `reply_to` ");
  389. q("ALTER TABLE `item` ADD `pubmail` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `private` ");
  390. }
  391. function update_1053() {
  392. q("ALTER TABLE `item` ADD `extid` CHAR( 255 ) NOT NULL AFTER `parent-uri` , ADD INDEX ( `extid` ) ");
  393. }
  394. function update_1054() {
  395. q("ALTER TABLE `register` ADD `language` CHAR( 16 ) NOT NULL AFTER `password` ");
  396. }
  397. function update_1055() {
  398. q("ALTER TABLE `profile` ADD `hidewall` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `hide-friends` ");
  399. }
  400. function update_1056() {
  401. q("ALTER TABLE `attach` ADD `hash` CHAR( 64 ) NOT NULL AFTER `uid` ");
  402. }
  403. function update_1057() {
  404. q("ALTER TABLE `attach` ADD `filename` CHAR( 255 ) NOT NULL AFTER `hash` ");
  405. }
  406. function update_1058() {
  407. q("ALTER TABLE `item` ADD `event-id` INT NOT NULL AFTER `resource-id` ");
  408. }
  409. function update_1059() {
  410. q("ALTER TABLE `queue` ADD `network` CHAR( 32 ) NOT NULL AFTER `cid` ");
  411. }
  412. function update_1060() {
  413. q("ALTER TABLE `event` ADD `uri` CHAR( 255 ) NOT NULL AFTER `cid` ");
  414. }
  415. function update_1061() {
  416. q("ALTER TABLE `event` ADD `nofinish` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `type` ");
  417. }
  418. function update_1062() {
  419. q("ALTER TABLE `user` ADD `prvnets` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `page-flags` ");
  420. }
  421. function update_1063() {
  422. q("ALTER TABLE `addon` ADD `plugin_admin` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `timestamp` ");
  423. }
  424. function update_1064() {
  425. q("ALTER TABLE `item` ADD `app` CHAR( 255 ) NOT NULL AFTER `body` ");
  426. }
  427. function update_1065() {
  428. q("ALTER TABLE `intro` ADD `fid` INT NOT NULL DEFAULT '0' AFTER `uid`");
  429. }
  430. function update_1066() {
  431. $r = q("ALTER TABLE `item` ADD `received` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `edited` ");
  432. if($r)
  433. q("ALTER TABLE `item` ADD INDEX ( `received` ) ");
  434. $r = q("UPDATE `item` SET `received` = `edited` WHERE 1");
  435. }
  436. function update_1067() {
  437. q("ALTER TABLE `ffinder` ADD `type` CHAR( 16 ) NOT NULL AFTER `id` ,
  438. ADD `note` TEXT NOT NULL AFTER `type` ");
  439. }
  440. function update_1068() {
  441. // 1067 was short-sighted. Undo it.
  442. q("ALTER TABLE `ffinder` DROP `type` , DROP `note` ");
  443. // and do this instead.
  444. q("CREATE TABLE IF NOT EXISTS `fsuggest` (
  445. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  446. `uid` INT NOT NULL ,
  447. `cid` INT NOT NULL ,
  448. `name` CHAR( 255 ) NOT NULL ,
  449. `url` CHAR( 255 ) NOT NULL ,
  450. `photo` CHAR( 255 ) NOT NULL ,
  451. `note` TEXT NOT NULL ,
  452. `created` DATETIME NOT NULL
  453. ) ENGINE = MYISAM DEFAULT CHARSET=utf8");
  454. }
  455. function update_1069() {
  456. q("ALTER TABLE `fsuggest` ADD `request` CHAR( 255 ) NOT NULL AFTER `url` ");
  457. q("ALTER TABLE `fcontact` ADD `request` CHAR( 255 ) NOT NULL AFTER `photo` ");
  458. }
  459. // mail body needs to accomodate private photos
  460. function update_1070() {
  461. q("ALTER TABLE `mail` CHANGE `body` `body` MEDIUMTEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ");
  462. }
  463. function update_1071() {
  464. q("ALTER TABLE `photo` ADD INDEX ( `uid` ) ");
  465. q("ALTER TABLE `photo` ADD INDEX ( `resource-id` ) ");
  466. q("ALTER TABLE `photo` ADD INDEX ( `album` ) ");
  467. q("ALTER TABLE `photo` ADD INDEX ( `scale` ) ");
  468. q("ALTER TABLE `photo` ADD INDEX ( `profile` ) ");
  469. }
  470. function update_1072() {
  471. q("ALTER TABLE `item` ADD `starred` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `visible` ");
  472. q("ALTER TABLE `item` ADD INDEX ( `starred` ) ");
  473. }
  474. function update_1073() {
  475. q("ALTER TABLE `contact` ADD `remote_self` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `self` ");
  476. }
  477. function update_1074() {
  478. q("ALTER TABLE `user` ADD `hidewall` TINYINT( 1) NOT NULL DEFAULT '0' AFTER `blockwall` ");
  479. $r = q("SELECT `uid` FROM `profile` WHERE `is-default` = 1 AND `hidewall` = 1");
  480. if(count($r)) {
  481. foreach($r as $rr)
  482. q("UPDATE `user` SET `hidewall` = 1 WHERE `uid` = %d",
  483. intval($rr['uid'])
  484. );
  485. }
  486. q("ALTER TABLE `profile` DROP `hidewall`");
  487. }
  488. function update_1075() {
  489. q("ALTER TABLE `user` ADD `guid` CHAR( 16 ) NOT NULL AFTER `uid` ");
  490. $r = q("SELECT `uid` FROM `user` WHERE 1");
  491. if(count($r)) {
  492. foreach($r as $rr) {
  493. $found = true;
  494. do {
  495. $guid = substr(random_string(),0,16);
  496. $x = q("SELECT `uid` FROM `user` WHERE `guid` = '%s' LIMIT 1",
  497. dbesc($guid)
  498. );
  499. if(! count($x))
  500. $found = false;
  501. } while ($found == true );
  502. q("UPDATE `user` SET `guid` = '%s' WHERE `uid` = %d",
  503. dbesc($guid),
  504. intval($rr['uid'])
  505. );
  506. }
  507. }
  508. }
  509. function update_1076() {
  510. q("CREATE TABLE `guid` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  511. `guid` CHAR( 16 ) NOT NULL , INDEX ( `guid` ) ) ENGINE = MYISAM ");
  512. }
  513. // There was a typo in 1076 so we'll try again in 1077 to make sure
  514. // We'll also make it big enough to allow for future growth, I seriously
  515. // doubt Diaspora will be able to leave guids at 16 bytes,
  516. // and we can also use the same structure for our own larger guids
  517. function update_1077() {
  518. q("CREATE TABLE IF NOT EXISTS `guid` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  519. `guid` CHAR( 16 ) NOT NULL , INDEX ( `guid` ) ) ENGINE = MYISAM ");
  520. q("ALTER TABLE `guid` CHANGE `guid` `guid` CHAR( 64 ) NOT NULL");
  521. }
  522. function update_1078() {
  523. q("ALTER TABLE `item` ADD `guid` CHAR( 64 ) NOT NULL AFTER `id` , ADD INDEX ( `guid` ) ");
  524. }
  525. function update_1079() {
  526. q("CREATE TABLE IF NOT EXISTS `sign` (
  527. `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  528. `iid` INT UNSIGNED NOT NULL ,
  529. `signed_text` MEDIUMTEXT NOT NULL ,
  530. `signature` TEXT NOT NULL ,
  531. `signer` CHAR( 255 ) NOT NULL ,
  532. INDEX ( `iid` )
  533. ) ENGINE = MYISAM ");
  534. q("ALTER TABLE `fcontact` ADD `nick` CHAR( 255 ) NOT NULL ,
  535. ADD `addr` CHAR( 255 ) NOT NULL ,
  536. ADD `notify` CHAR( 255 ) NOT NULL ,
  537. ADD `poll` CHAR( 255 ) NOT NULL ,
  538. ADD `confirm` CHAR( 255 ) NOT NULL ,
  539. ADD `priority` TINYINT( 1 ) NOT NULL ,
  540. ADD `network` CHAR( 32 ) NOT NULL ,
  541. ADD `alias` CHAR( 255 ) NOT NULL ,
  542. ADD `pubkey` TEXT NOT NULL ,
  543. ADD INDEX ( `addr` ) ,
  544. ADD INDEX ( `network` ) ");
  545. }
  546. function update_1080() {
  547. q("ALTER TABLE `fcontact` ADD `updated` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'");
  548. }
  549. function update_1081() {
  550. // there was a typo in update 1081 so it was corrected and moved up to 1082
  551. }
  552. function update_1082() {
  553. q("ALTER TABLE `photo` ADD `guid` CHAR( 64 ) NOT NULL AFTER `contact-id`,
  554. ADD INDEX ( `guid` ) ");
  555. // make certain the following code is only executed once
  556. $r = q("select `id` from `photo` where `guid` != '' limit 1");
  557. if($r && count($r))
  558. return;
  559. $r = q("SELECT distinct(`resource-id`) FROM `photo` WHERE 1 group by `id`");
  560. if(count($r)) {
  561. foreach($r as $rr) {
  562. $guid = get_guid();
  563. q("update `photo` set `guid` = '%s' where `resource-id` = '%s'",
  564. dbesc($guid),
  565. dbesc($rr['resource-id'])
  566. );
  567. }
  568. }
  569. }
  570. function update_1083() {
  571. q("CREATE TABLE IF NOT EXISTS `deliverq` (
  572. `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  573. `cmd` CHAR( 32 ) NOT NULL ,
  574. `item` INT NOT NULL ,
  575. `contact` INT NOT NULL
  576. ) ENGINE = MYISAM ");
  577. }
  578. function update_1084() {
  579. q("ALTER TABLE `contact` ADD `attag` CHAR( 255 ) NOT NULL AFTER `nick` ");
  580. }
  581. function update_1085() {
  582. q("CREATE TABLE IF NOT EXISTS `search` (
  583. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  584. `uid` INT NOT NULL ,
  585. `term` CHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  586. INDEX ( `uid` ),
  587. INDEX ( `term` )
  588. ) ENGINE = MYISAM ");
  589. }
  590. function update_1086() {
  591. q("ALTER TABLE `item` ADD `bookmark` tinyint(1) NOT NULL DEFAULT '0' AFTER `starred` ");
  592. }
  593. function update_1087() {
  594. q("ALTER TABLE `item` ADD `commented` datetime NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `edited` ");
  595. $r = q("SELECT `id` FROM `item` WHERE `parent` = `id` ");
  596. if(count($r)) {
  597. foreach($r as $rr) {
  598. $x = q("SELECT max(`created`) AS `cdate` FROM `item` WHERE `parent` = %d LIMIT 1",
  599. intval($rr['id'])
  600. );
  601. if(count($x))
  602. q("UPDATE `item` SET `commented` = '%s' WHERE `id` = %d",
  603. dbesc($x[0]['cdate']),
  604. intval($rr['id'])
  605. );
  606. }
  607. }
  608. }
  609. function update_1088() {
  610. q("ALTER TABLE `user` ADD `account_expired` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `expire` ,
  611. ADD `account_expires_on` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `account_expired` ,
  612. ADD `expire_notification_sent` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `account_expires_on` ");
  613. }
  614. function update_1089() {
  615. q("ALTER TABLE `user` ADD `blocktags` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `hidewall` ");
  616. }
  617. function update_1090() {
  618. q("ALTER TABLE `contact` ADD `batch` char(255) NOT NULL AFTER `prvkey` ");
  619. q("UPDATE `contact` SET `batch` = concat(substring_index(`url`,'/',3),'/receive/public') WHERE `network` = 'dspr' ");
  620. }
  621. function update_1091() {
  622. // catch a few stragglers that may have crept in before we added this on remote connects
  623. q("UPDATE `contact` SET `batch` = concat(substring_index(`url`,'/',3),'/receive/public') WHERE `network` = 'dspr' AND `batch` = '' ");
  624. q("ALTER TABLE `queue` ADD `batch` TINYINT( 1 ) NOT NULL DEFAULT '0' ");
  625. q("ALTER TABLE `fcontact` ADD `batch` char(255) NOT NULL AFTER `addr` ");
  626. }
  627. function update_1092() {
  628. q("ALTER TABLE `user` ADD INDEX ( `login_date` ) ");
  629. q("ALTER TABLE `user` ADD INDEX ( `account_expired` ) ");
  630. }
  631. function update_1093() {
  632. q("CREATE TABLE IF NOT EXISTS `fserver` (
  633. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  634. `server` CHAR( 255 ) NOT NULL ,
  635. `posturl` CHAR( 255 ) NOT NULL ,
  636. `key` TEXT NOT NULL,
  637. INDEX ( `server` )
  638. ) ENGINE = MYISAM ");
  639. q("ALTER TABLE `group` ADD `visible` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `uid` ");
  640. }
  641. function update_1094() {
  642. q("ALTER TABLE `item` ADD `postopts` TEXT NOT NULL AFTER `target` ");
  643. }
  644. function update_1095() {
  645. q("ALTER TABLE `contact` ADD `bd` DATE NOT NULL AFTER `bdyear` ");
  646. }
  647. function update_1096() {
  648. q("ALTER TABLE `item` ADD `origin` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `deleted` , ADD INDEX ( `origin` ) ");
  649. }
  650. function update_1097() {
  651. q("ALTER TABLE `queue`
  652. ADD INDEX (`cid`),
  653. ADD INDEX (`created`),
  654. ADD INDEX (`last`),
  655. ADD INDEX (`network`),
  656. ADD INDEX (`batch`)
  657. ");
  658. }
  659. function update_1098() {
  660. q("ALTER TABLE `contact`
  661. ADD INDEX (`network`),
  662. ADD INDEX (`name`),
  663. ADD INDEX (`nick`),
  664. ADD INDEX (`attag`),
  665. ADD INDEX (`url`),
  666. ADD INDEX (`addr`),
  667. ADD INDEX (`batch`)
  668. ");
  669. }
  670. function update_1099() {
  671. q("CREATE TABLE IF NOT EXISTS `gcontact` (
  672. `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  673. `name` CHAR( 255 ) NOT NULL ,
  674. `url` CHAR( 255 ) NOT NULL ,
  675. `nurl` CHAR( 255 ) NOT NULL ,
  676. `photo` CHAR( 255 ) NOT NULL
  677. ) ENGINE = MYISAM ");
  678. q("CREATE TABLE IF NOT EXISTS `glink` (
  679. `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  680. `cid` INT NOT NULL ,
  681. `uid` INT NOT NULL ,
  682. `gcid` INT NOT NULL,
  683. `updated` DATETIME NOT NULL
  684. ) ENGINE = MYISAM ");
  685. q("ALTER TABLE `gcontact` ADD INDEX (`nurl`) ");
  686. q("ALTER TABLE `glink` ADD INDEX (`cid`), ADD INDEX (`uid`), ADD INDEX (`gcid`), ADD INDEX (`updated`) ");
  687. q("ALTER TABLE `contact` ADD `poco` TEXT NOT NULL AFTER `confirm` ");
  688. }
  689. function update_1100() {
  690. q("ALTER TABLE `contact` ADD `nurl` CHAR( 255 ) NOT NULL AFTER `url` ");
  691. q("alter table contact add index (`nurl`) ");
  692. require_once('include/text.php');
  693. $r = q("select id, url from contact where url != '' and nurl = '' ");
  694. if(count($r)) {
  695. foreach($r as $rr) {
  696. q("update contact set nurl = '%s' where id = %d",
  697. dbesc(normalise_link($rr['url'])),
  698. intval($rr['id'])
  699. );
  700. }
  701. }
  702. }
  703. function update_1101() {
  704. q("CREATE TABLE IF NOT EXISTS `gcign` (
  705. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  706. `uid` INT NOT NULL ,
  707. `gcid` INT NOT NULL
  708. ) ENGINE = MYISAM ");
  709. q("ALTER TABLE `gcign` ADD INDEX (`uid`), ADD INDEX (`gcid`) ");
  710. }
  711. function update_1102() {
  712. q("ALTER TABLE `clients` ADD `name` TEXT NULL DEFAULT NULL AFTER `redirect_uri` ");
  713. q("ALTER TABLE `clients` ADD `icon` TEXT NULL DEFAULT NULL AFTER `name` ");
  714. q("ALTER TABLE `clients` ADD `uid` INT NOT NULL DEFAULT 0 AFTER `icon` ");
  715. q("ALTER TABLE `tokens` ADD `secret` TEXT NOT NULL AFTER `id` ");
  716. q("ALTER TABLE `tokens` ADD `uid` INT NOT NULL AFTER `scope` ");
  717. }
  718. function update_1103() {
  719. // q("ALTER TABLE `item` ADD INDEX ( `wall` ) ");
  720. q("ALTER TABLE `item` ADD FULLTEXT ( `tag` ) ");
  721. q("ALTER TABLE `contact` ADD INDEX ( `pending` ) ");
  722. q("ALTER TABLE `user` ADD INDEX ( `hidewall` ) ");
  723. q("ALTER TABLE `user` ADD INDEX ( `blockwall` ) ");
  724. q("ALTER TABLE `user` ADD INDEX ( `blocked` ) ");
  725. q("ALTER TABLE `user` ADD INDEX ( `verified` ) ");
  726. }
  727. function update_1104() {
  728. q("ALTER TABLE `item` ADD `forum_mode` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `origin` , ADD INDEX ( `forum_mode` ) ");
  729. }
  730. function update_1105() {
  731. q("ALTER TABLE `mail` ADD `convid` INT NOT NULL AFTER `contact-id` ");
  732. q("ALTER TABLE `mail` ADD `guid` CHAR( 64 ) NOT NULL AFTER `uid` ");
  733. q("CREATE TABLE IF NOT EXISTS `conv` (
  734. `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  735. `guid` CHAR( 64 ) NOT NULL ,
  736. `recips` MEDIUMTEXT NOT NULL ,
  737. `uid` INT NOT NULL
  738. ) ENGINE = MYISAM ");
  739. }
  740. function update_1106() {
  741. q("ALTER TABLE `item` ADD INDEX ( `author-link` ) ");
  742. }
  743. function update_1107() {
  744. q("ALTER TABLE `item` ADD INDEX ( `bookmark` ) ");
  745. }
  746. function update_1108() {
  747. q("ALTER TABLE `contact` ADD `hidden` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `writable` ,
  748. ADD INDEX ( `hidden` ) ");
  749. }
  750. function update_1109() {
  751. q("ALTER TABLE `conv` ADD `creator` CHAR( 255 ) NOT NULL ,
  752. ADD `created` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
  753. ADD `updated` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
  754. ADD `subject` MEDIUMTEXT NOT NULL,
  755. ADD INDEX ( `created` ), ADD INDEX ( `updated` ) ");
  756. }
  757. function update_1110() {
  758. q("ALTER TABLE `mail` ADD `reply` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `seen`,
  759. ADD INDEX ( `reply` ), ADD INDEX ( `uid` ), ADD INDEX ( `guid` ), ADD INDEX ( `seen` ),
  760. ADD INDEX ( `uri` ), ADD INDEX ( `parent-uri`), ADD INDEX ( `created` ), ADD INDEX ( `convid` ) ");
  761. }
  762. function update_1111() {
  763. q("ALTER TABLE `gcontact` ADD `connect` CHAR( 255 ) NOT NULL ");
  764. }
  765. function update_1112() {
  766. q("CREATE TABLE IF NOT EXISTS `notify` (
  767. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  768. `type` INT( 11 ) NOT NULL ,
  769. `name` CHAR( 255 ) NOT NULL ,
  770. `url` CHAR( 255 ) NOT NULL ,
  771. `photo` CHAR( 255 ) NOT NULL ,
  772. `date` DATETIME NOT NULL ,
  773. `msg` MEDIUMTEXT NOT NULL ,
  774. `uid` INT NOT NULL ,
  775. `link` CHAR( 255 ) NOT NULL ,
  776. `seen` TINYINT( 1 ) NOT NULL DEFAULT '0'
  777. ) ENGINE = MYISAM ");
  778. q("ALTER TABLE `notify` ADD INDEX ( `type` ), ADD INDEX ( `uid`), ADD INDEX (`seen`), ADD INDEX (`date`) ");
  779. }
  780. function update_1113() {
  781. q("ALTER TABLE `notify` ADD `verb` CHAR( 255 ) NOT NULL ,
  782. ADD `otype` CHAR( 16 ) NOT NULL");
  783. }
  784. function update_1114() {
  785. q("CREATE TABLE IF NOT EXISTS `item_id` (
  786. `iid` INT NOT NULL ,
  787. `uid` INT NOT NULL ,
  788. `face` CHAR( 255 ) NOT NULL ,
  789. `dspr` CHAR( 255 ) NOT NULL ,
  790. `twit` CHAR( 255 ) NOT NULL ,
  791. `stat` CHAR( 255 ) NOT NULL ,
  792. PRIMARY KEY ( `iid` ),
  793. INDEX ( `uid` ),
  794. INDEX ( `face` ),
  795. INDEX ( `dspr` ),
  796. INDEX ( `twit` ),
  797. INDEX ( `stat` )
  798. ) ENGINE = MYISAM ");
  799. }
  800. function update_1115() {
  801. q("ALTER TABLE `item` ADD `moderated`
  802. TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `pubmail`,
  803. ADD INDEX (`moderated`) ");
  804. }
  805. function update_1116() {
  806. //typo! corrected update was rolled forward
  807. }
  808. function update_1117() {
  809. q("create table if not exists `manage` (
  810. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  811. `uid` INT NOT NULL ,
  812. `mid` INT NOT NULL,
  813. INDEX ( `uid` ),
  814. INDEX ( `mid` )
  815. ) ENGINE = MYISAM ");
  816. }
  817. function update_1118() {
  818. // rolled forward
  819. }
  820. function update_1119() {
  821. q("ALTER TABLE `contact` ADD `closeness` TINYINT( 2 ) NOT NULL DEFAULT '99' AFTER `reason` , ADD INDEX (`closeness`) ");
  822. q("update contact set closeness = 0 where self = 1");
  823. q("ALTER TABLE `item` ADD `spam` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `visible` , ADD INDEX (`spam`) ");
  824. }
  825. function update_1120() {
  826. // item table update from 1119 did not get into database.sql file.
  827. // might be missing on new installs. We'll check.
  828. $r = q("describe item");
  829. if($r && count($r)) {
  830. foreach($r as $rr)
  831. if($rr['Field'] == 'spam')
  832. return;
  833. }
  834. q("ALTER TABLE `item` ADD `spam` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `visible` , ADD INDEX (`spam`) ");
  835. }
  836. function update_1121() {
  837. q("CREATE TABLE IF NOT EXISTS `poll_result` (
  838. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  839. `poll_id` INT NOT NULL ,
  840. `choice` INT NOT NULL ,
  841. INDEX ( `poll_id` ),
  842. INDEX ( `choice` )
  843. ) ENGINE = MYISAM ");
  844. q("CREATE TABLE IF NOT EXISTS `poll` (
  845. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  846. `uid` INT NOT NULL ,
  847. `q0` MEDIUMTEXT NOT NULL ,
  848. `q1` MEDIUMTEXT NOT NULL ,
  849. `q2` MEDIUMTEXT NOT NULL ,
  850. `q3` MEDIUMTEXT NOT NULL ,
  851. `q4` MEDIUMTEXT NOT NULL ,
  852. `q5` MEDIUMTEXT NOT NULL ,
  853. `q6` MEDIUMTEXT NOT NULL ,
  854. `q7` MEDIUMTEXT NOT NULL ,
  855. `q8` MEDIUMTEXT NOT NULL ,
  856. `q9` MEDIUMTEXT NOT NULL ,
  857. INDEX ( `uid` )
  858. ) ENGINE = MYISAM ");
  859. }
  860. function update_1122() {
  861. q("ALTER TABLE `notify` ADD `hash` CHAR( 64 ) NOT NULL AFTER `id` ,
  862. ADD INDEX ( `hash` ) ");
  863. }
  864. function update_1123() {
  865. set_config('system','allowed_themes','dispy,quattro,testbubble,vier,darkbubble,darkzero,duepuntozero,greenzero,purplezero,quattro-green,slackr');
  866. }
  867. function update_1124() {
  868. q("alter table item add index (`author-name`) ");
  869. }
  870. function update_1125() {
  871. q("CREATE TABLE IF NOT EXISTS `notify-threads` (
  872. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  873. `notify-id` INT NOT NULL,
  874. `master-parent-item` INT( 10 ) unsigned NOT NULL DEFAULT '0',
  875. `parent-item` INT( 10 ) unsigned NOT NULL DEFAULT '0',
  876. `receiver-uid` INT NOT NULL,
  877. INDEX ( `master-parent-item` ),
  878. INDEX ( `receiver-uid` )
  879. ) ENGINE = MyISAM DEFAULT CHARSET=utf8");
  880. }
  881. function update_1126() {
  882. q("ALTER TABLE `mailacct` ADD `action` INT NOT NULL AFTER `pass`,
  883. ADD `movetofolder` CHAR(255) NOT NULL AFTER `action`");
  884. }
  885. function update_1127() {
  886. q("CREATE TABLE IF NOT EXISTS `spam` (
  887. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  888. `uid` INT NOT NULL,
  889. `spam` INT NOT NULL DEFAULT '0',
  890. `ham` INT NOT NULL DEFAULT '0',
  891. `term` CHAR(255) NOT NULL,
  892. INDEX ( `uid` ),
  893. INDEX ( `spam` ),
  894. INDEX ( `ham` ),
  895. INDEX ( `term` )
  896. ) ENGINE = MyISAM DEFAULT CHARSET=utf8");
  897. }
  898. function update_1128() {
  899. q("alter table spam add `date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `term` ");
  900. }
  901. function update_1129() {
  902. q("ALTER TABLE `notify` ADD `parent` INT NOT NULL AFTER `link` , ADD INDEX ( `parent` ), ADD INDEX ( `link` ), ADD INDEX ( `otype` ) ");
  903. }
  904. function update_1130() {
  905. q("ALTER TABLE `item` ADD `file` MEDIUMTEXT NOT NULL AFTER `inform`, ADD FULLTEXT KEY (`file`) ");
  906. }
  907. function update_1131() {
  908. q("ALTER TABLE `contact` ADD `forum` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `writable` , ADD INDEX ( `forum` ) ");
  909. }
  910. function update_1132() {
  911. q("CREATE TABLE IF NOT EXISTS `userd` (
  912. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  913. `username` CHAR( 255 ) NOT NULL,
  914. INDEX ( `username` )
  915. ) ENGINE = MYISAM ");
  916. }
  917. function update_1133() {
  918. q("ALTER TABLE `user` ADD `unkmail` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `blocktags` , ADD INDEX ( `unkmail` ) ");
  919. q("ALTER TABLE `user` ADD `cntunkmail` INT NOT NULL DEFAULT '10' AFTER `unkmail` , ADD INDEX ( `cntunkmail` ) ");
  920. q("ALTER TABLE `mail` ADD `unknown` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `replied` , ADD INDEX ( `unknown` ) ");
  921. }
  922. function update_1134() {
  923. // faulty update merged forward
  924. // had a hardwired tablename of 'friendica' which isn't the right name on most systems
  925. }
  926. function update_1135() {
  927. //there can't be indexes with more than 1000 bytes in mysql,
  928. //so change charset to be smaller
  929. q("ALTER TABLE `config` CHANGE `cat` `cat` CHAR( 255 ) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL ,
  930. CHANGE `k` `k` CHAR( 255 ) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL");
  931. //same thing for pconfig
  932. q("ALTER TABLE `pconfig` CHANGE `cat` `cat` CHAR( 255 ) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL ,
  933. CHANGE `k` `k` CHAR( 255 ) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL");
  934. // faulty update merged forward. Bad update in 1134 caused duplicate k,cat pairs
  935. // these have to be cleared before the unique keys can be added.
  936. }
  937. function update_1136() {
  938. $arr = array();
  939. // order in reverse so that we save the newest entry
  940. $r = q("select * from config where 1 order by id desc");
  941. if(count($r)) {
  942. foreach($r as $rr) {
  943. $found = false;
  944. foreach($arr as $x) {
  945. if($x['cat'] == $rr['cat'] && $x['k'] == $rr['k']) {
  946. $found = true;
  947. q("delete from config where id = %d",
  948. intval($rr['id'])
  949. );
  950. }
  951. }
  952. if(! $found) {
  953. $arr[] = $rr;
  954. }
  955. }
  956. }
  957. $arr = array();
  958. $r = q("select * from pconfig where 1 order by id desc");
  959. if(count($r)) {
  960. foreach($r as $rr) {
  961. $found = false;
  962. foreach($arr as $x) {
  963. if($x['uid'] == $rr['uid'] && $x['cat'] == $rr['cat'] && $x['k'] == $rr['k']) {
  964. $found = true;
  965. q("delete from pconfig where id = %d",
  966. intval($rr['id'])
  967. );
  968. }
  969. }
  970. if(! $found) {
  971. $arr[] = $rr;
  972. }
  973. }
  974. }
  975. q("ALTER TABLE `config` ADD UNIQUE `access` ( `cat` , `k` ) ");
  976. q("ALTER TABLE `pconfig` ADD UNIQUE `access` ( `uid` , `cat` , `k` )");
  977. }
  978. function update_1137() {
  979. q("alter table item_id DROP `face` , DROP `dspr` , DROP `twit` , DROP `stat` ");
  980. q("ALTER TABLE `item_id` ADD `sid` CHAR( 255 ) NOT NULL AFTER `uid` , ADD `service` CHAR( 255 ) NOT NULL AFTER `sid` , add index (`sid`), add index ( `service`) ");
  981. }
  982. function update_1138() {
  983. q("alter table contact add archive tinyint(1) not null default '0' after hidden, add index (archive)");
  984. }
  985. function update_1139() {
  986. $r = q("alter table user add account_removed tinyint(1) not null default '0' after expire, add index(account_removed) ");
  987. if(! $r)
  988. return UPDATE_FAILED ;
  989. return UPDATE_SUCCESS ;
  990. }
  991. function update_1140() {
  992. $r = q("alter table addon add hidden tinyint(1) not null default '0' after installed, add index(hidden) ");
  993. if(! $r)
  994. return UPDATE_FAILED ;
  995. return UPDATE_SUCCESS ;
  996. }
  997. function update_1141() {
  998. $r = q("alter table glink add zcid int(11) not null after gcid, add index(zcid) ");
  999. if(! $r)
  1000. return UPDATE_FAILED ;
  1001. return UPDATE_SUCCESS ;
  1002. }
  1003. function update_1142() {
  1004. $r = q("alter table user add service_class char(32) not null after expire_notification_sent, add index(service_class) ");
  1005. if(! $r)
  1006. return UPDATE_FAILED ;
  1007. return UPDATE_SUCCESS ;
  1008. }
  1009. function update_1143() {
  1010. $r = q("alter table user add def_gid int(11) not null default '0' after service_class");
  1011. if(! $r)
  1012. return UPDATE_FAILED ;
  1013. return UPDATE_SUCCESS ;
  1014. }
  1015. function update_1144() {
  1016. $r = q("alter table contact add prv tinyint(1) not null default '0' after forum");
  1017. if(! $r)
  1018. return UPDATE_FAILED ;
  1019. return UPDATE_SUCCESS ;
  1020. }
  1021. function update_1145() {
  1022. $r = q("alter table profile add howlong datetime not null default '0000-00-00 00:00:00' after `with`");
  1023. if(! $r)
  1024. return UPDATE_FAILED ;
  1025. return UPDATE_SUCCESS ;
  1026. }
  1027. function update_1146() {
  1028. $r = q("alter table profile add hometown char(255) not null after `country-name`, add index ( `hometown` ) ");
  1029. if(! $r)
  1030. return UPDATE_FAILED ;
  1031. return UPDATE_SUCCESS ;
  1032. }
  1033. function update_1147() {
  1034. $r1 = q("ALTER TABLE `sign` ALTER `iid` SET DEFAULT '0'");
  1035. $r2 = q("ALTER TABLE `sign` ADD `retract_iid` INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER `iid`");
  1036. $r3 = q("ALTER TABLE `sign` ADD INDEX ( `retract_iid` )");
  1037. if((! $r1) || (! $r2) || (! $r3))
  1038. return UPDATE_FAILED ;
  1039. return UPDATE_SUCCESS ;
  1040. }
  1041. function update_1148() {
  1042. $r = q("ALTER TABLE photo ADD type CHAR(128) NOT NULL DEFAULT 'image/jpeg' AFTER filename");
  1043. if (!$r)
  1044. return UPDATE_FAILED;
  1045. return UPDATE_SUCCESS;
  1046. }
  1047. function update_1149() {
  1048. $r1 = q("ALTER TABLE profile ADD likes text NOT NULL after prv_keywords");
  1049. $r2 = q("ALTER TABLE profile ADD dislikes text NOT NULL after likes");
  1050. if (! ($r1 && $r2))
  1051. return UPDATE_FAILED;
  1052. return UPDATE_SUCCESS;
  1053. }
  1054. function update_1150() {
  1055. $r = q("ALTER TABLE event ADD summary text NOT NULL after finish, add index ( uid ), add index ( cid ), add index ( uri ), add index ( `start` ), add index ( finish ), add index ( `type` ), add index ( adjust ) ");
  1056. if(! $r)
  1057. return UPDATE_FAILED;
  1058. return UPDATE_SUCCESS;
  1059. }
  1060. function update_1151() {
  1061. $r = q("CREATE TABLE IF NOT EXISTS locks (
  1062. id INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  1063. name CHAR( 128 ) NOT NULL ,
  1064. locked TINYINT( 1 ) NOT NULL DEFAULT '0'
  1065. ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
  1066. if (!$r)
  1067. return UPDATE_FAILED;
  1068. return UPDATE_SUCCESS;
  1069. }
  1070. function update_1152() {
  1071. $r = q("CREATE TABLE IF NOT EXISTS `term` (
  1072. `tid` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  1073. `oid` INT UNSIGNED NOT NULL ,
  1074. `otype` TINYINT( 3 ) UNSIGNED NOT NULL ,
  1075. `type` TINYINT( 3 ) UNSIGNED NOT NULL ,
  1076. `term` CHAR( 255 ) NOT NULL ,
  1077. `url` CHAR( 255 ) NOT NULL,
  1078. KEY `oid` ( `oid` ),
  1079. KEY `otype` ( `otype` ),
  1080. KEY `type` ( `type` ),
  1081. KEY `term` ( `term` )
  1082. ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
  1083. if (!$r)
  1084. return UPDATE_FAILED;
  1085. return UPDATE_SUCCESS;
  1086. }
  1087. function update_1153() {
  1088. $r = q("ALTER TABLE `hook` ADD `priority` INT(11) UNSIGNED NOT NULL DEFAULT '0'");
  1089. if(!$r) return UPDATE_FAILED;
  1090. return UPDATE_SUCCESS;
  1091. }
  1092. function update_1154() {
  1093. $r = q("ALTER TABLE `event` ADD `ignore` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0' AFTER `adjust` , ADD INDEX ( `ignore` )");
  1094. if(!$r) return UPDATE_FAILED;
  1095. return UPDATE_SUCCESS;
  1096. }
  1097. function update_1155() {
  1098. $r1 = q("ALTER TABLE `item_id` DROP PRIMARY KEY");
  1099. $r2 = q("ALTER TABLE `item_id` ADD `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST");
  1100. $r3 = q("ALTER TABLE `item_id` ADD INDEX ( `iid` ) ");
  1101. if($r1 && $r2 && $r3)
  1102. return UPDATE_SUCCESS;
  1103. return UPDATE_FAILED;
  1104. }
  1105. function update_1156() {
  1106. $r = q("ALTER TABLE `photo` ADD `datasize` INT UNSIGNED NOT NULL DEFAULT '0' AFTER `width` ,
  1107. ADD INDEX ( `datasize` ) ");
  1108. if(!$r) return UPDATE_FAILED;
  1109. return UPDATE_SUCCESS;
  1110. }
  1111. function update_1157() {
  1112. $r = q("CREATE TABLE IF NOT EXISTS `dsprphotoq` (
  1113. `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  1114. `uid` int(11) NOT NULL,
  1115. `msg` mediumtext NOT NULL,
  1116. `attempt` tinyint(4) NOT NULL,
  1117. PRIMARY KEY (`id`)
  1118. ) ENGINE=MyISAM DEFAULT CHARSET=utf8"
  1119. );
  1120. if($r)
  1121. return UPDATE_SUCCESS;
  1122. }
  1123. function update_1158() {
  1124. set_config('system', 'maintenance', 1);
  1125. // Wait for 15 seconds for current requests to
  1126. // clear before locking up the database
  1127. sleep(15);
  1128. $r = q("CREATE INDEX event_id ON item(`event-id`)");
  1129. set_config('system', 'maintenance', 0);
  1130. if($r)
  1131. return UPDATE_SUCCESS;
  1132. return UPDATE_FAILED;
  1133. }
  1134. function update_1159() {
  1135. $r = q("ALTER TABLE `term` ADD `aid` int(10) unsigned NOT NULL DEFAULT '0',
  1136. ADD `uid` int(10) unsigned NOT NULL DEFAULT '0',
  1137. ADD INDEX (`uid`),
  1138. ADD INDEX (`aid`)");
  1139. if(!$r)
  1140. return UPDATE_FAILED;
  1141. return UPDATE_SUCCESS;
  1142. }
  1143. function update_1160() {
  1144. set_config('system', 'maintenance', 1);
  1145. // Wait for 15 seconds for current requests to
  1146. // clear before locking up the database
  1147. sleep(15);
  1148. $r = q("ALTER TABLE `item` ADD `mention` TINYINT(1) NOT NULL DEFAULT '0', ADD INDEX (`mention`)");
  1149. set_config('system', 'maintenance', 0);
  1150. if(!$r)
  1151. return UPDATE_FAILED;
  1152. return UPDATE_SUCCESS;
  1153. }
  1154. function update_1161() {
  1155. $r = q("ALTER TABLE `pconfig` ADD INDEX (`cat`)");
  1156. if(!$r)
  1157. return UPDATE_FAILED;
  1158. return UPDATE_SUCCESS;
  1159. }
  1160. function update_1162() {
  1161. require_once('include/tags.php');
  1162. update_items();
  1163. return UPDATE_SUCCESS;
  1164. }
  1165. function update_1163() {
  1166. set_config('system', 'maintenance', 1);
  1167. $r = q("ALTER TABLE `item` ADD `network` char(32) NOT NULL");
  1168. set_config('system', 'maintenance', 0);
  1169. if(!$r)
  1170. return UPDATE_FAILED;
  1171. return UPDATE_SUCCESS;
  1172. }
  1173. function update_1164() {
  1174. set_config('system', 'maintenance', 1);
  1175. $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '' AND `contact`.`uid` = `item`.`uid`)",
  1176. NETWORK_DFRN);
  1177. $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '%s' AND `contact`.`uid` = `item`.`uid`)",
  1178. NETWORK_DFRN, NETWORK_DFRN);
  1179. $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '%s' AND `contact`.`uid` = `item`.`uid`)",
  1180. NETWORK_ZOT, NETWORK_ZOT);
  1181. $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '%s' AND `contact`.`uid` = `item`.`uid`)",
  1182. NETWORK_OSTATUS, NETWORK_OSTATUS);
  1183. $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '%s' AND `contact`.`uid` = `item`.`uid`)",
  1184. NETWORK_FEED, NETWORK_FEED);
  1185. $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '%s' AND `contact`.`uid` = `item`.`uid`)",
  1186. NETWORK_DIASPORA, NETWORK_DIASPORA);
  1187. $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '%s' AND `contact`.`uid` = `item`.`uid`)",
  1188. NETWORK_MAIL, NETWORK_MAIL);
  1189. $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '%s' AND `contact`.`uid` = `item`.`uid`)",
  1190. NETWORK_MAIL2, NETWORK_MAIL2);
  1191. $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '%s' AND `contact`.`uid` = `item`.`uid`)",
  1192. NETWORK_FACEBOOK, NETWORK_FACEBOOK);
  1193. $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '%s' AND `contact`.`uid` = `item`.`uid`)",
  1194. NETWORK_LINKEDIN, NETWORK_LINKEDIN);
  1195. $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '%s' AND `contact`.`uid` = `item`.`uid`)",
  1196. NETWORK_XMPP, NETWORK_XMPP);
  1197. $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '%s' AND `contact`.`uid` = `item`.`uid`)",
  1198. NETWORK_MYSPACE, NETWORK_MYSPACE);
  1199. $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '%s' AND `contact`.`uid` = `item`.`uid`)",
  1200. NETWORK_GPLUS, NETWORK_GPLUS);
  1201. $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '%s' AND `contact`.`uid` = `item`.`uid`)",
  1202. NETWORK_PUMPIO, NETWORK_PUMPIO);
  1203. $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '%s' AND `contact`.`uid` = `item`.`uid`)",
  1204. NETWORK_TWITTER, NETWORK_TWITTER);
  1205. set_config('system', 'maintenance', 0);
  1206. return UPDATE_SUCCESS;
  1207. }
  1208. function update_1165() {
  1209. $r = q("CREATE TABLE IF NOT EXISTS `push_subscriber` (
  1210. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  1211. `uid` INT NOT NULL,
  1212. `callback_url` CHAR( 255 ) NOT NULL,
  1213. `topic` CHAR( 255 ) NOT NULL,
  1214. `nickname` CHAR( 255 ) NOT NULL,
  1215. `push` INT NOT NULL,
  1216. `last_update` DATETIME NOT NULL,
  1217. `secret` CHAR( 255 ) NOT NULL
  1218. ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
  1219. if (!$r)
  1220. return UPDATE_FAILED;
  1221. return UPDATE_SUCCESS;
  1222. }
  1223. function update_1166() {
  1224. $r = q("CREATE TABLE IF NOT EXISTS `unique_contacts` (
  1225. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  1226. `url` CHAR(255) NOT NULL,
  1227. `nick` CHAR(255) NOT NULL,
  1228. `name` CHAR(255) NOT NULL,
  1229. `avatar` CHAR(255) NOT NULL,
  1230. INDEX (`url`)
  1231. ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
  1232. if (!$r)
  1233. return UPDATE_FAILED;
  1234. return UPDATE_SUCCESS;
  1235. }
  1236. function update_1167() {
  1237. $r = q("ALTER TABLE `contact` ADD `notify_new_posts` TINYINT(1) NOT NULL DEFAULT '0'");
  1238. if (!$r)
  1239. return UPDATE_FAILED;
  1240. return UPDATE_SUCCESS;
  1241. }
  1242. function update_1168() {
  1243. $r = q("ALTER TABLE `contact` ADD `fetch_further_information` TINYINT(1) NOT NULL DEFAULT '0'");
  1244. if (!$r)
  1245. return UPDATE_FAILED;
  1246. return UPDATE_SUCCESS;
  1247. }
  1248. function update_1169() {
  1249. $r = q("CREATE TABLE IF NOT EXISTS `thread` (
  1250. `iid` int(10) unsigned NOT NULL DEFAULT '0',
  1251. `uid` int(10) unsigned NOT NULL DEFAULT '0',
  1252. `contact-id` int(11) unsigned NOT NULL DEFAULT '0',
  1253. `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  1254. `edited` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  1255. `commented` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  1256. `received` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  1257. `changed` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  1258. `wall` tinyint(1) NOT NULL DEFAULT '0',
  1259. `private` tinyint(1) NOT NULL DEFAULT '0',
  1260. `pubmail` tinyint(1) NOT NULL DEFAULT '0',
  1261. `moderated` tinyint(1) NOT NULL DEFAULT '0',
  1262. `visible` tinyint(1) NOT NULL DEFAULT '0',
  1263. `spam` tinyint(1) NOT NULL DEFAULT '0',
  1264. `starred` tinyint(1) NOT NULL DEFAULT '0',
  1265. `bookmark` tinyint(1) NOT NULL DEFAULT '0',
  1266. `unseen` tinyint(1) NOT NULL DEFAULT '1',
  1267. `deleted` tinyint(1) NOT NULL DEFAULT '0',
  1268. `origin` tinyint(1) NOT NULL DEFAULT '0',
  1269. `forum_mode` tinyint(1) NOT NULL DEFAULT '0',
  1270. `mention` tinyint(1) NOT NULL DEFAULT '0',
  1271. `network` char(32) NOT NULL,
  1272. PRIMARY KEY (`iid`),
  1273. KEY `created` (`created`),
  1274. KEY `commented` (`commented`),
  1275. KEY `uid_network_commented` (`uid`,`network`,`commented`),
  1276. KEY `uid_network_created` (`uid`,`network`,`created`),
  1277. KEY `uid_contactid_commented` (`uid`,`contact-id`,`commented`),
  1278. KEY `uid_contactid_created` (`uid`,`contact-id`,`created`),
  1279. KEY `wall_private_received` (`wall`,`private`,`received`),
  1280. KEY `uid_created` (`uid`,`created`),
  1281. KEY `uid_commented` (`uid`,`commented`)
  1282. ) ENGINE=MyISAM DEFAULT CHARSET=utf8;");
  1283. if (!$r)
  1284. return UPDATE_FAILED;
  1285. proc_run('php',"include/threadupdate.php");
  1286. return UPDATE_SUCCESS;
  1287. }
  1288. /*
  1289. ==========
  1290. ATTENTION!
  1291. ==========
  1292. All following update functions are ONLY for jobs that need to run AFTER the database changes are applied.
  1293. Database changes are ONLY applied in the file include/dbstructure.php.
  1294. */
  1295. function update_1177() {
  1296. require_once("mod/profiles.php");
  1297. $profiles = q("SELECT `uid`, `about`, `locality`, `pub_keywords`, `gender` FROM `profile` WHERE `is-default`");
  1298. foreach ($profiles AS $profile) {
  1299. if ($profile["about"].$profile["locality"].$profile["pub_keywords"].$profile["gender"] == "")
  1300. continue;
  1301. $profile["pub_keywords"] = profile_clean_keywords($profile["pub_keywords"]);
  1302. $r = q("UPDATE `contact` SET `about` = '%s', `location` = '%s', `keywords` = '%s', `gender` = '%s' WHERE `self` AND `uid` = %d",
  1303. dbesc($profile["about"]),
  1304. dbesc($profile["locality"]),
  1305. dbesc($profile["pub_keywords"]),
  1306. dbesc($profile["gender"]),
  1307. intval($profile["uid"])
  1308. );
  1309. }
  1310. }
  1311. function update_1178() {
  1312. if (get_config('system','no_community_page'))
  1313. set_config('system','community_page_style', CP_NO_COMMUNITY_PAGE);
  1314. // Update the central item storage with uid=0
  1315. proc_run('php',"include/threadupdate.php");
  1316. return UPDATE_SUCCESS;
  1317. }
  1318. function update_1180() {
  1319. // Fill the new fields in the term table.
  1320. proc_run('php',"include/tagupdate.php");
  1321. return UPDATE_SUCCESS;
  1322. }
  1323. function update_1188() {
  1324. if (strlen(get_config('system','directory_submit_url')) AND
  1325. !strlen(get_config('system','directory'))) {
  1326. set_config('system','directory', dirname(get_config('system','directory_submit_url')));
  1327. del_config('system','directory_submit_url');
  1328. }
  1329. return UPDATE_SUCCESS;
  1330. }
  1331. function update_1190() {
  1332. require_once('include/plugin.php');
  1333. set_config('system', 'maintenance', 1);
  1334. if (plugin_enabled('forumlist')) {
  1335. $plugin = 'forumlist';
  1336. $plugins = get_config('system','addon');
  1337. $plugins_arr = array();
  1338. if($plugins) {
  1339. $plugins_arr = explode(",",str_replace(" ", "",$plugins));
  1340. $idx = array_search($plugin, $plugins_arr);
  1341. if ($idx !== false){
  1342. unset($plugins_arr[$idx]);
  1343. //delete forumlist manually from addon and hook table
  1344. // since uninstall_plugin() don't work here
  1345. q("DELETE FROM `addon` WHERE `name` = 'forumlist' ");
  1346. q("DELETE FROM `hook` WHERE `file` = 'addon/forumlist/forumlist.php' ");
  1347. set_config('system','addon', implode(", ",$plugins_arr));
  1348. }
  1349. }
  1350. }
  1351. // select old formlist addon entries
  1352. $r = q("SELECT `uid`, `cat`, `k`, `v` FROM `pconfig` WHERE `cat` = '%s' ",
  1353. dbesc('forumlist')
  1354. );
  1355. // convert old forumlist addon entries in new config entries
  1356. if (count($r)) {
  1357. foreach ($r as $rr) {
  1358. $uid = $rr['uid'];
  1359. $family = $rr['cat'];
  1360. $key = $rr['k'];
  1361. $value = $rr['v'];
  1362. if ($key === 'randomise')
  1363. del_pconfig($uid,$family,$key);
  1364. if ($key === 'show_on_profile') {
  1365. if ($value)
  1366. set_pconfig($uid,feature,forumlist_profile,$value);
  1367. del_pconfig($uid,$family,$key);
  1368. }
  1369. if ($key === 'show_on_network') {
  1370. if ($value)
  1371. set_pconfig($uid,feature,forumlist_widget,$value);
  1372. del_pconfig($uid,$family,$key);
  1373. }
  1374. }
  1375. }
  1376. set_config('system', 'maintenance', 0);
  1377. return UPDATE_SUCCESS;
  1378. }